Skip to content

Commit e2a95dd

Browse files
committed
Merge from origin/develop
2 parents f5d8968 + 9435f4f commit e2a95dd

File tree

9 files changed

+328
-29
lines changed

9 files changed

+328
-29
lines changed

api/configs/setup.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ func GetCollection(collectionName string) *mongo.Collection {
5656
return collection
5757
}
5858

59-
// Returns *options.FindOptions with a limit and offset applied. Produces an error if user-provided offset isn't able to be parsed.
59+
// Returns *options.FindOptions with a limit and offset applied.
60+
// Produces an error if user-provided offset isn't able to be parsed.
6061
func GetOptionLimit(query *bson.M, c *gin.Context) (*options.FindOptions, error) {
6162
delete(*query, "offset") // removes offset (if present) in query --offset is not field in collections
6263

api/controllers/astra.go

Lines changed: 103 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,117 @@ func AstraEvents(c *gin.Context) {
3232

3333
date := c.Param("date")
3434

35-
var astraEvents schema.MultiBuildingEvents[schema.AstraEvent]
35+
var astra_events schema.MultiBuildingEvents[schema.AstraEvent]
3636

3737
// Find astra event given date
38-
err := astraCollection.FindOne(ctx, bson.M{"date": date}).Decode(&astraEvents)
38+
err := astraCollection.FindOne(ctx, bson.M{"date": date}).Decode(&astra_events)
39+
if err != nil {
40+
respondWithInternalError(c, err)
41+
return
42+
}
43+
44+
respond(c, http.StatusOK, "success", astra_events)
45+
}
46+
47+
// @Id AstraEventsByBuilding
48+
// @Router /astra/{date}/{building} [get]
49+
// @Tags Events
50+
// @Description "Returns AstraEvent based on the input date and building name"
51+
// @Produce json
52+
// @Param date path string true "date (ISO format) to retrieve astra events"
53+
// @Param building path string true "building abbreviation of event locations"
54+
// @Success 200 {object} schema.APIResponse[schema.SingleBuildingEvents[schema.AstraEvent]] "All sections with meetings on the specified date in the specified building"
55+
// @Failure 500 {object} schema.APIResponse[string] "A string describing the error"
56+
// @Failure 404 {object} schema.APIResponse[string] "A string describing the error"
57+
func AstraEventsByBuilding(c *gin.Context) {
58+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
59+
defer cancel()
60+
61+
date := c.Param("date")
62+
building := c.Param("building")
63+
64+
var astra_events schema.MultiBuildingEvents[schema.AstraEvent]
65+
var astra_eventsByBuilding schema.SingleBuildingEvents[schema.AstraEvent]
66+
67+
// Find astra event given date
68+
err := astraCollection.FindOne(ctx, bson.M{"date": date}).Decode(&astra_events)
3969
if err != nil {
4070
if errors.Is(err, mongo.ErrNoDocuments) {
41-
astraEvents.Date = date
42-
astraEvents.Buildings = []schema.SingleBuildingEvents[schema.AstraEvent]{}
71+
astra_events.Date = date
72+
astra_events.Buildings = []schema.SingleBuildingEvents[schema.AstraEvent]{}
4373
} else {
4474
respondWithInternalError(c, err)
4575
return
4676
}
4777
}
4878

49-
respond(c, http.StatusOK, "success", astraEvents)
79+
//parse response for requested building
80+
for _, b := range astra_events.Buildings {
81+
if b.Building == building {
82+
astra_eventsByBuilding = b
83+
break
84+
}
85+
}
86+
87+
if astra_eventsByBuilding.Building == "" {
88+
respond(c, http.StatusNotFound, "error", "No events found for the specified building")
89+
return
90+
}
91+
92+
respond(c, http.StatusOK, "success", astra_eventsByBuilding)
93+
}
94+
95+
// @Id AstraEventsByBuildingandRoom
96+
// @Router /astra/{date}/{building}/{room} [get]
97+
// @Tags Events
98+
// @Description "Returns AstraEvent based on the input date building name and room number"
99+
// @Produce json
100+
// @Param date path string true "date (ISO format) to retrieve astra events"
101+
// @Param building path string true "building abbreviation of event locations"
102+
// @Param room path string true "room number for event"
103+
// @Success 200 {object} schema.APIResponse[schema.SingleBuildingEvents[schema.AstraEvent]] "All sections with meetings on the specified date in the specified building"
104+
// @Failure 500 {object} schema.APIResponse[string] "A string describing the error"
105+
// @Failure 404 {object} schema.APIResponse[string] "A string describing the error"
106+
func AstraEventsByBuildingAndRoom(c *gin.Context) {
107+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
108+
defer cancel()
109+
110+
date := c.Param("date")
111+
building := c.Param("building")
112+
room := c.Param("room")
113+
114+
var astra_events schema.MultiBuildingEvents[schema.AstraEvent]
115+
var roomEvents schema.RoomEvents[schema.AstraEvent]
116+
117+
// Find astra event given date
118+
err := astraCollection.FindOne(ctx, bson.M{"date": date}).Decode(&astra_events)
119+
if err != nil {
120+
if errors.Is(err, mongo.ErrNoDocuments) {
121+
astra_events.Date = date
122+
astra_events.Buildings = []schema.SingleBuildingEvents[schema.AstraEvent]{}
123+
} else {
124+
respondWithInternalError(c, err)
125+
return
126+
}
127+
}
128+
129+
//parse response for requested building and room
130+
for _, b := range astra_events.Buildings {
131+
if b.Building == building {
132+
for _, r := range b.Rooms {
133+
if r.Room == room {
134+
roomEvents = r
135+
break
136+
}
137+
}
138+
break
139+
}
140+
}
141+
142+
if roomEvents.Room == "" {
143+
respond(c, http.StatusNotFound, "error", "No rooms found for the specified building or event")
144+
return
145+
}
146+
147+
respond(c, http.StatusOK, "success", roomEvents)
50148
}

api/controllers/grades.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func GradesByProfessorID() gin.HandlerFunc {
156156
// base function, returns the grade distribution depending on type of flag
157157
func gradesAggregation(flag string, c *gin.Context) {
158158
var grades []schema.GradeData
159-
var results []map[string]interface{}
159+
var results []map[string]any
160160

161161
var sectionTypeGrades []schema.TypedGradeData // used to parse the response to section-type endpoints
162162

api/controllers/storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func DeleteObject(c *gin.Context) {
269269
return
270270
}
271271
err = objectHandle.Delete(ctx)
272-
if err != nil {
272+
if err != nil && !errors.Is(err, storage.ErrObjectNotExist) {
273273
respondWithInternalError(c, err)
274274
return
275275
}

api/docs/docs.go

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,109 @@ const docTemplate = `{
5050
}
5151
}
5252
},
53+
"/astra/{date}/{building}": {
54+
"get": {
55+
"description": "\"Returns AstraEvent based on the input date and building name\"",
56+
"produces": [
57+
"application/json"
58+
],
59+
"tags": [
60+
"Events"
61+
],
62+
"operationId": "AstraEventsByBuilding",
63+
"parameters": [
64+
{
65+
"type": "string",
66+
"description": "date (ISO format) to retrieve astra events",
67+
"name": "date",
68+
"in": "path",
69+
"required": true
70+
},
71+
{
72+
"type": "string",
73+
"description": "building abbreviation of event locations",
74+
"name": "building",
75+
"in": "path",
76+
"required": true
77+
}
78+
],
79+
"responses": {
80+
"200": {
81+
"description": "All sections with meetings on the specified date in the specified building",
82+
"schema": {
83+
"$ref": "#/definitions/schema.APIResponse-schema_SingleBuildingEvents-schema_AstraEvent"
84+
}
85+
},
86+
"404": {
87+
"description": "A string describing the error",
88+
"schema": {
89+
"$ref": "#/definitions/schema.APIResponse-string"
90+
}
91+
},
92+
"500": {
93+
"description": "A string describing the error",
94+
"schema": {
95+
"$ref": "#/definitions/schema.APIResponse-string"
96+
}
97+
}
98+
}
99+
}
100+
},
101+
"/astra/{date}/{building}/{room}": {
102+
"get": {
103+
"description": "\"Returns AstraEvent based on the input date building name and room number\"",
104+
"produces": [
105+
"application/json"
106+
],
107+
"tags": [
108+
"Events"
109+
],
110+
"operationId": "AstraEventsByBuildingandRoom",
111+
"parameters": [
112+
{
113+
"type": "string",
114+
"description": "date (ISO format) to retrieve astra events",
115+
"name": "date",
116+
"in": "path",
117+
"required": true
118+
},
119+
{
120+
"type": "string",
121+
"description": "building abbreviation of event locations",
122+
"name": "building",
123+
"in": "path",
124+
"required": true
125+
},
126+
{
127+
"type": "string",
128+
"description": "room number for event",
129+
"name": "room",
130+
"in": "path",
131+
"required": true
132+
}
133+
],
134+
"responses": {
135+
"200": {
136+
"description": "All sections with meetings on the specified date in the specified building",
137+
"schema": {
138+
"$ref": "#/definitions/schema.APIResponse-schema_SingleBuildingEvents-schema_AstraEvent"
139+
}
140+
},
141+
"404": {
142+
"description": "A string describing the error",
143+
"schema": {
144+
"$ref": "#/definitions/schema.APIResponse-string"
145+
}
146+
},
147+
"500": {
148+
"description": "A string describing the error",
149+
"schema": {
150+
"$ref": "#/definitions/schema.APIResponse-string"
151+
}
152+
}
153+
}
154+
}
155+
},
53156
"/autocomplete/dag": {
54157
"get": {
55158
"description": "\"Returns an aggregation of courses for use in generating autocomplete DAGs\"",
@@ -3069,6 +3172,20 @@ const docTemplate = `{
30693172
}
30703173
}
30713174
},
3175+
"schema.APIResponse-schema_SingleBuildingEvents-schema_AstraEvent": {
3176+
"type": "object",
3177+
"properties": {
3178+
"data": {
3179+
"$ref": "#/definitions/schema.SingleBuildingEvents-schema_AstraEvent"
3180+
},
3181+
"message": {
3182+
"type": "string"
3183+
},
3184+
"status": {
3185+
"type": "integer"
3186+
}
3187+
}
3188+
},
30723189
"schema.APIResponse-schema_SingleBuildingEvents-schema_SectionWithTime": {
30733190
"type": "object",
30743191
"properties": {

api/docs/swagger.yaml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ definitions:
186186
status:
187187
type: integer
188188
type: object
189+
schema.APIResponse-schema_SingleBuildingEvents-schema_AstraEvent:
190+
properties:
191+
data:
192+
$ref: '#/definitions/schema.SingleBuildingEvents-schema_AstraEvent'
193+
message:
194+
type: string
195+
status:
196+
type: integer
197+
type: object
189198
schema.APIResponse-schema_SingleBuildingEvents-schema_SectionWithTime:
190199
properties:
191200
data:
@@ -743,6 +752,78 @@ paths:
743752
$ref: '#/definitions/schema.APIResponse-string'
744753
tags:
745754
- Events
755+
/astra/{date}/{building}:
756+
get:
757+
description: '"Returns AstraEvent based on the input date and building name"'
758+
operationId: AstraEventsByBuilding
759+
parameters:
760+
- description: date (ISO format) to retrieve astra events
761+
in: path
762+
name: date
763+
required: true
764+
type: string
765+
- description: building abbreviation of event locations
766+
in: path
767+
name: building
768+
required: true
769+
type: string
770+
produces:
771+
- application/json
772+
responses:
773+
"200":
774+
description: All sections with meetings on the specified date in the specified
775+
building
776+
schema:
777+
$ref: '#/definitions/schema.APIResponse-schema_SingleBuildingEvents-schema_AstraEvent'
778+
"404":
779+
description: A string describing the error
780+
schema:
781+
$ref: '#/definitions/schema.APIResponse-string'
782+
"500":
783+
description: A string describing the error
784+
schema:
785+
$ref: '#/definitions/schema.APIResponse-string'
786+
tags:
787+
- Events
788+
/astra/{date}/{building}/{room}:
789+
get:
790+
description: '"Returns AstraEvent based on the input date building name and
791+
room number"'
792+
operationId: AstraEventsByBuildingandRoom
793+
parameters:
794+
- description: date (ISO format) to retrieve astra events
795+
in: path
796+
name: date
797+
required: true
798+
type: string
799+
- description: building abbreviation of event locations
800+
in: path
801+
name: building
802+
required: true
803+
type: string
804+
- description: room number for event
805+
in: path
806+
name: room
807+
required: true
808+
type: string
809+
produces:
810+
- application/json
811+
responses:
812+
"200":
813+
description: All sections with meetings on the specified date in the specified
814+
building
815+
schema:
816+
$ref: '#/definitions/schema.APIResponse-schema_SingleBuildingEvents-schema_AstraEvent'
817+
"404":
818+
description: A string describing the error
819+
schema:
820+
$ref: '#/definitions/schema.APIResponse-string'
821+
"500":
822+
description: A string describing the error
823+
schema:
824+
$ref: '#/definitions/schema.APIResponse-string'
825+
tags:
826+
- Events
746827
/autocomplete/dag:
747828
get:
748829
description: '"Returns an aggregation of courses for use in generating autocomplete

0 commit comments

Comments
 (0)