Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 125 additions & 3 deletions backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ definitions:
example: John
type: string
hotel_id:
example: hotel_123
example: 550e8400-e29b-41d4-a716-446655440000
type: string
id:
example: user_123
Expand Down Expand Up @@ -299,7 +299,7 @@ definitions:
minimum: 1
type: integer
id:
example: "550e8400-e29b-41d4-a\t716-446655440000"
example: org_2abc123
type: string
name:
example: Hotel California
Expand Down Expand Up @@ -389,6 +389,48 @@ definitions:
user_id:
type: string
type: object
RequestPatchInput:
properties:
completed_at:
type: string
department:
type: string
description:
type: string
estimated_completion_time:
type: integer
guest_id:
type: string
name:
type: string
notes:
type: string
priority:
enum:
- low
- medium
- high
type: string
request_category:
type: string
request_type:
type: string
reservation_id:
type: string
room_id:
type: string
scheduled_time:
type: string
status:
enum:
- pending
- assigned
- in progress
- completed
type: string
user_id:
type: string
type: object
RegisterDeviceTokenInput:
properties:
platform:
Expand Down Expand Up @@ -559,7 +601,7 @@ definitions:
example: John
type: string
hotel_id:
example: hotel_123
example: 550e8400-e29b-41d4-a716-446655440000
type: string
id:
example: user_123
Expand Down Expand Up @@ -1093,6 +1135,48 @@ paths:
summary: creates a request
tags:
- requests
/request/{id}:
put:
consumes:
- application/json
description: Partially updates a request — only fields present in the body are
applied; omitted fields keep their current values
parameters:
- description: Request ID (UUID)
in: path
name: id
required: true
type: string
- description: Fields to update
in: body
name: request
required: true
schema:
$ref: '#/definitions/RequestPatchInput'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/Request'
"400":
description: Bad Request
schema:
$ref: '#/definitions/github_com_generate_selfserve_internal_errs.HTTPError'
"404":
description: Not Found
schema:
$ref: '#/definitions/github_com_generate_selfserve_internal_errs.HTTPError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/github_com_generate_selfserve_internal_errs.HTTPError'
security:
- BearerAuth: []
summary: Update a request
tags:
- requests
/request/cursor:
post:
consumes:
Expand Down Expand Up @@ -1286,6 +1370,44 @@ paths:
summary: List rooms with filters
tags:
- rooms
/rooms/{id}:
get:
description: Retrieves a single room by its UUID
parameters:
- description: Hotel ID (UUID)
in: header
name: X-Hotel-ID
required: true
type: string
- description: Room ID (UUID)
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/RoomWithOptionalGuestBooking'
"400":
description: Bad Request
schema:
$ref: '#/definitions/github_com_generate_selfserve_internal_errs.HTTPError'
"404":
description: Not Found
schema:
$ref: '#/definitions/github_com_generate_selfserve_internal_errs.HTTPError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/github_com_generate_selfserve_internal_errs.HTTPError'
security:
- BearerAuth: []
summary: Get room by ID
tags:
- rooms
/rooms/floors:
get:
description: Retrieves all distinct floor numbers
Expand Down
32 changes: 29 additions & 3 deletions backend/internal/handler/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,45 @@ func (r *RequestsHandler) CreateRequest(c *fiber.Ctx) error {
return c.JSON(res)
}

// UpdateRequest godoc
// @Summary Update a request
// @Description Partially updates a request — only fields present in the body are applied; omitted fields keep their current values
// @Tags requests
// @Accept json
// @Produce json
// @Param id path string true "Request ID (UUID)"
// @Param request body models.RequestPatchInput true "Fields to update"
// @Success 200 {object} models.Request
// @Failure 400 {object} errs.HTTPError
// @Failure 404 {object} errs.HTTPError
// @Failure 500 {object} errs.HTTPError
// @Security BearerAuth
// @Router /request/{id} [put]
func (r *RequestsHandler) UpdateRequest(c *fiber.Ctx) error {
id := c.Params("id")
if !validUUID(id) {
return errs.BadRequest("request id is not a valid UUID")
}

var requestBody models.MakeRequest
if err := httpx.BindAndValidate(c, &requestBody); err != nil {
var patchInput models.RequestPatchInput
if err := httpx.BindAndValidate(c, &patchInput); err != nil {
return err
}

res, err := r.RequestRepository.InsertRequest(c.Context(), &models.Request{ID: id, MakeRequest: requestBody})
request, err := r.RequestRepository.FindRequest(c.Context(), id)
if err != nil {
if errors.Is(err, errs.ErrNotFoundInDB) {
return errs.NotFound("Request", "id", id)
}
slog.Error("failed to get request for update", "err", err, "requestID", id)
return errs.InternalServerError()
}

request.ApplyPatch(&patchInput)

res, err := r.RequestRepository.InsertRequest(c.Context(), request)
if err != nil {
slog.Error("failed to insert updated request version", "err", err, "requestID", id)
return errs.InternalServerError()
}

Expand Down
Loading
Loading