bill-server-go/internal/label/service.go

42 lines
1.0 KiB
Go
Raw Normal View History

2023-05-31 16:36:45 +08:00
package label
2023-06-01 19:40:48 +08:00
import (
"context"
2023-06-02 16:07:54 +08:00
"github.com/samber/lo"
2023-06-01 19:40:48 +08:00
)
type labelService struct {
labelRepository LabelRepository
}
func NewLabelService(labelRepository LabelRepository) LabelService {
return &labelService{labelRepository: labelRepository}
}
2023-06-02 16:07:54 +08:00
func (l *labelService) GetLabels(ctx context.Context) ([]interface{}, error) {
labels, err := l.labelRepository.GetLabels(ctx)
return lo.Map(labels, func(l Label, _ int) interface{} { return l.Dto() }), err
2023-06-01 19:40:48 +08:00
}
2023-06-02 16:07:54 +08:00
func (l *labelService) GetLabelById(ctx context.Context, id int) (interface{}, error) {
label, err := l.labelRepository.GetLabelById(ctx, id)
if err != nil {
return nil, err
}
return label.Dto(), nil
2023-06-01 19:40:48 +08:00
}
func (l *labelService) CreateLabel(ctx context.Context, label *Label) error {
2023-06-02 16:07:54 +08:00
return l.labelRepository.CreateLabel(ctx, label)
2023-06-01 19:40:48 +08:00
}
func (l *labelService) UpdateLabel(ctx context.Context, label *Label) error {
2023-06-02 16:07:54 +08:00
return l.labelRepository.UpdateLabel(ctx, label)
2023-06-01 19:40:48 +08:00
}
func (l *labelService) DeleteLabel(ctx context.Context, id int) error {
2023-06-02 16:07:54 +08:00
return l.labelRepository.DeleteLabel(ctx, id)
2023-06-01 19:40:48 +08:00
}