This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user