Created
June 11, 2018 07:35
-
-
Save juancho088/998b4d123b6a422ea52201f1b9a44d09 to your computer and use it in GitHub Desktop.
User management models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// You can use the same models.kt class | |
// ------------------------------------------------------ | |
// User management | |
// ------------------------------------------------------ | |
/** | |
* It's a way to keep a canonical Datetime serializer | |
*/ | |
class DateTimeSerializer @JvmOverloads constructor(t: Class<DateTime>? = null) : StdSerializer<DateTime>(t) { | |
@Throws(IOException::class, JsonProcessingException::class) | |
override fun serialize(value: DateTime, gen: JsonGenerator, arg2: SerializerProvider) { | |
gen.writeString(formatter.print(value)) | |
} | |
private val formatter = ISODateTimeFormat.basicDateTime() | |
} | |
/** | |
* A base model with some minimum attributes that any entity in the system should have | |
* @property id Unique ID of that element | |
* @property createdAt When it was created | |
* @property updatedAt Last time that the entity changed | |
*/ | |
abstract class BaseModel(override var id: Int?): Model { | |
constructor(): this(0) | |
@JsonSerialize(using = DateTimeSerializer::class) | |
var createdAt: DateTime? = DateTime() | |
@JsonSerialize(using = DateTimeSerializer::class) | |
var updatedAt: DateTime? = DateTime() | |
} | |
/** | |
* Basic fields that a User needs | |
* @property email User email | |
*/ | |
abstract class User: BaseModel() { | |
open var email: String = "" | |
} | |
/** | |
* Anonymous User -> User who is not logged into the system | |
*/ | |
class AnonymousUser: User() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment