-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_layer_items.go
41 lines (33 loc) · 1.08 KB
/
update_layer_items.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package character
import (
"errors"
validation "github.com/go-ozzo/ozzo-validation"
"github.com/kaikourok/lunchtote-backend/entity/model"
"github.com/kaikourok/lunchtote-backend/entity/service"
usecaseErrors "github.com/kaikourok/lunchtote-backend/usecase/errors"
)
func (s *CharacterUsecase) UpdateLayerItems(characterId, groupId int, items *[]model.CharacterIconLayerItemEditData) (result *[]model.CharacterIconLayerItem, err error) {
logger := s.registry.GetLogger()
repository := s.registry.GetRepository()
err = validation.Validate(groupId, validation.Min(1))
if err != nil {
return nil, usecaseErrors.ErrValidate
}
if items == nil {
return nil, usecaseErrors.ErrValidate
}
for _, item := range *items {
character, err := service.ParseFilePath(item.Path)
if err != nil {
return nil, usecaseErrors.ErrValidate
}
if character != characterId {
return nil, errors.New("自身のものではない画像を参照しています")
}
}
result, err = repository.UpdateLayerItems(characterId, groupId, items)
if err != nil {
logger.Error(err)
}
return result, err
}