From 89f4e1016e77b4d28db772168bf2d8ce32c15594 Mon Sep 17 00:00:00 2001 From: Stephen von Takach Date: Mon, 2 Sep 2024 10:43:42 +1000 Subject: [PATCH] fix(bookings): add approve and reject routes for recurring instances --- OPENAPI_DOC.yml | 240 ++++++++++++++++++++++++++++++++++++ src/controllers/bookings.cr | 12 +- 2 files changed, 250 insertions(+), 2 deletions(-) diff --git a/OPENAPI_DOC.yml b/OPENAPI_DOC.yml index 3894141..1529586 100644 --- a/OPENAPI_DOC.yml +++ b/OPENAPI_DOC.yml @@ -1610,6 +1610,126 @@ paths: schema: type: string nullable: true + - name: instance + in: query + description: a recurring instance id + example: "1234567" + required: false + schema: + type: integer + format: Int64 + nullable: true + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/PlaceOS__Model__Booking' + 429: + description: Too Many Requests + content: + application/json: + schema: + $ref: '#/components/schemas/Application__CommonError' + 400: + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/Application__CommonError' + 401: + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/Application__CommonError' + 403: + description: Forbidden + 404: + description: Not Found + content: + application/json: + schema: + $ref: '#/components/schemas/Application__CommonError' + 511: + description: Network Authentication Required + content: + application/json: + schema: + $ref: '#/components/schemas/Application__CommonError' + 406: + description: Not Acceptable + content: + application/json: + schema: + $ref: '#/components/schemas/Application__ContentError' + 415: + description: Unsupported Media Type + content: + application/json: + schema: + $ref: '#/components/schemas/Application__ContentError' + 422: + description: Unprocessable Entity + content: + application/json: + schema: + $ref: '#/components/schemas/Application__ValidationError' + 500: + description: Internal Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/Application__CommonError' + 405: + description: Method Not Allowed + content: + application/json: + schema: + $ref: '#/components/schemas/Application__CommonError' + 409: + description: Conflict + content: + application/json: + schema: + $ref: '#/components/schemas/Bookings__BookingError' + 410: + description: Gone + content: + application/json: + schema: + $ref: '#/components/schemas/Bookings__BookingError' + /api/staff/v1/bookings/{id}/approve/{instance}: + post: + summary: approves a booking (if booking approval is required in an organisation) + tags: + - Bookings + operationId: Bookings_approve{2} + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: Int64 + - name: instance + in: path + description: a recurring instance id + example: "1234567" + required: true + schema: + type: integer + format: Int64 + nullable: true + - name: utm_source + in: query + description: provided for use with analytics + example: mobile + required: false + schema: + type: string + nullable: true responses: 200: description: OK @@ -1712,6 +1832,126 @@ paths: schema: type: string nullable: true + - name: instance + in: query + description: a recurring instance id + example: "1234567" + required: false + schema: + type: integer + format: Int64 + nullable: true + responses: + 200: + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/PlaceOS__Model__Booking' + 429: + description: Too Many Requests + content: + application/json: + schema: + $ref: '#/components/schemas/Application__CommonError' + 400: + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/Application__CommonError' + 401: + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/Application__CommonError' + 403: + description: Forbidden + 404: + description: Not Found + content: + application/json: + schema: + $ref: '#/components/schemas/Application__CommonError' + 511: + description: Network Authentication Required + content: + application/json: + schema: + $ref: '#/components/schemas/Application__CommonError' + 406: + description: Not Acceptable + content: + application/json: + schema: + $ref: '#/components/schemas/Application__ContentError' + 415: + description: Unsupported Media Type + content: + application/json: + schema: + $ref: '#/components/schemas/Application__ContentError' + 422: + description: Unprocessable Entity + content: + application/json: + schema: + $ref: '#/components/schemas/Application__ValidationError' + 500: + description: Internal Server Error + content: + application/json: + schema: + $ref: '#/components/schemas/Application__CommonError' + 405: + description: Method Not Allowed + content: + application/json: + schema: + $ref: '#/components/schemas/Application__CommonError' + 409: + description: Conflict + content: + application/json: + schema: + $ref: '#/components/schemas/Bookings__BookingError' + 410: + description: Gone + content: + application/json: + schema: + $ref: '#/components/schemas/Bookings__BookingError' + /api/staff/v1/bookings/{id}/reject/{instance}: + post: + summary: rejects a booking + tags: + - Bookings + operationId: Bookings_reject{2} + parameters: + - name: id + in: path + required: true + schema: + type: integer + format: Int64 + - name: instance + in: path + description: a recurring instance id + example: "1234567" + required: true + schema: + type: integer + format: Int64 + nullable: true + - name: utm_source + in: query + description: provided for use with analytics + example: mobile + required: false + schema: + type: string + nullable: true responses: 200: description: OK diff --git a/src/controllers/bookings.cr b/src/controllers/bookings.cr index 8c96025..6e42389 100644 --- a/src/controllers/bookings.cr +++ b/src/controllers/bookings.cr @@ -723,10 +723,14 @@ class Bookings < Application # approves a booking (if booking approval is required in an organisation) @[AC::Route::POST("/:id/approve")] + @[AC::Route::POST("/:id/approve/:instance")] def approve( @[AC::Param::Info(description: "provided for use with analytics", example: "mobile")] - utm_source : String? = nil + utm_source : String? = nil, + @[AC::Param::Info(description: "a recurring instance id", example: "1234567")] + instance : Int64? = nil ) : Booking + booking.instance = instance booking.utm_source = utm_source set_approver(booking, true) @@ -738,10 +742,14 @@ class Bookings < Application # rejects a booking @[AC::Route::POST("/:id/reject")] + @[AC::Route::POST("/:id/reject/:instance")] def reject( @[AC::Param::Info(description: "provided for use with analytics", example: "mobile")] - utm_source : String? = nil + utm_source : String? = nil, + @[AC::Param::Info(description: "a recurring instance id", example: "1234567")] + instance : Int64? = nil ) : Booking + booking.instance = instance booking.utm_source = utm_source set_approver(booking, false) update_booking(booking, "rejected")