|
|
- package Messages
-
- import (
- "encoding/json"
- "net/http"
-
- "git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
- "git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
- )
-
- type RawMessageData struct {
- MessageData Models.MessageData `json:"message_data"`
- Messages []Models.Message `json:"message"`
- }
-
- func CreateMessage(w http.ResponseWriter, r *http.Request) {
- var (
- rawMessageData RawMessageData
- err error
- )
-
- err = json.NewDecoder(r.Body).Decode(&rawMessageData)
- if err != nil {
- http.Error(w, "Error", http.StatusInternalServerError)
- return
- }
-
- err = Database.CreateMessageData(&rawMessageData.MessageData)
- if err != nil {
- http.Error(w, "Error", http.StatusInternalServerError)
- return
- }
-
- err = Database.CreateMessages(&rawMessageData.Messages)
- if err != nil {
- http.Error(w, "Error", http.StatusInternalServerError)
- return
- }
-
- w.WriteHeader(http.StatusOK)
- }
|