-
Notifications
You must be signed in to change notification settings - Fork 0
/
words.go
35 lines (31 loc) · 900 Bytes
/
words.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
package handler
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/shoriwe/rollee-test-2/models"
)
func (h *Handler) AddWord(ctx *gin.Context) {
var word models.Word
bErr := ctx.Bind(&word)
if bErr != nil {
ctx.AbortWithStatusJSON(http.StatusInternalServerError, Status{Succeed: false, Error: bErr.Error()})
}
qErr := h.c.AddWord(&word)
if qErr != nil {
ctx.AbortWithStatusJSON(http.StatusInternalServerError, Status{Succeed: false, Error: qErr.Error()})
}
ctx.JSON(http.StatusOK, Status{Succeed: true})
}
func (h *Handler) QueryWord(ctx *gin.Context) {
word, qErr := h.c.QueryWord(ctx.Param(PatternParam))
if qErr != nil {
ctx.AbortWithStatusJSON(http.StatusInternalServerError, Status{Succeed: false, Error: qErr.Error()})
}
if word == nil {
ctx.JSON(http.StatusOK, models.Word{IsNull: true})
ctx.Done()
return
}
ctx.JSON(http.StatusOK, word)
ctx.Done()
}