-
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: Added sync and task endpoints.
- Loading branch information
1 parent
45a6944
commit ebca3a5
Showing
19 changed files
with
576 additions
and
82 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 |
---|---|---|
@@ -1,13 +1,9 @@ | ||
ENV=local | ||
|
||
# Database | ||
DATABASE_DSB="database.db" | ||
DATABASE_DSN="database.db" | ||
DATABASE_TYPE="sqlite" | ||
DATABASE_AUTO_MIGRATE=true | ||
|
||
# Strava | ||
STRAVA_ACCESS_TOKEN="" | ||
STRAVA_ATHLETE_ID= | ||
|
||
# API | ||
API_PORT=9000 |
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,46 @@ | ||
package api | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/bahattincinic/fitwave/strava" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
// syncData godoc | ||
// | ||
// @Summary Sync Strava data | ||
// @Tags data | ||
// @Accept json | ||
// @Param Authorization header string true "Strava Access Token" | ||
// @Success 200 {object} queue.TaskResult | ||
// @Router /data/sync [post] | ||
func (a *API) syncData(c echo.Context) error { | ||
user := c.Get(userContextKey).(*strava.User) | ||
|
||
task := a.q.AddTask(func() (interface{}, error) { | ||
if err := a.im.Import(user); err != nil { | ||
return nil, err | ||
} | ||
return nil, nil | ||
}) | ||
|
||
return c.JSON(http.StatusOK, task) | ||
} | ||
|
||
// getTask godoc | ||
// | ||
// @Summary Get Task Detail | ||
// @Tags data | ||
// @Accept json | ||
// @Param id path string true "Task ID" | ||
// @Success 200 {object} queue.TaskResult | ||
// @Router /data/task/{id} [get] | ||
func (a *API) getTask(c echo.Context) error { | ||
task, err := a.q.GetResult(c.Param("id")) | ||
|
||
if err != nil { | ||
return c.JSON(http.StatusNotFound, err) | ||
} | ||
return c.JSON(http.StatusOK, task) | ||
} |
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.