Skip to content

Commit 09a3880

Browse files
committed
Refactor the sectionsByRoomDetailed and update the docs
1 parent b447a51 commit 09a3880

File tree

3 files changed

+90
-48
lines changed

3 files changed

+90
-48
lines changed

api/controllers/events.go

Lines changed: 17 additions & 16 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()
@@ -168,12 +168,12 @@ func EventsByRoom(c *gin.Context) {
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
}
@@ -229,13 +231,12 @@ func SectionsByRoomDetailed(c *gin.Context) {
229231
}
230232
defer cursor.Close(ctx)
231233

232-
var sections []schema.Section
233-
if err = cursor.All(ctx, &sections); err != nil {
234+
if err = cursor.All(ctx, &sectionsByRoom.Events); err != nil {
234235
respondWithInternalError(c, err)
235236
return
236237
}
237238

238-
if len(sections) == 0 {
239+
if len(sectionsByRoom.Events) == 0 {
239240
c.JSON(http.StatusNotFound, schema.APIResponse[string]{
240241
Status: http.StatusNotFound,
241242
Message: "error",
@@ -244,5 +245,5 @@ func SectionsByRoomDetailed(c *gin.Context) {
244245
return
245246
}
246247

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

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)