1 /*
2  *  Make.org Core API
3  *  Copyright (C) 2018 Make.org
4  *
5  * This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU Affero General Public License as
7  *  published by the Free Software Foundation, either version 3 of the
8  *  License, or (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU Affero General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Affero General Public License
16  *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  *
18  */
19 
20 package org.make.api.idea
21 
22 import java.time.ZonedDateTime
23 import com.sksamuel.avro4s._
24 import org.make.core.idea.{Idea, IdeaId}
25 import org.make.core.{DateHelper, MakeSerializable}
26 
27 sealed trait IdeaEvent {
28   def ideaId: IdeaId
29   def eventDate: ZonedDateTime
30   def version(): Int
31 }
32 
33 object IdeaEvent {
34   val defaultDate: ZonedDateTime = ZonedDateTime.parse("2017-11-01T09:00:00Z")
35 }
36 
37 @AvroSortPriority(2)
38 final case class IdeaCreatedEvent(
39   override val ideaId: IdeaId,
40   @AvroDefault("2017-11-01T09:00Z") override val eventDate: ZonedDateTime = IdeaEvent.defaultDate
41 ) extends IdeaEvent {
42 
43   def version(): Int = MakeSerializable.V1
44 }
45 
46 object IdeaCreatedEvent {
47   def apply(idea: Idea): IdeaCreatedEvent = {
48     IdeaCreatedEvent(ideaId = idea.ideaId, eventDate = DateHelper.now())
49   }
50 }
51 
52 @AvroSortPriority(1)
53 final case class IdeaUpdatedEvent(
54   override val ideaId: IdeaId,
55   @AvroDefault("2017-11-01T09:00Z") override val eventDate: ZonedDateTime = IdeaEvent.defaultDate
56 ) extends IdeaEvent {
57   def version(): Int = MakeSerializable.V1
58 }
59 
60 object IdeaUpdatedEvent {
61   def apply(idea: Idea): IdeaUpdatedEvent = {
62     IdeaUpdatedEvent(ideaId = idea.ideaId, eventDate = DateHelper.now())
63   }
64 }
Line Stmt Id Pos Tree Symbol Tests Code
34 14521 1081 - 1124 Apply java.time.ZonedDateTime.parse org.make.api.avro.avrocompatibilitytest java.time.ZonedDateTime.parse("2017-11-01T09:00:00Z")
43 11011 1359 - 1378 Select org.make.core.MakeSerializable.V1 org.make.core.MakeSerializable.V1
48 11265 1458 - 1526 Apply org.make.api.idea.IdeaCreatedEvent.apply IdeaCreatedEvent.apply(idea.ideaId, org.make.core.DateHelper.now())
48 13313 1509 - 1525 Apply org.make.core.DefaultDateHelper.now org.make.core.DateHelper.now()
48 16739 1484 - 1495 Select org.make.core.idea.Idea.ideaId idea.ideaId
57 17460 1764 - 1783 Select org.make.core.MakeSerializable.V1 org.make.core.MakeSerializable.V1
62 10182 1914 - 1930 Apply org.make.core.DefaultDateHelper.now org.make.core.DateHelper.now()
62 16608 1863 - 1931 Apply org.make.api.idea.IdeaUpdatedEvent.apply IdeaUpdatedEvent.apply(idea.ideaId, org.make.core.DateHelper.now())
62 13778 1889 - 1900 Select org.make.core.idea.Idea.ideaId idea.ideaId