Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.7 KiB

package Friends
import (
"encoding/json"
"net/http"
"net/url"
"strings"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Api/Auth"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
)
func EncryptedFriendRequestList(w http.ResponseWriter, r *http.Request) {
var (
userSession Models.Session
friends []Models.FriendRequest
returnJson []byte
err error
)
userSession, err = Auth.CheckCookie(r)
if err != nil {
http.Error(w, "Forbidden", http.StatusUnauthorized)
return
}
friends, err = Database.GetFriendRequestsByUserId(userSession.UserID.String())
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)
}
func EncryptedFriendList(w http.ResponseWriter, r *http.Request) {
var (
friends []Models.Friend
query url.Values
friendIds []string
returnJson []byte
ok bool
err error
)
query = r.URL.Query()
friendIds, ok = query["friend_ids"]
if !ok {
http.Error(w, "Invalid Data", http.StatusBadGateway)
return
}
// TODO: Fix error handling here
friendIds = strings.Split(friendIds[0], ",")
friends, err = Database.GetFriendsByIds(friendIds)
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)
}