-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpackage.scala
More file actions
103 lines (84 loc) · 3.19 KB
/
package.scala
File metadata and controls
103 lines (84 loc) · 3.19 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package utils
import java.time.Instant
import models.discount.offers.{Offer, OfferType}
import models.discount.qualifiers.{Qualifier, QualifierType}
import models.objects.ObjectUtils
import models.promotion.Promotion
import org.json4s.jackson.JsonMethods._
import org.json4s.jackson.Serialization._
import utils.JsonFormatters.phoenixFormats
package object seeds {
case class BaseDiscount(title: String, discountId: Int = 0, formId: Int = 0, shadowId: Int = 0)
case class BaseDiscountForm(title: String, qualifier: Qualifier, offer: Offer) {
implicit val formats = phoenixFormats
val qualifierType = QualifierType.show(qualifier.qualifierType)
val offerType = OfferType.show(offer.offerType)
val qualifierJson = s"""{"$qualifierType": ${write(qualifier)}}"""
val offerJson = s"""{"$offerType": ${write(offer)}}"""
val (keyMap, form) = ObjectUtils.createForm(parse(s"""
{
"title" : "$title",
"description" : "$title",
"tags" : [],
"qualifier": $qualifierJson,
"offer" : $offerJson
}"""))
}
case class BaseDiscountShadow(f: BaseDiscountForm) {
val shadow = ObjectUtils.newShadow(
parse("""
{
"title" : {"type": "string", "ref": "title"},
"description" : {"type": "richText", "ref": "description"},
"tags" : {"type": "tags", "ref": "tags"},
"qualifier" : {"type": "qualifier", "ref": "qualifier"},
"offer" : {"type": "offer", "ref": "offer"}
}"""),
f.keyMap)
}
case class BasePromotion(promotionId: Int = 0,
formId: Int = 0,
shadowId: Int = 0,
applyType: Promotion.ApplyType,
title: String)
case object BasePromotionForm {
val (keyMap, form) = ObjectUtils.createForm(parse(s"""{ "tags" : [] }"""))
}
case object BasePromotionShadow {
val shadow = ObjectUtils
.newShadow(parse("""{"tags" : {"type": "tags", "ref": "tags"}}"""), BasePromotionForm.keyMap)
}
case class BaseCoupon(formId: Int = 0, shadowId: Int = 0, promotionId: Int)
case class BaseCouponForm(title: String) {
val (keyMap, form) = ObjectUtils.createForm(parse(s"""
{
"name" : "$title",
"storefrontName" : "$title",
"description" : "$title",
"details" : "",
"activeFrom" : "${Instant.now}",
"activeTo" : null,
"tags" : [],
"usageRules": {
"isExclusive": false,
"isUnlimitedPerCode": true,
"isUnlimitedPerCustomer": true
}
}"""))
}
case class BaseCouponShadow(f: BaseCouponForm) {
val shadow = ObjectUtils.newShadow(
parse("""
{
"name" : {"type": "string", "ref": "name"},
"storefrontName" : {"type": "richText", "ref": "storefrontName"},
"description" : {"type": "text", "ref": "description"},
"details" : {"type": "richText", "ref": "details"},
"activeFrom" : {"type": "date", "ref": "activeFrom"},
"activeTo" : {"type": "date", "ref": "activeTo"},
"tags" : {"type": "tags", "ref": "tags"},
"usageRules" : {"type": "usageRules", "ref": "usageRules"}
}"""),
f.keyMap)
}
}