|
|
- package Messages
-
- import (
- "encoding/json"
- "fmt"
- "net/http"
-
- "github.com/gofrs/uuid"
-
- "git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
- "git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
- )
-
- type RawConversationData struct {
- ID string `json:"id"`
- Name string `json:"name"`
- Users string `json:"users"`
- UserConversations []Models.UserConversation `json:"user_conversations"`
- }
-
- func CreateConversation(w http.ResponseWriter, r *http.Request) {
- var (
- rawConversationData RawConversationData
- messageThread Models.ConversationDetail
- err error
- )
-
- err = json.NewDecoder(r.Body).Decode(&rawConversationData)
- if err != nil {
- http.Error(w, "Error", http.StatusInternalServerError)
- return
- }
-
- messageThread = Models.ConversationDetail{
- Base: Models.Base{
- ID: uuid.FromStringOrNil(rawConversationData.ID),
- },
- Name: rawConversationData.Name,
- Users: rawConversationData.Users,
- }
-
- err = Database.CreateConversationDetail(&messageThread)
- if err != nil {
- http.Error(w, "Error", http.StatusInternalServerError)
- return
- }
-
- fmt.Println(rawConversationData.UserConversations[0])
-
- err = Database.CreateUserConversations(&rawConversationData.UserConversations)
- if err != nil {
- http.Error(w, "Error", http.StatusInternalServerError)
- return
- }
-
- w.WriteHeader(http.StatusOK)
- }
|