Initial commit: dating app backend (Go/Gin/GORM/Postgres)
Phone+OTP auth, staged onboarding, admin approval workflow, and a full discovery/swipe/match/chat system with photo upload and approximate distance (haversine) based on user location. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
"dating-app/internal/models"
|
||||
)
|
||||
|
||||
type MessageRepository struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func NewMessageRepository(db *gorm.DB) *MessageRepository {
|
||||
return &MessageRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *MessageRepository) Create(msg *models.Message) error {
|
||||
return r.db.Create(msg).Error
|
||||
}
|
||||
|
||||
func (r *MessageRepository) ListByMatch(matchID uint) ([]models.Message, error) {
|
||||
var messages []models.Message
|
||||
err := r.db.Where("match_id = ?", matchID).Order("created_at asc").Find(&messages).Error
|
||||
return messages, err
|
||||
}
|
||||
|
||||
// LastMessage آخرین پیام یک مچ رو برمیگردونه (برای پیشنمایش لیست گفتگوها)
|
||||
func (r *MessageRepository) LastMessage(matchID uint) (*models.Message, error) {
|
||||
var msg models.Message
|
||||
err := r.db.Where("match_id = ?", matchID).Order("created_at desc").First(&msg).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &msg, nil
|
||||
}
|
||||
Reference in New Issue
Block a user