mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-14 03:54:47 +00:00
Refactor Chats Service (#48)
This commit is contained in:
@@ -26,7 +26,7 @@ func (s *Streams) CreateMessage(ctx context.Context, req *pb.CreateMessageReques
|
||||
return s.DB.Transaction(func(tx *gorm.DB) error {
|
||||
// lookup the conversation
|
||||
var conv Conversation
|
||||
if err := s.DB.Where(&Conversation{ID: req.ConversationId}).First(&conv).Error; err == gorm.ErrRecordNotFound {
|
||||
if err := tx.Where(&Conversation{ID: req.ConversationId}).First(&conv).Error; err == gorm.ErrRecordNotFound {
|
||||
return ErrNotFound
|
||||
} else if err != nil {
|
||||
logger.Errorf("Error reading conversation: %v", err)
|
||||
@@ -41,7 +41,7 @@ func (s *Streams) CreateMessage(ctx context.Context, req *pb.CreateMessageReques
|
||||
AuthorID: req.AuthorId,
|
||||
ConversationID: req.ConversationId,
|
||||
}
|
||||
if err := s.DB.Create(msg).Error; err != nil {
|
||||
if err := tx.Create(msg).Error; err != nil {
|
||||
logger.Errorf("Error creating message: %v", err)
|
||||
return errors.InternalServerError("DATABASE_ERROR", "Error connecting to database")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user