package Database
|
|
|
|
import (
|
|
"github.com/gofrs/uuid"
|
|
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
)
|
|
|
|
// ConversationDetail stores the name for the conversation
|
|
type ConversationDetail struct {
|
|
Base
|
|
Name string `gorm:"not null" json:"name"` // Stored encrypted
|
|
Users []ConversationDetailUser ` json:"users"`
|
|
TwoUser string `gorm:"not null" json:"two_user"`
|
|
AttachmentID *uuid.UUID ` json:"attachment_id"`
|
|
Attachment Attachment ` json:"attachment"`
|
|
MessageExpiryDefault MessageExpiry `gorm:"default:no_expiry" json:"-" sql:"type:ENUM('fifteen_min', 'thirty_min', 'one_hour', 'three_hour', 'six_hour', 'twelve_hour', 'one_day', 'three_day', 'no_expiry')"` // Stored encrypted
|
|
MessageExpiry string `gorm:"-" json:"message_expiry"` // Stored encrypted
|
|
AdminAddMembers string ` json:"admin_add_members"` // Stored encrypted
|
|
AdminEditInfo string ` json:"admin_edit_info"` // Stored encrypted
|
|
AdminSendMessages string ` json:"admin_send_messages"` // Stored encrypted
|
|
}
|
|
|
|
// GetConversationDetailByID gets by id
|
|
func GetConversationDetailByID(id string) (ConversationDetail, error) {
|
|
var (
|
|
conversationDetail ConversationDetail
|
|
err error
|
|
)
|
|
|
|
err = DB.Preload(clause.Associations).
|
|
Where("id = ?", id).
|
|
First(&conversationDetail).
|
|
Error
|
|
|
|
return conversationDetail, err
|
|
}
|
|
|
|
// GetConversationDetailsByIds gets by multiple ids
|
|
func GetConversationDetailsByIds(id []string) ([]ConversationDetail, error) {
|
|
var (
|
|
conversationDetail []ConversationDetail
|
|
err error
|
|
)
|
|
|
|
err = DB.Preload(clause.Associations).
|
|
Where("id IN ?", id).
|
|
Find(&conversationDetail).
|
|
Error
|
|
|
|
return conversationDetail, err
|
|
}
|
|
|
|
// CreateConversationDetail creates a ConversationDetail record
|
|
func (conversationDetail *ConversationDetail) CreateConversationDetail() error {
|
|
return DB.Session(&gorm.Session{FullSaveAssociations: true}).
|
|
Create(conversationDetail).
|
|
Error
|
|
}
|
|
|
|
// UpdateConversationDetail updates a ConversationDetail record
|
|
func (conversationDetail *ConversationDetail) UpdateConversationDetail() error {
|
|
return DB.Session(&gorm.Session{FullSaveAssociations: true}).
|
|
Where("id = ?", conversationDetail.ID).
|
|
Updates(conversationDetail).
|
|
Error
|
|
}
|
|
|
|
// DeleteConversationDetail deletes a ConversationDetail record
|
|
func (conversationDetail *ConversationDetail) DeleteConversationDetail() error {
|
|
return DB.Session(&gorm.Session{FullSaveAssociations: true}).
|
|
Delete(conversationDetail).
|
|
Error
|
|
}
|