diff --git a/api/controllers/games.go b/api/controllers/games.go new file mode 100644 index 0000000..f144016 --- /dev/null +++ b/api/controllers/games.go @@ -0,0 +1,44 @@ +package controllers + +import ( + "context" + "net/http" + "time" + + "github.com/UTDNebula/nebula-api/api/configs" + + "github.com/UTDNebula/nebula-api/api/schema" + + "github.com/gin-gonic/gin" + + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" +) + +var lettersCollection *mongo.Collection = configs.GetCollection("letters") + +// @Id letters +// @Router /games/letters/{date} [get] +// @Description "Returns letters for the specified date" +// @Produce json +// @Param date path string true "ISO date of the letters to get" +// @Success 200 {object} schema.APIResponse[schema.Letters] "Letters for the specified date" +// @Failure 500 {object} schema.APIResponse[string] "A string describing the error" +func Letters(c *gin.Context) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + + date := c.Param("date") + + var letters schema.Letters + + defer cancel() + + // find and parse matching date + err := lettersCollection.FindOne(ctx, bson.M{"date": date}).Decode(&letters) + if err != nil { + respondWithInternalError(c, err) + return + } + + respond(c, http.StatusOK, "success", letters) +} diff --git a/api/docs/docs.go b/api/docs/docs.go index c5c7f26..9aec153 100644 --- a/api/docs/docs.go +++ b/api/docs/docs.go @@ -541,6 +541,38 @@ const docTemplate = `{ } } }, + "/games/letters/{date}": { + "get": { + "description": "\"Returns letters for the specified date\"", + "produces": [ + "application/json" + ], + "operationId": "letters", + "parameters": [ + { + "type": "string", + "description": "ISO date of the letters to get", + "name": "date", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Letters for the specified date", + "schema": { + "$ref": "#/definitions/schema.APIResponse-schema_Letters" + } + }, + "500": { + "description": "A string describing the error", + "schema": { + "$ref": "#/definitions/schema.APIResponse-string" + } + } + } + } + }, "/grades/overall": { "get": { "description": "\"Returns the overall grade distribution\"", @@ -1631,13 +1663,13 @@ const docTemplate = `{ "parameters": [ { "type": "number", - "description": "The starting position of the current page of sections (e.g. For starting at the 17th section, former_offset=16).", + "description": "The starting position of the current page of professors (e.g. For starting at the 17th professor, former_offset=16).", "name": "former_offset", "in": "query" }, { "type": "number", - "description": "The starting position of the current page of courses from the predefined page of sections (e.g. For starting at the 18th course, latter_offset=17).", + "description": "The starting position of the current page of sections (e.g. For starting at the 17th professor, offset=16).", "name": "latter_offset", "in": "query" }, @@ -1800,13 +1832,13 @@ const docTemplate = `{ "parameters": [ { "type": "number", - "description": "The starting position of the current page of sections (e.g. For starting at the 17th section, former_offset=16).", + "description": "The starting position of the current page of professors (e.g. For starting at the 17th professor, former_offset=16).", "name": "former_offset", "in": "query" }, { "type": "number", - "description": "The starting position of the current page of professors from the predefined page of sections (e.g. For starting at the 18th professor, latter_offset=17).", + "description": "The starting position of the current page of sections (e.g. For starting at the 17th professor, offset=16).", "name": "latter_offset", "in": "query" }, @@ -2338,7 +2370,7 @@ const docTemplate = `{ "required": true }, { - "description": "params for Signed URL", + "description": "Request body", "name": "body", "in": "body", "required": true, @@ -2393,28 +2425,6 @@ const docTemplate = `{ } }, "definitions": { - "schema.ObjectSignedURLBody": { - "description": "request body", - "type": "object", - "properties": { - "expiration": { - "description": "timestamp for when the signed URL will expire", - "type": "string" - }, - "headers": { - "description": "headers for signed URL", - "type": "array", - "items": { - "type": "string" - } - }, - "method": { - "description": "method to be used with signed URL", - "type": "string", - "example": "PUT" - } - } - }, "schema.APIResponse-array_int": { "type": "object", "properties": { @@ -2593,6 +2603,20 @@ const docTemplate = `{ } } }, + "schema.APIResponse-schema_Letters": { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/schema.Letters" + }, + "message": { + "type": "string" + }, + "status": { + "type": "integer" + } + } + }, "schema.APIResponse-schema_MultiBuildingEvents-schema_AstraEvent": { "type": "object", "properties": { @@ -2951,6 +2975,17 @@ const docTemplate = `{ } } }, + "schema.Letters": { + "type": "object", + "properties": { + "date": { + "type": "string" + }, + "letters": { + "type": "string" + } + } + }, "schema.Location": { "type": "object", "properties": { @@ -3103,6 +3138,26 @@ const docTemplate = `{ } } }, + "schema.ObjectSignedURLBody": { + "type": "object", + "properties": { + "expiration": { + "description": "timestamp for when the signed URL will expire", + "type": "string" + }, + "headers": { + "description": "headers for signed URL", + "type": "array", + "items": { + "type": "string" + } + }, + "method": { + "description": "method to be used with signed URL. For example, PUT", + "type": "string" + } + } + }, "schema.Professor": { "type": "object", "properties": { diff --git a/api/docs/swagger.yaml b/api/docs/swagger.yaml index 893001f..e3163fe 100644 --- a/api/docs/swagger.yaml +++ b/api/docs/swagger.yaml @@ -1,20 +1,4 @@ definitions: - schema.ObjectSignedURLBody: - description: request body - properties: - expiration: - description: timestamp for when the signed URL will expire - type: string - headers: - description: headers for signed URL - items: - type: string - type: array - method: - description: method to be used with signed URL - example: PUT - type: string - type: object schema.APIResponse-array_int: properties: data: @@ -130,6 +114,15 @@ definitions: status: type: integer type: object + schema.APIResponse-schema_Letters: + properties: + data: + $ref: '#/definitions/schema.Letters' + message: + type: string + status: + type: integer + type: object schema.APIResponse-schema_MultiBuildingEvents-schema_AstraEvent: properties: data: @@ -363,6 +356,13 @@ definitions: type: integer type: array type: object + schema.Letters: + properties: + date: + type: string + letters: + type: string + type: object schema.Location: properties: building: @@ -462,6 +462,20 @@ definitions: updated: type: string type: object + schema.ObjectSignedURLBody: + properties: + expiration: + description: timestamp for when the signed URL will expire + type: string + headers: + description: headers for signed URL + items: + type: string + type: array + method: + description: method to be used with signed URL. For example, PUT + type: string + type: object schema.Professor: properties: _id: @@ -1007,6 +1021,27 @@ paths: description: A string describing the error schema: $ref: '#/definitions/schema.APIResponse-string' + /games/letters/{date}: + get: + description: '"Returns letters for the specified date"' + operationId: letters + parameters: + - description: ISO date of the letters to get + in: path + name: date + required: true + type: string + produces: + - application/json + responses: + "200": + description: Letters for the specified date + schema: + $ref: '#/definitions/schema.APIResponse-schema_Letters' + "500": + description: A string describing the error + schema: + $ref: '#/definitions/schema.APIResponse-string' /grades/overall: get: description: '"Returns the overall grade distribution"' @@ -1773,8 +1808,7 @@ paths: $ref: '#/definitions/schema.APIResponse-string' /section/{id}/course: get: - description: '"Returns the course of the section with given - ID"' + description: '"Returns the course of the section with given ID"' operationId: sectionCourseById parameters: - description: ID of the section to get @@ -1855,13 +1889,13 @@ paths: for pagination details."' operationId: sectionCourseSearch parameters: - - description: The starting position of the current page of sections (e.g. - For starting at the 17th section, former_offset=16). + - description: The starting position of the current page of professors (e.g. + For starting at the 17th professor, former_offset=16). in: query name: former_offset type: number - - description: The starting position of the current page of courses (e.g. For - starting at the 4th course, latter_offset=3). + - description: The starting position of the current page of sections (e.g. For + starting at the 17th professor, offset=16). in: query name: latter_offset type: number @@ -1971,13 +2005,13 @@ paths: for pagination details."' operationId: sectionProfessorSearch parameters: - - description: The starting position of the current page of sections (e.g. - For starting at the 17th section, former_offset=16). + - description: The starting position of the current page of professors (e.g. + For starting at the 17th professor, former_offset=16). in: query name: former_offset type: number - - description: The starting position of the current page of professors (e.g. For - starting at the 4th professor, latter_offset=3). + - description: The starting position of the current page of sections (e.g. For + starting at the 17th professor, offset=16). in: query name: latter_offset type: number @@ -2240,7 +2274,7 @@ paths: name: objectID required: true type: string - - description: Request body + - description: Request body in: body name: body required: true diff --git a/api/routes/events.go b/api/routes/events.go index 7efb100..0120bc1 100644 --- a/api/routes/events.go +++ b/api/routes/events.go @@ -7,7 +7,7 @@ import ( ) func EventsRoute(router *gin.Engine) { - // All routes related to sections come here + // All routes related to coursebook events come here eventsGroup := router.Group("/events") eventsGroup.OPTIONS("", controllers.Preflight) diff --git a/api/routes/games.go b/api/routes/games.go new file mode 100644 index 0000000..4c48695 --- /dev/null +++ b/api/routes/games.go @@ -0,0 +1,15 @@ +package routes + +import ( + "github.com/gin-gonic/gin" + + "github.com/UTDNebula/nebula-api/api/controllers" +) + +func GamesRoute(router *gin.Engine) { + // All routes related to games come here + gamesGroup := router.Group("/games") + + gamesGroup.OPTIONS("", controllers.Preflight) + gamesGroup.GET("/letters/:date", controllers.Letters) +} diff --git a/api/server.go b/api/server.go index 2019eaf..6dc3fba 100644 --- a/api/server.go +++ b/api/server.go @@ -70,6 +70,7 @@ func main() { routes.EventsRoute(router) routes.AstraRoute(router) routes.MazevoRoute(router) + routes.GamesRoute(router) // Retrieve the port string to serve traffic on portString := configs.GetPortString()