diff --git a/server/backend/cron/emailTemplates/feedbackBody.gohtml b/server/backend/cron/emailTemplates/feedbackBody.gohtml index 4aa48e92..c4a2fc1d 100644 --- a/server/backend/cron/emailTemplates/feedbackBody.gohtml +++ b/server/backend/cron/emailTemplates/feedbackBody.gohtml @@ -1,36 +1,42 @@

Feedback via TumCampusApp:

+{{ if .Feedback.Valid }} +
+ {{ .Feedback.String }} +
+{{ end }} + - {{ if .Latitude }} + {{ if .Latitude.Valid }} {{ end }} - + - +
Inforation type Details
Nutzer-Standort - - latitude: {{ .Latitude }}, longitude: {{.Longitude}} + + latitude: {{ .Latitude.Float64 }}, longitude: {{ .Longitude.Float64 }}
OS-Version{{ if .OSVersion.Valid }}{{.OSVersion }}{{else}}unknown{{end}}{{ if .OsVersion.Valid }}{{.OsVersion.String }}{{else}}unknown{{end}}
App-Version{{ if .AppVersion.Valid }}{{.APPVersion }}{{else}}unknown{{end}}{{ if .AppVersion.Valid }}{{.APPVersion.String }}{{else}}unknown{{end}}
{{ if .ImageCount }}

Fotos:


    - {{ range .ImageCount }} + {{ range $val := Iterate .ImageCount }}
  1. - Foto ' . $x . ' + Foto {{ $val }}
  2. {{ end }}
diff --git a/server/backend/cron/emailTemplates/feedbackBody.txt.tmpl b/server/backend/cron/emailTemplates/feedbackBody.txt.tmpl index 1d61a41b..27761a8f 100644 --- a/server/backend/cron/emailTemplates/feedbackBody.txt.tmpl +++ b/server/backend/cron/emailTemplates/feedbackBody.txt.tmpl @@ -1 +1,20 @@ -Body with txt \ No newline at end of file +Feedback via TumCampusApp: + +{{- if .Feedback.Valid }} +{{ .Feedback.String }} +{{- end }} + +{{- if .Latitude.Valid }} + Nutzer-Standort: + latitude: {{ .Latitude.Float64 }}, longitude: {{ .Longitude.Float64 }} + https://www.google.com/maps/search/?api=1&query={{ .Latitude.Float64 }},{{ .Longitude.Float64 }} +{{- end }} + OS-Version: {{ if .OsVersion.Valid }}{{.OsVersion.String }}{{else}}unknown{{end}} + App-Version: {{ if .AppVersion.Valid }}{{.APPVersion.String }}{{else}}unknown{{end}} + +{{ if .ImageCount }} +Fotos: + {{- range $val := Iterate .ImageCount }} + - Foto {{ $val }}: https://app.tum.de/File/feedback/{{ $.Id }}/{{ $val }}.png + {{ end }} +{{ end }} diff --git a/server/backend/cron/feedbackEmail.go b/server/backend/cron/feedbackEmail.go index 52957a70..29abe6da 100644 --- a/server/backend/cron/feedbackEmail.go +++ b/server/backend/cron/feedbackEmail.go @@ -14,6 +14,15 @@ import ( ) import _ "embed" +func Iterate(count int32) []int32 { + var Items []int32 + var i int32 + for i = 0; i < count; i++ { + Items = append(Items, i) + } + return Items +} + //go:embed emailTemplates/feedbackBody.gohtml var htmlFeedbackBody string @@ -26,12 +35,13 @@ func (c *CronService) feedbackEmailCron() error { log.WithError(err).Fatal("could not get unprocessed feedback") return err } - parsedHtmlBody, err := htmlTemplate.New("htmlFeedbackBody").Parse(htmlFeedbackBody) + funcMap := textTemplate.FuncMap{"Iterate": Iterate} + parsedHtmlBody, err := htmlTemplate.New("htmlFeedbackBody").Funcs(funcMap).Parse(htmlFeedbackBody) if err != nil { log.WithError(err).Fatal("htmlFeedbackBody is not a valid template") return err } - parsedTxtBody, err := textTemplate.New("txtFeedbackBody").Parse(txtFeedbackBody) + parsedTxtBody, err := textTemplate.New("txtFeedbackBody").Funcs(funcMap).Parse(txtFeedbackBody) if err != nil { log.WithError(err).Fatal("txtFeedbackBody is not a valid template") return err diff --git a/server/backend/migration/20230826000000.go b/server/backend/migration/20230826000000.go index 0bfe5f0f..dd94953c 100644 --- a/server/backend/migration/20230826000000.go +++ b/server/backend/migration/20230826000000.go @@ -10,7 +10,7 @@ import ( type Feedback struct { Processed bool `gorm:"column:processed;type:boolean;default:false;not null;"` - OSVersion sql.NullString `gorm:"column:os_version;type:text;null;"` + OsVersion sql.NullString `gorm:"column:os_version;type:text;null;"` AppVersion sql.NullString `gorm:"column:app_version;type:text;null;"` } @@ -28,7 +28,7 @@ func (m TumDBMigrator) migrate20230826000000() *gormigrate.Migration { if err := tx.Migrator().AddColumn(&Feedback{}, "Processed"); err != nil { return err } - if err := tx.Migrator().AddColumn(&Feedback{}, "OSVersion"); err != nil { + if err := tx.Migrator().AddColumn(&Feedback{}, "OsVersion"); err != nil { return err } if err := tx.Migrator().AddColumn(&Feedback{}, "AppVersion"); err != nil { @@ -48,7 +48,7 @@ func (m TumDBMigrator) migrate20230826000000() *gormigrate.Migration { if err := tx.Migrator().DropColumn(&Feedback{}, "Processed"); err != nil { return err } - if err := tx.Migrator().DropColumn(&Feedback{}, "OSVersion"); err != nil { + if err := tx.Migrator().DropColumn(&Feedback{}, "OsVersion"); err != nil { return err } if err := tx.Migrator().DropColumn(&Feedback{}, "AppVersion"); err != nil {