Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmagnus committed Feb 29, 2024
2 parents d3d82d3 + 0d5b205 commit b98536f
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions backend/internal/controller/http/v1/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package v1

import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
"strconv"

Expand Down Expand Up @@ -52,6 +54,7 @@ func newAssetsRoutes(handler *gin.RouterGroup, w usecase.WalletUseCase, as useca
h.GET("/toml-data", r.getTomlData)
h.PUT("/:id/update-contract-id", r.updateContractId)
h.GET("/:id/image.png", r.getAssetImage)
h.GET("/price-conversion", r.priceConversion)


allowedRoute := h.Group("/").Use(Auth(a.ValidateToken())).Use(rolePermission.Validate(rP))
Expand Down Expand Up @@ -135,6 +138,12 @@ type UpdateNameRequest struct {
Code string `json:"code" binding:"required" example:"USDC"`
}

type PriceConversionResponse struct {
Status string `json:"status"`
XLM float64 `json:"XLM"`
USD float64 `json:"USD"`
}

// @Summary Create a new asset
// @Description Create and issue a new asset on Stellar
// @Tags Assets
Expand Down Expand Up @@ -1235,4 +1244,37 @@ func (r *assetsRoutes) updateNameAndCode(c *gin.Context) {
}

c.JSON(http.StatusOK, gin.H{"message": "asset information updated"})
}

// @Summary Get XLM price in USD
// @Description Get XLM price in USD
// @Tags Assets
// @Accept json
// @Produce json
// @Success 200 {object} PriceConversionResponse
// @Failure 400 {object} response
// @Failure 500 {object} response
// @Router /assets/price-conversion [get]
func (r *assetsRoutes) priceConversion(c *gin.Context) {
const convertURL = "https://api.coinconvert.net/convert/xlm/usd?amount=1"
resp, err := http.Get(convertURL)
if err != nil {
errorResponse(c, http.StatusInternalServerError, "error making request to convert API:", err)
return
}

body, err := io.ReadAll(resp.Body)
if err != nil {
errorResponse(c, http.StatusInternalServerError, "error reading response body:", err)
return
}

var conversionResponse PriceConversionResponse
err = json.Unmarshal(body, &conversionResponse)
if err != nil {
errorResponse(c, http.StatusInternalServerError, "error parsing JSON:", err)
return
}

c.JSON(http.StatusOK, conversionResponse)
}

0 comments on commit b98536f

Please sign in to comment.