Ma Suhyeon

Implement get extractions

...@@ -59,6 +59,7 @@ func NewApp(config Config) *App { ...@@ -59,6 +59,7 @@ func NewApp(config Config) *App {
59 59
60 app.echo.POST("/users", app.PostUsers) 60 app.echo.POST("/users", app.PostUsers)
61 app.echo.POST("/users/tokens", app.PostTokens) 61 app.echo.POST("/users/tokens", app.PostTokens)
62 + app.echo.GET("/extractions", app.GetExtractions, auth)
62 app.echo.POST("/extractions", app.PostExtractions, auth) 63 app.echo.POST("/extractions", app.PostExtractions, auth)
63 64
64 extraction := app.echo.Group("/extractions/:no") 65 extraction := app.echo.Group("/extractions/:no")
......
...@@ -15,6 +15,27 @@ import ( ...@@ -15,6 +15,27 @@ import (
15 _ "github.com/mattn/go-sqlite3" 15 _ "github.com/mattn/go-sqlite3"
16 ) 16 )
17 17
18 +func (app *App) GetExtractions(c echo.Context) error {
19 + userNo := c.Get("user").(*jwt.Token).Claims.(*AuthClaims).UserNo
20 + phone := c.QueryParam("phone")
21 +
22 + extractions := []uint64{}
23 + var err error
24 + if phone == "" {
25 + query := "SELECT `no` FROM extractions WHERE `owner`=?"
26 + err = app.db.Select(&extractions, query, userNo)
27 + } else {
28 + query := "SELECT `no` FROM extractions WHERE `owner`=? AND `phone`=?"
29 + err = app.db.Select(&extractions, query, userNo, phone)
30 + }
31 +
32 + if err != nil {
33 + return err
34 + }
35 +
36 + return c.JSON(http.StatusOK, extractions)
37 +}
38 +
18 func (app *App) PostExtractions(c echo.Context) error { 39 func (app *App) PostExtractions(c echo.Context) error {
19 userNo := c.Get("user").(*jwt.Token).Claims.(*AuthClaims).UserNo 40 userNo := c.Get("user").(*jwt.Token).Claims.(*AuthClaims).UserNo
20 41
......