Go workspace (go.work) with 5 microservices + shared library: - gateway (8080), auth-service (8081), purchaser-service (8082) - textile-service (8083), washing-service (8084) - shared: proto definitions, common packages Infrastructure: docker-compose for local dev, K8s manifests for K3s cluster deployment (mysql/redis/etcd + traefik ingress). Frontend (iloom-flatten) added as git submodule. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
42 lines
893 B
Go
42 lines
893 B
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
|
|
"github.com/muyuqingfeng/iloom/purchaser-service/internal/model"
|
|
"github.com/muyuqingfeng/iloom/purchaser-service/internal/repository"
|
|
)
|
|
|
|
type APService struct {
|
|
repo *repository.APRepo
|
|
db *sql.DB
|
|
}
|
|
|
|
func NewAPService(repo *repository.APRepo, db *sql.DB) *APService {
|
|
return &APService{repo: repo, db: db}
|
|
}
|
|
|
|
func (s *APService) List(ctx context.Context, companyID string) ([]model.AccountsPayable, error) {
|
|
return s.repo.List(ctx, companyID)
|
|
}
|
|
|
|
func (s *APService) Pay(ctx context.Context, apID, companyID string, amount float64) error {
|
|
if amount <= 0 {
|
|
return fmt.Errorf("amount must be positive")
|
|
}
|
|
|
|
tx, err := s.db.BeginTx(ctx, nil)
|
|
if err != nil {
|
|
return fmt.Errorf("begin tx: %w", err)
|
|
}
|
|
defer tx.Rollback()
|
|
|
|
if err := s.repo.Pay(ctx, tx, apID, amount); err != nil {
|
|
return err
|
|
}
|
|
|
|
return tx.Commit()
|
|
}
|