Skip to content

Commit

Permalink
implemented the ability to save emails in the databse
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Aug 30, 2023
1 parent 919dc0a commit d0ed986
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .env
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=
4 changes: 4 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
53 changes: 53 additions & 0 deletions server/backend/feedback.go
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
}
38 changes: 38 additions & 0 deletions server/backend/migration/20230826000000.go
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")
},
}
}
1 change: 1 addition & 0 deletions server/backend/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (m TumDBMigrator) Migrate() error {
m.migrate20220713000000(),
m.migrate20221119131300(),
m.migrate20221210000000(),
m.migrate20230826000000(),
})
err := mig.Migrate()
return err
Expand Down
24 changes: 24 additions & 0 deletions server/model/feedback.go
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"
}

0 comments on commit d0ed986

Please sign in to comment.