39 lines
827 B
Go
39 lines
827 B
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"kontor-api-gin/internal/models"
|
|
"log/slog"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type ProfileRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewProfileRepository(db *gorm.DB) *ProfileRepository {
|
|
repository := &ProfileRepository{db: db}
|
|
return repository
|
|
}
|
|
|
|
func (repository *ProfileRepository) FindAll(context context.Context) ([]models.Profile, error) {
|
|
var profiles []models.Profile
|
|
|
|
result := repository.db.Find(&profiles)
|
|
slog.Info("ProfileRepository#FindAll", "count", result.RowsAffected)
|
|
|
|
return profiles, nil
|
|
}
|
|
|
|
func (repository *ProfileRepository) FindProfileByEmail(email string) (*models.Profile, error) {
|
|
var profile models.Profile
|
|
|
|
err := repository.db.Model(models.Profile{}).Where("email = ?", email).Take(&profile).Error
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &profile, nil
|
|
}
|