Skip to content

Commit

Permalink
🐛 Fix the query params
Browse files Browse the repository at this point in the history
  • Loading branch information
wjuniorbh92 committed Aug 23, 2023
1 parent 58cad69 commit 756d2ac
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 68 deletions.
6 changes: 3 additions & 3 deletions backend/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions backend/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -561,16 +561,16 @@
},
{
"type": "string",
"description": "Time range for the query (e.g., '24h')",
"description": "Time range for the query (e.g., '24h', ",
"name": "time_range",
"in": "path",
"required": true
},
{
"type": "string",
"description": "Time frame for grouping (e.g., '1h'). Default is '1h'",
"description": "Time frame for the query (e.g., '1h')",
"name": "time_frame",
"in": "query"
"in": "path"
}
],
"responses": {
Expand Down
6 changes: 3 additions & 3 deletions backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -805,13 +805,13 @@ paths:
name: asset_id
required: true
type: integer
- description: Time range for the query (e.g., '24h')
- description: 'Time range for the query (e.g., ''24h'', '
in: path
name: time_range
required: true
type: string
- description: Time frame for grouping (e.g., '1h'). Default is '1h'
in: query
- description: Time frame for the query (e.g., '1h')
in: path
name: time_frame
type: string
produces:
Expand Down
36 changes: 18 additions & 18 deletions backend/internal/controller/http/v1/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ func (r *assetsRoutes) createAsset(c *gin.Context) {
token := c.Request.Header.Get("Authorization")
user, err := r.a.GetUserByToken(token)
if err != nil {
errorResponse(c, http.StatusNotFound, "user not found")
errorResponse(c, http.StatusNotFound, "user not found", err)
return
}

userID, err := strconv.Atoi(user.ID)
if err != nil {
errorResponse(c, http.StatusNotFound, "error to parse user id")
errorResponse(c, http.StatusNotFound, "error to parse user id", err)
}

amount, err := strconv.ParseFloat(request.Amount, 64)
Expand All @@ -243,7 +243,7 @@ func (r *assetsRoutes) createAsset(c *gin.Context) {
Description: createLogDescription(entity.CreateAsset, asset.Code, nil, nil),
})
if err != nil {
errorResponse(c, http.StatusNotFound, "error to create log transaction")
errorResponse(c, http.StatusNotFound, "error to create log transaction", err)
return
}

Expand Down Expand Up @@ -308,13 +308,13 @@ func (r *assetsRoutes) mintAsset(c *gin.Context) {
token := c.Request.Header.Get("Authorization")
user, err := r.a.GetUserByToken(token)
if err != nil {
errorResponse(c, http.StatusNotFound, "user not found")
errorResponse(c, http.StatusNotFound, "user not found", err)
return
}

userID, err := strconv.Atoi(user.ID)
if err != nil {
errorResponse(c, http.StatusNotFound, "error to parse user id")
errorResponse(c, http.StatusNotFound, "error to parse user id", err)
}

amount, err := strconv.ParseFloat(request.Amount, 64)
Expand All @@ -329,7 +329,7 @@ func (r *assetsRoutes) mintAsset(c *gin.Context) {
Description: createLogDescription(entity.MintAsset, asset.Code, nil, nil),
})
if err != nil {
errorResponse(c, http.StatusNotFound, "error to create log transaction")
errorResponse(c, http.StatusNotFound, "error to create log transaction", err)
return
}

Expand Down Expand Up @@ -396,13 +396,13 @@ func (r *assetsRoutes) burnAsset(c *gin.Context) {
token := c.Request.Header.Get("Authorization")
user, err := r.a.GetUserByToken(token)
if err != nil {
errorResponse(c, http.StatusNotFound, "user not found")
errorResponse(c, http.StatusNotFound, "user not found", err)
return
}

userID, err := strconv.Atoi(user.ID)
if err != nil {
errorResponse(c, http.StatusNotFound, "error to parse user id")
errorResponse(c, http.StatusNotFound, "error to parse user id", err)
}

amount, err := strconv.ParseFloat(request.Amount, 64)
Expand All @@ -417,7 +417,7 @@ func (r *assetsRoutes) burnAsset(c *gin.Context) {
Description: createLogDescription(entity.BurnAsset, asset.Code, nil, nil),
})
if err != nil {
errorResponse(c, http.StatusNotFound, "error to create log transaction")
errorResponse(c, http.StatusNotFound, "error to create log transaction", err)
return
}

Expand Down Expand Up @@ -490,13 +490,13 @@ func (r *assetsRoutes) transferAsset(c *gin.Context) {
token := c.Request.Header.Get("Authorization")
user, err := r.a.GetUserByToken(token)
if err != nil {
errorResponse(c, http.StatusNotFound, "user not found")
errorResponse(c, http.StatusNotFound, "user not found", err)
return
}

userID, err := strconv.Atoi(user.ID)
if err != nil {
errorResponse(c, http.StatusNotFound, "error to parse user id")
errorResponse(c, http.StatusNotFound, "error to parse user id", err)
}

amount, err := strconv.ParseFloat(request.Amount, 64)
Expand All @@ -511,7 +511,7 @@ func (r *assetsRoutes) transferAsset(c *gin.Context) {
Description: createLogDescription(entity.TransferAsset, asset.Code, nil, nil),
})
if err != nil {
errorResponse(c, http.StatusNotFound, "error to create log transaction")
errorResponse(c, http.StatusNotFound, "error to create log transaction", err)
return
}

Expand Down Expand Up @@ -578,13 +578,13 @@ func (r *assetsRoutes) clawbackAsset(c *gin.Context) {
token := c.Request.Header.Get("Authorization")
user, err := r.a.GetUserByToken(token)
if err != nil {
errorResponse(c, http.StatusNotFound, "user not found")
errorResponse(c, http.StatusNotFound, "user not found", err)
return
}

userID, err := strconv.Atoi(user.ID)
if err != nil {
errorResponse(c, http.StatusNotFound, "error to parse user id")
errorResponse(c, http.StatusNotFound, "error to parse user id", err)
}

amount, err := strconv.ParseFloat(request.Amount, 64)
Expand All @@ -599,7 +599,7 @@ func (r *assetsRoutes) clawbackAsset(c *gin.Context) {
Description: createLogDescription(entity.ClawbackAsset, asset.Code, nil, nil),
})
if err != nil {
errorResponse(c, http.StatusNotFound, "error to create log transaction")
errorResponse(c, http.StatusNotFound, "error to create log transaction", err)
return
}

Expand Down Expand Up @@ -673,13 +673,13 @@ func (r *assetsRoutes) updateAuthFlags(c *gin.Context) {
token := c.Request.Header.Get("Authorization")
user, err := r.a.GetUserByToken(token)
if err != nil {
errorResponse(c, http.StatusNotFound, "user not found")
errorResponse(c, http.StatusNotFound, "user not found", err)
return
}

userID, err := strconv.Atoi(user.ID)
if err != nil {
errorResponse(c, http.StatusNotFound, "error to parse user id")
errorResponse(c, http.StatusNotFound, "error to parse user id", err)
}

err = r.l.CreateLogTransaction(entity.LogTransaction{
Expand All @@ -689,7 +689,7 @@ func (r *assetsRoutes) updateAuthFlags(c *gin.Context) {
Description: createLogDescription(entity.UpdateAuthFlags, asset.Code, request.SetFlags, request.ClearFlags),
})
if err != nil {
errorResponse(c, http.StatusNotFound, "error to create log transaction")
errorResponse(c, http.StatusNotFound, "error to create log transaction", err)
return
}

Expand Down
33 changes: 16 additions & 17 deletions backend/internal/controller/http/v1/log_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (r *logTransactionsRoutes) getLogTransactions(c *gin.Context) {

logTransactions, err := r.l.GetLogTransactions(timeRange)
if err != nil {
errorResponse(c, http.StatusInternalServerError, fmt.Sprintf("error getting log transactions: %s", err.Error()))
errorResponse(c, http.StatusInternalServerError, "error getting log transactions: %s", err)
return
}

Expand All @@ -67,13 +67,13 @@ func (r *logTransactionsRoutes) getLogTransactionsByAssetID(c *gin.Context) {

assetID, err := strconv.Atoi(assetIDStr)
if err != nil {
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid asset ID: %s", err.Error()))
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid asset ID: %s", err.Error()), err)
return
}

logTransactions, err := r.l.GetLogTransactionsByAssetID(assetID, timeRange)
if err != nil {
errorResponse(c, http.StatusInternalServerError, fmt.Sprintf("error getting log transactions: %s", err.Error()))
errorResponse(c, http.StatusInternalServerError, fmt.Sprintf("error getting log transactions: %s", err.Error()), err)
return
}

Expand All @@ -95,13 +95,13 @@ func (r *logTransactionsRoutes) getLogTransactionsByUserID(c *gin.Context) {

userID, err := strconv.Atoi(userIDStr)
if err != nil {
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid user ID: %s", err.Error()))
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid user ID: %s", err.Error()), err)
return
}

logTransactions, err := r.l.GetLogTransactionsByUserID(userID, timeRange)
if err != nil {
errorResponse(c, http.StatusInternalServerError, fmt.Sprintf("error getting log transactions: %s", err.Error()))
errorResponse(c, http.StatusInternalServerError, fmt.Sprintf("error getting log transactions: %s", err.Error()), err)
return
}

Expand All @@ -123,13 +123,13 @@ func (r *logTransactionsRoutes) getLogTransactionsByTransactionTypeID(c *gin.Con

transactionTypeID, err := strconv.Atoi(transactionTypeIDStr)
if err != nil {
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid asset ID: %s", err.Error()))
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid asset ID: %s", err.Error()), err)
return
}

logTransactions, err := r.l.GetLogTransactionsByTransactionTypeID(transactionTypeID, timeRange)
if err != nil {
errorResponse(c, http.StatusInternalServerError, fmt.Sprintf("error getting log transactions: %s", err.Error()))
errorResponse(c, http.StatusInternalServerError, fmt.Sprintf("error getting log transactions: %s", err.Error()), err)
return
}

Expand All @@ -142,8 +142,8 @@ func (r *logTransactionsRoutes) getLogTransactionsByTransactionTypeID(c *gin.Con
// @Accept json
// @Produce json
// @Param asset_id path int true "Asset ID"
// @Param time_range path string true "Time range for the query (e.g., '24h')"
// @Param time_frame query string false "Time frame for grouping (e.g., '1h'). Default is '1h'"
// @Param time_range path string true "Time range for the query (e.g., '24h', "7d")"
// @Param time_frame path string false "Time frame for the query (e.g., '1h')".
// @Security ApiKeyAuth
// @Success 200 {object} entity.SumLogTransaction "Sum log transaction for the specified asset"
// @Failure 400 {string} string "Invalid time_frame format"
Expand All @@ -152,23 +152,23 @@ func (r *logTransactionsRoutes) getLogTransactionsByTransactionTypeID(c *gin.Con
func (r *logTransactionsRoutes) sumAmountsByAssetID(c *gin.Context) {
assetIDStr := c.Param("asset_id")
timeRange := c.Param("time_range")
timeFrame := c.DefaultQuery("time_frame", "1h") // Default to 1 hour if not provided
timeFrame := c.Param("time_frame")

duration, err := time.ParseDuration(timeFrame)
if err != nil {
errorResponse(c, http.StatusBadRequest, "Invalid time_frame format")
errorResponse(c, http.StatusBadRequest, "Invalid time_frame format", err)
return
}

assetID, err := strconv.Atoi(assetIDStr)
if err != nil {
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid asset ID: %s", err.Error()))
errorResponse(c, http.StatusBadRequest, fmt.Sprintf("invalid asset ID: %s", err.Error()), err)
return
}

sum, err := r.l.SumLogTransactionsByAssetID(assetID, timeRange, duration)
if err != nil {
errorResponse(c, http.StatusInternalServerError, fmt.Sprintf("error getting log transactions: %s", err.Error()))
errorResponse(c, http.StatusInternalServerError, fmt.Sprintf("error getting log transactions: %s", err.Error()), err)
return
}

Expand All @@ -189,17 +189,16 @@ func (r *logTransactionsRoutes) sumAmountsByAssetID(c *gin.Context) {
// @Router /log_transactions/assets/sum/{time_range}/{time_frame} [get]
func (r *logTransactionsRoutes) sumAmountsForAllAssets(c *gin.Context) {
timeRange := c.Param("time_range")
timeFrame := c.DefaultQuery("time_frame", "1h") // Default to 1 hour if not provided
timeFrame := c.Param("time_frame")

duration, err := time.ParseDuration(timeFrame)
if err != nil {
errorResponse(c, http.StatusBadRequest, "Invalid time_frame format")
errorResponse(c, http.StatusBadRequest, "Invalid time_frame format", err)
return
}

sum, err := r.l.SumLogTransactions(timeRange, duration)
if err != nil {
errorResponse(c, http.StatusInternalServerError, fmt.Sprintf("error getting log transactions: %s", err.Error()))
errorResponse(c, http.StatusInternalServerError, fmt.Sprintf("error getting log transactions: %s", err.Error()), err)
return
}

Expand Down
Loading

0 comments on commit 756d2ac

Please sign in to comment.