mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-13 17:29:54 +01:00
GET user
This commit is contained in:
47
ober.go
47
ober.go
@@ -17,7 +17,7 @@ func RunWebserv() {
|
||||
r.GET("/", Headers(Start))
|
||||
r.GET("/api/season", Headers(Season))
|
||||
r.GET("/api/anime/{id}", Headers(AnimeGet))
|
||||
r.GET("/api/user/{id?}", Headers(AnimeGet))
|
||||
r.GET("/api/user/{user?}", Headers(UserGet))
|
||||
r.GET("/api/watch/{user?}", Headers(WatchGet))
|
||||
r.POST("/api/register", Headers(Register))
|
||||
r.POST("/api/watch/{user}", Headers(WatchPost))
|
||||
@@ -95,6 +95,49 @@ func AnimeGet(ctx *fasthttp.RequestCtx) {
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
}
|
||||
|
||||
func UserGet(ctx *fasthttp.RequestCtx) {
|
||||
usrVal := ctx.UserValue("user")
|
||||
users := make([]User, 0)
|
||||
if usrVal != nil {
|
||||
// get specific user
|
||||
user, _, err := GetUserData(fmt.Sprintf("%s", usrVal))
|
||||
if err != nil {
|
||||
ctx.WriteString(err.Error())
|
||||
ctx.SetStatusCode(fasthttp.StatusNotFound)
|
||||
return
|
||||
}
|
||||
users = append(users, *user)
|
||||
} else {
|
||||
regUsers, err := ReadRegisteredUsers()
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
for _, u := range regUsers {
|
||||
user, _, err := GetUserData(u.Username)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
users = append(users, *user)
|
||||
}
|
||||
}
|
||||
|
||||
bytes, err := json.Marshal(users)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
_, err = ctx.Write(bytes)
|
||||
if err != nil {
|
||||
addErrorToCtx(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.SetContentType("application/json; charset=utf-8")
|
||||
ctx.SetStatusCode(fasthttp.StatusOK)
|
||||
}
|
||||
|
||||
func WatchGet(ctx *fasthttp.RequestCtx) {
|
||||
usrVal := ctx.UserValue("user")
|
||||
var userId int64
|
||||
@@ -185,7 +228,7 @@ func Register(ctx *fasthttp.RequestCtx) {
|
||||
ctx.SetStatusCode(fasthttp.StatusExpectationFailed)
|
||||
return
|
||||
}
|
||||
if userData.Data.MalID != register.MalID {
|
||||
if userData.MalID != register.MalID {
|
||||
ctx.WriteString("Dich gibts nicht auf MAL")
|
||||
ctx.SetStatusCode(fasthttp.StatusExpectationFailed)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user