fix: check duplicate photo in AddPhoto
This commit is contained in:
parent
f32fc41be3
commit
f8d1083b2d
@ -112,6 +112,11 @@ func (r *FaceGalleryRepo) AddPhoto(personID int, photoPath string) error {
|
||||
return err
|
||||
}
|
||||
defer db.Close()
|
||||
// Skip if already exists
|
||||
var existing int
|
||||
if db.QueryRow(`SELECT COUNT(*) FROM face_photos WHERE person_id = ? AND photo_path = ?`, personID, photoPath).Scan(&existing) == nil && existing > 0 {
|
||||
return nil
|
||||
}
|
||||
now := time.Now().Format(time.RFC3339)
|
||||
_, err = db.Exec(`INSERT INTO face_photos(person_id, photo_path, created_at) VALUES(?, ?, ?)`, personID, photoPath, now)
|
||||
return err
|
||||
|
||||
Loading…
Reference in New Issue
Block a user