Ma Suhyeon

Implement get extractions

......@@ -59,6 +59,7 @@ func NewApp(config Config) *App {
app.echo.POST("/users", app.PostUsers)
app.echo.POST("/users/tokens", app.PostTokens)
app.echo.GET("/extractions", app.GetExtractions, auth)
app.echo.POST("/extractions", app.PostExtractions, auth)
extraction := app.echo.Group("/extractions/:no")
......
......@@ -15,6 +15,27 @@ import (
_ "github.com/mattn/go-sqlite3"
)
func (app *App) GetExtractions(c echo.Context) error {
userNo := c.Get("user").(*jwt.Token).Claims.(*AuthClaims).UserNo
phone := c.QueryParam("phone")
extractions := []uint64{}
var err error
if phone == "" {
query := "SELECT `no` FROM extractions WHERE `owner`=?"
err = app.db.Select(&extractions, query, userNo)
} else {
query := "SELECT `no` FROM extractions WHERE `owner`=? AND `phone`=?"
err = app.db.Select(&extractions, query, userNo, phone)
}
if err != nil {
return err
}
return c.JSON(http.StatusOK, extractions)
}
func (app *App) PostExtractions(c echo.Context) error {
userNo := c.Get("user").(*jwt.Token).Claims.(*AuthClaims).UserNo
......