Skip to content

Commit

Permalink
Student Clubs (#388)
Browse files Browse the repository at this point in the history
* implemented a student club scraping cronjob and db-migration

* implemented a GRPC access to said table

* tested if weird joinging of the ORM is now better
  • Loading branch information
CommanderStorm authored Jul 20, 2024
1 parent 0a14f38 commit d77fd75
Show file tree
Hide file tree
Showing 18 changed files with 4,566 additions and 225 deletions.
758 changes: 535 additions & 223 deletions server/api/tumdev/campus_backend.pb.go

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions server/api/tumdev/campus_backend.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions server/api/tumdev/campus_backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ service Campus {
rpc DeleteDevice(DeleteDeviceRequest) returns (DeleteDeviceReply) {
option (google.api.http) = {delete: "/device/{device_id}"};
}

// Delete a device from push notifications
rpc ListStudentClub(ListStudentClubRequest) returns (ListStudentClubReply) {
option (google.api.http) = {delete: "/student_clubs"};
}
}

enum DeviceType {
Expand Down Expand Up @@ -559,3 +564,22 @@ message GetCanteenHeadCountReply {
// A time stamp indicating how up to date the response is. Only valid in case percent != -1.
google.protobuf.Timestamp timestamp = 4;
}
message ListStudentClubRequest {}
message ListStudentClubReply {
repeated StudentClubCollection collections = 1;
}
message StudentClub {
// The name of the club
string name = 1;
// How the club describes itsself
optional string description = 2;
// Where the clubs main internet presence is
optional string link_url = 3;
// Where to find a image for this club
optional string cover_url = 4;
}
message StudentClubCollection {
string title = 1;
string description = 2;
repeated StudentClub clubs = 3;
}
74 changes: 74 additions & 0 deletions server/api/tumdev/campus_backend.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,29 @@
]
}
},
"/student_clubs": {
"delete": {
"summary": "Delete a device from push notifications",
"operationId": "Campus_ListStudentClub",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/apiListStudentClubReply"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"tags": [
"Campus"
]
}
},
"/updatenote/{version}": {
"get": {
"operationId": "Campus_GetUpdateNote",
Expand Down Expand Up @@ -1315,6 +1338,18 @@
}
}
},
"apiListStudentClubReply": {
"type": "object",
"properties": {
"collections": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/apiStudentClubCollection"
}
}
}
},
"apiMovie": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1551,6 +1586,45 @@
}
}
},
"apiStudentClub": {
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "The name of the club"
},
"description": {
"type": "string",
"title": "How the club describes itsself"
},
"linkUrl": {
"type": "string",
"title": "Where the clubs main internet presence is"
},
"coverUrl": {
"type": "string",
"title": "Where to find a image for this club"
}
}
},
"apiStudentClubCollection": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"description": {
"type": "string"
},
"clubs": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/apiStudentClub"
}
}
}
},
"apiTagsOverview": {
"type": "object",
"properties": {
Expand Down
40 changes: 40 additions & 0 deletions server/api/tumdev/campus_backend_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion server/backend/cron/cronjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
CanteenHeadcount = "canteenHeadCount"
MovieType = "movie"
FeedbackEmail = "feedbackEmail"
StudentClubType = "scrapeStudentClubs"

/* MensaType = "mensa"
AlarmType = "alarm" */
Expand All @@ -46,14 +47,15 @@ func (c *CronService) Run() error {
var res []model.Crontab

c.db.Model(&model.Crontab{}).
Find(&res, "`interval` > 0 AND (lastRun+`interval`) < ? AND type IN (?, ?, ?, ?, ?, ?)",
Find(&res, "`interval` > 0 AND (lastRun+`interval`) < ? AND type IN (?, ?, ?, ?, ?, ?, ?)",
time.Now().Unix(),
NewsType,
FileDownloadType,
DishNameDownload,
CanteenHeadcount,
MovieType,
FeedbackEmail,
StudentClubType,
)

for _, cronjob := range res {
Expand All @@ -66,6 +68,8 @@ func (c *CronService) Run() error {

// Run each job in a separate goroutine, so we can parallelize them
switch cronjob.Type.String {
case StudentClubType:
g.Go(func() error { return c.studentClubCron() })
case NewsType:
// if this is not copied here, this may not be threads save due to go's guarantees
// loop variable cronjob captured by func literal (govet)
Expand Down
Loading

0 comments on commit d77fd75

Please sign in to comment.