-
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.
implemented the ability to save emails in the databse
- Loading branch information
1 parent
919dc0a
commit d0ed986
Showing
6 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,10 +1,16 @@ | ||
DB_NAME=campus_db | ||
DB_ROOT_PASSWORD=secret_root_password | ||
DB_PORT=3306 | ||
|
||
APNS_KEY_ID= | ||
APNS_TEAM_ID= | ||
APNS_P8_FILE_PATH=/secrets/AuthKey_XXXX.p8 | ||
|
||
ENVIRONMENT=dev | ||
|
||
SENTRY_DSN= | ||
SENTRY_DSN= | ||
|
||
SMTP_PASSWORD= | ||
SMTP_URL= | ||
SMTP_USERNAME= | ||
SMTP_PORT= |
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 |
---|---|---|
|
@@ -13,6 +13,10 @@ services: | |
- APNS_KEY_ID=${APNS_KEY_ID} | ||
- APNS_TEAM_ID=${APNS_TEAM_ID} | ||
- APNS_P8_FILE_PATH=${APNS_P8_FILE_PATH} | ||
- SMTP_PASSWORD=${SMTP_PASSWORD} | ||
- SMTP_URL=${SMTP_URL:-postout.lrz.de} | ||
- SMTP_USERNAME=${SMTP_USERNAME:[email protected]} | ||
- SMTP_PORT=${SMTP_PORT:-587} | ||
volumes: | ||
- ./apns_auth_key.p8:${APNS_P8_FILE_PATH} | ||
depends_on: | ||
|
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package backend | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
pb "github.com/TUM-Dev/Campus-Backend/server/api" | ||
"github.com/TUM-Dev/Campus-Backend/server/model" | ||
log "github.com/sirupsen/logrus" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
"google.golang.org/protobuf/types/known/emptypb" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func (s *CampusServer) SendFeedback(ctx context.Context, req *pb.SendFeedbackRequest) (*emptypb.Empty, error) { | ||
if err := s.checkDevice(ctx); err != nil { | ||
return nil, err | ||
} | ||
|
||
reciever := "[email protected]" | ||
if req.Topic != "tca" { | ||
reciever = "[email protected]" | ||
} | ||
|
||
feedback := model.Feedback{ | ||
EmailId: sql.NullString{String: req.EmailId, Valid: true}, | ||
Receiver: sql.NullString{String: reciever, Valid: true}, | ||
ReplyTo: sql.NullString{String: req.Email, Valid: true}, | ||
Feedback: sql.NullString{String: req.Message, Valid: true}, | ||
ImageCount: req.ImageCount, | ||
Latitude: sql.NullFloat64{Float64: req.Latitude, Valid: true}, | ||
Longitude: sql.NullFloat64{Float64: req.Longitude, Valid: true}, | ||
AppVersion: sql.NullString{String: req.AppVersion, Valid: true}, | ||
OsVersion: sql.NullString{String: req.OsVersion, Valid: true}, | ||
} | ||
if err := s.db.Model(&model.Feedback{}).Create(&feedback).Error; err != nil { | ||
log.WithError(err).Error("Error while creating feedback") | ||
return nil, status.Error(codes.Internal, err.Error()) | ||
} | ||
|
||
return &emptypb.Empty{}, nil | ||
} | ||
|
||
func (s *CampusServer) SendFeedbackImage(stream pb.Campus_SendFeedbackImageServer) error { | ||
if err := s.checkDevice(stream.Context()); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package migration | ||
|
||
import ( | ||
"database/sql" | ||
"github.com/go-gormigrate/gormigrate/v2" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type Feedback struct { | ||
OsVersion sql.NullString `gorm:"column:os_version;type:text;null;"` | ||
AppVersion sql.NullString `gorm:"column:app_version;type:text;null;"` | ||
} | ||
|
||
// TableName sets the insert table name for this struct type | ||
func (n *Feedback) TableName() string { | ||
return "feedback" | ||
} | ||
|
||
// migrate20230826000000 | ||
// adds a "feedbackEmail" cron job that runs every 30 minutes. | ||
func (m TumDBMigrator) migrate20230826000000() *gormigrate.Migration { | ||
return &gormigrate.Migration{ | ||
ID: "20230826000000", | ||
Migrate: func(tx *gorm.DB) error { | ||
if err := tx.Migrator().AddColumn(&Feedback{}, "OsVersion"); err != nil { | ||
return err | ||
} | ||
return tx.Migrator().AddColumn(&Feedback{}, "AppVersion") | ||
}, | ||
|
||
Rollback: func(tx *gorm.DB) error { | ||
if err := tx.Migrator().DropColumn(&Feedback{}, "OsVersion"); err != nil { | ||
return err | ||
} | ||
return tx.Migrator().DropColumn(&Feedback{}, "AppVersion") | ||
}, | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package model | ||
|
||
import ( | ||
"database/sql" | ||
) | ||
|
||
type Feedback struct { | ||
Id int32 `gorm:"column:id;primary_key;AUTO_INCREMENT;type:int;not null;"` | ||
ImageCount int32 `gorm:"column:image_count;type:int;not null;"` | ||
EmailId sql.NullString `gorm:"column:email_id;type:text;null"` | ||
Receiver sql.NullString `gorm:"column:receiver;type:text;null"` | ||
ReplyTo sql.NullString `gorm:"column:reply_to;type:text;null"` | ||
Feedback sql.NullString `gorm:"column:feedback;type:text;null"` | ||
Latitude sql.NullFloat64 `gorm:"column:latitude;type:float;null;"` | ||
Longitude sql.NullFloat64 `gorm:"column:longitude;type:float;null;"` | ||
OsVersion sql.NullString `gorm:"column:os_version;type:text;null;"` | ||
AppVersion sql.NullString `gorm:"column:app_version;type:text;null;"` | ||
Timestamp sql.NullTime `gorm:"column:timestamp;type:timestamp;default:CURRENT_TIMESTAMP;null;"` | ||
} | ||
|
||
// TableName sets the insert table name for this struct type | ||
func (n *Feedback) TableName() string { | ||
return "feedback" | ||
} |