Skip to content

Commit

Permalink
Merge pull request #234 from COS301-SE-2024/feat/backend/pfps
Browse files Browse the repository at this point in the history
Feat/backend/pfps
  • Loading branch information
waveyboym authored Jul 20, 2024
2 parents 7246c97 + bed657d commit d7b0c6e
Show file tree
Hide file tree
Showing 13 changed files with 734 additions and 15 deletions.
186 changes: 186 additions & 0 deletions documentation/occupi-docs/pages/api-documentation/api-usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ The API also allows you to retrieve information about these resources.
- [Get Security Settings](#GetSecuritySettings)
- [Update Notification Settings](#UpdateNotificationSettings)
- [Get Notification Settings](#GetNotificationSettings)
- [Upload Profile Image](#UploadProfileImage)
- [Download Profile Image](#DownloadProfileImage)
- [Image ID](#ImageID)
- [Upload Image](#UploadImage)
- [Upload Room Image](#UploadRoomImage)

## Api

Expand Down Expand Up @@ -718,3 +723,184 @@ or

- **Content:** `{ "status": 500, "message": "Internal server error", "error": {"code":"INTERNAL_SERVER_ERROR","details":null,"message":"Failed to update settings"} }`


### UploadProfileImage

This endpoint is used to upload a profile image for a user in the Occupi system. Images must be in jpg, jpeg, or png format otherwise an error will be returned.

- **URL**

`/api/upload-profile-image`

- **Method**

`POST`

- **Request Form Data**

- **Content**

```copy
"image": image_data, // required
"email": "abcd@gmail.com" // optional if you are logged in
```

**Success Response**

- **Code:** 200

- **Content:** `{ "status": 200, "message": "Successfully uploaded image!", "data": null }`

**Error Response**

- **Code:** 500

- **Content:** `{ "status": 500, "message": "Internal server error", "error": {"code":"INTERNAL_SERVER_ERROR","details":null,"message":"Internal server error"} }`

### DownloadProfileImage

This endpoint is used to download a profile image for a user in the Occupi system.

- **URL**

`/api/download-profile-image`

- **Method**

`GET`

- **Request JSON Data**

- **Content**

```json copy
"email": "abcd@gmail.com" // optional if you are logged in
"quality": "mid" // optional, can be "thumbnail", "low", "medium", "high but defaults to mid
```

or

```
/api/download-profile-image?email=abcd@gmail.com&quality=mid
```

**note that the higher quality, the longer it will take to download**

**Success Response**

- **Code:** 200

- **Content:** `{ "status": 200, "message": "Successfully fetched image!", "data": null }`

**Error Response**

- **Code:** 500

- **Content:** `{ "status": 500, "message": "Internal server error", "error": {"code":"INTERNAL_SERVER_ERROR","details":null,"message":"Internal server error"} }`

### Image ID

This endpoint is used to get the image in the Occupi system given an image ID as a url parameter.

- **URL**

`/api/image/:id`

- **Method**

`GET`

- **Request JSON Data**

- **Content**

```json copy
"quality": "mid" // optional, can be "thumbnail", "low", "medium", "high but defaults to mid
```

or

```
/api/image/000000000000000000?quality=mid
```

**the id is the id of the image which you will get when you get a room and is required for all requests on this endpoint**

**note that the higher quality, the longer it will take to download**

**Success Response**

- **Code:** 200

- **Content:** `{ "status": 200, "message": "Successfully fetched image!", "data": null }`

**Error Response**

- **Code:** 500

- **Content:** `{ "status": 500, "message": "Internal server error", "error": {"code":"INTERNAL_SERVER_ERROR","details":null,"message":"Internal server error"} }`

### Upload Image

This endpoint is used to upload an image in the Occupi system. Only Admins can upload images.

- **URL**

`/api/upload-image`

- **Method**

`POST`

- **Request Form Data**

- **Content**

```copy
"image": image_data, // required
```

**Success Response**

- **Code:** 200

- **Content:** `{ "status": 200, "message": "Successfully uploaded image!", "data": {"id": "000000000000000000000"} }`

**Error Response**

- **Code:** 500

- **Content:** `{ "status": 500, "message": "Internal server error", "error": {"code":"INTERNAL_SERVER_ERROR","details":null,"message":"Internal server error"} }`

### Upload Room Image

This endpoint is used to upload an image for a room in the Occupi system. Only Admins can upload images.

- **URL**

`/api/upload-room-image`

- **Method**

`POST`

- **Request Form Data**

- **Content**

```copy
"image": image_data, // required
"roomId": "RM000" // required
```

**Success Response**

- **Code:** 200

- **Content:** `{ "status": 200, "message": "Successfully uploaded image!", "data": {"id": "000000000000000000000"} }`

**Error Response**

- **Code:** 500

- **Content:** `{ "status": 500, "message": "Internal server error", "error": {"code":"INTERNAL_SERVER_ERROR","details":null,"message":"Internal server error"} }`
1 change: 1 addition & 0 deletions occupi-backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (

require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/rabbitmq/amqp091-go v1.10.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect
Expand Down
2 changes: 2 additions & 0 deletions occupi-backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ github.com/newrelic/go-agent/v3 v3.33.1 h1:eWOtty43cyxrMKws4VNPdebgEB6ujFTf0yxPs
github.com/newrelic/go-agent/v3 v3.33.1/go.mod h1:SMdqPzE/ghkWdY0rYGSD7Clw2daK/XH6pUnVd4albg4=
github.com/newrelic/go-agent/v3/integrations/nrgin v1.3.1 h1:JoIIS37S/tW/6Y/5cGInNA7ngfd2lGsfX0HYh82UOPk=
github.com/newrelic/go-agent/v3/integrations/nrgin v1.3.1/go.mod h1:/EjSYMXsMO34+imRoQlPU5hFUlP+u/dwowF+OKMw8TQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/oliveroneill/exponent-server-sdk-golang v0.0.0-20210823140141-d050598be512 h1:/ZSmjwl1inqsiHMhn+sPlEtSHdVTf+TH3LNGGdMQ/vA=
github.com/oliveroneill/exponent-server-sdk-golang v0.0.0-20210823140141-d050598be512/go.mod h1:Isv/48UnAjtxS8FD80Bito3ZJqZRyIMxKARIEITfW4k=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
Expand Down
9 changes: 9 additions & 0 deletions occupi-backend/pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const (
IncompleteAuthCode = "INCOMPLETE_AUTH"
InternalServerErrorCode = "INTERNAL_SERVER_ERROR"
UnAuthorizedCode = "UNAUTHORIZED"
RequestEntityTooLargeCode = "REQUEST_ENTITY_TOO_LARGE"
Admin = "admin"
Basic = "basic"
AdminDBAccessOption = "authSource=admin"
Expand All @@ -22,4 +23,12 @@ const (
ConfirmIPAddress = "confirmIPAddress"
Off = "off"
On = "on"
ThumbnailRes = "thumbnail"
LowRes = "low"
MidRes = "mid"
HighRes = "high"
ThumbnailWidth = 200
LowWidth = 600
MidWidth = 1200
HighWidth = 2000
)
Loading

0 comments on commit d7b0c6e

Please sign in to comment.