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.

43 lines
865 B

  1. package Messages
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
  6. "git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
  7. "github.com/gorilla/mux"
  8. )
  9. func MessageThread(w http.ResponseWriter, r *http.Request) {
  10. var (
  11. messages []Models.Message
  12. urlVars map[string]string
  13. threadID string
  14. returnJson []byte
  15. ok bool
  16. err error
  17. )
  18. urlVars = mux.Vars(r)
  19. threadID, ok = urlVars["threadID"]
  20. if !ok {
  21. http.Error(w, "Not Found", http.StatusNotFound)
  22. return
  23. }
  24. messages, err = Database.GetMessagesByThreadId(threadID)
  25. if !ok {
  26. http.Error(w, "Not Found", http.StatusNotFound)
  27. return
  28. }
  29. returnJson, err = json.MarshalIndent(messages, "", " ")
  30. if err != nil {
  31. http.Error(w, "Error", http.StatusInternalServerError)
  32. return
  33. }
  34. w.WriteHeader(http.StatusOK)
  35. w.Write(returnJson)
  36. }