Files
kra-new/internal/service/business/preference.go
T

34 lines
1.1 KiB
Go

package business
import (
"context"
"kra/internal/biz/business"
"kra/internal/service/dto"
)
type PreferenceUsecase interface {
Current(context.Context) (*business.UserPreference, error)
UpdateCurrent(context.Context, business.UserPreference) error
}
type UserPreferenceService struct{ uc PreferenceUsecase }
func NewUserPreferenceService(uc *business.UserPreferenceUsecase) *UserPreferenceService {
return &UserPreferenceService{uc: uc}
}
func (s *UserPreferenceService) Current(ctx context.Context) (*dto.UserPreferenceResponse, error) {
pref, err := s.uc.Current(ctx)
if err != nil {
return nil, err
}
return &dto.UserPreferenceResponse{IncludeSubPromote: pref.IncludeSubPromote, IDCardDedup: pref.IDCardDedup}, nil
}
func (s *UserPreferenceService) UpdateCurrent(ctx context.Context, req *dto.UserPreferenceRequest) error {
if req == nil || req.IncludeSubPromote == nil || req.IDCardDedup == nil {
return business.ErrPreferenceRequired
}
return s.uc.UpdateCurrent(ctx, business.UserPreference{IncludeSubPromote: *req.IncludeSubPromote, IDCardDedup: *req.IDCardDedup})
}