Improve chat endpoints

This commit is contained in:
daru
2022-05-17 20:24:52 +02:00
parent 83ff446836
commit 011103395d
4 changed files with 35 additions and 3 deletions

20
ober.go
View File

@@ -155,11 +155,20 @@ func ChatGet(ctx *fasthttp.RequestCtx) {
ctx.SetStatusCode(fasthttp.StatusBadRequest)
return
}
found, err := CheckAnimeExistInDb(animeId)
if err != nil {
addErrorToCtx(ctx, err)
return
}
if !found {
ctx.SetStatusCode(fasthttp.StatusNotFound)
return
}
text, err := ReadChat(animeId)
if err != nil {
if strings.Contains(err.Error(), "not found") {
ctx.WriteString(err.Error())
ctx.SetStatusCode(fasthttp.StatusNotFound)
ctx.SetStatusCode(fasthttp.StatusNoContent)
return
}
addErrorToCtx(ctx, err)
@@ -367,6 +376,15 @@ func ChatPost(ctx *fasthttp.RequestCtx) {
ctx.SetStatusCode(fasthttp.StatusBadRequest)
return
}
found, err := CheckAnimeExistInDb(animeId)
if err != nil {
addErrorToCtx(ctx, err)
return
}
if !found {
ctx.SetStatusCode(fasthttp.StatusNotFound)
return
}
sent := strings.TrimSpace(string(ctx.PostBody()))
if sent == "" {
ctx.SetStatusCode(fasthttp.StatusBadRequest)