From ee4f929d6c7e89d7277a8004cc9bdf4afa1e519c Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 18 May 2024 20:39:46 +0800 Subject: [PATCH] :bug: Bug fixes in update avatar --- .idea/workspace.xml | 68 ++++++++++++++++------------------------ pkg/cmd/main.go | 5 +++ pkg/server/avatar_api.go | 14 +++++++-- 3 files changed, 44 insertions(+), 43 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 7536419..a71933a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,24 +4,10 @@ - @@ -179,7 +164,8 @@ - true diff --git a/pkg/cmd/main.go b/pkg/cmd/main.go index f092b93..4dd3f45 100644 --- a/pkg/cmd/main.go +++ b/pkg/cmd/main.go @@ -53,6 +53,11 @@ func main() { log.Info().Msg("Successfully setup firebase communication.") } + // Connect other services + if err := grpc.ConnectPaperclip(); err != nil { + log.Fatal().Err(err).Msg("An error occurred when connecting to paperclip...") + } + // Server server.NewServer() go server.Listen() diff --git a/pkg/server/avatar_api.go b/pkg/server/avatar_api.go index 6cb6c53..2582e93 100644 --- a/pkg/server/avatar_api.go +++ b/pkg/server/avatar_api.go @@ -7,6 +7,7 @@ import ( "git.solsynth.dev/hydrogen/passport/pkg/database" "git.solsynth.dev/hydrogen/passport/pkg/grpc" "git.solsynth.dev/hydrogen/passport/pkg/models" + "git.solsynth.dev/hydrogen/passport/pkg/utils" "github.com/gofiber/fiber/v2" "github.com/samber/lo" ) @@ -15,7 +16,11 @@ func setAvatar(c *fiber.Ctx) error { user := c.Locals("principal").(models.Account) var data struct { - AttachmentID string `json:"attachment"` + AttachmentID string `json:"attachment" validate:"required"` + } + + if err := utils.BindAndValidate(c, &data); err != nil { + return err } if _, err := grpc.Attachments.CheckAttachmentExists(context.Background(), &pcpb.AttachmentLookupRequest{ @@ -36,8 +41,13 @@ func setAvatar(c *fiber.Ctx) error { func setBanner(c *fiber.Ctx) error { user := c.Locals("principal").(models.Account) + var data struct { - AttachmentID string `json:"attachment"` + AttachmentID string `json:"attachment" validate:"required"` + } + + if err := utils.BindAndValidate(c, &data); err != nil { + return err } if _, err := grpc.Attachments.CheckAttachmentExists(context.Background(), &pcpb.AttachmentLookupRequest{