Skip to content

Commit d20d5dc

Browse files
committed
Merge branch 'develop'
2 parents 3195a03 + c193422 commit d20d5dc

File tree

7 files changed

+323
-13
lines changed

7 files changed

+323
-13
lines changed

api/controllers/astra.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package controllers
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"time"
7+
8+
"github.com/gin-gonic/gin"
9+
10+
"go.mongodb.org/mongo-driver/bson"
11+
"go.mongodb.org/mongo-driver/mongo"
12+
13+
"github.com/UTDNebula/nebula-api/api/configs"
14+
"github.com/UTDNebula/nebula-api/api/responses"
15+
"github.com/UTDNebula/nebula-api/api/schema"
16+
)
17+
18+
var astraCollection *mongo.Collection = configs.GetCollection("astra")
19+
20+
// @Id AstraEvents
21+
// @Router /astra/{date} [get]
22+
// @Description "Returns AstraEvent based on the input date"
23+
// @Produce json
24+
// @Param date path string true "date (ISO format) to retrieve astra events"
25+
// @Success 200 {array} schema.MultiBuildingEvents[schema.AstraEvent] "All AstraEvents with events on the inputted date"
26+
func AstraEvents(c *gin.Context) {
27+
//gin context has info about request and allows converting to json format
28+
29+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
30+
defer cancel() //make resources available if function returns before timeout
31+
32+
date := c.Param("date") //input date
33+
34+
var astra_events schema.MultiBuildingEvents[schema.AstraEvent] //stores astra events for input date
35+
36+
//find astra event given date
37+
err := astraCollection.FindOne(ctx, bson.M{"date": date}).Decode(&astra_events)
38+
39+
//if there is an error
40+
if err != nil {
41+
c.JSON(http.StatusInternalServerError, responses.ErrorResponse{Status: http.StatusInternalServerError, Message: "error", Data: err.Error()})
42+
return
43+
}
44+
//no error
45+
c.JSON(http.StatusOK, responses.MultiBuildingEventsResponse[schema.AstraEvent]{Status: http.StatusOK, Message: "success", Data: astra_events})
46+
}

api/controllers/course.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ func CourseAll(c *gin.Context) {
139139

140140
// @Id courseSectionSearch
141141
// @Router /course/sections [get]
142-
// @Description "Returns all the sections of all the courses matching the query's string-typed key-value pairs"
142+
// @Description "Returns paginated list of sections of all the courses matching the query's string-typed key-value pairs. See former_offset and latter_offset for pagination details."
143143
// @Produce json
144+
// @Param former_offset query number false "The starting position of the current page of courses (e.g. For starting at the 17th course, former_offset=16)."
145+
// @Param latter_offset query number false "The starting position of the current page of sections (e.g. For starting at the 4th section, latter_offset=3)."
144146
// @Param course_number query string false "The course's official number"
145147
// @Param subject_prefix query string false "The course's subject prefix"
146148
// @Param title query string false "The course's title"
@@ -243,6 +245,9 @@ func courseSection(flag string, c *gin.Context) {
243245
// replace the courses with sections
244246
bson.D{{Key: "$replaceWith", Value: "$sections"}},
245247

248+
// keep order deterministic between calls
249+
bson.D{{Key: "$sort", Value: bson.D{{Key: "_id", Value: 1}}}},
250+
246251
// paginate the sections
247252
bson.D{{Key: "$skip", Value: paginateMap["latter_offset"]}},
248253
bson.D{{Key: "$limit", Value: paginateMap["limit"]}},

api/controllers/professor.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ func ProfessorAll(c *gin.Context) {
148148

149149
// @Id professorCourseSearch
150150
// @Router /professor/courses [get]
151-
// @Description "Returns all of the courses of all the professors matching the query's string-typed key-value pairs"
151+
// @Description "Returns paginated list of the courses of all the professors matching the query's string-typed key-value pairs. See former_offset and latter_offset for pagination details."
152152
// @Produce json
153+
// @Param former_offset query number false "The starting position of the current page of professors (e.g. For starting at the 17th professor, former_offset=16)."
154+
// @Param latter_offset query number false "The starting position of the current page of courses (e.g. For starting at the 4th course, latter_offset=3)."
153155
// @Param first_name query string false "The professor's first name"
154156
// @Param last_name query string false "The professor's last name"
155157
// @Param titles query string false "One of the professor's title"
@@ -252,6 +254,9 @@ func professorCourse(flag string, c *gin.Context) {
252254
// replace the combination of ids and courses with the courses entirely
253255
bson.D{{Key: "$replaceWith", Value: "$courses"}},
254256

257+
// keep order deterministic between calls
258+
bson.D{{Key: "$sort", Value: bson.D{{Key: "_id", Value: 1}}}},
259+
255260
// paginate the courses
256261
bson.D{{Key: "$skip", Value: paginateMap["latter_offset"]}},
257262
bson.D{{Key: "$limit", Value: paginateMap["limit"]}},
@@ -275,8 +280,10 @@ func professorCourse(flag string, c *gin.Context) {
275280

276281
// @Id professorSectionSearch
277282
// @Router /professor/sections [get]
278-
// @Description "Returns all of the sections of all the professors matching the query's string-typed key-value pairs"
283+
// @Description "Returns paginated list of the sections of all the professors matching the query's string-typed key-value pairs. See former_offset and latter_offset for pagination details."
279284
// @Produce json
285+
// @Param former_offset query number false "The starting position of the current page of professors (e.g. For starting at the 17th professor, former_offset=16)."
286+
// @Param latter_offset query number false "The starting position of the current page of sections (e.g. For starting at the 4th section, latter_offset=3)."
280287
// @Param first_name query string false "The professor's first name"
281288
// @Param last_name query string false "The professor's last name"
282289
// @Param titles query string false "One of the professor's title"
@@ -368,6 +375,9 @@ func professorSection(flag string, c *gin.Context) {
368375
// replace the combination of ids and sections with the sections entirely
369376
bson.D{{Key: "$replaceWith", Value: "$sections"}},
370377

378+
// keep order deterministic between calls
379+
bson.D{{Key: "$sort", Value: bson.D{{Key: "_id", Value: 1}}}},
380+
371381
// paginate the sections
372382
bson.D{{Key: "$skip", Value: paginateMap["latter_offset"]}},
373383
bson.D{{Key: "$limit", Value: paginateMap["limit"]}},

api/docs/docs.go

Lines changed: 140 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,35 @@ const docTemplate = `{
1515
"host": "{{.Host}}",
1616
"basePath": "{{.BasePath}}",
1717
"paths": {
18+
"/astra/{date}": {
19+
"get": {
20+
"description": "\"Returns AstraEvent based on the input date\"",
21+
"produces": [
22+
"application/json"
23+
],
24+
"operationId": "AstraEvents",
25+
"parameters": [
26+
{
27+
"type": "string",
28+
"description": "date (ISO format) to retrieve astra events",
29+
"name": "date",
30+
"in": "path",
31+
"required": true
32+
}
33+
],
34+
"responses": {
35+
"200": {
36+
"description": "All AstraEvents with events on the inputted date",
37+
"schema": {
38+
"type": "array",
39+
"items": {
40+
"$ref": "#/definitions/schema.MultiBuildingEvents-schema_AstraEvent"
41+
}
42+
}
43+
}
44+
}
45+
}
46+
},
1847
"/autocomplete/dag": {
1948
"get": {
2049
"description": "\"Returns an aggregation of courses for use in generating autocomplete DAGs\"",
@@ -137,12 +166,24 @@ const docTemplate = `{
137166
},
138167
"/course/sections": {
139168
"get": {
140-
"description": "\"Returns all the sections of all the courses matching the query's string-typed key-value pairs\"",
169+
"description": "\"Returns paginated list of sections of all the courses matching the query's string-typed key-value pairs. See former_offset and latter_offset for pagination details.\"",
141170
"produces": [
142171
"application/json"
143172
],
144173
"operationId": "courseSectionSearch",
145174
"parameters": [
175+
{
176+
"type": "number",
177+
"description": "The starting position of the current page of courses (e.g. For starting at the 17th course, former_offset=16).",
178+
"name": "former_offset",
179+
"in": "query"
180+
},
181+
{
182+
"type": "number",
183+
"description": "The starting position of the current page of sections (e.g. For starting at the 4th section, latter_offset=3).",
184+
"name": "latter_offset",
185+
"in": "query"
186+
},
146187
{
147188
"type": "string",
148189
"description": "The course's official number",
@@ -655,12 +696,24 @@ const docTemplate = `{
655696
},
656697
"/professor/courses": {
657698
"get": {
658-
"description": "\"Returns all of the courses of all the professors matching the query's string-typed key-value pairs\"",
699+
"description": "\"Returns paginated list of the courses of all the professors matching the query's string-typed key-value pairs. See former_offset and latter_offset for pagination details.\"",
659700
"produces": [
660701
"application/json"
661702
],
662703
"operationId": "professorCourseSearch",
663704
"parameters": [
705+
{
706+
"type": "number",
707+
"description": "The starting position of the current page of professors (e.g. For starting at the 17th professor, former_offset=16).",
708+
"name": "former_offset",
709+
"in": "query"
710+
},
711+
{
712+
"type": "number",
713+
"description": "The starting position of the current page of courses (e.g. For starting at the 4th course, latter_offset=3).",
714+
"name": "latter_offset",
715+
"in": "query"
716+
},
664717
{
665718
"type": "string",
666719
"description": "The professor's first name",
@@ -797,12 +850,24 @@ const docTemplate = `{
797850
},
798851
"/professor/sections": {
799852
"get": {
800-
"description": "\"Returns all of the sections of all the professors matching the query's string-typed key-value pairs\"",
853+
"description": "\"Returns paginated list of the sections of all the professors matching the query's string-typed key-value pairs. See former_offset and latter_offset for pagination details.\"",
801854
"produces": [
802855
"application/json"
803856
],
804857
"operationId": "professorSectionSearch",
805858
"parameters": [
859+
{
860+
"type": "number",
861+
"description": "The starting position of the current page of professors (e.g. For starting at the 17th professor, former_offset=16).",
862+
"name": "former_offset",
863+
"in": "query"
864+
},
865+
{
866+
"type": "number",
867+
"description": "The starting position of the current page of sections (e.g. For starting at the 4th section, latter_offset=3).",
868+
"name": "latter_offset",
869+
"in": "query"
870+
},
806871
{
807872
"type": "string",
808873
"description": "The professor's first name",
@@ -1344,6 +1409,35 @@ const docTemplate = `{
13441409
}
13451410
}
13461411
},
1412+
"schema.AstraEvent": {
1413+
"type": "object",
1414+
"properties": {
1415+
"activity_name": {
1416+
"type": "string"
1417+
},
1418+
"capacity": {
1419+
"type": "number"
1420+
},
1421+
"current_state": {
1422+
"type": "string"
1423+
},
1424+
"end_date": {
1425+
"type": "string"
1426+
},
1427+
"meeting_type": {
1428+
"type": "string"
1429+
},
1430+
"not_allowed_usage_mask": {
1431+
"type": "number"
1432+
},
1433+
"start_date": {
1434+
"type": "string"
1435+
},
1436+
"usage_color": {
1437+
"type": "string"
1438+
}
1439+
}
1440+
},
13471441
"schema.Autocomplete": {
13481442
"type": "object",
13491443
"properties": {
@@ -1516,6 +1610,20 @@ const docTemplate = `{
15161610
}
15171611
}
15181612
},
1613+
"schema.MultiBuildingEvents-schema_AstraEvent": {
1614+
"type": "object",
1615+
"properties": {
1616+
"buildings": {
1617+
"type": "array",
1618+
"items": {
1619+
"$ref": "#/definitions/schema.SingleBuildingEvents-schema_AstraEvent"
1620+
}
1621+
},
1622+
"date": {
1623+
"type": "string"
1624+
}
1625+
}
1626+
},
15191627
"schema.MultiBuildingEvents-schema_SectionWithTime": {
15201628
"type": "object",
15211629
"properties": {
@@ -1577,6 +1685,20 @@ const docTemplate = `{
15771685
}
15781686
}
15791687
},
1688+
"schema.RoomEvents-schema_AstraEvent": {
1689+
"type": "object",
1690+
"properties": {
1691+
"events": {
1692+
"type": "array",
1693+
"items": {
1694+
"$ref": "#/definitions/schema.AstraEvent"
1695+
}
1696+
},
1697+
"room": {
1698+
"type": "string"
1699+
}
1700+
}
1701+
},
15801702
"schema.RoomEvents-schema_SectionWithTime": {
15811703
"type": "object",
15821704
"properties": {
@@ -1698,6 +1820,20 @@ const docTemplate = `{
16981820
}
16991821
}
17001822
},
1823+
"schema.SingleBuildingEvents-schema_AstraEvent": {
1824+
"type": "object",
1825+
"properties": {
1826+
"building": {
1827+
"type": "string"
1828+
},
1829+
"rooms": {
1830+
"type": "array",
1831+
"items": {
1832+
"$ref": "#/definitions/schema.RoomEvents-schema_AstraEvent"
1833+
}
1834+
}
1835+
}
1836+
},
17011837
"schema.SingleBuildingEvents-schema_SectionWithTime": {
17021838
"type": "object",
17031839
"properties": {
@@ -1761,7 +1897,7 @@ const docTemplate = `{
17611897
// SwaggerInfo holds exported Swagger Info so clients can modify it
17621898
var SwaggerInfo = &swag.Spec{
17631899
Version: "1.0.0",
1764-
Host: "",
1900+
Host: "api.utdnebula.com",
17651901
BasePath: "",
17661902
Schemes: []string{"http", "https"},
17671903
Title: "nebula-api",

0 commit comments

Comments
 (0)