From 457d10fb6687d5680ca1c85774e53cf3a3f928b2 Mon Sep 17 00:00:00 2001 From: SystemGlitch Date: Fri, 10 May 2024 19:49:08 +0200 Subject: [PATCH] Return default profile picture if user has no profile picture --- database/model/user.go | 2 +- dto/user.go | 4 ++-- http/controller/user/user.go | 8 +++++++- main.go | 11 ++++++++--- resources/img/default_profile_picture.png | Bin 0 -> 17253 bytes service/storage/storage.go | 12 +++++++++--- service/user/user.go | 6 +++--- 7 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 resources/img/default_profile_picture.png diff --git a/database/model/user.go b/database/model/user.go index f23cb27..69bd6ec 100644 --- a/database/model/user.go +++ b/database/model/user.go @@ -9,7 +9,7 @@ import ( type User struct { Email string Username string - Avatar string + Avatar null.String Password string CreatedAt time.Time `json:"createdAt"` UpdatedAt null.Time `json:"updatedAt"` diff --git a/dto/user.go b/dto/user.go index 3c21ec5..13d4552 100644 --- a/dto/user.go +++ b/dto/user.go @@ -19,8 +19,8 @@ type User struct { // InternalUser contains private user info that should not be exposed to clients. type InternalUser struct { - Avatar string `json:"avatar"` - Password string `json:"password"` + Avatar null.String `json:"avatar"` + Password string `json:"password"` User } diff --git a/http/controller/user/user.go b/http/controller/user/user.go index 2f12701..2691da1 100644 --- a/http/controller/user/user.go +++ b/http/controller/user/user.go @@ -23,6 +23,7 @@ type Service interface { type StorageService interface { GetFS() fs.StatFS + GetEmbedImagesFS() fs.StatFS } type Controller struct { @@ -68,7 +69,12 @@ func (ctrl *Controller) ShowAvatar(response *goyave.Response, request *goyave.Re return } - response.File(ctrl.StorageService.GetFS(), user.Avatar) + if !user.Avatar.Valid { + response.File(ctrl.StorageService.GetEmbedImagesFS(), "default_profile_picture.png") + return + } + + response.File(ctrl.StorageService.GetFS(), user.Avatar.String) } func (ctrl *Controller) Register(response *goyave.Response, request *goyave.Request) { diff --git a/main.go b/main.go index c28d498..9bbde17 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,11 @@ func main() { fmt.Fprintln(os.Stderr, err.(*errors.Error).String()) os.Exit(1) } + imgFS, err := resources.Sub("resources/img") + if err != nil { + fmt.Fprintln(os.Stderr, err.(*errors.Error).String()) + os.Exit(1) + } opts := goyave.Options{ LangFS: langFS, @@ -58,7 +63,7 @@ func main() { s.Logger.Info("Server is shutting down") }) - registerServices(server) + registerServices(server, imgFS) server.Logger.Info("Registering routes") server.RegisterRoutes(route.Register) @@ -74,7 +79,7 @@ func main() { } } -func registerServices(server *goyave.Server) { +func registerServices(server *goyave.Server, imgFS fsutil.Embed) { server.Logger.Info("Registering services") session := session.GORM(server.DB(), nil) @@ -86,7 +91,7 @@ func registerServices(server *goyave.Server) { if err != nil { panic(errors.New(err)) } - storageService := storage.NewService(storageFS) + storageService := storage.NewService(storageFS, imgFS) server.RegisterService(storageService) server.RegisterService(user.NewService(session, server.Logger, userRepo, storageService)) diff --git a/resources/img/default_profile_picture.png b/resources/img/default_profile_picture.png new file mode 100644 index 0000000000000000000000000000000000000000..31dc9315eac71ee69934ad1f8221c56182acd701 GIT binary patch literal 17253 zcmeHvRalf?)bBgP07D~)Gz@|$jdZ613L+xiC?VZl14t-{AR;9o(jlNo*B~h!5;DRN z(%m({dB^|FxjeV$d%g=F@!fl`z2djlUVE*Lue3B($%q+<0RSL-pmt9i0H8?RA2^g00lq+3jhM7f!`Hk!4J`QLCSZ*8Hi4BsGUv$K+=J8DW8Lrp8fBn|A8uC3Gk^- zQn`U|adN@R(V6l?DOH5Lm92W%JDP!sJvvrbfyMIpcRF{E=Dbn&c6#xLqr3_-~|6amr zWGb3A7$3I`0l+m_ChwebakP`2SN+JAcOLc25wZZPgEJ}>|F?;PRD~6`@|Z1xv-4li zyEHr2aVwCosG`Q3WUEn?5+ovj&Vp8t390JQ&U8j6qSMEJro|WYjS^!@7*GA(xC)kO z-QD#Paz@MDPZo8K-Zpp7%zd3^sqIp|ZR@^qdGXzy&35aYM}NXS$T-QU$+GMFrwxLw z6j`6XP@;h0yNL=`{&2)0C`A!9;jh7L+k|BnLT#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s4qQn;%D9Icc{XxX_PwKIdetU@2RsIY@2?>qX54#v7{SY81I(iB z7maG`PAV!HWpSKXd)7BeykIG)5;BzO15mft0Nb@)bT4KTAEc^(HL-rY&{i;=l9Cxy zf6)SH(YJ*TIkd=eb=5If?RC>iUISW2fN#4tqreNG@KaG;#Ea5WdN?0o#t-C=@2WmF zZ+9X?09ulE!7lc&2ahtq7l1I-cG7E=43sg_v?M0eARNnuYcSD&2B6V7~8gtzPTj~KtBD5tOP)J6erR8w}>{X z|2gjSJoq`w11;7M|9{EK>NQEDU zYH1-S095YrpWdW}A^=nh*Z>1M!PYn+XajaQkaxj?JrD~%;{q)Da80e};0p?XPWbgAX-GYQxV14#F3Sh}U$;YfP$|BFbu22%e2?FXV66YsL+!fS~*aUR^)yjP}V5%zxo D4maS) literal 0 HcmV?d00001 diff --git a/service/storage/storage.go b/service/storage/storage.go index b5cae7b..5453193 100644 --- a/service/storage/storage.go +++ b/service/storage/storage.go @@ -15,15 +15,21 @@ type FS interface { } type Service struct { - FS FS + FS FS + EmbedImagesFS fs.StatFS } -func NewService(fs FS) *Service { +func NewService(fs FS, imgFS fs.StatFS) *Service { return &Service{ - FS: fs, + FS: fs, + EmbedImagesFS: imgFS, } } +func (s *Service) GetEmbedImagesFS() fs.StatFS { + return s.EmbedImagesFS +} + func (s *Service) GetFS() fs.StatFS { return s.FS } diff --git a/service/user/user.go b/service/user/user.go index 1868f6a..cc9ab62 100644 --- a/service/user/user.go +++ b/service/user/user.go @@ -82,12 +82,12 @@ func (s *Service) Register(ctx context.Context, registerDTO *dto.RegisterUser) e if err != nil { return errors.New(err) } - user.Avatar = filename + user.Avatar.SetValid(filename) } _, err = s.Repository.Create(ctx, user) - if err != nil { - if err := s.StorageService.Delete(user.Avatar); err != nil { + if err != nil && user.Avatar.Valid { + if err := s.StorageService.Delete(user.Avatar.String); err != nil { s.Logger.Error(errors.New(err)) } }