Files
chat_room/backend/internal/repository/swipe_repository.go
T
mobiniqow 35f5084005 chore: merge backend repo history into monorepo at backend/
git-subtree-dir: backend
git-subtree-mainline: dc11190527
git-subtree-split: acae976622
2026-09-27 10:30:16 +03:30

43 lines
1.0 KiB
Go

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
}