-
Notifications
You must be signed in to change notification settings - Fork 2
/
retrieve_room_message_edit_required_data.go
86 lines (70 loc) · 2.14 KB
/
retrieve_room_message_edit_required_data.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package room
import (
"errors"
"github.com/kaikourok/lunchtote-backend/entity/model"
)
func (s *RoomUsecase) RetrieveRoomMessageEditRequiredData(characterId int) (data *model.RoomMessageEditRequiredData, err error) {
logger := s.registry.GetLogger()
repository := s.registry.GetRepository()
type nameResultStruct struct {
name string
err error
}
type iconsResultStruct struct {
icons *[]model.Icon
err error
}
type listsResultStruct struct {
lists *[]model.ListOverview
err error
}
type fetchConfigResultStruct struct {
config *[]model.RoomMessageFetchConfigWithId
err error
}
nameChannnel := make(chan nameResultStruct)
iconsChannel := make(chan iconsResultStruct)
listsChannel := make(chan listsResultStruct)
fetchConfigChannel := make(chan fetchConfigResultStruct)
go func() {
name, err := repository.RetrieveCharacterNickname(characterId)
nameChannnel <- nameResultStruct{name, err}
}()
go func() {
icons, err := repository.RetrieveCharacterIcons(characterId)
iconsChannel <- iconsResultStruct{icons, err}
}()
go func() {
lists, err := repository.RetrieveLists(characterId)
listsChannel <- listsResultStruct{lists, err}
}()
go func() {
config, err := repository.RetrieveRoomMessageFetchConfig(characterId)
fetchConfigChannel <- fetchConfigResultStruct{config, err}
}()
nameResult := <-nameChannnel
iconsResult := <-iconsChannel
listsResult := <-listsChannel
fetchConfigResult := <-fetchConfigChannel
if nameResult.err != nil || iconsResult.err != nil || listsResult.err != nil || fetchConfigResult.err != nil {
if nameResult.err != nil {
logger.Error(nameResult.err)
}
if iconsResult.err != nil {
logger.Error(iconsResult.err)
}
if listsResult.err != nil {
logger.Error(listsResult.err)
}
if fetchConfigResult.err != nil {
logger.Error(fetchConfigResult.err)
}
return nil, errors.New("データの取得中にエラーが発生しました")
}
var result model.RoomMessageEditRequiredData
result.Character.Name = nameResult.name
result.Icons = *iconsResult.icons
result.Lists = *listsResult.lists
result.FetchConfigs = *fetchConfigResult.config
return &result, nil
}