Files
.github
.vscode
docker
internal
app
applicant
certificate
deployer
domain
notify
pkg
repository
access.go
acme_account.go
certificate.go
settings.go
statistics.go
workflow.go
workflow_output.go
workflow_run.go
rest
scheduler
statistics
workflow
migrations
ui
.dockerignore
.editorconfig
.gitignore
.goreleaser.yml
CHANGELOG.md
CONTRIBUTING.md
CONTRIBUTING_EN.md
Dockerfile
LICENSE.md
Makefile
README.md
README_EN.md
go.mod
go.sum
main.go
nixpacks.toml
usage.gif
certimate/internal/repository/settings.go
2025-01-18 22:25:20 +08:00

43 lines
961 B
Go

package repository
import (
"context"
"database/sql"
"errors"
"github.com/pocketbase/dbx"
"github.com/usual2970/certimate/internal/app"
"github.com/usual2970/certimate/internal/domain"
)
type SettingsRepository struct{}
func NewSettingsRepository() *SettingsRepository {
return &SettingsRepository{}
}
func (r *SettingsRepository) GetByName(ctx context.Context, name string) (*domain.Settings, error) {
record, err := app.GetApp().FindFirstRecordByFilter(
domain.CollectionNameSettings,
"name={:name}",
dbx.Params{"name": name},
)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, domain.ErrRecordNotFound
}
return nil, err
}
settings := &domain.Settings{
Meta: domain.Meta{
Id: record.Id,
CreatedAt: record.GetDateTime("created").Time(),
UpdatedAt: record.GetDateTime("updated").Time(),
},
Name: record.GetString("name"),
Content: record.GetString("content"),
}
return settings, nil
}