- package Friends
-
- import (
- "encoding/json"
- "net/http"
- "net/url"
- "strconv"
-
- "git.tovijaeschke.xyz/tovi/Envelope/Backend/Api/Auth"
- "git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
- )
-
- // FriendRequestList gets friend request list
- func FriendRequestList(w http.ResponseWriter, r *http.Request) {
- var (
- userSession Database.Session
- friends Database.FriendRequestList
- values url.Values
- returnJSON []byte
- page int
- err error
- )
-
- values = r.URL.Query()
-
- page, err = strconv.Atoi(values.Get("page"))
- if err != nil {
- page = 0
- }
-
- userSession, _ = Auth.CheckCookie(r)
-
- friends, err = Database.GetFriendRequestsByUserID(userSession.UserID.String(), page)
- if err != nil {
- http.Error(w, "Error", http.StatusInternalServerError)
- return
- }
-
- returnJSON, err = json.MarshalIndent(friends, "", " ")
- if err != nil {
- http.Error(w, "Error", http.StatusInternalServerError)
- return
- }
-
- w.WriteHeader(http.StatusOK)
- w.Write(returnJSON)
- }
|