Merge branch 'main' into parent-location-sync

This commit is contained in:
slid1amo2n3e4
2024-12-13 15:01:02 +01:00
committed by GitHub
56 changed files with 6401 additions and 4784 deletions

View File

@@ -28,8 +28,8 @@ type (
}
LoginForm struct {
Username string `json:"username"`
Password string `json:"password"`
Username string `json:"username" example:"admin@admin.com"`
Password string `json:"password" example:"admin"`
StayLoggedIn bool `json:"stayLoggedIn"`
}
)
@@ -79,17 +79,15 @@ type AuthProvider interface {
// HandleAuthLogin godoc
//
// @Summary User Login
// @Tags Authentication
// @Accept x-www-form-urlencoded
// @Accept application/json
// @Param username formData string false "string" example(admin@admin.com)
// @Param password formData string false "string" example(admin)
// @Param payload body LoginForm true "Login Data"
// @Param provider query string false "auth provider"
// @Produce json
// @Success 200 {object} TokenResponse
// @Router /v1/users/login [POST]
// @Summary User Login
// @Tags Authentication
// @Accept x-www-form-urlencoded
// @Accept application/json
// @Param payload body LoginForm true "Login Data"
// @Param provider query string false "auth provider"
// @Produce json
// @Success 200 {object} TokenResponse
// @Router /v1/users/login [POST]
func (ctrl *V1Controller) HandleAuthLogin(ps ...AuthProvider) errchain.HandlerFunc {
if len(ps) == 0 {
panic("no auth providers provided")

View File

@@ -4,10 +4,12 @@ import (
"database/sql"
"encoding/csv"
"errors"
"fmt"
"math/big"
"net/http"
"net/url"
"strings"
"time"
"github.com/google/uuid"
"github.com/hay-kot/httpkit/errchain"
@@ -290,13 +292,14 @@ func (ctrl *V1Controller) HandleGetAllCustomFieldValues() errchain.HandlerFunc {
// HandleItemsImport godocs
//
// @Summary Import Items
// @Tags Items
// @Produce json
// @Success 204
// @Param csv formData file true "Image to upload"
// @Router /v1/items/import [Post]
// @Security Bearer
// @Summary Import Items
// @Tags Items
// @Accept multipart/form-data
// @Produce json
// @Success 204
// @Param csv formData file true "Image to upload"
// @Router /v1/items/import [Post]
// @Security Bearer
func (ctrl *V1Controller) HandleItemsImport() errchain.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) error {
err := r.ParseMultipartForm(ctrl.maxUploadSize << 20)
@@ -340,8 +343,11 @@ func (ctrl *V1Controller) HandleItemsExport() errchain.HandlerFunc {
return validate.NewRequestError(err, http.StatusInternalServerError)
}
timestamp := time.Now().Format("2006-01-02_15-04-05") // YYYY-MM-DD_HH-MM-SS format
filename := fmt.Sprintf("homebox-items_%s.csv", timestamp) // add timestamp to filename
w.Header().Set("Content-Type", "text/csv")
w.Header().Set("Content-Disposition", "attachment;filename=homebox-items.csv")
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment;filename=%s", filename))
writer := csv.NewWriter(w)
writer.Comma = ','

View File

@@ -23,17 +23,18 @@ type (
// HandleItemAttachmentCreate godocs
//
// @Summary Create Item Attachment
// @Tags Items Attachments
// @Produce json
// @Param id path string true "Item ID"
// @Param file formData file true "File attachment"
// @Param type formData string true "Type of file"
// @Param name formData string true "name of the file including extension"
// @Success 200 {object} repo.ItemOut
// @Failure 422 {object} validate.ErrorResponse
// @Router /v1/items/{id}/attachments [POST]
// @Security Bearer
// @Summary Create Item Attachment
// @Tags Items Attachments
// @Accept multipart/form-data
// @Produce json
// @Param id path string true "Item ID"
// @Param file formData file true "File attachment"
// @Param type formData string true "Type of file"
// @Param name formData string true "name of the file including extension"
// @Success 200 {object} repo.ItemOut
// @Failure 422 {object} validate.ErrorResponse
// @Router /v1/items/{id}/attachments [POST]
// @Security Bearer
func (ctrl *V1Controller) HandleItemAttachmentCreate() errchain.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) error {
err := r.ParseMultipartForm(ctrl.maxUploadSize << 20)

View File

@@ -12,13 +12,14 @@ import (
// HandleMaintenanceLogGet godoc
//
// @Summary Get Maintenance Log
// @Tags Item Maintenance
// @Produce json
// @Param filters query repo.MaintenanceFilters false "which maintenance to retrieve"
// @Success 200 {array} repo.MaintenanceEntryWithDetails[]
// @Router /v1/items/{id}/maintenance [GET]
// @Security Bearer
// @Summary Get Maintenance Log
// @Tags Item Maintenance
// @Produce json
// @Param id path string true "Item ID"
// @Param filters query repo.MaintenanceFilters false "which maintenance to retrieve"
// @Success 200 {array} repo.MaintenanceEntryWithDetails[]
// @Router /v1/items/{id}/maintenance [GET]
// @Security Bearer
func (ctrl *V1Controller) HandleMaintenanceLogGet() errchain.HandlerFunc {
fn := func(r *http.Request, ID uuid.UUID, filters repo.MaintenanceFilters) ([]repo.MaintenanceEntryWithDetails, error) {
auth := services.NewContext(r.Context())
@@ -30,13 +31,14 @@ func (ctrl *V1Controller) HandleMaintenanceLogGet() errchain.HandlerFunc {
// HandleMaintenanceEntryCreate godoc
//
// @Summary Create Maintenance Entry
// @Tags Item Maintenance
// @Produce json
// @Param payload body repo.MaintenanceEntryCreate true "Entry Data"
// @Success 201 {object} repo.MaintenanceEntry
// @Router /v1/items/{id}/maintenance [POST]
// @Security Bearer
// @Summary Create Maintenance Entry
// @Tags Item Maintenance
// @Produce json
// @Param id path string true "Item ID"
// @Param payload body repo.MaintenanceEntryCreate true "Entry Data"
// @Success 201 {object} repo.MaintenanceEntry
// @Router /v1/items/{id}/maintenance [POST]
// @Security Bearer
func (ctrl *V1Controller) HandleMaintenanceEntryCreate() errchain.HandlerFunc {
fn := func(r *http.Request, itemID uuid.UUID, body repo.MaintenanceEntryCreate) (repo.MaintenanceEntry, error) {
auth := services.NewContext(r.Context())

View File

@@ -30,13 +30,14 @@ func (ctrl *V1Controller) HandleMaintenanceGetAll() errchain.HandlerFunc {
// HandleMaintenanceEntryUpdate godoc
//
// @Summary Update Maintenance Entry
// @Tags Maintenance
// @Produce json
// @Param payload body repo.MaintenanceEntryUpdate true "Entry Data"
// @Success 200 {object} repo.MaintenanceEntry
// @Router /v1/maintenance/{id} [PUT]
// @Security Bearer
// @Summary Update Maintenance Entry
// @Tags Maintenance
// @Produce json
// @Param id path string true "Maintenance ID"
// @Param payload body repo.MaintenanceEntryUpdate true "Entry Data"
// @Success 200 {object} repo.MaintenanceEntry
// @Router /v1/maintenance/{id} [PUT]
// @Security Bearer
func (ctrl *V1Controller) HandleMaintenanceEntryUpdate() errchain.HandlerFunc {
fn := func(r *http.Request, entryID uuid.UUID, body repo.MaintenanceEntryUpdate) (repo.MaintenanceEntry, error) {
auth := services.NewContext(r.Context())
@@ -48,12 +49,13 @@ func (ctrl *V1Controller) HandleMaintenanceEntryUpdate() errchain.HandlerFunc {
// HandleMaintenanceEntryDelete godoc
//
// @Summary Delete Maintenance Entry
// @Tags Maintenance
// @Produce json
// @Success 204
// @Router /v1/maintenance/{id} [DELETE]
// @Security Bearer
// @Summary Delete Maintenance Entry
// @Tags Maintenance
// @Produce json
// @Param id path string true "Maintenance ID"
// @Success 204
// @Router /v1/maintenance/{id} [DELETE]
// @Security Bearer
func (ctrl *V1Controller) HandleMaintenanceEntryDelete() errchain.HandlerFunc {
fn := func(r *http.Request, entryID uuid.UUID) (any, error) {
auth := services.NewContext(r.Context())

View File

@@ -83,14 +83,13 @@ func (ctrl *V1Controller) HandleUpdateNotifier() errchain.HandlerFunc {
// HandlerNotifierTest godoc
//
// @Summary Test Notifier
// @Tags Notifiers
// @Produce json
// @Param id path string true "Notifier ID"
// @Param url query string true "URL"
// @Success 204
// @Router /v1/notifiers/test [POST]
// @Security Bearer
// @Summary Test Notifier
// @Tags Notifiers
// @Produce json
// @Param url query string true "URL"
// @Success 204
// @Router /v1/notifiers/test [POST]
// @Security Bearer
func (ctrl *V1Controller) HandlerNotifierTest() errchain.HandlerFunc {
type body struct {
URL string `json:"url" validate:"required"`

View File

@@ -566,6 +566,9 @@ const docTemplate = `{
"Bearer": []
}
],
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
@@ -737,6 +740,9 @@ const docTemplate = `{
"Bearer": []
}
],
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
@@ -921,6 +927,13 @@ const docTemplate = `{
],
"summary": "Get Maintenance Log",
"parameters": [
{
"type": "string",
"description": "Item ID",
"name": "id",
"in": "path",
"required": true
},
{
"enum": [
"scheduled",
@@ -963,6 +976,13 @@ const docTemplate = `{
],
"summary": "Create Maintenance Entry",
"parameters": [
{
"type": "string",
"description": "Item ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Entry Data",
"name": "payload",
@@ -1434,6 +1454,13 @@ const docTemplate = `{
],
"summary": "Update Maintenance Entry",
"parameters": [
{
"type": "string",
"description": "Maintenance ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Entry Data",
"name": "payload",
@@ -1466,6 +1493,15 @@ const docTemplate = `{
"Maintenance"
],
"summary": "Delete Maintenance Entry",
"parameters": [
{
"type": "string",
"description": "Maintenance ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"description": "No Content"
@@ -1548,13 +1584,6 @@ const docTemplate = `{
],
"summary": "Test Notifier",
"parameters": [
{
"type": "string",
"description": "Notifier ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "URL",
@@ -1752,20 +1781,6 @@ const docTemplate = `{
],
"summary": "User Login",
"parameters": [
{
"type": "string",
"example": "admin@admin.com",
"description": "string",
"name": "username",
"in": "formData"
},
{
"type": "string",
"example": "admin",
"description": "string",
"name": "password",
"in": "formData"
},
{
"description": "Login Data",
"name": "payload",
@@ -2289,6 +2304,10 @@ const docTemplate = `{
"archived": {
"type": "boolean"
},
"assetId": {
"type": "string",
"example": "0"
},
"createdAt": {
"type": "string"
},
@@ -3052,13 +3071,15 @@ const docTemplate = `{
"type": "object",
"properties": {
"password": {
"type": "string"
"type": "string",
"example": "admin"
},
"stayLoggedIn": {
"type": "boolean"
},
"username": {
"type": "string"
"type": "string",
"example": "admin@admin.com"
}
}
},

View File

@@ -559,6 +559,9 @@
"Bearer": []
}
],
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
@@ -730,6 +733,9 @@
"Bearer": []
}
],
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
@@ -914,6 +920,13 @@
],
"summary": "Get Maintenance Log",
"parameters": [
{
"type": "string",
"description": "Item ID",
"name": "id",
"in": "path",
"required": true
},
{
"enum": [
"scheduled",
@@ -956,6 +969,13 @@
],
"summary": "Create Maintenance Entry",
"parameters": [
{
"type": "string",
"description": "Item ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Entry Data",
"name": "payload",
@@ -1427,6 +1447,13 @@
],
"summary": "Update Maintenance Entry",
"parameters": [
{
"type": "string",
"description": "Maintenance ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Entry Data",
"name": "payload",
@@ -1459,6 +1486,15 @@
"Maintenance"
],
"summary": "Delete Maintenance Entry",
"parameters": [
{
"type": "string",
"description": "Maintenance ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"description": "No Content"
@@ -1541,13 +1577,6 @@
],
"summary": "Test Notifier",
"parameters": [
{
"type": "string",
"description": "Notifier ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "string",
"description": "URL",
@@ -1745,20 +1774,6 @@
],
"summary": "User Login",
"parameters": [
{
"type": "string",
"example": "admin@admin.com",
"description": "string",
"name": "username",
"in": "formData"
},
{
"type": "string",
"example": "admin",
"description": "string",
"name": "password",
"in": "formData"
},
{
"description": "Login Data",
"name": "payload",
@@ -2282,6 +2297,10 @@
"archived": {
"type": "boolean"
},
"assetId": {
"type": "string",
"example": "0"
},
"createdAt": {
"type": "string"
},
@@ -3045,13 +3064,15 @@
"type": "object",
"properties": {
"password": {
"type": "string"
"type": "string",
"example": "admin"
},
"stayLoggedIn": {
"type": "boolean"
},
"username": {
"type": "string"
"type": "string",
"example": "admin@admin.com"
}
}
},

View File

@@ -219,6 +219,9 @@ definitions:
properties:
archived:
type: boolean
assetId:
example: "0"
type: string
createdAt:
type: string
description:
@@ -730,10 +733,12 @@ definitions:
v1.LoginForm:
properties:
password:
example: admin
type: string
stayLoggedIn:
type: boolean
username:
example: admin@admin.com
type: string
type: object
v1.TokenResponse:
@@ -1136,6 +1141,8 @@ paths:
- Items
/v1/items/{id}/attachments:
post:
consumes:
- multipart/form-data
parameters:
- description: Item ID
in: path
@@ -1249,6 +1256,11 @@ paths:
/v1/items/{id}/maintenance:
get:
parameters:
- description: Item ID
in: path
name: id
required: true
type: string
- enum:
- scheduled
- completed
@@ -1276,6 +1288,11 @@ paths:
- Item Maintenance
post:
parameters:
- description: Item ID
in: path
name: id
required: true
type: string
- description: Entry Data
in: body
name: payload
@@ -1362,6 +1379,8 @@ paths:
- Items
/v1/items/import:
post:
consumes:
- multipart/form-data
parameters:
- description: Image to upload
in: formData
@@ -1624,6 +1643,12 @@ paths:
- Maintenance
/v1/maintenance/{id}:
delete:
parameters:
- description: Maintenance ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
@@ -1636,6 +1661,11 @@ paths:
- Maintenance
put:
parameters:
- description: Maintenance ID
in: path
name: id
required: true
type: string
- description: Entry Data
in: body
name: payload
@@ -1732,11 +1762,6 @@ paths:
/v1/notifiers/test:
post:
parameters:
- description: Notifier ID
in: path
name: id
required: true
type: string
- description: URL
in: query
name: url
@@ -1820,16 +1845,6 @@ paths:
- application/x-www-form-urlencoded
- application/json
parameters:
- description: string
example: admin@admin.com
in: formData
name: username
type: string
- description: string
example: admin
in: formData
name: password
type: string
- description: Login Data
in: body
name: payload