Skip to content

Commit

Permalink
Merge branch 'main' into chore/new-deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm authored Mar 12, 2024
2 parents fc2447b + 5deab4e commit 6883105
Show file tree
Hide file tree
Showing 20 changed files with 344 additions and 233 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ CAMPUS_API_TOKEN=

SMTP_PASSWORD=
SMTP_URL=
SMTP_FROM=
SMTP_USERNAME=
SMTP_PORT=
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ spec:
secretKeyRef:
name: backend-api-keys
key: SMTP_URL
- name: SMTP_FROM
valueFrom:
secretKeyRef:
name: backend-api-keys
key: SMTP_FROM
- name: SMTP_USERNAME
valueFrom:
secretKeyRef:
Expand Down Expand Up @@ -177,6 +182,7 @@ data:
APNS_TEAM_ID: {{ $.Values.backend.apns.team_id | b64enc }}
SMTP_PASSWORD: {{ $.Values.backend.smtp.password | b64enc }}
SMTP_URL: {{ $.Values.backend.smtp.url | b64enc }}
SMTP_FROM: {{ $.Values.backend.smtp.username | b64enc }}
SMTP_USERNAME: {{ $.Values.backend.smtp.username | b64enc }}
SMTP_PORT: {{ $.Values.backend.smtp.port | b64enc }}
---
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ services:
- CAMPUS_API_TOKEN=${CAMPUS_API_TOKEN}
- SMTP_PASSWORD=${SMTP_PASSWORD}
- SMTP_URL=${SMTP_URL:-postout.lrz.de}
- SMTP_USERNAME=${SMTP_USERNAME:[email protected]}
- SMTP_USERNAME=${SMTP_USERNAME:[email protected]}
- SMTP_FROM=${SMTP_FROM:[email protected]}
- SMTP_PORT=${SMTP_PORT:-587}
- MensaCronDisabled=true
volumes:
Expand Down
204 changes: 102 additions & 102 deletions server/api/tumdev/campus_backend.pb.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 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.

8 changes: 5 additions & 3 deletions server/api/tumdev/campus_backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ service Campus {
};
}

// Returns all dishes for a specific cafeteria, year, week and day
rpc ListDishes(ListDishesRequest) returns (ListDishesReply) {
option (google.api.http) = {
get: "/dish/allDishes",
get: "/dishes",
response_body: "dish"
};
}
Expand Down Expand Up @@ -389,9 +390,10 @@ message ListDishesRequest {
string canteen_id = 1;
// >=2022 until the current year
int32 year = 2;
// range 1 - 53
// Must be in the range 1 - 52
int32 week = 3;
// range 0 (Monday) - 4 (Friday)
// Day of the week
// Days must be in the range 0 (Monday) - 4 (Friday)
int32 day = 4;
}

Expand Down
115 changes: 58 additions & 57 deletions server/api/tumdev/campus_backend.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,63 +315,6 @@
]
}
},
"/dish/allDishes": {
"get": {
"operationId": "Campus_ListDishes",
"responses": {
"200": {
"description": "",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "canteenId",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "year",
"description": "\u003e=2022 until the current year",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "week",
"description": "range 1 - 53",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "day",
"description": "range 0 (Monday) - 4 (Friday)",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
}
],
"tags": [
"Campus"
]
}
},
"/dish/rating/allDishTags": {
"get": {
"operationId": "Campus_ListNameTags",
Expand Down Expand Up @@ -489,6 +432,64 @@
]
}
},
"/dishes": {
"get": {
"summary": "Returns all dishes for a specific cafeteria, year, week and day",
"operationId": "Campus_ListDishes",
"responses": {
"200": {
"description": "",
"schema": {
"type": "array",
"items": {
"type": "string"
}
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "canteenId",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "year",
"description": "\u003e=2022 until the current year",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "week",
"description": "Must be in the range 1 - 52",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "day",
"description": "Day of the week\nDays must be in the range 0 (Monday) - 4 (Friday)",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
}
],
"tags": [
"Campus"
]
}
},
"/feedback": {
"post": {
"operationId": "Campus_CreateFeedback",
Expand Down
2 changes: 2 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.

11 changes: 7 additions & 4 deletions server/backend/cafeteria.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,21 +642,24 @@ func (s *CampusServer) ListDishes(ctx context.Context, req *pb.ListDishesRequest
if req.Year < 2022 {
return &pb.ListDishesReply{}, status.Error(codes.Internal, "Years must be larger or equal to 2022 ") // currently, no previous values have been added
}
if req.Week < 1 || req.Week > 53 {
return &pb.ListDishesReply{}, status.Error(codes.Internal, "Weeks must be in the range 1 - 53")
if req.Week < 1 || req.Week > 52 {
return &pb.ListDishesReply{}, status.Error(codes.Internal, "Weeks must be in the range 1 - 52")
}
if req.Day < 0 || req.Day > 4 {
return &pb.ListDishesReply{}, status.Error(codes.Internal, "Days must be in the range 1 (Monday) - 4 (Friday)")
return &pb.ListDishesReply{}, status.Error(codes.Internal, "Days must be in the range 0 (Monday) - 4 (Friday)")
}

var requestStatus error = nil
var results []string
// the eat api has two types of ids, the enum ids (uppercase, with `_`) and the ids (lowercase, with `-`)
cafeteriaName := strings.ReplaceAll(strings.ToUpper(req.CanteenId), "-", "_")

err := s.db.WithContext(ctx).Table("dishes_of_the_week weekly").
Where("weekly.day = ? AND weekly.week = ? and weekly.year = ?", req.Day, req.Week, req.Year).
Select("weekly.dishID").
Joins("JOIN dish d ON d.dish = weekly.dishID").
Joins("JOIN cafeteria c ON c.cafeteria = d.cafeteriaID").
Where("c.name LIKE ?", req.CanteenId).
Where("c.name LIKE ?", cafeteriaName).
Select("d.name").
Find(&results).Error

Expand Down
2 changes: 1 addition & 1 deletion server/backend/cron/dish_name_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func downloadDailyDishes(c *CronService) {
for _, v := range result {
cafeteriaName := strings.Replace(strings.ToLower(v.Name), "_", "-", 10)

req := fmt.Sprintf("https://tum-dev.github.io/eat-api/%s/%d/%d.json", cafeteriaName, year, week)
req := fmt.Sprintf("https://tum-dev.github.io/eat-api/%s/%d/%02d.json", cafeteriaName, year, week)
log.WithField("req", req).Debug("Fetching menu")
var resp, err = http.Get(req)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions server/backend/cron/email_templates/feedback_body.gohtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1>Feedback via TumCampusApp:</h1>
{{ if .Feedback.Valid -}}
<b>Feedback via the TUM Campus App:</b>
{{ if .Feedback -}}
<blockquote>
{{- .Feedback.String -}}
{{- .Feedback -}}
</blockquote>
{{- else -}}
<i>no feedback provided</i>
Expand Down
6 changes: 3 additions & 3 deletions server/backend/cron/email_templates/feedback_body.txt.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feedback via TumCampusApp:
Feedback via the TUM Campus App:

{{ if .Feedback.Valid }}
{{- .Feedback.String -}}
{{ if .Feedback }}
{{- .Feedback -}}
{{ else -}}
no feedback provided
{{- end }}
Expand Down
38 changes: 33 additions & 5 deletions server/backend/cron/feedback_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cron

import (
"bytes"
"fmt"
htmlTemplate "html/template"
"os"
"strconv"
Expand Down Expand Up @@ -56,12 +57,12 @@ type MailHeaders struct {
func messageWithHeaders(feedback *model.Feedback) *gomail.Message {
m := gomail.NewMessage()
// From
m.SetAddressHeader("From", os.Getenv("SMTP_USERNAME"), "TUM Campus App")
m.SetAddressHeader("From", os.Getenv("SMTP_FROM"), "TUM Campus App")
// To
if feedback.Recipient.Valid {
m.SetHeader("To", feedback.Recipient.String)
if feedback.Recipient != "" {
m.SetHeader("To", feedback.Recipient)
} else {
m.SetHeader("To", "[email protected]")
m.SetHeader("To", "[email protected]") // should not ever happen as checked in the api
}
// ReplyTo
if feedback.ReplyTo.Valid {
Expand All @@ -74,10 +75,37 @@ func messageWithHeaders(feedback *model.Feedback) *gomail.Message {
m.SetDateHeader("Date", time.Now())
}
// Subject
m.SetHeader("Subject", "Feedback via Tum Campus App")
if feedback.Recipient == "[email protected]" {
versionString := "TCA"
if feedback.AppVersion.Valid {
versionString = fmt.Sprintf("TCA %s", feedback.AppVersion.String)
}
m.SetHeader("Subject", fmt.Sprintf("[%s] %s", truncate(versionString, 10), truncate(feedback.Feedback, 150)))
} else {
m.SetHeader("Subject", "Feedback via the TUM Campus App")
}

return m
}

func truncate(str string, length int) string {
if length <= 0 {
return ""
}
if len(str) <= length {
return str
}
truncated := ""
for i, char := range str {
if i >= length {
break
}
truncated += string(char)
}
truncated += ".."
return truncated
}

func generateTemplatedMail(parsedHtmlBody *htmlTemplate.Template, parsedTxtBody *textTemplate.Template, feedback *model.Feedback) (string, string, error) {
var htmlBodyBuffer bytes.Buffer
if err := parsedHtmlBody.Execute(&htmlBodyBuffer, feedback); err != nil {
Expand Down
Loading

0 comments on commit 6883105

Please sign in to comment.