package repository import ( "errors" "gorm.io/gorm" "dating-app/internal/models" ) type SwipeRepository struct { db *gorm.DB } func NewSwipeRepository(db *gorm.DB) *SwipeRepository { return &SwipeRepository{db: db} } func (r *SwipeRepository) Create(swipe *models.Swipe) error { return r.db.Create(swipe).Error } // HasLiked یعنی swiperID قبلاً swipedID رو لایک/سوپرلایک کرده func (r *SwipeRepository) HasLiked(swiperID, swipedID uint) (bool, error) { var swipe models.Swipe err := r.db. Where("swiper_id = ? AND swiped_id = ? AND action IN ?", swiperID, swipedID, []models.SwipeAction{models.SwipeLike, models.SwipeSuperlike}). First(&swipe).Error if errors.Is(err, gorm.ErrRecordNotFound) { return false, nil } if err != nil { return false, err } return true, nil } func (r *SwipeRepository) Exists(swiperID, swipedID uint) (bool, error) { var count int64 err := r.db.Model(&models.Swipe{}).Where("swiper_id = ? AND swiped_id = ?", swiperID, swipedID).Count(&count).Error return count > 0, err }