Skip to content

Instantly share code, notes, and snippets.

@juancho088
Created June 11, 2018 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juancho088/998b4d123b6a422ea52201f1b9a44d09 to your computer and use it in GitHub Desktop.
Save juancho088/998b4d123b6a422ea52201f1b9a44d09 to your computer and use it in GitHub Desktop.
User management models
// 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