CHANGE: adde OpenAPI Docs + swagger UI
This commit is contained in:
5
.vscode/launch.json
vendored
5
.vscode/launch.json
vendored
@@ -12,7 +12,10 @@
|
|||||||
"request": "launch",
|
"request": "launch",
|
||||||
"mode": "auto",
|
"mode": "auto",
|
||||||
"program": "${workspaceFolder}/Backend",
|
"program": "${workspaceFolder}/Backend",
|
||||||
"dlvFlags": ["--check-go-version=false"]
|
"dlvFlags": ["--check-go-version=false"],
|
||||||
|
"env": {
|
||||||
|
"DEBUG": "true"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
27
API.apib
27
API.apib
@@ -1,27 +0,0 @@
|
|||||||
#Group Bookings
|
|
||||||
|
|
||||||
## Bookings Collection [/time{?cardID}]
|
|
||||||
|
|
||||||
### List all bookings for specific card_id [GET]
|
|
||||||
|
|
||||||
+ Parameters
|
|
||||||
+ cardID:test_card (string) - the id of the rfid card
|
|
||||||
|
|
||||||
+ Response 200 (application/json)
|
|
||||||
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"cradID": "test_card",
|
|
||||||
"readerID": "test_reader",
|
|
||||||
"bookingTyp": 2,
|
|
||||||
"loggedTime": "2024-09-05T08:37:53.117641Z",
|
|
||||||
"id": 5
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cradID": "test_card",
|
|
||||||
"readerID": "mytest",
|
|
||||||
"bookingTyp": 1,
|
|
||||||
"loggedTime": "2024-09-05T08:51:12.670827Z",
|
|
||||||
"id": 6
|
|
||||||
},
|
|
||||||
]
|
|
||||||
@@ -25,7 +25,7 @@ func main() {
|
|||||||
http.HandleFunc("/time", timeHandler)
|
http.HandleFunc("/time", timeHandler)
|
||||||
|
|
||||||
fmt.Printf("Server is running at http://localhost:8080 exposed to port %s\n", getEnv("EXPOSED_PORT", "8000"))
|
fmt.Printf("Server is running at http://localhost:8080 exposed to port %s\n", getEnv("EXPOSED_PORT", "8000"))
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
log.Fatal(http.ListenAndServe(":8000", nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func timeCreateHandler(w http.ResponseWriter, r *http.Request) {
|
func timeCreateHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -38,6 +38,9 @@ func timeCreateHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func timeHandler(w http.ResponseWriter, r *http.Request) {
|
func timeHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if os.Getenv("DEBUG") == "true" {
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
}
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case "GET":
|
case "GET":
|
||||||
getBookings(w, r)
|
getBookings(w, r)
|
||||||
@@ -46,6 +49,7 @@ func timeHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
default:
|
default:
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createBooking(w http.ResponseWriter, r *http.Request) {
|
func createBooking(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -69,6 +73,10 @@ func createBooking(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func getBookings(w http.ResponseWriter, r *http.Request) {
|
func getBookings(w http.ResponseWriter, r *http.Request) {
|
||||||
card_id := r.URL.Query().Get("cardID")
|
card_id := r.URL.Query().Get("cardID")
|
||||||
|
if card_id == "" {
|
||||||
|
http.Error(w, "Missing cardID query parameter", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
bookings, err := (*models.Booking).GetBookingsByCardID(nil, card_id)
|
bookings, err := (*models.Booking).GetBookingsByCardID(nil, card_id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error getting bookings: ", err)
|
log.Println("Error getting bookings: ", err)
|
||||||
|
|||||||
210
Docker/arbeitszeitmessung.json
Normal file
210
Docker/arbeitszeitmessung.json
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
{
|
||||||
|
"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": "bookingID",
|
||||||
|
"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": "cardID",
|
||||||
|
"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": "cardID",
|
||||||
|
"in": "query",
|
||||||
|
"description": "id of the RFID card scanned",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "readerID",
|
||||||
|
"in": "query",
|
||||||
|
"description": "id of the RFID reader scanning the card",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "bookingType",
|
||||||
|
"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": {
|
||||||
|
"id": {
|
||||||
|
"type": "integer",
|
||||||
|
"format": "int64",
|
||||||
|
"example": 100
|
||||||
|
},
|
||||||
|
"cardID": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "test_card"
|
||||||
|
},
|
||||||
|
"readerID": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "test_reader"
|
||||||
|
},
|
||||||
|
"bookingType": {
|
||||||
|
"type": "integer",
|
||||||
|
"example": 1,
|
||||||
|
"enum": [
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
255
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"loggedTime": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time",
|
||||||
|
"example": "2024-09-05T08:51:12.670Z"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"xml": {
|
||||||
|
"name": "booking"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
138
Docker/arbeitszeitmessung.yaml
Normal file
138
Docker/arbeitszeitmessung.yaml
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
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: bookingID
|
||||||
|
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: cardID
|
||||||
|
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: cardID
|
||||||
|
in: query
|
||||||
|
description: id of the RFID card scanned
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
- name: readerID
|
||||||
|
in: query
|
||||||
|
description: id of the RFID reader scanning the card
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
- name: bookingType
|
||||||
|
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:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
|
example: 100
|
||||||
|
cardID:
|
||||||
|
type: string
|
||||||
|
example: test_card
|
||||||
|
readerID:
|
||||||
|
type: string
|
||||||
|
example: test_reader
|
||||||
|
bookingType:
|
||||||
|
type: integer
|
||||||
|
example: 1
|
||||||
|
enum:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
- 255
|
||||||
|
loggedTime:
|
||||||
|
type: string
|
||||||
|
format: date-time
|
||||||
|
example: 2024-09-05T08:51:12.670827Z
|
||||||
|
xml:
|
||||||
|
name: booking
|
||||||
@@ -31,5 +31,17 @@ services:
|
|||||||
POSTGRES_USER: ${POSTGRES_USER}
|
POSTGRES_USER: ${POSTGRES_USER}
|
||||||
POSTGRES_PASS: ${POSTGRES_PASSWORD}
|
POSTGRES_PASS: ${POSTGRES_PASSWORD}
|
||||||
EXPOSED_PORT: ${EXPOSED_PORT}
|
EXPOSED_PORT: ${EXPOSED_PORT}
|
||||||
|
DEBUG: true
|
||||||
ports:
|
ports:
|
||||||
- 8000:8080
|
- 8000:8080
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
swagger:
|
||||||
|
image: swaggerapi/swagger-ui
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
SWAGGER_JSON: /api/swagger.json
|
||||||
|
ports:
|
||||||
|
- 8002:8080
|
||||||
|
volumes:
|
||||||
|
- ./arbeitszeitmessung.json:/api/swagger.json
|
||||||
|
|||||||
Reference in New Issue
Block a user