Refactor Chats Service (#48)

This commit is contained in:
ben-toogood
2021-01-27 11:43:09 +00:00
committed by GitHub
parent 6ab2b2d9fa
commit 54c5994faf
30 changed files with 1855 additions and 82 deletions

View File

@@ -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")
}