-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
863 additions
and
172 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package prices | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/emerishq/demeris-api-server/lib/ginutils" | ||
"github.com/emerishq/demeris-api-server/usecase" | ||
"github.com/emerishq/emeris-utils/logging" | ||
"github.com/gin-gonic/gin" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type PricesAPI struct { | ||
app usecase.IApp | ||
} | ||
|
||
func New(app usecase.IApp) *PricesAPI { | ||
return &PricesAPI{ | ||
app: app, | ||
} | ||
} | ||
|
||
func Register(router *gin.Engine, app usecase.IApp) { | ||
api := New(app) | ||
|
||
router.Group("/prices"). | ||
GET("/pools", api.GetPoolsPrices) | ||
} | ||
|
||
type GetPoolsPricesResponse struct { | ||
PoolResults usecase.PoolPricesResult `json:"pool_results"` | ||
} | ||
|
||
// GetPoolsPrices returns the list of available pools and their associated token's price. | ||
// @Summary Get pools' tokens prices | ||
// @Tags Price | ||
// @ID get-pools-prices | ||
// @Produce json | ||
// @Success 200 {object} GetPoolsPricesResponse | ||
// @Failure 500 {object} apierrors.UserFacingError | ||
// @Router /prices/pools [get] | ||
func (api *PricesAPI) GetPoolsPrices(c *gin.Context) { | ||
prices := api.app.PoolPrices(c.Request.Context()) | ||
|
||
logger := ginutils.GetValue[*zap.SugaredLogger](c, logging.LoggerKey) | ||
for _, opt := range prices { | ||
if opt.Err != nil { | ||
logger.Errorw("fetching pool price", "err", opt.Err) | ||
} | ||
} | ||
|
||
c.JSON(http.StatusOK, GetPoolsPricesResponse{ | ||
PoolResults: prices, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.