Skip to content

Commit

Permalink
feat: pet repo
Browse files Browse the repository at this point in the history
  • Loading branch information
bookpanda committed Dec 21, 2023
1 parent 4dae331 commit f24248a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/app/repository/pet/pet.repository.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package pet

import (
"github.com/isd-sgcu/johnjud-backend/src/app/model/pet"
"gorm.io/gorm"
)

type Repository struct {
db *gorm.DB
}

func NewRepository(db *gorm.DB) *Repository {
return &Repository{db: db}
}

func (r *Repository) FindAll(result *[]*pet.Pet) error {
return r.db.Model(&pet.Pet{}).Find(result).Error
}

func (r *Repository) FindOne(id string, result *[]*pet.Pet) error {
return r.db.Model(&pet.Pet{}).Find(result, "id = ?", id).Error
}

func (r *Repository) Create(in *pet.Pet) error {
return r.db.Create(&in).Error
}

func (r *Repository) Update(id string, result *pet.Pet) error {
return r.db.Where(id, "id = ?", id).Updates(&result).First(&result, "id = ?", id).Error
}

func (r *Repository) Delete(id string) error {
return r.db.Where("id = ?", id).Delete(&pet.Pet{}).Error
}

0 comments on commit f24248a

Please sign in to comment.