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.

40 lines
902 B

  1. package Friends
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "git.tovijaeschke.xyz/tovi/Envelope/Backend/Api/Auth"
  6. "git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
  7. "git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
  8. )
  9. func EncryptedFriendRequestList(w http.ResponseWriter, r *http.Request) {
  10. var (
  11. userSession Models.Session
  12. friends []Models.FriendRequest
  13. returnJson []byte
  14. err error
  15. )
  16. userSession, err = Auth.CheckCookie(r)
  17. if err != nil {
  18. http.Error(w, "Forbidden", http.StatusUnauthorized)
  19. return
  20. }
  21. friends, err = Database.GetFriendRequestsByUserId(userSession.UserID.String())
  22. if err != nil {
  23. http.Error(w, "Error", http.StatusInternalServerError)
  24. return
  25. }
  26. returnJson, err = json.MarshalIndent(friends, "", " ")
  27. if err != nil {
  28. http.Error(w, "Error", http.StatusInternalServerError)
  29. return
  30. }
  31. w.WriteHeader(http.StatusOK)
  32. w.Write(returnJson)
  33. }