feat: add invoice-configs management functionality
This commit is contained in:
52
internal/repositories/invoice_config_repository.go
Normal file
52
internal/repositories/invoice_config_repository.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package repositories
|
||||
|
||||
import (
|
||||
"context"
|
||||
"wm-backend/internal/mapper"
|
||||
"wm-backend/internal/models"
|
||||
db "wm-backend/sqlc_gen"
|
||||
)
|
||||
|
||||
func CreateInvoiceConfig(ctx context.Context, queries *db.Queries, body models.InvoiceConfig) (models.InvoiceConfig, error) {
|
||||
result, err := queries.CreateInvoiceConfig(ctx, *mapper.ToModelInvoiceConfig(&body))
|
||||
if err != nil {
|
||||
return models.InvoiceConfig{}, err
|
||||
}
|
||||
return *mapper.ToDomainInvoiceConfig(result), nil
|
||||
}
|
||||
|
||||
func GetInvoiceConfigByID(ctx context.Context, queries *db.Queries, id int64) (models.InvoiceConfig, error) {
|
||||
result, err := queries.GetInvoiceConfigByID(ctx, id)
|
||||
if err != nil {
|
||||
return models.InvoiceConfig{}, err
|
||||
}
|
||||
return *mapper.ToDomainInvoiceConfig(result), nil
|
||||
}
|
||||
|
||||
func ListInvoiceConfigs(ctx context.Context, queries *db.Queries) ([]models.InvoiceConfig, error) {
|
||||
results, err := queries.ListInvoiceConfigs(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var items []models.InvoiceConfig
|
||||
for _, r := range results {
|
||||
items = append(items, *mapper.ToDomainInvoiceConfig(r))
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func UpdateInvoiceConfig(ctx context.Context, queries *db.Queries, body models.InvoiceConfig) (models.InvoiceConfig, error) {
|
||||
result, err := queries.UpdateInvoiceConfig(ctx, *mapper.ToUpdateModelInvoiceConfig(&body))
|
||||
if err != nil {
|
||||
return models.InvoiceConfig{}, err
|
||||
}
|
||||
return *mapper.ToDomainInvoiceConfig(result), nil
|
||||
}
|
||||
|
||||
func DeleteInvoiceConfig(ctx context.Context, queries *db.Queries, id int64) (int64, error) {
|
||||
rowsAffected, err := queries.DeleteInvoiceConfig(ctx, id)
|
||||
if err != nil {
|
||||
return rowsAffected, err
|
||||
}
|
||||
return rowsAffected, nil
|
||||
}
|
||||
Reference in New Issue
Block a user