Skip to content

Commit 2599ecd

Browse files
authored
Merge pull request #394 from Kumud-Arora/feature/combined-sections-trends
feat: add /combined/sections/trends endpoint
2 parents 88035af + a3109d9 commit 2599ecd

5 files changed

Lines changed: 102 additions & 0 deletions

File tree

api/controllers/trends.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ func TrendsProfessorSectionSearch(c *gin.Context) {
3939
trendsSectionSearch("Professor", c)
4040
}
4141

42+
// @Id trendsCombinedSectionSearch
43+
// @Router /combined/sections/trends [get]
44+
// @Tags Combined
45+
// @Description "Returns sections matching both course and professor criteria from the combined trends collection. Specialized high-speed convenience endpoint for UTD Trends internal use; limited query flexibility."
46+
// @Produce json
47+
// @Param course_number query string true "The course's official number"
48+
// @Param subject_prefix query string true "The course's subject prefix"
49+
// @Param first_name query string true "The professor's first name"
50+
// @Param last_name query string true "The professor's last name"
51+
// @Success 200 {object} schema.APIResponse[[]schema.Section] "A list of Sections"
52+
// @Failure 500 {object} schema.APIResponse[string] "A string describing the error"
53+
func TrendsCombinedSectionSearch(c *gin.Context) {
54+
trendsSectionSearch("Combined", c)
55+
}
56+
4257
// trendsSectionSearch handles trends-based section routes for both course and professor query.
4358
// Reduce the repetitiveness of routes whose aggregation behaviors are identical.
4459
// This is subject to change as requests might be more complex.
@@ -66,6 +81,15 @@ func trendsSectionSearch(flag string, c *gin.Context) {
6681
if err != nil {
6782
return
6883
}
84+
case "Combined":
85+
trendsCollection = configs.GetCollection("trends_course_and_prof_sections")
86+
trendsQuery = bson.M{
87+
"_id": bson.M{
88+
"course": c.Query("subject_prefix") + c.Query("course_number"),
89+
"prof_first": c.Query("first_name"),
90+
"prof_last": c.Query("last_name"),
91+
},
92+
}
6993
default:
7094
// This should never happen, but act as a fallback
7195
err = fmt.Errorf("invalid flag for trendsSectionSearch: %s", flag)

api/docs/docs.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,46 @@ const docTemplate = `{
317317
}
318318
}
319319
},
320+
"/combined/sections/trends": {
321+
"get": {
322+
"description": "\"Returns sections matching both course and professor criteria from the combined trends collection. Specialized high-speed convenience endpoint for UTD Trends internal use; limited query flexibility.\"",
320323
"/club/search": {
321324
"get": {
322325
"description": "\"Returns list of clubs matching the search string\"",
323326
"produces": [
324327
"application/json"
325328
],
326329
"tags": [
330+
"Combined"
331+
],
332+
"operationId": "trendsCombinedSectionSearch",
333+
"parameters": [
334+
{
335+
"type": "string",
336+
"description": "The course's official number",
337+
"name": "course_number",
338+
"in": "query",
339+
"required": true
340+
},
341+
{
342+
"type": "string",
343+
"description": "The course's subject prefix",
344+
"name": "subject_prefix",
345+
"in": "query",
346+
"required": true
347+
},
348+
{
349+
"type": "string",
350+
"description": "The professor's first name",
351+
"name": "first_name",
352+
"in": "query",
353+
"required": true
354+
},
355+
{
356+
"type": "string",
357+
"description": "The professor's last name",
358+
"name": "last_name",
359+
"in": "query",
327360
"Clubs"
328361
],
329362
"operationId": "clubSearch",
@@ -379,6 +412,9 @@ const docTemplate = `{
379412
],
380413
"responses": {
381414
"200": {
415+
"description": "A list of Sections",
416+
"schema": {
417+
"$ref": "#/definitions/schema.APIResponse-array_schema_Section"
382418
"description": "A club",
383419
"schema": {
384420
"$ref": "#/definitions/schema.APIResponse-schema_Club"

api/docs/swagger.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,31 @@ paths:
11841184
$ref: '#/definitions/schema.APIResponse-string'
11851185
tags:
11861186
- Events
1187+
/combined/sections/trends:
1188+
get:
1189+
description: '"Returns sections matching both course and professor criteria
1190+
from the combined trends collection. Specialized high-speed convenience endpoint
1191+
for UTD Trends internal use; limited query flexibility."'
1192+
operationId: trendsCombinedSectionSearch
1193+
parameters:
1194+
- description: The course's official number
1195+
in: query
1196+
name: course_number
1197+
required: true
1198+
type: string
1199+
- description: The course's subject prefix
1200+
in: query
1201+
name: subject_prefix
1202+
required: true
1203+
type: string
1204+
- description: The professor's first name
1205+
in: query
1206+
name: first_name
1207+
required: true
1208+
type: string
1209+
- description: The professor's last name
1210+
in: query
1211+
name: last_name
11871212
/club/{id}:
11881213
get:
11891214
description: '"Returns the directory info for given club."'
@@ -1225,6 +1250,9 @@ paths:
12251250
- application/json
12261251
responses:
12271252
"200":
1253+
description: A list of Sections
1254+
schema:
1255+
$ref: '#/definitions/schema.APIResponse-array_schema_Section'
12281256
description: List of matching clubs
12291257
schema:
12301258
$ref: '#/definitions/schema.APIResponse-array_schema_Club'
@@ -1237,6 +1265,7 @@ paths:
12371265
schema:
12381266
$ref: '#/definitions/schema.APIResponse-string'
12391267
tags:
1268+
- Combined
12401269
- Clubs
12411270
/course:
12421271
get:

api/routes/combined.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package routes
2+
3+
import (
4+
"github.com/UTDNebula/nebula-api/api/controllers"
5+
"github.com/gin-gonic/gin"
6+
)
7+
8+
func CombinedRoute(router *gin.Engine) {
9+
combinedGroup := router.Group("/combined")
10+
combinedGroup.OPTIONS("", controllers.Preflight)
11+
combinedGroup.GET("/sections/trends", controllers.TrendsCombinedSectionSearch)
12+
}

api/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func main() {
7878
routes.CourseRoute(router)
7979
routes.SectionRoute(router)
8080
routes.ProfessorRoute(router)
81+
routes.CombinedRoute(router)
8182
routes.GradesRoute(router)
8283
routes.AutocompleteRoute(router)
8384
routes.StorageRoute(router)

0 commit comments

Comments
 (0)