Skip to content

Commit

Permalink
fix: restore api create guild (#1255)
Browse files Browse the repository at this point in the history
  • Loading branch information
trkhoi authored Nov 28, 2023
1 parent 70d27ff commit 312c81c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pkg/entities/guild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
17 changes: 17 additions & 0 deletions pkg/handler/guild/guild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
1 change: 1 addition & 0 deletions pkg/handler/guild/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/routes/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 312c81c

Please sign in to comment.