package Messages import ( "encoding/json" "net/http" "github.com/gofrs/uuid" "git.tovijaeschke.xyz/tovi/Envelope/Backend/Database" ) type rawUpdateConversationData struct { ID string `json:"id"` Name string `json:"name"` Users []Database.ConversationDetailUser `json:"users"` UserConversations Database.UserConversationList `json:"user_conversations"` } // UpdateConversation updates the conversation data, such as title, users, etc func UpdateConversation(w http.ResponseWriter, r *http.Request) { var ( rawConversationData rawUpdateConversationData messageThread Database.ConversationDetail err error ) err = json.NewDecoder(r.Body).Decode(&rawConversationData) if err != nil { http.Error(w, "Error", http.StatusInternalServerError) return } messageThread = Database.ConversationDetail{ Base: Database.Base{ ID: uuid.FromStringOrNil(rawConversationData.ID), }, Name: rawConversationData.Name, Users: rawConversationData.Users, } err = (&messageThread).UpdateConversationDetail() if err != nil { http.Error(w, "Error", http.StatusInternalServerError) return } if len(rawConversationData.UserConversations) > 0 { err = (&rawConversationData.UserConversations).UpdateOrCreateUserConversations() if err != nil { http.Error(w, "Error", http.StatusInternalServerError) return } } w.WriteHeader(http.StatusNoContent) }