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,42 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user