-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into unique-dishes
- Loading branch information
Showing
17 changed files
with
280 additions
and
220 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,10 +58,10 @@ func messageWithHeaders(feedback *model.Feedback) *gomail.Message { | |
// From | ||
m.SetAddressHeader("From", os.Getenv("SMTP_USERNAME"), "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 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,10 +23,10 @@ func TestIterate(t *testing.T) { | |
|
||
func fullFeedback() *model.Feedback { | ||
return &model.Feedback{ | ||
EmailId: null.StringFrom("magic-id"), | ||
Recipient: null.StringFrom("tca"), | ||
EmailId: "magic-id", | ||
Recipient: "tca", | ||
ReplyTo: null.StringFrom("[email protected]"), | ||
Feedback: null.StringFrom("This is a Test"), | ||
Feedback: "This is a Test", | ||
ImageCount: 1, | ||
Latitude: null.FloatFrom(0), | ||
Longitude: null.FloatFrom(0), | ||
|
@@ -38,10 +38,10 @@ func fullFeedback() *model.Feedback { | |
|
||
func emptyFeedback() *model.Feedback { | ||
return &model.Feedback{ | ||
EmailId: null.String{}, | ||
Recipient: null.String{}, | ||
EmailId: "", | ||
Recipient: "", | ||
ReplyTo: null.String{}, | ||
Feedback: null.String{}, | ||
Feedback: "", | ||
ImageCount: 0, | ||
Latitude: null.Float{}, | ||
Longitude: null.Float{}, | ||
|
@@ -56,7 +56,7 @@ func TestHeaderInstantiationWithFullFeedback(t *testing.T) { | |
fb := fullFeedback() | ||
m := messageWithHeaders(fb) | ||
assert.Equal(t, []string{`"TUM Campus App" <[email protected]>`}, m.GetHeader("From")) | ||
assert.Equal(t, []string{fb.Recipient.String}, m.GetHeader("To")) | ||
assert.Equal(t, []string{fb.Recipient}, m.GetHeader("To")) | ||
assert.Equal(t, []string{"[email protected]"}, m.GetHeader("Reply-To")) | ||
assert.Equal(t, []string{fb.Timestamp.Time.Format(time.RFC1123Z)}, m.GetHeader("Date")) | ||
assert.Equal(t, []string{"Feedback via Tum Campus App"}, m.GetHeader("Subject")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,10 +28,10 @@ func (s *CampusServer) CreateFeedback(stream pb.Campus_CreateFeedbackServer) err | |
log.WithError(err).Error("Error generating uuid") | ||
return status.Error(codes.Internal, "Error starting feedback submission") | ||
} | ||
feedback := &model.Feedback{EmailId: null.StringFrom(id.String())} | ||
feedback := &model.Feedback{EmailId: id.String(), Recipient: "[email protected]"} | ||
|
||
// download images | ||
dbPath := path.Join("feedback", feedback.EmailId.String) | ||
dbPath := path.Join("feedback", feedback.EmailId) | ||
var uploadedFilenames []*string | ||
for { | ||
req, err := stream.Recv() | ||
|
@@ -40,7 +40,7 @@ func (s *CampusServer) CreateFeedback(stream pb.Campus_CreateFeedbackServer) err | |
} | ||
if err != nil { | ||
log.WithError(err).Error("Error receiving feedback") | ||
deleteUploaded(feedback.EmailId.String) | ||
deleteUploaded(feedback.EmailId) | ||
return status.Error(codes.Internal, "Error receiving feedback") | ||
} | ||
mergeFeedback(feedback, req) | ||
|
@@ -53,6 +53,10 @@ func (s *CampusServer) CreateFeedback(stream pb.Campus_CreateFeedbackServer) err | |
} | ||
} | ||
feedback.ImageCount = int32(len(uploadedFilenames)) | ||
// validate feedback | ||
if feedback.Feedback == "" && feedback.ImageCount == 0 { | ||
return status.Error(codes.InvalidArgument, "Please attach an image or feedback for us") | ||
} | ||
// save feedback to db | ||
if err := s.db.WithContext(stream.Context()).Transaction(func(tx *gorm.DB) error { | ||
for _, filename := range uploadedFilenames { | ||
|
@@ -68,7 +72,7 @@ func (s *CampusServer) CreateFeedback(stream pb.Campus_CreateFeedbackServer) err | |
return tx.Create(feedback).Error | ||
}); err != nil { | ||
log.WithError(err).Error("Error creating feedback") | ||
deleteUploaded(feedback.EmailId.String) | ||
deleteUploaded(feedback.EmailId) | ||
return status.Error(codes.Internal, "Error creating feedback") | ||
} | ||
|
||
|
@@ -130,20 +134,20 @@ func inferFileName(mime *mimetype.MIME, dbPath string, counter int) (*string, *s | |
|
||
func mergeFeedback(feedback *model.Feedback, req *pb.CreateFeedbackRequest) { | ||
if req.Recipient.Enum() != nil { | ||
feedback.Recipient = null.StringFrom(receiverFromTopic(req.Recipient)) | ||
feedback.Recipient = receiverFromTopic(req.Recipient) | ||
} | ||
if req.OsVersion != "" { | ||
feedback.OsVersion = null.StringFrom(req.OsVersion) | ||
} | ||
if req.AppVersion != "" { | ||
feedback.AppVersion = null.StringFrom(req.AppVersion) | ||
} | ||
if req.Location != nil { | ||
if req.Location != nil && req.Location.Longitude != 0 && req.Location.Latitude != 0 { | ||
feedback.Longitude = null.FloatFrom(req.Location.Longitude) | ||
feedback.Latitude = null.FloatFrom(req.Location.Latitude) | ||
} | ||
if req.Message != "" { | ||
feedback.Feedback = null.StringFrom(req.Message) | ||
feedback.Feedback = req.Message | ||
} | ||
if req.FromEmail != "" { | ||
feedback.ReplyTo = null.StringFrom(req.FromEmail) | ||
|
Oops, something went wrong.