55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
|
|
package service
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"github.com/muyuqingfeng/iloom/washing-service/internal/model"
|
||
|
|
"github.com/muyuqingfeng/iloom/washing-service/internal/repository"
|
||
|
|
)
|
||
|
|
|
||
|
|
type PlanService struct {
|
||
|
|
repo *repository.PlanRepo
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewPlanService(repo *repository.PlanRepo) *PlanService {
|
||
|
|
return &PlanService{repo: repo}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *PlanService) List(ctx context.Context, companyID string) ([]model.WashingPlan, error) {
|
||
|
|
return s.repo.List(ctx, companyID)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *PlanService) GetByID(ctx context.Context, id, companyID string) (*model.WashingPlan, error) {
|
||
|
|
plan, err := s.repo.GetByID(ctx, id)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
if plan == nil {
|
||
|
|
return nil, fmt.Errorf("washing plan not found")
|
||
|
|
}
|
||
|
|
if plan.WashingFactoryID == nil || *plan.WashingFactoryID != companyID {
|
||
|
|
return nil, fmt.Errorf("washing plan not found")
|
||
|
|
}
|
||
|
|
return plan, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *PlanService) UpdateStatus(ctx context.Context, id, companyID, status string) error {
|
||
|
|
plan, err := s.repo.GetByID(ctx, id)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
if plan == nil || plan.WashingFactoryID == nil || *plan.WashingFactoryID != companyID {
|
||
|
|
return fmt.Errorf("washing plan not found")
|
||
|
|
}
|
||
|
|
return s.repo.UpdateStatus(ctx, id, status)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *PlanService) Pending(ctx context.Context, companyID string) ([]model.WashingPlan, error) {
|
||
|
|
return s.repo.Pending(ctx, companyID)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *PlanService) Completed(ctx context.Context, companyID string) ([]model.WashingPlan, error) {
|
||
|
|
return s.repo.Completed(ctx, companyID)
|
||
|
|
}
|