mirror of
https://github.com/usual2970/certimate.git
synced 2025-08-28 20:21:44 +00:00
refactor: clean code
This commit is contained in:
@@ -4,9 +4,12 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/pocketbase/pocketbase/models"
|
||||
"github.com/usual2970/certimate/internal/app"
|
||||
"github.com/usual2970/certimate/internal/domain"
|
||||
"github.com/usual2970/certimate/internal/pkg/utils/types"
|
||||
)
|
||||
|
||||
type AccessRepository struct{}
|
||||
@@ -15,7 +18,7 @@ func NewAccessRepository() *AccessRepository {
|
||||
return &AccessRepository{}
|
||||
}
|
||||
|
||||
func (a *AccessRepository) GetById(ctx context.Context, id string) (*domain.Access, error) {
|
||||
func (r *AccessRepository) GetById(ctx context.Context, id string) (*domain.Access, error) {
|
||||
record, err := app.GetApp().Dao().FindRecordById("access", id)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
@@ -24,6 +27,18 @@ func (a *AccessRepository) GetById(ctx context.Context, id string) (*domain.Acce
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !types.IsNil(record.Get("deleted")) {
|
||||
return nil, domain.ErrRecordNotFound
|
||||
}
|
||||
|
||||
return r.castRecordToModel(record)
|
||||
}
|
||||
|
||||
func (r *AccessRepository) castRecordToModel(record *models.Record) (*domain.Access, error) {
|
||||
if record == nil {
|
||||
return nil, fmt.Errorf("record is nil")
|
||||
}
|
||||
|
||||
access := &domain.Access{
|
||||
Meta: domain.Meta{
|
||||
Id: record.GetId(),
|
||||
|
Reference in New Issue
Block a user