-
Notifications
You must be signed in to change notification settings - Fork 2
/
user_controller.go
44 lines (37 loc) · 1.16 KB
/
user_controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package controllers
import (
"net/http"
"github.com/gin-gonic/gin"
"gozen/models"
"gozen/models/json"
)
// ユーザーコントローラー
type UserController struct{}
// 登録情報を返す
func (user UserController) Profile() gin.HandlerFunc {
return jsonController(func(c *gin.Context) (interface{}, models.Error) {
if models.LoginUser == nil {
return nil, models.NewError(http.StatusBadRequest, "ログインしてください。")
}
return models.LoginUser.ToJson(), nil
})
}
// registration idを登録する
func (user UserController) RegistrationID() gin.HandlerFunc {
return jsonController(func(c *gin.Context) (interface{}, models.Error) {
if models.LoginUser == nil {
return nil, models.NewError(http.StatusBadRequest, "ログインしてください。")
}
regID := c.PostForm("registration_id")
if regID == "" {
return nil, models.NewError(http.StatusNotAcceptable, "not registraion_id key")
}
user := models.NewUser()
if err := user.SaveRegistrationID(regID); err != nil {
return nil, models.NewError(http.StatusInternalServerError, err.Error())
}
return json.MessageResponse{
"saved registration id",
}, nil
})
}