Skip to content

Commit

Permalink
feat: Athlete, Activity and Gear APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
bahattincinic committed May 17, 2024
1 parent de25dbf commit 45a6944
Show file tree
Hide file tree
Showing 15 changed files with 1,600 additions and 47 deletions.
55 changes: 55 additions & 0 deletions api/activity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package api

import (
"net/http"

"github.com/labstack/echo/v4"
)

// listActivities godoc
//
// @Summary List Activities
// @Tags activity
// @Accept json
// @Produce json
// @Param limit query string false "pagination limit"
// @Param page query string false "active page"
// @Success 200 {object} PaginatedResponse{Results=[]models.Activity, count=int}
// @Router /activities/ [get]
func (a *API) listActivities(c echo.Context) error {
offset, limit, err := a.GetPageAndSize(c, 20)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}

count, activities, err := a.db.ListActivities(int(offset), int(limit))
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

return c.JSON(http.StatusOK, PaginatedResponse{
Results: activities,
Count: count,
})
}

// getActivity godoc
//
// @Summary Get Activity
// @Tags activity
// @Accept json
// @Param id path string true "Activity ID"
// @Success 200 {object} models.Activity
// @Router /activities/{id} [get]
func (a *API) getActivity(c echo.Context) error {
act, err := a.db.GetActivity(c.Param("id"))
if err != nil {
return err
}

if act == nil {
return echo.NewHTTPError(http.StatusNotFound, "activity Not Found")
}

return c.JSON(http.StatusOK, act)
}
55 changes: 55 additions & 0 deletions api/athlete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package api

import (
"net/http"

"github.com/labstack/echo/v4"
)

// listAthletes godoc
//
// @Summary List Athletes
// @Tags athlete
// @Accept json
// @Produce json
// @Param limit query string false "pagination limit"
// @Param page query string false "active page"
// @Success 200 {object} PaginatedResponse{Results=[]models.Athlete, count=int}
// @Router /athletes/ [get]
func (a *API) listAthletes(c echo.Context) error {
offset, limit, err := a.GetPageAndSize(c, 20)
if err != nil {
return echo.NewHTTPError(http.StatusBadRequest, err)
}

count, athletes, err := a.db.ListAthletes(int(offset), int(limit))
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

return c.JSON(http.StatusOK, PaginatedResponse{
Results: athletes,
Count: count,
})
}

// getActivity godoc
//
// @Summary Get Athlete
// @Tags athlete
// @Accept json
// @Param id path string true "Athlete ID"
// @Success 200 {object} models.Athlete
// @Router /athletes/{id} [get]
func (a *API) getAthlete(c echo.Context) error {
ath, err := a.db.GetAthlete(c.Param("id"))
if err != nil {
return err
}

if ath == nil {
return echo.NewHTTPError(http.StatusNotFound, "athlete Not Found")
}

return c.JSON(http.StatusOK, ath)
}
10 changes: 5 additions & 5 deletions api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// @Tags config
// @Accept json
// @Success 200 {object} models.Config
// @Router /config [get]
// @Router /config/ [get]
func (a *API) getConfig(c echo.Context) error {
cfg, err := a.db.GetCurrentConfig()
if err != nil {
Expand All @@ -28,11 +28,11 @@ func (a *API) getConfig(c echo.Context) error {
// @Summary Upsert Application Config
// @Tags config
// @Accept json
// @Param config body models.ConfigInput true "Config Input"
// @Success 200 {object} models.ConfigInput
// @Router /config [put]
// @Param config body models.Config true "Config Input"
// @Success 200 {object} models.Config
// @Router /config/ [put]
func (a *API) upsertConfig(c echo.Context) error {
var in models.ConfigInput
var in models.Config
if err := c.Bind(&in); err != nil {
return err
}
Expand Down
Loading

0 comments on commit 45a6944

Please sign in to comment.