Skip to content

Commit fda88b1

Browse files
committed
Merge the newly created changes from develop
2 parents 2b62ac9 + 6ae8470 commit fda88b1

File tree

6 files changed

+111
-69
lines changed

6 files changed

+111
-69
lines changed

api/controllers/course.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
)
1717

1818
var courseCollection *mongo.Collection = configs.GetCollection("courses")
19+
var trendsCourseCollection *mongo.Collection = configs.GetCollection("trends_course_sections")
1920

2021
// @Id courseSearch
2122
// @Router /course [get]
@@ -418,9 +419,8 @@ func TrendsCourseSectionSearch(c *gin.Context) {
418419
bson.D{{Key: "$sort", Value: bson.D{{Key: "_id", Value: 1}}}},
419420
}
420421

421-
trendsCollection := configs.GetCollection("trends_course_sections")
422422
// perform aggregation on the pipeline
423-
cursor, err := trendsCollection.Aggregate(ctx, pipeline)
423+
cursor, err := trendsCourseCollection.Aggregate(ctx, pipeline)
424424
if err != nil {
425425
// return error for any aggregation problem
426426
respondWithInternalError(c, err)

api/controllers/events.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ func EventsByBuilding(c *gin.Context) {
109109
// @Tags Events
110110
// @Description "Returns all sections with meetings on the specified date in the specified building and room"
111111
// @Produce json
112-
// @Param date path string true "ISO date of the set of events to get"
113-
// @Param building path string true "building abbreviation of the event location"
114-
// @Param room path string true "room number"
115-
// @Success 200 {object} schema.APIResponse[[]schema.SectionWithTime] "All sections with meetings on the specified date in the specified building and room"
116-
// @Failure 500 {object} schema.APIResponse[string] "A string describing the error"
117-
// @Failure 404 {object} schema.APIResponse[string] "A string describing the error"
112+
// @Param date path string true "ISO date of the set of events to get"
113+
// @Param building path string true "building abbreviation of the event location"
114+
// @Param room path string true "room number"
115+
// @Success 200 {object} schema.APIResponse[schema.RoomEvents[schema.SectionWithTime]] "All sections with meetings on the specified date in the specified building and room"
116+
// @Failure 500 {object} schema.APIResponse[string] "A string describing the error"
117+
// @Failure 404 {object} schema.APIResponse[string] "A string describing the error"
118118
func EventsByRoom(c *gin.Context) {
119119
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
120120
defer cancel()
@@ -124,7 +124,7 @@ func EventsByRoom(c *gin.Context) {
124124
room := c.Param("room")
125125

126126
var events schema.MultiBuildingEvents[schema.SectionWithTime]
127-
var foundSections []schema.SectionWithTime
127+
var eventsByRoom schema.RoomEvents[schema.SectionWithTime]
128128

129129
// find and parse matching date
130130
err := eventsCollection.FindOne(ctx, bson.M{"date": date}).Decode(&events)
@@ -143,15 +143,15 @@ func EventsByRoom(c *gin.Context) {
143143
if b.Building == building {
144144
for _, r := range b.Rooms {
145145
if r.Room == room {
146-
foundSections = r.Events
146+
eventsByRoom = r
147147
break
148148
}
149149
}
150150
break
151151
}
152152
}
153153

154-
if len(foundSections) == 0 {
154+
if eventsByRoom.Room == "" {
155155
c.JSON(http.StatusNotFound, schema.APIResponse[string]{
156156
Status: http.StatusNotFound,
157157
Message: "error",
@@ -160,20 +160,20 @@ func EventsByRoom(c *gin.Context) {
160160
return
161161
}
162162

163-
respond(c, http.StatusOK, "success", foundSections)
163+
respond(c, http.StatusOK, "success", eventsByRoom)
164164
}
165165

166166
// @Id sectionsByRoomDetailed
167167
// @Router /events/{date}/{building}/{room}/sections [get]
168168
// @Tags Events
169169
// @Description "Returns full section objects with meetings on the specified date in the specified building and room"
170170
// @Produce json
171-
// @Param date path string true "ISO date of the set of events to get"
172-
// @Param building path string true "building abbreviation of the event location"
173-
// @Param room path string true "room number"
174-
// @Success 200 {object} schema.APIResponse[[]schema.Section] "Full section objects with meetings on the specified date in the specified building and room"
175-
// @Failure 500 {object} schema.APIResponse[string] "A string describing the error"
176-
// @Failure 404 {object} schema.APIResponse[string] "A string describing the error"
171+
// @Param date path string true "ISO date of the set of events to get"
172+
// @Param building path string true "building abbreviation of the event location"
173+
// @Param room path string true "room number"
174+
// @Success 200 {object} schema.APIResponse[schema.RoomEvents[schema.Section]] "Full section objects with meetings on the specified date in the specified building and room"
175+
// @Failure 500 {object} schema.APIResponse[string] "A string describing the error"
176+
// @Failure 404 {object} schema.APIResponse[string] "A string describing the error"
177177
func SectionsByRoomDetailed(c *gin.Context) {
178178
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
179179
defer cancel()
@@ -183,6 +183,7 @@ func SectionsByRoomDetailed(c *gin.Context) {
183183
room := c.Param("room")
184184

185185
var events schema.MultiBuildingEvents[schema.SectionWithTime]
186+
var sectionsByRoom schema.RoomEvents[schema.Section]
186187

187188
// Step 1: Find events for the specified date
188189
err := eventsCollection.FindOne(ctx, bson.M{"date": date}).Decode(&events)
@@ -202,6 +203,7 @@ func SectionsByRoomDetailed(c *gin.Context) {
202203
if b.Building == building {
203204
for _, r := range b.Rooms {
204205
if r.Room == room {
206+
sectionsByRoom.Room = r.Room
205207
for _, event := range r.Events {
206208
sectionIDs = append(sectionIDs, event.Section)
207209
}
@@ -222,21 +224,19 @@ func SectionsByRoomDetailed(c *gin.Context) {
222224
}
223225

224226
// Step 3: Fetch full section objects from the sections collection
225-
sectionsCollection := configs.GetCollection("sections")
226-
cursor, err := sectionsCollection.Find(ctx, bson.M{"_id": bson.M{"$in": sectionIDs}})
227+
cursor, err := sectionCollection.Find(ctx, bson.M{"_id": bson.M{"$in": sectionIDs}})
227228
if err != nil {
228229
respondWithInternalError(c, err)
229230
return
230231
}
231232
defer cursor.Close(ctx)
232233

233-
var sections []schema.Section
234-
if err = cursor.All(ctx, &sections); err != nil {
234+
if err = cursor.All(ctx, &sectionsByRoom.Events); err != nil {
235235
respondWithInternalError(c, err)
236236
return
237237
}
238238

239-
if len(sections) == 0 {
239+
if len(sectionsByRoom.Events) == 0 {
240240
c.JSON(http.StatusNotFound, schema.APIResponse[string]{
241241
Status: http.StatusNotFound,
242242
Message: "error",
@@ -245,5 +245,5 @@ func SectionsByRoomDetailed(c *gin.Context) {
245245
return
246246
}
247247

248-
respond(c, http.StatusOK, "success", sections)
248+
respond(c, http.StatusOK, "success", sectionsByRoom)
249249
}

api/controllers/grades.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,11 @@ func gradesAggregation(flag string, c *gin.Context) {
203203
{Key: "subject_prefix", Value: prefix},
204204
{Key: "course_number", Value: number},
205205
}
206-
// Parse the queried document into the sample course
206+
207207
err = courseCollection.FindOne(ctx, sampleCourseFind).Decode(&sampleCourse)
208-
// If the error is not that there is no matching documents, throw an internal server error
209208
if err != nil && !errors.Is(err, mongo.ErrNoDocuments) {
209+
// If the error is not that there is no matching documents,
210+
// throw an internal server error
210211
respondWithInternalError(c, err)
211212
return
212213
}
@@ -216,24 +217,25 @@ func gradesAggregation(flag string, c *gin.Context) {
216217
typeRegexes := [14]string{"0[0-9][0-9]", "0W[0-9]", "0H[0-9]", "0L[0-9]", "5H[0-9]", "1[0-9][0-9]", "2[0-9][0-9]", "3[0-9][0-9]", "5[0-9][0-9]", "6[0-9][0-9]", "7[0-9][0-9]", "HN[0-9]", "HON", "[0-9]U[0-9]"}
217218
typeStrings := [14]string{"0xx", "0Wx", "0Hx", "0Lx", "5Hx", "1xx", "2xx", "3xx", "5xx", "6xx", "7xx", "HNx", "HON", "xUx"}
218219

219-
var branches []bson.D // for without section pipeline
220-
var withSectionBranches []bson.D // for with section pipeline
220+
var branches [14]bson.D // for without-section pipeline
221+
var withSectionBranches [14]bson.D // for with-section pipeline
222+
221223
for i, typeRegex := range typeRegexes {
222-
branches = append(branches, bson.D{
224+
branches[i] = bson.D{
223225
{Key: "case", Value: bson.D{{Key: "$regexMatch", Value: bson.D{
224226
{Key: "input", Value: "$sections.section_number"},
225227
{Key: "regex", Value: typeRegex},
226228
}}}},
227229
{Key: "then", Value: typeStrings[i]},
228-
})
230+
}
229231

230-
withSectionBranches = append(withSectionBranches, bson.D{
232+
withSectionBranches[i] = bson.D{
231233
{Key: "case", Value: bson.D{{Key: "$regexMatch", Value: bson.D{
232234
{Key: "input", Value: "$section_number"},
233235
{Key: "regex", Value: typeRegex},
234236
}}}},
235237
{Key: "then", Value: typeStrings[i]},
236-
})
238+
}
237239
}
238240

239241
// Stage to look up sections
@@ -293,7 +295,7 @@ func gradesAggregation(flag string, c *gin.Context) {
293295
{Key: "ix", Value: "$ix"},
294296
}
295297
if flag == "section_type" {
296-
// add section_type to _id to group grades by both academic_session and section_type
298+
// Add section_type to _id to group grades by both academic_session and section_type
297299
groupID = append(groupID, bson.E{Key: "section_type", Value: "$section_type"})
298300
}
299301
groupGradesStage := bson.D{
@@ -320,7 +322,7 @@ func gradesAggregation(flag string, c *gin.Context) {
320322
// Stage to group grade distribution
321323
var groupDistributionID any = "$_id.academic_session"
322324
if flag == "section_type" {
323-
// add the section-type criteria
325+
// Add the section-type criteria
324326
groupDistributionID = bson.D{
325327
{Key: "academic_section", Value: "$_id.academic_session"},
326328
{Key: "section_type", Value: "$_id.section_type"},

api/controllers/professor.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
)
1717

1818
var professorCollection *mongo.Collection = configs.GetCollection("professors")
19+
var trendsProfCollection *mongo.Collection = configs.GetCollection("trends_prof_sections")
1920

2021
// @Id professorSearch
2122
// @Router /professor [get]
@@ -454,9 +455,7 @@ func TrendsProfessorSectionSearch(c *gin.Context) {
454455
bson.D{{Key: "$sort", Value: bson.D{{Key: "_id", Value: 1}}}},
455456
}
456457

457-
trendsCollection := configs.GetCollection("trends_prof_sections")
458-
459-
cursor, err := trendsCollection.Aggregate(ctx, pipeline)
458+
cursor, err := trendsProfCollection.Aggregate(ctx, pipeline)
460459
if err != nil {
461460
respondWithInternalError(c, err)
462461
return

api/docs/docs.go

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ const docTemplate = `{
770770
"200": {
771771
"description": "All sections with meetings on the specified date in the specified building and room",
772772
"schema": {
773-
"$ref": "#/definitions/schema.APIResponse-array_schema_SectionWithTime"
773+
"$ref": "#/definitions/schema.APIResponse-schema_RoomEvents-schema_SectionWithTime"
774774
}
775775
},
776776
"404": {
@@ -825,7 +825,7 @@ const docTemplate = `{
825825
"200": {
826826
"description": "Full section objects with meetings on the specified date in the specified building and room",
827827
"schema": {
828-
"$ref": "#/definitions/schema.APIResponse-array_schema_Section"
828+
"$ref": "#/definitions/schema.APIResponse-schema_RoomEvents-schema_Section"
829829
}
830830
},
831831
"404": {
@@ -2898,23 +2898,6 @@ const docTemplate = `{
28982898
}
28992899
}
29002900
},
2901-
"schema.APIResponse-array_schema_SectionWithTime": {
2902-
"type": "object",
2903-
"properties": {
2904-
"data": {
2905-
"type": "array",
2906-
"items": {
2907-
"$ref": "#/definitions/schema.SectionWithTime"
2908-
}
2909-
},
2910-
"message": {
2911-
"type": "string"
2912-
},
2913-
"status": {
2914-
"type": "integer"
2915-
}
2916-
}
2917-
},
29182901
"schema.APIResponse-array_schema_TypedGradeData": {
29192902
"type": "object",
29202903
"properties": {
@@ -3044,6 +3027,34 @@ const docTemplate = `{
30443027
}
30453028
}
30463029
},
3030+
"schema.APIResponse-schema_RoomEvents-schema_Section": {
3031+
"type": "object",
3032+
"properties": {
3033+
"data": {
3034+
"$ref": "#/definitions/schema.RoomEvents-schema_Section"
3035+
},
3036+
"message": {
3037+
"type": "string"
3038+
},
3039+
"status": {
3040+
"type": "integer"
3041+
}
3042+
}
3043+
},
3044+
"schema.APIResponse-schema_RoomEvents-schema_SectionWithTime": {
3045+
"type": "object",
3046+
"properties": {
3047+
"data": {
3048+
"$ref": "#/definitions/schema.RoomEvents-schema_SectionWithTime"
3049+
},
3050+
"message": {
3051+
"type": "string"
3052+
},
3053+
"status": {
3054+
"type": "integer"
3055+
}
3056+
}
3057+
},
30473058
"schema.APIResponse-schema_Section": {
30483059
"type": "object",
30493060
"properties": {
@@ -3648,6 +3659,20 @@ const docTemplate = `{
36483659
}
36493660
}
36503661
},
3662+
"schema.RoomEvents-schema_Section": {
3663+
"type": "object",
3664+
"properties": {
3665+
"events": {
3666+
"type": "array",
3667+
"items": {
3668+
"$ref": "#/definitions/schema.Section"
3669+
}
3670+
},
3671+
"room": {
3672+
"type": "string"
3673+
}
3674+
}
3675+
},
36513676
"schema.RoomEvents-schema_SectionWithTime": {
36523677
"type": "object",
36533678
"properties": {

api/docs/swagger.yaml

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,6 @@ definitions:
7676
status:
7777
type: integer
7878
type: object
79-
schema.APIResponse-array_schema_SectionWithTime:
80-
properties:
81-
data:
82-
items:
83-
$ref: '#/definitions/schema.SectionWithTime'
84-
type: array
85-
message:
86-
type: string
87-
status:
88-
type: integer
89-
type: object
9079
schema.APIResponse-array_schema_TypedGradeData:
9180
properties:
9281
data:
@@ -170,6 +159,24 @@ definitions:
170159
status:
171160
type: integer
172161
type: object
162+
schema.APIResponse-schema_RoomEvents-schema_Section:
163+
properties:
164+
data:
165+
$ref: '#/definitions/schema.RoomEvents-schema_Section'
166+
message:
167+
type: string
168+
status:
169+
type: integer
170+
type: object
171+
schema.APIResponse-schema_RoomEvents-schema_SectionWithTime:
172+
properties:
173+
data:
174+
$ref: '#/definitions/schema.RoomEvents-schema_SectionWithTime'
175+
message:
176+
type: string
177+
status:
178+
type: integer
179+
type: object
173180
schema.APIResponse-schema_Section:
174181
properties:
175182
data:
@@ -565,6 +572,15 @@ definitions:
565572
room:
566573
type: string
567574
type: object
575+
schema.RoomEvents-schema_Section:
576+
properties:
577+
events:
578+
items:
579+
$ref: '#/definitions/schema.Section'
580+
type: array
581+
room:
582+
type: string
583+
type: object
568584
schema.RoomEvents-schema_SectionWithTime:
569585
properties:
570586
events:
@@ -1225,7 +1241,7 @@ paths:
12251241
description: All sections with meetings on the specified date in the specified
12261242
building and room
12271243
schema:
1228-
$ref: '#/definitions/schema.APIResponse-array_schema_SectionWithTime'
1244+
$ref: '#/definitions/schema.APIResponse-schema_RoomEvents-schema_SectionWithTime'
12291245
"404":
12301246
description: A string describing the error
12311247
schema:
@@ -1264,7 +1280,7 @@ paths:
12641280
description: Full section objects with meetings on the specified date in
12651281
the specified building and room
12661282
schema:
1267-
$ref: '#/definitions/schema.APIResponse-array_schema_Section'
1283+
$ref: '#/definitions/schema.APIResponse-schema_RoomEvents-schema_Section'
12681284
"404":
12691285
description: A string describing the error
12701286
schema:

0 commit comments

Comments
 (0)