diff --git a/Backend/main.go b/Backend/main.go index 5f4eb42..b21ed7f 100644 --- a/Backend/main.go +++ b/Backend/main.go @@ -69,13 +69,13 @@ func logoutHandler(w http.ResponseWriter, r *http.Request) { setCors(w) switch r.Method { case "GET": - autoLogout(w, r) + autoLogout(w) default: http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) } } -func autoLogout(w http.ResponseWriter, r *http.Request) { +func autoLogout(w http.ResponseWriter) { users, err := (*models.User).GetAll(nil) var logged_out_users []models.User if err != nil { diff --git a/Backend/models/user.go b/Backend/models/user.go index 6e48ac3..9008fc4 100644 --- a/Backend/models/user.go +++ b/Backend/models/user.go @@ -5,10 +5,10 @@ import ( ) type User struct { - CardUID string - Name string - Vorname string - HauptbeschaeftigungsOrt int8 + CardUID string `json:"card_uid"` + Name string `json:"name"` + Vorname string `json:"vorname"` + HauptbeschaeftigungsOrt int8 `json:"hauptbeschaeftigungsort"` } func (u *User) GetAll() ([]User, error) { diff --git a/Docker/arbeitszeitmessung.json b/Docker/arbeitszeitmessung.json index a84bbaa..5f20b9d 100644 --- a/Docker/arbeitszeitmessung.json +++ b/Docker/arbeitszeitmessung.json @@ -72,6 +72,7 @@ "tags": ["booking"], "summary": "Gets all the bookings limited", "description": "Returns all the bookings optionally filtered with cardID", + "operationId": "getBooking", "parameters": [ { "name": "card_uid", @@ -83,7 +84,6 @@ } } ], - "operationId": "addPet", "responses": { "200": { "description": "Successful operation", @@ -207,6 +207,29 @@ } } } + }, + "/logout": { + "get": { + "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", + "responses": { + "200": { + "description": "Succesful", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/User" + } + } + } + } + } + } + } } }, "components": { @@ -241,6 +264,28 @@ "xml": { "name": "booking" } + }, + "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 + } + } } } } diff --git a/Docker/arbeitszeitmessung.yaml b/Docker/arbeitszeitmessung.yaml index 1e13574..cff5cf2 100644 --- a/Docker/arbeitszeitmessung.yaml +++ b/Docker/arbeitszeitmessung.yaml @@ -1,8 +1,7 @@ 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 @@ -28,7 +27,9 @@ paths: schema: type: string requestBody: - description: Update an existent booking in the db. Not all values have to be updated + description: >- + Update an existent booking in the db. Not all values have to be + updated content: application/json: schema: @@ -50,6 +51,7 @@ paths: - booking summary: Gets all the bookings limited description: Returns all the bookings optionally filtered with cardID + operationId: getBooking parameters: - name: card_uid in: query @@ -57,7 +59,6 @@ paths: required: false schema: type: string - operationId: addPet responses: '200': description: Successful operation @@ -66,7 +67,7 @@ paths: schema: type: array items: - $ref: '#/components/schemas/Booking' + $ref: '#/components/schemas/Booking' '400': description: Invalid cardID /time/new: @@ -75,7 +76,7 @@ paths: - booking summary: Create new Booking description: Creates a new booking with the supplied parameters - operationId: createBooking + operationId: pcreateBooking parameters: - name: card_uid in: query @@ -108,6 +109,60 @@ paths: $ref: '#/components/schemas/Booking' '409': description: Same booking type as last booking + get: + tags: + - booking + summary: Create new Booking + description: Creates a new booking with the supplied parameters + operationId: gcreateBooking + parameters: + - name: card_uid + in: query + description: id of the RFID card scanned + required: true + schema: + type: string + - name: geraet_id + in: query + description: id of the RFID reader scanning the card + required: true + schema: + type: string + - name: check_in_out + in: query + description: booking Type + required: true + schema: + type: integer + enum: + - 1 + - 2 + - 255 + responses: + '200': + description: successfully created booking + content: + application/json: + schema: + $ref: '#/components/schemas/Booking' + '409': + description: Same booking type as last booking + /logout: + get: + 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 + responses: + '200': + description: Succesful + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/User' components: schemas: Booking: @@ -133,6 +188,22 @@ components: timestamp: type: string format: date-time - example: 2024-09-05T08:51:12.670827Z + example: '2024-09-05T08:51:12.670Z' xml: name: booking + 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