CHANGE: Minor improvements + updated api docs

This commit is contained in:
2025-02-28 13:10:44 +01:00
parent 23cb312644
commit dafcd95428
8 changed files with 561 additions and 345 deletions

View File

@@ -11,10 +11,11 @@ import (
//
// in DEBUG == "true" everything is set to "*" so that no cors errors will be happen
func SetCors(w http.ResponseWriter) {
if os.Getenv("DEBUG") == "true" {
if os.Getenv("NO_CORS") == "true" {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "*")
w.Header().Set("Access-Control-Allow-Headers", "*")
// log.Println("Setting cors to *")
}
}

View File

@@ -203,7 +203,7 @@ func checkLastBooking(b Booking) bool {
log.Println("Error checking last booking: ", err)
return false
}
if int16(check_in_out) == b.CheckInOut {
if int16(check_in_out)%2 == b.CheckInOut%2 {
return false
}
return true

View File

@@ -7,8 +7,8 @@ import (
)
type WorkDay struct {
Day time.Time
Bookings []Booking
Day time.Time `json:"day"`
Bookings []Booking `json:"bookings"`
workTime time.Duration
pauseTime time.Duration
}

View File

@@ -7,7 +7,7 @@ psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-E
CREATE USER $POSTGRES_API_USER WITH ENCRYPTED PASSWORD '$POSTGRES_API_PASSWORD';
GRANT CONNECT ON DATABASE $POSTGRES_DB TO $POSTGRES_API_USER;
GRANT USAGE ON SCHEMA public TO $POSTGRES_API_USER;
GRANT SELECT, INSERT, UPDATE ON anwesenheit, personal_daten, user_password, buchung_wochen TO $POSTGRES_API_USER;
GRANT SELECT, INSERT, UPDATE ON anwesenheit, personal_daten, user_password, wochen_report TO $POSTGRES_API_USER;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO $POSTGRES_API_USER;
EOSQL

View File

@@ -11,7 +11,12 @@
},
"servers": [
{
"url": "http://localhost:8000"
"url": "http://localhost:8000",
"description": "Docker Server"
},
{
"url": "http://localhost:8080",
"description": "Local Development"
}
],
"tags": [
@@ -22,55 +27,11 @@
],
"paths": {
"/time": {
"put": {
"tags": ["booking"],
"summary": "Update a existing booking",
"description": "Update an existing booking by Id",
"operationId": "updateBooking",
"parameters": [
{
"name": "counter_id",
"in": "query",
"description": "Booking ID to update",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"description": "Update an existent booking in the db. Not all values have to be updated",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Booking"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Booking Updated",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Booking"
}
}
}
},
"400": {
"description": "Invalid ID supplied"
},
"500": {
"description": "Server Error"
}
}
},
"get": {
"tags": ["booking"],
"summary": "Gets all the bookings limited",
"tags": [
"booking"
],
"summary": "Gets all the bookings from one card_uid",
"description": "Returns all the bookings optionally filtered with cardID",
"operationId": "getBooking",
"parameters": [
@@ -78,10 +39,30 @@
"name": "card_uid",
"in": "query",
"description": "CardID to filter for",
"required": false,
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "time_from",
"in": "query",
"description": "Timestamp since when all bookings are shown (default=1 month ago)",
"required": false,
"schema": {
"type": "string",
"example": "2025-02-28"
}
},
{
"name": "time_to",
"in": "query",
"description": "Timestamp till when all bookings are shown (default=today)",
"required": false,
"schema": {
"type": "string",
"example": "2025-02-28"
}
}
],
"responses": {
@@ -92,7 +73,51 @@
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Booking"
"type": "object",
"properties": {
"day": {
"type": "string",
"format": "date"
},
"bookings": {
"type": "array",
"items": {
"type": "object",
"properties": {
"counter_id": {
"type": "integer",
"format": "int64",
"example": 100
},
"card_uid": {
"type": "string",
"example": "test_card"
},
"geraet_id": {
"type": "string",
"example": "test_reader"
},
"check_in_out": {
"type": "integer",
"example": 1,
"enum": [
1,
2,
255
]
},
"timestamp": {
"type": "string",
"format": "date-time",
"example": "2024-09-05T08:51:12.670Z"
}
},
"xml": {
"name": "booking"
}
}
}
}
}
}
}
@@ -106,11 +131,21 @@
},
"/time/new": {
"put": {
"tags": ["booking"],
"tags": [
"booking"
],
"summary": "Create new Booking",
"description": "Creates a new booking with the supplied parameters",
"operationId": "pcreateBooking",
"parameters": [
{
"in": "header",
"name": "Authorization",
"description": "Predefined API Key to authorize access",
"schema": {
"type": "string"
}
},
{
"name": "card_uid",
"in": "query",
@@ -136,7 +171,11 @@
"required": true,
"schema": {
"type": "integer",
"enum": [1, 2, 255]
"enum": [
1,
2,
255
]
}
}
],
@@ -146,7 +185,39 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Booking"
"type": "object",
"properties": {
"counter_id": {
"type": "integer",
"format": "int64",
"example": 100
},
"card_uid": {
"type": "string",
"example": "test_card"
},
"geraet_id": {
"type": "string",
"example": "test_reader"
},
"check_in_out": {
"type": "integer",
"example": 1,
"enum": [
1,
2,
255
]
},
"timestamp": {
"type": "string",
"format": "date-time",
"example": "2024-09-05T08:51:12.670Z"
}
},
"xml": {
"name": "booking"
}
}
}
}
@@ -157,11 +228,30 @@
}
},
"get": {
"tags": ["booking"],
"tags": [
"booking"
],
"summary": "Create new Booking",
"description": "Creates a new booking with the supplied parameters",
"operationId": "gcreateBooking",
"parameters": [
{
"in": "header",
"name": "Authorization",
"description": "Predefined API Key to authorize access",
"schema": {
"type": "string"
}
},
{
"in": "query",
"name": "api_key",
"description": "Predefined API Key to authorize access",
"required": false,
"schema": {
"type": "string"
}
},
{
"name": "card_uid",
"in": "query",
@@ -187,7 +277,11 @@
"required": true,
"schema": {
"type": "integer",
"enum": [1, 2, 255]
"enum": [
1,
2,
255
]
}
}
],
@@ -197,10 +291,45 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Booking"
"type": "object",
"properties": {
"counter_id": {
"type": "integer",
"format": "int64",
"example": 100
},
"card_uid": {
"type": "string",
"example": "test_card"
},
"geraet_id": {
"type": "string",
"example": "test_reader"
},
"check_in_out": {
"type": "integer",
"example": 1,
"enum": [
1,
2,
255
]
},
"timestamp": {
"type": "string",
"format": "date-time",
"example": "2024-09-05T08:51:12.670Z"
}
},
"xml": {
"name": "booking"
}
}
}
}
},
"401": {
"description": "none or wrong api key provided!"
},
"409": {
"description": "Same booking type as last booking"
@@ -210,7 +339,9 @@
},
"/logout": {
"get": {
"tags": ["booking"],
"tags": [
"booking"
],
"summary": "Logs out all logged in users",
"description": "With this call all actively logged in users (last booking today has check_in_out=1) will be logged out automaticly (check_in_out=255)",
"operationId": "autoLogout",
@@ -222,7 +353,26 @@
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/User"
"type": "object",
"properties": {
"card_uid": {
"type": "string",
"example": "test_card"
},
"name": {
"type": "string",
"example": "Mustermann"
},
"vorname": {
"type": "string",
"example": "Max"
},
"hauptbeschäftigungsort": {
"type": "integer",
"format": "int8",
"example": 1
}
}
}
}
}
@@ -234,6 +384,53 @@
},
"components": {
"schemas": {
"BookingGrouped": {
"type": "object",
"properties": {
"day": {
"type": "string",
"format": "date"
},
"bookings": {
"type": "array",
"items": {
"type": "object",
"properties": {
"counter_id": {
"type": "integer",
"format": "int64",
"example": 100
},
"card_uid": {
"type": "string",
"example": "test_card"
},
"geraet_id": {
"type": "string",
"example": "test_reader"
},
"check_in_out": {
"type": "integer",
"example": 1,
"enum": [
1,
2,
255
]
},
"timestamp": {
"type": "string",
"format": "date-time",
"example": "2024-09-05T08:51:12.670Z"
}
},
"xml": {
"name": "booking"
}
}
}
}
},
"Booking": {
"type": "object",
"properties": {
@@ -253,7 +450,11 @@
"check_in_out": {
"type": "integer",
"example": 1,
"enum": [1, 2, 255]
"enum": [
1,
2,
255
]
},
"timestamp": {
"type": "string",

View File

@@ -1,74 +1,58 @@
openapi: 3.0.3
info:
title: Arbeitszeitmessung - OpenAPI 3.0
description: 'This demos the API for the Arbeitszeitmessung Project '
description: "This demos the API for the Arbeitszeitmessung Project "
version: 0.1.0
externalDocs:
description: Git-Repository
url: https://git.letsstein.de/tom/arbeitszeitmessung
servers:
- url: http://localhost:8000
description: Docker Server
- url: http://localhost:8080
description: Local Development
tags:
- name: booking
description: all Bookings
paths:
/time:
put:
tags:
- booking
summary: Update a existing booking
description: Update an existing booking by Id
operationId: updateBooking
parameters:
- name: counter_id
in: query
description: Booking ID to update
required: true
schema:
type: string
requestBody:
description: >-
Update an existent booking in the db. Not all values have to be
updated
content:
application/json:
schema:
$ref: '#/components/schemas/Booking'
required: true
responses:
'200':
description: Booking Updated
content:
application/json:
schema:
$ref: '#/components/schemas/Booking'
'400':
description: Invalid ID supplied
'500':
description: Server Error
get:
tags:
- booking
summary: Gets all the bookings limited
summary: Gets all the bookings from one card_uid
description: Returns all the bookings optionally filtered with cardID
operationId: getBooking
parameters:
- name: card_uid
in: query
description: CardID to filter for
required: true
schema:
type: string
- name: time_from
in: query
description: Timestamp since when all bookings are shown (default=1 month ago)
required: false
schema:
type: string
example: "2025-02-28"
- name: time_to
in: query
description: Timestamp till when all bookings are shown (default=today)
required: false
schema:
type: string
example: "2025-02-28"
responses:
'200':
"200":
description: Successful operation
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Booking'
'400':
$ref: "#/components/schemas/BookingGrouped"
"400":
description: Invalid cardID
/time/new:
put:
@@ -78,6 +62,11 @@ paths:
description: Creates a new booking with the supplied parameters
operationId: pcreateBooking
parameters:
- in: header
name: Authorization
description: Predefined API Key to authorize access
schema:
type: string
- name: card_uid
in: query
description: id of the RFID card scanned
@@ -101,13 +90,13 @@ paths:
- 2
- 255
responses:
'200':
"200":
description: successfully created booking
content:
application/json:
schema:
$ref: '#/components/schemas/Booking'
'409':
$ref: "#/components/schemas/Booking"
"409":
description: Same booking type as last booking
get:
tags:
@@ -116,6 +105,17 @@ paths:
description: Creates a new booking with the supplied parameters
operationId: gcreateBooking
parameters:
- in: header
name: Authorization
description: Predefined API Key to authorize access
schema:
type: string
- in: query
name: api_key
description: Predefined API Key to authorize access
required: false
schema:
type: string
- name: card_uid
in: query
description: id of the RFID card scanned
@@ -139,13 +139,15 @@ paths:
- 2
- 255
responses:
'200':
"200":
description: successfully created booking
content:
application/json:
schema:
$ref: '#/components/schemas/Booking'
'409':
$ref: "#/components/schemas/Booking"
"401":
description: none or wrong api key provided!
"409":
description: Same booking type as last booking
/logout:
get:
@@ -155,16 +157,26 @@ paths:
description: With this call all actively logged in users (last booking today has check_in_out=1) will be logged out automaticly (check_in_out=255)
operationId: autoLogout
responses:
'200':
"200":
description: Succesful
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
$ref: "#/components/schemas/User"
components:
schemas:
BookingGrouped:
type: object
properties:
day:
type: string
format: date
bookings:
type: array
items:
$ref: "#/components/schemas/Booking"
Booking:
type: object
properties:
@@ -188,7 +200,7 @@ components:
timestamp:
type: string
format: date-time
example: '2024-09-05T08:51:12.670Z'
example: "2024-09-05T08:51:12.670Z"
xml:
name: booking
User:

View File

@@ -20,16 +20,16 @@ services:
- 8001:8080
backend:
build: ../Backend
image: git.letsstein.de/tom/arbeitszeit-backend
image: git.letsstein.de/tom/arbeitszeit-backend:0.1.1
env_file:
- .env
environment:
POSTGRES_HOST: db
POSTGRES_DB: ${POSTGRES_DB}
EXPOSED_PORT: ${EXPOSED_PORT}
DEBUG: true
NO_CORS: true
ports:
- 8000:8080
- ${EXPOSED_PORT}:8080
depends_on:
- db
swagger:

View File

@@ -13,6 +13,8 @@ services:
volumes:
- ${POSTGRES_PATH}:/var/lib/postgresql/data
- ${POSTGRES_PATH}/initdb:/docker-entrypoint-initdb.d
ports:
- 5432:5432
backend:
image: git.letsstein.de/tom/arbeitszeit-backend