Skip to content

Commit b447a51

Browse files
committed
Modify the response data for event routes
1 parent 3179653 commit b447a51

File tree

2 files changed

+5
-18
lines changed

2 files changed

+5
-18
lines changed

api/controllers/events.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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,7 +160,7 @@ 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
@@ -222,8 +222,7 @@ func SectionsByRoomDetailed(c *gin.Context) {
222222
}
223223

224224
// 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}})
225+
cursor, err := sectionCollection.Find(ctx, bson.M{"_id": bson.M{"$in": sectionIDs}})
227226
if err != nil {
228227
respondWithInternalError(c, err)
229228
return

api/server.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import (
1111
"github.com/gin-gonic/gin"
1212
swaggerFiles "github.com/swaggo/files"
1313
ginSwagger "github.com/swaggo/gin-swagger"
14-
15-
"github.com/UTDNebula/nebula-api/api/controllers"
1614
)
1715

1816
// Unauthenticated placeholder endpoint for the built-in ginSwagger swagger documentation endpoint
@@ -111,13 +109,3 @@ func LogRequest(c *gin.Context) {
111109
log.Printf("%s %s %s", c.Request.Method, c.Request.URL.Path, c.Request.Host)
112110
c.Next()
113111
}
114-
115-
func EventsRoute(router *gin.Engine) {
116-
eventsGroup := router.Group("/events")
117-
{
118-
eventsGroup.GET("/:date", controllers.Events)
119-
eventsGroup.GET("/:date/:building", controllers.EventsByBuilding)
120-
eventsGroup.GET("/:date/:building/:room/sections", controllers.EventsByRoom)
121-
eventsGroup.GET("/:date/:building/:room/sections", controllers.SectionsByRoomDetailed)
122-
}
123-
}

0 commit comments

Comments
 (0)