-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpictures-grpc-mapper.go
278 lines (234 loc) · 7.49 KB
/
pictures-grpc-mapper.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package goautowp
import (
"time"
"github.com/autowp/goautowp/pictures"
"github.com/autowp/goautowp/query"
"github.com/autowp/goautowp/schema"
"github.com/autowp/goautowp/util"
)
func extractPictureModerVoteTemplate(tpl *schema.PictureModerVoteTemplateRow) *ModerVoteTemplate {
return &ModerVoteTemplate{
Id: tpl.ID,
UserId: tpl.UserID,
Message: tpl.Message,
Vote: int32(tpl.Vote),
}
}
func extractPictureItemType(pictureItemType schema.PictureItemType) PictureItemType {
switch pictureItemType {
case 0:
return PictureItemType_PICTURE_ITEM_UNKNOWN
case schema.PictureItemContent:
return PictureItemType_PICTURE_ITEM_CONTENT
case schema.PictureItemAuthor:
return PictureItemType_PICTURE_ITEM_AUTHOR
case schema.PictureItemCopyrights:
return PictureItemType_PICTURE_ITEM_COPYRIGHTS
}
return PictureItemType_PICTURE_ITEM_UNKNOWN
}
func convertPictureItemType(pictureItemType PictureItemType) schema.PictureItemType {
switch pictureItemType {
case PictureItemType_PICTURE_ITEM_UNKNOWN:
return 0
case PictureItemType_PICTURE_ITEM_CONTENT:
return schema.PictureItemContent
case PictureItemType_PICTURE_ITEM_AUTHOR:
return schema.PictureItemAuthor
case PictureItemType_PICTURE_ITEM_COPYRIGHTS:
return schema.PictureItemCopyrights
}
return 0
}
func convertPictureStatus(status PictureStatus) schema.PictureStatus {
switch status {
case PictureStatus_PICTURE_STATUS_UNKNOWN:
return ""
case PictureStatus_PICTURE_STATUS_ACCEPTED:
return schema.PictureStatusAccepted
case PictureStatus_PICTURE_STATUS_REMOVING:
return schema.PictureStatusRemoving
case PictureStatus_PICTURE_STATUS_REMOVED:
return schema.PictureStatusRemoved
case PictureStatus_PICTURE_STATUS_INBOX:
return schema.PictureStatusInbox
}
return ""
}
func convertPictureItemOptions(in *PictureItemListOptions) (*query.PictureItemListOptions, error) {
if in == nil {
return nil, nil //nolint: nilnil
}
result := query.PictureItemListOptions{
PictureID: in.GetPictureId(),
ItemID: in.GetItemId(),
TypeID: convertPictureItemType(in.GetTypeId()),
PerspectiveID: in.GetPerspectiveId(),
ExcludePerspectiveID: in.GetExcludePerspectiveId(),
ExcludeAncestorOrSelfID: in.GetExcludeAncestorOrSelfId(),
HasNoPerspectiveID: in.GetHasNoPerspectiveId(),
ItemVehicleType: convertItemVehicleTypeListOptions(in.GetItemVehicleType()),
}
var err error
result.Item, err = convertItemListOptions(in.GetItem())
if err != nil {
return nil, err
}
result.Pictures, err = convertPictureListOptions(in.GetPictures())
if err != nil {
return nil, err
}
result.ItemParentCacheAncestor, err = convertItemParentCacheListOptions(in.GetItemParentCacheAncestor())
if err != nil {
return nil, err
}
return &result, nil
}
func convertItemVehicleTypeListOptions(in *ItemVehicleTypeListOptions) *query.ItemVehicleTypeListOptions {
if in == nil {
return nil
}
result := query.ItemVehicleTypeListOptions{
VehicleTypeID: in.GetVehicleTypeId(),
}
return &result
}
func convertPictureListOptions(in *PictureListOptions) (*query.PictureListOptions, error) {
if in == nil {
return nil, nil //nolint: nilnil
}
result := query.PictureListOptions{
ID: in.GetId(),
Status: convertPictureStatus(in.GetStatus()),
AcceptedInDays: in.GetAcceptedInDays(),
OwnerID: in.GetOwnerId(),
Identity: in.GetIdentity(),
HasNoComments: in.GetHasNoComments(),
HasPoint: in.GetHasPoint(),
HasNoPoint: in.GetHasNoPoint(),
HasNoPictureItem: in.GetHasNoPictureItem(),
HasNoReplacePicture: in.GetHasNoReplacePicture(),
HasNoPictureModerVote: in.GetHasNoPictureModerVote(),
CommentTopic: convertCommentTopicListOptions(in.GetCommentTopic()),
PictureModerVote: convertPictureModerVoteListOptions(in.GetPictureModerVote()),
HasSpecialName: in.GetHasSpecialName(),
}
var err error
result.DfDistance, err = convertDfDistanceListOptions(in.GetDfDistance())
if err != nil {
return nil, err
}
inStatuses := in.GetStatuses()
if len(inStatuses) > 0 {
statuses := make([]schema.PictureStatus, 0, len(inStatuses))
for _, status := range inStatuses {
statuses = append(statuses, convertPictureStatus(status))
}
result.Statuses = statuses
}
addDate := in.GetAddDate()
if addDate != nil {
result.AddDate = &util.Date{
Year: int(addDate.GetYear()),
Month: time.Month(addDate.GetMonth()),
Day: int(addDate.GetDay()),
}
}
acceptDate := in.GetAcceptDate()
if acceptDate != nil {
result.AcceptDate = &util.Date{
Year: int(acceptDate.GetYear()),
Month: time.Month(acceptDate.GetMonth()),
Day: int(acceptDate.GetDay()),
}
}
addedFrom := in.GetAddedFrom()
if addedFrom != nil {
result.AddedFrom = &util.Date{
Year: int(addedFrom.GetYear()),
Month: time.Month(addedFrom.GetMonth()),
Day: int(addedFrom.GetDay()),
}
}
result.PictureItem, err = convertPictureItemOptions(in.GetPictureItem())
if err != nil {
return nil, err
}
result.ReplacePicture, err = convertPictureListOptions(in.GetReplacePicture())
if err != nil {
return nil, err
}
return &result, nil
}
func convertPictureModerVoteListOptions(in *PictureModerVoteListOptions) *query.PictureModerVoteListOptions {
if in == nil {
return nil
}
return &query.PictureModerVoteListOptions{
VoteGtZero: in.GetVoteGtZero(),
VoteLteZero: in.GetVoteLteZero(),
}
}
func convertDfDistanceListOptions(in *DfDistanceListOptions) (*query.DfDistanceListOptions, error) {
if in == nil {
return nil, nil //nolint: nilnil
}
var err error
result := query.DfDistanceListOptions{}
result.DstPicture, err = convertPictureListOptions(in.GetDstPicture())
if err != nil {
return nil, err
}
return &result, nil
}
func convertCommentTopicListOptions(in *CommentTopicListOptions) *query.CommentTopicListOptions {
if in == nil {
return nil
}
result := query.CommentTopicListOptions{
MessagesGtZero: in.GetMessagesGtZero(),
}
return &result
}
func convertPictureFields(fields *PictureFields) pictures.PictureFields {
return pictures.PictureFields{
NameText: fields.GetNameText(),
}
}
func convertPicturesOrder(order PicturesRequest_Order) pictures.OrderBy {
switch order {
case PicturesRequest_ORDER_NONE:
return pictures.OrderByNone
case PicturesRequest_ORDER_ADD_DATE_DESC:
return pictures.OrderByAddDateDesc
case PicturesRequest_ORDER_ADD_DATE_ASC:
return pictures.OrderByAddDateAsc
case PicturesRequest_ORDER_RESOLUTION_DESC:
return pictures.OrderByResolutionDesc
case PicturesRequest_ORDER_RESOLUTION_ASC:
return pictures.OrderByResolutionAsc
case PicturesRequest_ORDER_FILESIZE_DESC:
return pictures.OrderByFilesizeDesc
case PicturesRequest_ORDER_FILESIZE_ASC:
return pictures.OrderByFilesizeAsc
case PicturesRequest_ORDER_COMMENTS:
return pictures.OrderByComments
case PicturesRequest_ORDER_VIEWS:
return pictures.OrderByViews
case PicturesRequest_ORDER_MODER_VOTES:
return pictures.OrderByModerVotes
case PicturesRequest_ORDER_REMOVING_DATE:
return pictures.OrderByRemovingDate
case PicturesRequest_ORDER_LIKES:
return pictures.OrderByLikes
case PicturesRequest_ORDER_DISLIKES:
return pictures.OrderByDislikes
case PicturesRequest_ORDER_ACCEPT_DATETIME_DESC:
return pictures.OrderByAcceptDatetimeDesc
case PicturesRequest_ORDER_PERSPECTIVES:
return pictures.OrderByPerspectives
case PicturesRequest_ORDER_DF_DISTANCE_SIMILARITY:
return pictures.OrderByDfDistanceSimilarity
}
return pictures.OrderByNone
}