Skip to content

Commit b809a42

Browse files
recursiveTurtlejpahm
andauthored
Astra route (#257)
* Simplify .gitignore * Update master workflow * Fix dockerfile * Update master host config * add astra route in server.go * astra controller and route * Fix conflicts w/ master branch --------- Co-authored-by: jpahm <20374744+jpahm@users.noreply.github.com>
1 parent 3b199d0 commit b809a42

File tree

5 files changed

+229
-1
lines changed

5 files changed

+229
-1
lines changed

api/controllers/astra.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package controllers
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"time"
7+
8+
"github.com/gin-gonic/gin"
9+
10+
"go.mongodb.org/mongo-driver/bson"
11+
"go.mongodb.org/mongo-driver/mongo"
12+
13+
"github.com/UTDNebula/nebula-api/api/configs"
14+
"github.com/UTDNebula/nebula-api/api/responses"
15+
"github.com/UTDNebula/nebula-api/api/schema"
16+
)
17+
18+
var astraCollection *mongo.Collection = configs.GetCollection("astra")
19+
20+
// @Id AstraEvents
21+
// @Router /astra/{date} [get]
22+
// @Description "Returns AstraEvent based on the input date"
23+
// @Produce json
24+
// @Param date path string true "date (ISO format) to retrieve astra events"
25+
// @Success 200 {array} schema.MultiBuildingEvents[schema.AstraEvent] "All AstraEvents with events on the inputted date"
26+
func AstraEvents(c *gin.Context) {
27+
//gin context has info about request and allows converting to json format
28+
29+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
30+
defer cancel() //make resources available if function returns before timeout
31+
32+
date := c.Param("date") //input date
33+
34+
var astra_events schema.MultiBuildingEvents[schema.AstraEvent] //stores astra events for input date
35+
36+
//find astra event given date
37+
err := astraCollection.FindOne(ctx, bson.M{"date": date}).Decode(&astra_events)
38+
39+
//if there is an error
40+
if err != nil {
41+
c.JSON(http.StatusInternalServerError, responses.ErrorResponse{Status: http.StatusInternalServerError, Message: "error", Data: err.Error()})
42+
return
43+
}
44+
//no error
45+
c.JSON(http.StatusOK, responses.MultiBuildingEventsResponse[schema.AstraEvent]{Status: http.StatusOK, Message: "success", Data: astra_events})
46+
}

api/docs/docs.go

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,35 @@ const docTemplate = `{
1515
"host": "{{.Host}}",
1616
"basePath": "{{.BasePath}}",
1717
"paths": {
18+
"/astra/{date}": {
19+
"get": {
20+
"description": "\"Returns AstraEvent based on the input date\"",
21+
"produces": [
22+
"application/json"
23+
],
24+
"operationId": "AstraEvents",
25+
"parameters": [
26+
{
27+
"type": "string",
28+
"description": "date (ISO format) to retrieve astra events",
29+
"name": "date",
30+
"in": "path",
31+
"required": true
32+
}
33+
],
34+
"responses": {
35+
"200": {
36+
"description": "All AstraEvents with events on the inputted date",
37+
"schema": {
38+
"type": "array",
39+
"items": {
40+
"$ref": "#/definitions/schema.MultiBuildingEvents-schema_AstraEvent"
41+
}
42+
}
43+
}
44+
}
45+
}
46+
},
1847
"/autocomplete/dag": {
1948
"get": {
2049
"description": "\"Returns an aggregation of courses for use in generating autocomplete DAGs\"",
@@ -1344,6 +1373,35 @@ const docTemplate = `{
13441373
}
13451374
}
13461375
},
1376+
"schema.AstraEvent": {
1377+
"type": "object",
1378+
"properties": {
1379+
"activity_name": {
1380+
"type": "string"
1381+
},
1382+
"capacity": {
1383+
"type": "number"
1384+
},
1385+
"current_state": {
1386+
"type": "string"
1387+
},
1388+
"end_date": {
1389+
"type": "string"
1390+
},
1391+
"meeting_type": {
1392+
"type": "string"
1393+
},
1394+
"not_allowed_usage_mask": {
1395+
"type": "number"
1396+
},
1397+
"start_date": {
1398+
"type": "string"
1399+
},
1400+
"usage_color": {
1401+
"type": "string"
1402+
}
1403+
}
1404+
},
13471405
"schema.Autocomplete": {
13481406
"type": "object",
13491407
"properties": {
@@ -1516,6 +1574,20 @@ const docTemplate = `{
15161574
}
15171575
}
15181576
},
1577+
"schema.MultiBuildingEvents-schema_AstraEvent": {
1578+
"type": "object",
1579+
"properties": {
1580+
"buildings": {
1581+
"type": "array",
1582+
"items": {
1583+
"$ref": "#/definitions/schema.SingleBuildingEvents-schema_AstraEvent"
1584+
}
1585+
},
1586+
"date": {
1587+
"type": "string"
1588+
}
1589+
}
1590+
},
15191591
"schema.MultiBuildingEvents-schema_SectionWithTime": {
15201592
"type": "object",
15211593
"properties": {
@@ -1577,6 +1649,20 @@ const docTemplate = `{
15771649
}
15781650
}
15791651
},
1652+
"schema.RoomEvents-schema_AstraEvent": {
1653+
"type": "object",
1654+
"properties": {
1655+
"events": {
1656+
"type": "array",
1657+
"items": {
1658+
"$ref": "#/definitions/schema.AstraEvent"
1659+
}
1660+
},
1661+
"room": {
1662+
"type": "string"
1663+
}
1664+
}
1665+
},
15801666
"schema.RoomEvents-schema_SectionWithTime": {
15811667
"type": "object",
15821668
"properties": {
@@ -1698,6 +1784,20 @@ const docTemplate = `{
16981784
}
16991785
}
17001786
},
1787+
"schema.SingleBuildingEvents-schema_AstraEvent": {
1788+
"type": "object",
1789+
"properties": {
1790+
"building": {
1791+
"type": "string"
1792+
},
1793+
"rooms": {
1794+
"type": "array",
1795+
"items": {
1796+
"$ref": "#/definitions/schema.RoomEvents-schema_AstraEvent"
1797+
}
1798+
}
1799+
}
1800+
},
17011801
"schema.SingleBuildingEvents-schema_SectionWithTime": {
17021802
"type": "object",
17031803
"properties": {
@@ -1761,7 +1861,7 @@ const docTemplate = `{
17611861
// SwaggerInfo holds exported Swagger Info so clients can modify it
17621862
var SwaggerInfo = &swag.Spec{
17631863
Version: "1.0.0",
1764-
Host: "",
1864+
Host: "api.utdnebula.com",
17651865
BasePath: "",
17661866
Schemes: []string{"http", "https"},
17671867
Title: "nebula-api",

api/docs/swagger.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,25 @@ definitions:
6060
role:
6161
type: string
6262
type: object
63+
schema.AstraEvent:
64+
properties:
65+
activity_name:
66+
type: string
67+
capacity:
68+
type: number
69+
current_state:
70+
type: string
71+
end_date:
72+
type: string
73+
meeting_type:
74+
type: string
75+
not_allowed_usage_mask:
76+
type: number
77+
start_date:
78+
type: string
79+
usage_color:
80+
type: string
81+
type: object
6382
schema.Autocomplete:
6483
properties:
6584
course_numbers:
@@ -173,6 +192,15 @@ definitions:
173192
start_time:
174193
type: string
175194
type: object
195+
schema.MultiBuildingEvents-schema_AstraEvent:
196+
properties:
197+
buildings:
198+
items:
199+
$ref: '#/definitions/schema.SingleBuildingEvents-schema_AstraEvent'
200+
type: array
201+
date:
202+
type: string
203+
type: object
176204
schema.MultiBuildingEvents-schema_SectionWithTime:
177205
properties:
178206
buildings:
@@ -213,6 +241,15 @@ definitions:
213241
type: string
214242
type: array
215243
type: object
244+
schema.RoomEvents-schema_AstraEvent:
245+
properties:
246+
events:
247+
items:
248+
$ref: '#/definitions/schema.AstraEvent'
249+
type: array
250+
room:
251+
type: string
252+
type: object
216253
schema.RoomEvents-schema_SectionWithTime:
217254
properties:
218255
events:
@@ -292,6 +329,15 @@ definitions:
292329
last_name:
293330
type: string
294331
type: object
332+
schema.SingleBuildingEvents-schema_AstraEvent:
333+
properties:
334+
building:
335+
type: string
336+
rooms:
337+
items:
338+
$ref: '#/definitions/schema.RoomEvents-schema_AstraEvent'
339+
type: array
340+
type: object
295341
schema.SingleBuildingEvents-schema_SectionWithTime:
296342
properties:
297343
building:
@@ -301,12 +347,32 @@ definitions:
301347
$ref: '#/definitions/schema.RoomEvents-schema_SectionWithTime'
302348
type: array
303349
type: object
350+
host: api.utdnebula.com
304351
info:
305352
contact: {}
306353
description: The public Nebula Labs API for access to pertinent UT Dallas data
307354
title: nebula-api
308355
version: 1.0.0
309356
paths:
357+
/astra/{date}:
358+
get:
359+
description: '"Returns AstraEvent based on the input date"'
360+
operationId: AstraEvents
361+
parameters:
362+
- description: date (ISO format) to retrieve astra events
363+
in: path
364+
name: date
365+
required: true
366+
type: string
367+
produces:
368+
- application/json
369+
responses:
370+
"200":
371+
description: All AstraEvents with events on the inputted date
372+
schema:
373+
items:
374+
$ref: '#/definitions/schema.MultiBuildingEvents-schema_AstraEvent'
375+
type: array
310376
/autocomplete/dag:
311377
get:
312378
description: '"Returns an aggregation of courses for use in generating autocomplete

api/routes/astra.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package routes
2+
3+
import (
4+
"github.com/UTDNebula/nebula-api/api/controllers"
5+
"github.com/gin-gonic/gin"
6+
)
7+
8+
func AstraRoute(router *gin.Engine) {
9+
//All routes related to astra events come here
10+
astraGroup := router.Group("/astra")
11+
12+
astraGroup.OPTIONS("", controllers.Preflight)
13+
astraGroup.GET(":date", controllers.AstraEvents)
14+
}

api/server.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func swagger_controller_placeholder() {}
2323
// @title nebula-api
2424
// @description The public Nebula Labs API for access to pertinent UT Dallas data
2525
// @version 1.0.0
26+
// @host api.utdnebula.com
2627
// @schemes http https
2728
// @x-google-backend {"address": "REDACTED"}
2829
// @x-google-endpoints [{"name": "nebula-api-2lntm5dxoflqn.apigateway.nebula-api-368223.cloud.goog", "allowCors": true}]
@@ -62,6 +63,7 @@ func main() {
6263
routes.StorageRoute(router)
6364
routes.RoomsRoute(router)
6465
routes.EventsRoute(router)
66+
routes.AstraRoute(router)
6567

6668
// Retrieve the port string to serve traffic on
6769
portString := configs.GetPortString()

0 commit comments

Comments
 (0)