51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package data
|
|
|
|
import (
|
|
"context"
|
|
"git.usbharu.dev/usbharu/unos/illust"
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
|
)
|
|
|
|
type IllustDataServiceImpl struct {
|
|
UnimplementedIllustDataServiceServer
|
|
IllustDataRepository
|
|
}
|
|
|
|
func NewIllustDataServiceImpl(repository IllustDataRepository) *IllustDataServiceImpl {
|
|
return &IllustDataServiceImpl{
|
|
IllustDataRepository: repository,
|
|
}
|
|
}
|
|
|
|
func (s *IllustDataServiceImpl) Save(ctx context.Context, req *illust.Illust) (*illust.Illust, error) {
|
|
|
|
err := req.Validate()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = s.IllustDataRepository.Save(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return req, nil
|
|
}
|
|
|
|
func (s *IllustDataServiceImpl) GetById(ctx context.Context, req *IllustGetById) (*illust.Illust, error) {
|
|
return s.IllustDataRepository.FindById(req.Id)
|
|
}
|
|
|
|
func (s *IllustDataServiceImpl) AddTag(ctx context.Context, tag *IllustAddTag) (*emptypb.Empty, error) {
|
|
id, err := s.IllustDataRepository.FindById(tag.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
id.Tags = append(id.Tags, tag.Tags...)
|
|
err = s.IllustDataRepository.Save(id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &emptypb.Empty{}, nil
|
|
}
|