-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy pathDbMapping.kt
More file actions
87 lines (84 loc) · 2.79 KB
/
DbMapping.kt
File metadata and controls
87 lines (84 loc) · 2.79 KB
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
package catchup.service.api
import catchup.service.api.Mark.MarkType
import catchup.service.db.CatchUpDbItem
fun CatchUpItem.toCatchUpDbItem(): CatchUpDbItem {
return CatchUpDbItem(
id = id,
title = title,
description = description,
timestamp = timestamp,
scoreChar = score?.first,
score = score?.second,
tag = tag,
tagHintColor = tagHintColor,
author = author,
source = source,
itemClickUrl = itemClickUrl,
detailKey = detailKey,
serviceId = serviceId,
indexInResponse = indexInResponse,
contentType = contentType?.name,
imagePreviewUrl = imagePreviewUrl,
imageUrl = imageInfo?.url,
imageDetailUrl = imageInfo?.detailUrl,
imageAnimatable = imageInfo?.animatable,
imageSourceUrl = imageInfo?.sourceUrl,
imageBestSizeX = imageInfo?.bestSize?.first,
imageBestSizeY = imageInfo?.bestSize?.second,
imageAspectRatio = imageInfo?.aspectRatio,
imageImageId = imageInfo?.imageId,
imageColor = imageInfo?.color,
imageBlurHash = imageInfo?.blurHash,
markText = mark?.text,
markTextPrefix = mark?.textPrefix,
markType = mark?.markType?.name,
markClickUrl = mark?._markClickUrl,
markIconTintColor = mark?.iconTintColor,
markFormatTextAsCount = mark?.formatTextAsCount,
)
}
fun CatchUpDbItem.toCatchUpItem(): CatchUpItem {
return CatchUpItem(
id = id,
title = title,
description = description,
timestamp = timestamp,
score = scoreChar?.let { Pair(it, score ?: 0) },
tag = tag,
tagHintColor = tagHintColor,
author = author,
source = source,
itemClickUrl = itemClickUrl,
detailKey = detailKey,
serviceId = serviceId,
indexInResponse = indexInResponse,
contentType = contentType?.let { ContentType.valueOf(it) },
imagePreviewUrl = imagePreviewUrl,
imageInfo =
imageUrl?.let {
ImageInfo(
url = it,
detailUrl = checkNotNull(imageDetailUrl) { "imageDetailUrl was null" },
animatable = checkNotNull(imageAnimatable) { "imageAnimatable was null" },
sourceUrl = checkNotNull(imageSourceUrl) { "imageSourceUrl was null" },
bestSize = imageBestSizeX?.let { Pair(it, imageBestSizeY ?: 0) },
aspectRatio = checkNotNull(imageAspectRatio) { "imageAspectRatio was null" },
imageId = checkNotNull(imageImageId) { "imageImageId was null" },
color = imageColor,
blurHash = imageBlurHash,
)
},
mark =
markType?.let {
Mark(
text = markText,
textPrefix = markTextPrefix,
markType = MarkType.valueOf(it),
_markClickUrl = markClickUrl,
iconTintColor = markIconTintColor,
formatTextAsCount =
checkNotNull(markFormatTextAsCount) { "markFormatTextAsCount was null" },
)
},
)
}