diff --git a/pkg/entities/guild.go b/pkg/entities/guild.go index 71c71751..a8277574 100644 --- a/pkg/entities/guild.go +++ b/pkg/entities/guild.go @@ -31,17 +31,17 @@ func (e *Entity) CreateGuild(guild request.CreateGuildRequest) error { return err } - guilds, err := e.repo.DiscordGuilds.Gets() - if err != nil { - e.log.Errorf(err, "[e.CreateGuild] failed to get all guilds") - return err - } + // guilds, err := e.repo.DiscordGuilds.Gets() + // if err != nil { + // e.log.Errorf(err, "[e.CreateGuild] failed to get all guilds") + // return err + // } // notifiy new guild to discord - err = e.svc.Discord.NotifyNewGuild(guild.ID, len(guilds)) - if err != nil { - e.log.Errorf(err, "failed to notify new guild %s to discord", guild.ID) - } + // err = e.svc.Discord.NotifyNewGuild(guild.ID, len(guilds)) + // if err != nil { + // e.log.Errorf(err, "failed to notify new guild %s to discord", guild.ID) + // } return nil } diff --git a/pkg/handler/guild/guild.go b/pkg/handler/guild/guild.go index 3af9c3ec..71ee3b5d 100644 --- a/pkg/handler/guild/guild.go +++ b/pkg/handler/guild/guild.go @@ -186,3 +186,20 @@ func (h *Handler) ValidateUser(c *gin.Context) { c.JSON(http.StatusOK, response.CreateResponse(resp, nil, nil, nil)) } + +func (h *Handler) CreateGuild(c *gin.Context) { + var req request.CreateGuildRequest + if err := c.BindJSON(&req); err != nil { + h.log.Fields(logger.Fields{"guildID": req.ID, "name": req.Name}).Error(err, "[handler.CreateGuild] - failed to read JSON") + c.JSON(http.StatusBadRequest, response.CreateResponse[any](nil, nil, err, nil)) + return + } + + if err := h.entities.CreateGuild(req); err != nil { + h.log.Fields(logger.Fields{"req": req}).Error(err, "[handler.UpdateGuild] - failed to update guild") + c.JSON(http.StatusInternalServerError, response.CreateResponse[any](nil, nil, err, nil)) + return + } + + c.JSON(http.StatusOK, response.CreateResponse(response.ResponseMessage{Message: "OK"}, nil, nil, nil)) +} diff --git a/pkg/handler/guild/interface.go b/pkg/handler/guild/interface.go index 50bff785..46be9d73 100644 --- a/pkg/handler/guild/interface.go +++ b/pkg/handler/guild/interface.go @@ -4,6 +4,7 @@ import "github.com/gin-gonic/gin" type IHandler interface { GetGuilds(c *gin.Context) + CreateGuild(c *gin.Context) GetGuild(c *gin.Context) ListMyGuilds(c *gin.Context) UpdateGuild(c *gin.Context) diff --git a/pkg/routes/v1.go b/pkg/routes/v1.go index 4c6880a7..19e05a85 100644 --- a/pkg/routes/v1.go +++ b/pkg/routes/v1.go @@ -23,6 +23,7 @@ func NewRoutes(r *gin.Engine, h *handler.Handler, cfg config.Config) { guildGroup := v1.Group("/guilds") { guildGroup.GET("", h.Guild.GetGuilds) + guildGroup.POST("", h.Guild.CreateGuild) guildGroup.GET("/:guild_id", h.Guild.GetGuild) guildGroup.GET("/:guild_id/custom-tokens", h.ConfigDefi.ListAllCustomToken) guildGroup.GET("/user-managed", middleware.AuthGuard(cfg), h.Guild.ListMyGuilds)