Skip to content

Commit 6558097

Browse files
authored
Merge branch 'develop' into develop
2 parents bf948fc + 864a5f1 commit 6558097

File tree

20 files changed

+1103
-275
lines changed

20 files changed

+1103
-275
lines changed

.github/workflows/go.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Set up Go
2626
uses: actions/setup-go@v4
2727
with:
28-
go-version: '1.23'
28+
go-version: '1.24'
2929
cache-dependency-path: "**/go.sum"
3030

3131
- name: Setup
@@ -50,7 +50,7 @@ jobs:
5050
- name: Set up Go
5151
uses: actions/setup-go@v4
5252
with:
53-
go-version: '1.23'
53+
go-version: '1.24'
5454
cache-dependency-path: "**\\go.sum"
5555

5656
- name: Check & Build

api/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# syntax=docker/dockerfile:1
22

3-
FROM docker.io/golang:1.23 AS builder
3+
FROM docker.io/golang:1.24 AS builder
44
WORKDIR /build
55

66
COPY ./configs ./configs

api/controllers/astra.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var astraCollection *mongo.Collection = configs.GetCollection("astra")
1919

2020
// @Id AstraEvents
2121
// @Router /astra/{date} [get]
22+
// @Tags Events
2223
// @Description "Returns AstraEvent based on the input date"
2324
// @Produce json
2425
// @Param date path string true "date (ISO format) to retrieve astra events"

api/controllers/autocomplete.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var DAGCollection *mongo.Collection = configs.GetCollection("DAG")
1919

2020
// @Id autocompleteDAG
2121
// @Router /autocomplete/dag [get]
22+
// @Tags Other
2223
// @Description "Returns an aggregation of courses for use in generating autocomplete DAGs"
2324
// @Produce json
2425
// @Success 200 {object} schema.APIResponse[[]schema.Autocomplete] "An aggregation of courses for use in generating autocomplete DAGs"

api/controllers/controller_utils.go

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,52 @@ import (
99
"github.com/getsentry/sentry-go"
1010
sentrygin "github.com/getsentry/sentry-go/gin"
1111
"github.com/gin-gonic/gin"
12+
"go.mongodb.org/mongo-driver/bson"
1213
"go.mongodb.org/mongo-driver/bson/primitive"
1314
)
1415

1516
// Sets the API's response to a request, producing valid JSON given a status code and data.
1617
func respond[T any](c *gin.Context, status int, message string, data T) {
17-
c.JSON(status, schema.APIResponse[T]{Status: status, Message: message, Data: data})
18+
c.JSON(
19+
status,
20+
schema.APIResponse[T]{
21+
Status: status,
22+
Message: message,
23+
Data: data,
24+
},
25+
)
26+
}
27+
28+
// Builds a MongoDB filter for type T based on the given flag search or byid
29+
func getQuery[T any](flag string, c *gin.Context) (bson.M, error) {
30+
switch flag {
31+
case "Search":
32+
q, err := schema.FilterQuery[T](c)
33+
if err != nil {
34+
respond(c, http.StatusBadRequest, "Invalid query parameters", err.Error())
35+
return nil, err
36+
}
37+
return q, nil
38+
39+
case "ById":
40+
objId, err := objectIDFromParam(c, "id")
41+
if err != nil {
42+
// objectIDFromParam already responds with 400 if conversion fails
43+
return nil, err
44+
}
45+
return bson.M{"_id": objId}, nil
46+
47+
default:
48+
err := fmt.Errorf("invalid flag for getQuery: %s", flag)
49+
respondWithInternalError(c, err)
50+
return nil, err
51+
}
1852
}
1953

2054
// Helper function for logging and responding to a generic internal server error.
2155
func respondWithInternalError(c *gin.Context, err error) {
22-
// Note that we use log.Output here to be able to set the stack depth to the frame above this one (2), which allows us to log the location this function was called from
56+
// Note that we use log.Output here to be able to set the stack depth to the frame above this one (2),
57+
// which allows us to log the location this function was called from
2358
log.Output(2, fmt.Sprintf("INTERNAL SERVER ERROR: %s", err.Error()))
2459
// Capture error with Sentry
2560
if hub := sentrygin.GetHubFromContext(c); hub != nil {
@@ -30,14 +65,19 @@ func respondWithInternalError(c *gin.Context, err error) {
3065
respond(c, http.StatusInternalServerError, "error", err.Error())
3166
}
3267

33-
// Attempts to convert the given parameter to an ObjectID for use with MongoDB. Automatically responds with http.StatusBadRequest if conversion fails.
68+
// Attempts to convert the given parameter to an ObjectID for use with MongoDB.
69+
// Automatically responds with http.StatusBadRequest if conversion fails.
3470
func objectIDFromParam(c *gin.Context, paramName string) (*primitive.ObjectID, error) {
3571
idHex := c.Param(paramName)
3672
objectId, convertIdErr := primitive.ObjectIDFromHex(idHex)
3773
if convertIdErr != nil {
3874
// Respond with an error if we can't covert successfully
3975
log.Println(convertIdErr)
40-
respond(c, http.StatusBadRequest, fmt.Sprintf("Parameter \"%s\" is not a valid ObjectID.", paramName), convertIdErr.Error())
76+
respond(c,
77+
http.StatusBadRequest,
78+
fmt.Sprintf("Parameter \"%s\" is not a valid ObjectID.", paramName),
79+
convertIdErr.Error(),
80+
)
4181
return nil, convertIdErr
4282
}
4383
return &objectId, nil

0 commit comments

Comments
 (0)