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
44 changes: 44 additions & 0 deletions api/controllers/games.go
Original file line number Diff line number Diff line change
@@ -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)
}
109 changes: 82 additions & 27 deletions api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\"",
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -2338,7 +2370,7 @@ const docTemplate = `{
"required": true
},
{
"description": "params for Signed URL",
"description": "Request body",
"name": "body",
"in": "body",
"required": true,
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -2951,6 +2975,17 @@ const docTemplate = `{
}
}
},
"schema.Letters": {
"type": "object",
"properties": {
"date": {
"type": "string"
},
"letters": {
"type": "string"
}
}
},
"schema.Location": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -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": {
Expand Down
88 changes: 61 additions & 27 deletions api/docs/swagger.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2240,7 +2274,7 @@ paths:
name: objectID
required: true
type: string
- description: Request body
- description: Request body
in: body
name: body
required: true
Expand Down
2 changes: 1 addition & 1 deletion api/routes/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions api/routes/games.go
Original file line number Diff line number Diff line change
@@ -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)
}
Loading
Loading