38 lines
876 B
Go
38 lines
876 B
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"kontor-api-gin/internal/models"
|
|
"log/slog"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type TokenRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewTokenRepository(db *gorm.DB) *TokenRepository {
|
|
repository := &TokenRepository{db: db}
|
|
return repository
|
|
}
|
|
|
|
func (repository *TokenRepository) FindAll(context context.Context) ([]models.Token, error) {
|
|
var tokens []models.Token
|
|
|
|
result := repository.db.Find(&tokens)
|
|
slog.Info("TokenRepository#FindAll", "count", result.RowsAffected)
|
|
|
|
return tokens, nil
|
|
}
|
|
|
|
func (repository *TokenRepository) GetById(context context.Context, id string) (models.Token, error) {
|
|
var token = models.Token{ID: id}
|
|
slog.Info("TokenRepository#GetById", "id", id)
|
|
result := repository.db.First(&token)
|
|
if result.Error != nil {
|
|
slog.Info("TokenRepository#GetById", "error", result.Error.Error())
|
|
}
|
|
return token, result.Error
|
|
}
|