-
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.
feat: Athlete, Activity and Gear APIs
- Loading branch information
1 parent
de25dbf
commit 45a6944
Showing
15 changed files
with
1,600 additions
and
47 deletions.
There are no files selected for viewing
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 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) | ||
} |
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 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) | ||
} |
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.