Skip to content

Commit

Permalink
Merge pull request #120 from COS301-SE-2024/docs/backend/Update-API-docs
Browse files Browse the repository at this point in the history
"Docs updated"
  • Loading branch information
Rethakgetse-Manaka authored Jun 30, 2024
2 parents 9c49032 + da5051d commit 7c4a4b9
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 53 deletions.
139 changes: 87 additions & 52 deletions documentation/occupi-docs/pages/api-documentation/api-usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -308,39 +308,34 @@ If there are any errors during the process, appropriate error messages are retur
```json copy
{
"roomId": "string",
"slot": "integer",
"emails": ["string"],
"creator": "string",
"floorNo": "integer"
"floorNo": "integer",
"date": "string",
"start": "string",
"end": "string"
}
```

**Success Response**

- **Code:** 200
- **Content:** `{ "message": "Resources fetched successfully"
"data" : "Booking ID" }`
- **Content:** `{ "status": 200, "message": "Successfully booked!", "data": {"1234567890"}, }`

**Error Response**

- **Code:** 400
- **Content:** `{ "message": "Invalid request Payload",
"code" : "InvalidRequestPayloadCode",
"details: "Expected RoomID, Slot, Emails[], Creator, FloorNo" }`
- **Content:** `{ "status": 400, "message": "Invalid request payload", "error": {"code":"BAD_REQUEST","details":null,"message":"missing field required: <name of field>"}, }`

**Error Response**

- **Code:** 500
- **Content:** `{ "message": "Failed to save booking",
"code": "InternalServerErrorCode",
"details": "Failed to save booking" }`
- **Content:** `{ "status": 500, "message": "Failed to save booking", "error": {"code":"INTERNAL_SERVER_ERROR","details":"Failed to save booking","message":"Failed to save booking"} }`

**Error Response**

- **Code:** 500
- **Content:** `{ "message": "Failed to send confirmation emails",
"code": "InternalServerErrorCode",
"details": "Failed to send confirmation emails" }`
- **Content:** `{ "status": 500, "message": "Failed to send confirmation emails", "error": {"code":"INTERNAL_SERVER_ERROR","details":"Failed to send confirmation emails","message":"Failed to send confirmation emails"} }`

### ViewBookings

Expand All @@ -362,29 +357,25 @@ If there are any errors during the process, appropriate error messages are retur

```json copy
{
"emails": "string",
"emails": "string"
}
```

**Success Response**

- **Code:** 200
- **Content:** `{ "message": "Bookings fetched successfully",
"data" : "List of bookings" }`
- **Content:** `{ "status": 200, "message": "Successfully fetched bookings!", "data": null }`

**Error Response**

- **Code:** 400
- **Content:** `{ "message": "Invalid request Payload",
"code" : "InvalidRequestPayloadCode",
"details: "Expected Email Address" }`
- **Content:** `{ "status": 400, "message": "Invalid request payload", "error": {"code":"BAD_REQUEST","details":null,"message":"Expected Email Address"}, }`


**Error Response**

- **Code:** 500
- **Content:** `{ "message": "Failed to fetch bookings",
"code": "InternalServerErrorCode",
"details": "Failed to fetch bookings" }`
- **Content:** `{ "status": 500, "message": "Failed to get bookings", "error": {"code":"INTERNAL_SERVER_ERROR","details":"Failed to get bookings","message":"Failed to get bookings"} }`

### CancelBooking

Expand All @@ -408,36 +399,46 @@ If there are any errors during the process, appropriate error messages are retur
```json copy
{
"bookingId": "string",
"roomId": "string",
"emails": ["string"],
"creator": "string",
"floorNo": "integer",
"date": "string",
"start": "string",
"end": "string"
}
```

**Success Response**

- **Code:** 200
- **Content:** `{ "message": "Booking canceled successfully",
"data" : "nil" }`
- **Content:** `{ "status": 200, "message": "Successfully cancelled booking!", "data":null }`

**Error Response**


- **Code:** 400
- **Content:** `{ "status": 400, "message": "Invalid request payload", "error": {"code":"BAD_REQUEST","details":null,"message":"missing field required: <name of field>"}, }`

**Error Response**

- **Code:** 400
- **Content:** `{ "message": "Invalid request Payload",
"code" : "InvalidRequestPayloadCode",
"details: "Expected Booking ID, Creator" }`
- **Content:** `{ "status": 400, "message": "Invalid request payload", "error": {"code":"BAD_REQUEST","details":null,"message":"Invalid JSON payload"}, }`

**Error Response**


- **Code:** 404
- **Content:** `{ "status": 404, "message": "Booking not found", "error": {"code":"BAD_REQUEST","details":null,"message":"Booking not found"}, }`

**Error Response**

- **Code:** 500
- **Content:** `{ "message": "Failed to cancel booking",
"code": "InternalServerErrorCode",
"details": "Failed to cancel booking" }`
- **Content:** `{ "status": 500, "message": "Failed to cancel booking", "error": {"code":"INTERNAL_SERVER_ERROR","details":null,"message":"Failed to save booking"} }`

**Error Response**

- **Code:** 500
- **Content:** `{ "message": "Failed to send confirmation emails",
"code": "InternalServerErrorCode",
"details": "Failed to send confirmation emails" }`
- **Content:** `{ "status": 500, "message": "Failed to send confirmation emails", "error": {"code":"INTERNAL_SERVER_ERROR","details":null,"message":"An error occured"} }`


### CheckIn

Expand All @@ -452,7 +453,7 @@ If there are any errors during the process, appropriate error messages are retur

- **Method**

`GET`
`POST`

- **Request Body**

Expand All @@ -461,37 +462,71 @@ If there are any errors during the process, appropriate error messages are retur
```json copy
{
"bookingId": "string",
"email": "string",
"roomId": "string",
"email": "string"
}
```

**Success Response**

- **Code:** 200
- **Content:** `{ "message": "Checked in successfully",
"data" : "nil" }`
- **Content:** `{ "status": 200, "message": "Successfully checked in!", "data":null }`

**Error Response**

- **Code:** 400
- **Content:** `{ "message": "Invalid request Payload",
"code" : "InvalidRequestPayloadCode",
"details: "Expected Booking ID, Email, RoomID" }`
- **Content:** `{ "status": 400, "message": "Invalid request payload", "error": {"code":"BAD_REQUEST","details":null,"message":"missing field required: <name of field>"}, }`


**Error Response**

- **Code:** 404
- **Content:** `{ "status": 404, "message": "Booking not found", "error": {"code":"BAD_REQUEST","details":null,"message":"Booking not found"}, }`

**Error Response**

- **Code:** 500
- **Content:** `{ "message": "Failed to check-in",
"code": "InternalServerErrorCode",
"details": "Failed to check-in" }`
- **Content:** `{ "status": 500, "message": "Failed to check in", "error": {"code":"INTERNAL_SERVER_ERROR","details":null,"message":"Failed to checkin"} }`

### ViewRooms

This endpoint is used to view all rooms in the Occupi system.
Upon a successful request, a list of all rooms is returned.
If there are any errors during the process, appropriate error messages are returned.

- **URL**

`/api/view-rooms`

- **Method**

`POST`

- **Request Body**

- **Content**

```json copy
{
"floorNo": "string"
}
```

**Success Response**

- **Code:** 200
- **Content:** `{ "status": 200, "message": "Successfully fetched rooms!", "data": {"list of all rooms"} }`

**Error Response**

- **Code:** 400
- **Content:** `{ "status": 400, "message": "Invalid request payload", "error": {"code":"BAD_REQUEST","details":null,"message":"missing field required: <name of field>"}, }`

**Error Response**

- **Code:** 500
- **Content:** `{ "message": "Failed to send confirmation emails",
"code": "InternalServerErrorCode",
"details": "Failed to send confirmation emails" }`
- **Content:** `{ "status": 500, "message": "Failed to get rooms", "error": {"code":"INTERNAL_SERVER_ERROR","details":null,"message":"Failed to get rooms"} }`





Expand Down
2 changes: 1 addition & 1 deletion occupi-backend/pkg/handlers/api_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func CancelBooking(ctx *gin.Context, appsession *models.AppSession) {
var cancel models.Cancel
cancelBytes, _ := json.Marshal(validatedData)
if err := json.Unmarshal(cancelBytes, &cancel); err != nil {
ctx.JSON(http.StatusInternalServerError, utils.ErrorResponse(http.StatusInternalServerError, "Failed to cancel", constants.InternalServerErrorCode, "Failed to check in", nil))
ctx.JSON(http.StatusInternalServerError, utils.ErrorResponse(http.StatusInternalServerError, "Failed to cancel", constants.InternalServerErrorCode, "Failed to cancel", nil))
return
}

Expand Down

0 comments on commit 7c4a4b9

Please sign in to comment.