-
Notifications
You must be signed in to change notification settings - Fork 2
/
retrieve_initial_data.go
37 lines (31 loc) · 1.13 KB
/
retrieve_initial_data.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
package character
import (
"net/http"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
)
func (u *CharacterController) RetrieveInitialData(c *gin.Context) {
session := sessions.Default(c)
id := session.Get("cid").(int)
existsUnreadNotification, existsUnreadMail, err := u.usecase.RetrieveInitialData(id)
if err != nil {
c.Status(http.StatusInternalServerError)
return
}
response := struct {
Id int `json:"id"`
CSRFToken string `json:"csrfToken"`
NotificationToken string `json:"notificationToken"`
ExistsUnreadNotification bool `json:"existsUnreadNotification"`
ExistsUnreadMail bool `json:"existsUnreadMail"`
Administrator bool `json:"administrator,omitempty"`
}{
Id: id,
CSRFToken: session.Get("csrf-token").(string),
NotificationToken: session.Get("notification-token").(string),
ExistsUnreadNotification: existsUnreadNotification,
ExistsUnreadMail: existsUnreadMail,
Administrator: session.Get("administrator").(bool),
}
c.JSON(http.StatusOK, response)
}