Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  fix: add retry nghenhan service (#1278)
  feat: mock API - global profile info
  • Loading branch information
trkhoi committed Dec 13, 2023
2 parents 956a849 + 8b87fa3 commit b275c84
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 24 deletions.
49 changes: 49 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5001,6 +5001,38 @@ const docTemplate = `{
}
}
},
"/profiles/{profile_id}/global-info": {
"get": {
"description": "Get profile's global info",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Profile"
],
"summary": "Get profile's global info",
"parameters": [
{
"type": "string",
"description": "profile ID",
"name": "profile_id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.GetGlobalProfileInfoResponse"
}
}
}
}
},
"/swap": {
"post": {
"description": "Execute swap token",
Expand Down Expand Up @@ -10035,6 +10067,23 @@ const docTemplate = `{
}
}
},
"response.GetGlobalProfileInfoResponse": {
"type": "object",
"properties": {
"level": {
"type": "integer"
},
"rank": {
"type": "integer"
},
"roles": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"response.GetGmConfigResponse": {
"type": "object",
"properties": {
Expand Down
49 changes: 49 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4993,6 +4993,38 @@
}
}
},
"/profiles/{profile_id}/global-info": {
"get": {
"description": "Get profile's global info",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Profile"
],
"summary": "Get profile's global info",
"parameters": [
{
"type": "string",
"description": "profile ID",
"name": "profile_id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.GetGlobalProfileInfoResponse"
}
}
}
}
},
"/swap": {
"post": {
"description": "Execute swap token",
Expand Down Expand Up @@ -10027,6 +10059,23 @@
}
}
},
"response.GetGlobalProfileInfoResponse": {
"type": "object",
"properties": {
"level": {
"type": "integer"
},
"rank": {
"type": "integer"
},
"roles": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"response.GetGmConfigResponse": {
"type": "object",
"properties": {
Expand Down
54 changes: 43 additions & 11 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,17 @@ definitions:
to:
type: string
type: object
response.GetGlobalProfileInfoResponse:
properties:
level:
type: integer
rank:
type: integer
roles:
items:
type: string
type: array
type: object
response.GetGmConfigResponse:
properties:
data:
Expand Down Expand Up @@ -2762,14 +2773,14 @@ definitions:
type: string
usd:
type: number
usd_14d_change:
type: number
usd_1h_change:
type: number
usd_1y_change:
type: number
usd_7d_change:
type: number
usd_14d_change:
type: number
usd_24h_change:
type: number
usd_24h_vol:
Expand Down Expand Up @@ -3390,27 +3401,27 @@ definitions:
additionalProperties:
type: number
type: object
price_change_percentage_7d:
price_change_percentage_14d:
type: number
price_change_percentage_7d_in_currency:
price_change_percentage_1h:
type: number
price_change_percentage_1h_in_currency:
additionalProperties:
type: number
type: object
price_change_percentage_14d:
price_change_percentage_1y:
type: number
price_change_percentage_14d_in_currency:
price_change_percentage_1y_in_currency:
additionalProperties:
type: number
type: object
price_change_percentage_1h:
price_change_percentage_7d:
type: number
price_change_percentage_1h_in_currency:
price_change_percentage_7d_in_currency:
additionalProperties:
type: number
type: object
price_change_percentage_1y:
type: number
price_change_percentage_1y_in_currency:
price_change_percentage_14d_in_currency:
additionalProperties:
type: number
type: object
Expand Down Expand Up @@ -7433,6 +7444,27 @@ paths:
summary: Get product bot commands
tags:
- ProductMetadata
/profiles/{profile_id}/global-info:
get:
consumes:
- application/json
description: Get profile's global info
parameters:
- description: profile ID
in: path
name: profile_id
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.GetGlobalProfileInfoResponse'
summary: Get profile's global info
tags:
- Profile
/swap:
post:
consumes:
Expand Down
8 changes: 8 additions & 0 deletions pkg/entities/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,14 @@ func (e *Entity) GetUserProfile(req request.GetUserProfileRequest) (*response.Ge
}, nil
}

func (e *Entity) GetGlobalProfileInfo(req request.GetGlobalProfileInfoRequest) (*response.GetGlobalProfileInfoResponse, error) {
return &response.GetGlobalProfileInfoResponse{
Level: 17,
Rank: 3,
Roles: []string{"@core", "@mod", "@labs"},
}, nil
}

func (e *Entity) GetRoleByGuildLevelConfig(guildID, profileID, userID string) (string, int, error) {
if e.discord == nil {
return "", 0, nil
Expand Down
1 change: 1 addition & 0 deletions pkg/handler/user/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ type IHandler interface {

SendUserXP(c *gin.Context)
GetUserBalance(c *gin.Context)
GetGlobalProfileInfo(c *gin.Context)
}
35 changes: 35 additions & 0 deletions pkg/handler/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,38 @@ func (h *Handler) GetUserBalance(c *gin.Context) {
}
c.JSON(http.StatusOK, response.CreateResponse(balance, nil, nil, nil))
}

// GET /profiles/:profile_id/global-info
// GetGlobalProfileInfo godoc
// @Summary Get profile's global info
// @Description Get profile's global info
// @Tags Profile
// @Accept json
// @Produce json
// @Param profile_id path string true "profile ID"
// @Success 200 {object} response.GetGlobalProfileInfoResponse
// @Router /profiles/{profile_id}/global-info [get]
func (h *Handler) GetGlobalProfileInfo(c *gin.Context) {
var req request.GetGlobalProfileInfoRequest
if err := c.BindUri(&req); err != nil {
h.log.Error(err, "[handler.GetGlobalProfileInfo] BindUri() failed")
c.JSON(http.StatusInternalServerError, response.CreateResponse[any](nil, nil, err, nil))
return
}

if !util.ValidateNumberSeries(req.ProfileID) {
err := errors.New("profile Id is invalid")
h.log.Error(err, "[handler.GetGlobalProfileInfo] invalid profile_id")
c.JSON(http.StatusBadRequest, response.CreateResponse[any](nil, nil, err, nil))
return
}

data, err := h.entities.GetGlobalProfileInfo(req)
if err != nil {
h.log.Fields(logger.Fields{"req": req}).Error(err, "[handler.GetGlobalProfileInfo] entity.GetGlobalProfileInfo() failed")
c.JSON(http.StatusInternalServerError, response.CreateResponse[any](nil, nil, err, nil))
return
}

c.JSON(http.StatusOK, response.CreateResponse(data, nil, nil, nil))
}
4 changes: 4 additions & 0 deletions pkg/request/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ type GetTopUsersRequest struct {
Query string `form:"query"`
Sort string `form:"sort"`
}

type GetGlobalProfileInfoRequest struct {
ProfileID string `uri:"profile_id" binding:"required"`
}
6 changes: 6 additions & 0 deletions pkg/response/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ type GetUserProfileResponse struct {
GuildRank int `json:"guild_rank"`
}

type GetGlobalProfileInfoResponse struct {
Level int `json:"level"`
Rank int `json:"rank"`
Roles []string `json:"roles"`
}

// For swagger
type GetDataUserProfileResponse struct {
Data *GetUserProfileResponse `json:"data"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/routes/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func NewRoutes(r *gin.Engine, h *handler.Handler, cfg config.Config) {
guildGroup.GET("/validate-user", h.Guild.ValidateUser)
}

profileGroup := v1.Group("/profiles")
{
profileGroup.GET("/:profile_id/global-info", h.User.GetGlobalProfileInfo)
}

userGroup := v1.Group("/users")
{
userGroup.POST("", h.User.IndexUsers)
Expand Down
37 changes: 24 additions & 13 deletions pkg/service/nghenhan/nghenhan.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,30 @@ func (n *Nghenhan) GetFiatHistoricalChart(base, target, interval string, limit i
}
statusCode, err := util.SendRequest(req)
if err != nil || statusCode != http.StatusOK {
n.sentry.CaptureErrorEvent(sentrygo.SentryCapturePayload{
Message: fmt.Sprintf("[API mochi] - Nghenhan - GetFiatHistoricalChart failed %v", err),
Tags: sentryTags,
Extra: map[string]interface{}{
"base": base,
"target": target,
"interval": interval,
"limit": limit,
},
})
return &response.NghenhanFiatHistoricalChartResponse{
Data: []response.NghenhanFiatHistoricalChart{},
}, nil
retry := 3
for retry > 0 {
statusCode, err = util.SendRequest(req)
if err == nil && statusCode == http.StatusOK {
break
}
retry--
}

if retry == 0 {
n.sentry.CaptureErrorEvent(sentrygo.SentryCapturePayload{
Message: fmt.Sprintf("[API mochi] - Nghenhan - GetFiatHistoricalChart failed %v", err),
Tags: sentryTags,
Extra: map[string]interface{}{
"base": base,
"target": target,
"interval": interval,
"limit": limit,
},
})
return &response.NghenhanFiatHistoricalChartResponse{
Data: []response.NghenhanFiatHistoricalChart{},
}, nil
}
}
return &data, nil
}

0 comments on commit b275c84

Please sign in to comment.