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.

41 lines
957 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. // EncryptedFriendRequestList gets friend request list
  10. func EncryptedFriendRequestList(w http.ResponseWriter, r *http.Request) {
  11. var (
  12. userSession Models.Session
  13. friends []Models.FriendRequest
  14. returnJSON []byte
  15. err error
  16. )
  17. userSession, err = Auth.CheckCookie(r)
  18. if err != nil {
  19. http.Error(w, "Forbidden", http.StatusUnauthorized)
  20. return
  21. }
  22. friends, err = Database.GetFriendRequestsByUserID(userSession.UserID.String())
  23. if err != nil {
  24. http.Error(w, "Error", http.StatusInternalServerError)
  25. return
  26. }
  27. returnJSON, err = json.MarshalIndent(friends, "", " ")
  28. if err != nil {
  29. http.Error(w, "Error", http.StatusInternalServerError)
  30. return
  31. }
  32. w.WriteHeader(http.StatusOK)
  33. w.Write(returnJSON)
  34. }