From 0c0034644e3496991d6d619aa6eba785c26ee227 Mon Sep 17 00:00:00 2001 From: tom Date: Tue, 10 Sep 2024 22:39:53 +0200 Subject: [PATCH] FIX: docker build with database and swagger api --- Backend/.dockerignore | 2 + Backend/main.go | 2 +- Docker/.env | 2 +- Docker/arbeitszeitmessung.json | 196 +++++++++++++++++++++++++++++++++ Docker/arbeitszeitmessung.yaml | 18 +-- 5 files changed, 209 insertions(+), 11 deletions(-) create mode 100644 Backend/.dockerignore create mode 100644 Docker/arbeitszeitmessung.json diff --git a/Backend/.dockerignore b/Backend/.dockerignore new file mode 100644 index 0000000..7ab2ceb --- /dev/null +++ b/Backend/.dockerignore @@ -0,0 +1,2 @@ +db +Dockerfile diff --git a/Backend/main.go b/Backend/main.go index cd9ba4c..776bef9 100644 --- a/Backend/main.go +++ b/Backend/main.go @@ -25,7 +25,7 @@ func main() { http.HandleFunc("/time", timeHandler) fmt.Printf("Server is running at http://localhost:8000 exposed to port %s\n", getEnv("EXPOSED_PORT", "8000")) - log.Fatal(http.ListenAndServe(":8000", nil)) + log.Fatal(http.ListenAndServe(":8080", nil)) } func timeCreateHandler(w http.ResponseWriter, r *http.Request) { diff --git a/Docker/.env b/Docker/.env index 5e44c07..11718f7 100644 --- a/Docker/.env +++ b/Docker/.env @@ -1,5 +1,5 @@ POSTGRES_USER=arbeit_zeit POSTGRES_PASSWORD=password -POSTGRES_PATH=../Backend/database +POSTGRES_PATH=../Backend/db POSTGRES_DB=arbeitszeitmessung EXPOSED_PORT=8000 diff --git a/Docker/arbeitszeitmessung.json b/Docker/arbeitszeitmessung.json new file mode 100644 index 0000000..96ebf83 --- /dev/null +++ b/Docker/arbeitszeitmessung.json @@ -0,0 +1,196 @@ +{ + "openapi": "3.0.3", + "info": { + "title": "Arbeitszeitmessung - OpenAPI 3.0", + "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" + } + ], + "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", + "description": "Returns all the bookings optionally filtered with cardID", + "parameters": [ + { + "name": "card_uid", + "in": "query", + "description": "CardID to filter for", + "required": false, + "schema": { + "type": "string" + } + } + ], + "operationId": "addPet", + "responses": { + "200": { + "description": "Successful operation", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Booking" + } + } + } + } + }, + "400": { + "description": "Invalid cardID" + } + } + } + }, + "/time/new": { + "put": { + "tags": ["booking"], + "summary": "Create new Booking", + "description": "Creates a new booking with the supplied parameters", + "operationId": "createBooking", + "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" + } + } + } + } + }, + "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" + } + } + } + } +} diff --git a/Docker/arbeitszeitmessung.yaml b/Docker/arbeitszeitmessung.yaml index e89abaa..1e13574 100644 --- a/Docker/arbeitszeitmessung.yaml +++ b/Docker/arbeitszeitmessung.yaml @@ -21,7 +21,7 @@ paths: description: Update an existing booking by Id operationId: updateBooking parameters: - - name: counterID + - name: counter_id in: query description: Booking ID to update required: true @@ -51,7 +51,7 @@ paths: summary: Gets all the bookings limited description: Returns all the bookings optionally filtered with cardID parameters: - - name: cardID + - name: card_uid in: query description: CardID to filter for required: false @@ -77,19 +77,19 @@ paths: description: Creates a new booking with the supplied parameters operationId: createBooking parameters: - - name: cardID + - name: card_uid in: query description: id of the RFID card scanned required: true schema: type: string - - name: geraetID + - name: geraet_id in: query description: id of the RFID reader scanning the card required: true schema: type: string - - name: checkInOut + - name: check_in_out in: query description: booking Type required: true @@ -113,17 +113,17 @@ components: Booking: type: object properties: - counterID: + counter_id: type: integer format: int64 example: 100 - cardID: + card_uid: type: string example: test_card - geraetID: + geraet_id: type: string example: test_reader - checkInOut: + check_in_out: type: integer example: 1 enum: