From 43abd31ededbd701ec859a5e3f80f803fc4f482d Mon Sep 17 00:00:00 2001 From: Pat Garrity Date: Tue, 2 Jul 2024 21:24:57 -0500 Subject: [PATCH] Reworking a bit and finalizing basic models. --- .../main/scala/gs/smolban/model/Group.scala | 5 +- .../main/scala/gs/smolban/model/Status.scala | 44 --------------- .../main/scala/gs/smolban/model/Ticket.scala | 54 +++++++++++++++++-- .../scala/gs/smolban/model/users/User.scala | 43 +++++++++++++-- .../gs/smolban/model/users/UserType.scala | 19 ------- 5 files changed, 94 insertions(+), 71 deletions(-) delete mode 100644 modules/model/src/main/scala/gs/smolban/model/Status.scala delete mode 100644 modules/model/src/main/scala/gs/smolban/model/users/UserType.scala diff --git a/modules/model/src/main/scala/gs/smolban/model/Group.scala b/modules/model/src/main/scala/gs/smolban/model/Group.scala index 31994b6..e9fa2aa 100644 --- a/modules/model/src/main/scala/gs/smolban/model/Group.scala +++ b/modules/model/src/main/scala/gs/smolban/model/Group.scala @@ -13,11 +13,14 @@ import gs.uuid.v0.UUID * The unique slug for the group. * @param createdAt * The instant at which this group was created. + * @param createdBy + * The unique identifier of the user who created this group. */ case class Group( id: Group.Id, slug: Slug, - createdAt: CreatedAt + createdAt: CreatedAt, + createdBy: CreatedBy ) object Group: diff --git a/modules/model/src/main/scala/gs/smolban/model/Status.scala b/modules/model/src/main/scala/gs/smolban/model/Status.scala deleted file mode 100644 index b880796..0000000 --- a/modules/model/src/main/scala/gs/smolban/model/Status.scala +++ /dev/null @@ -1,44 +0,0 @@ -package gs.smolban.model - -import java.time.Instant - -/** Enumeration that describes the status of a [[Ticket]] in Smolban. Smolban - * does not yet support custom status/workflow. - */ -sealed trait Status: - def name: String - def enteredAt: Instant - -object Status: - - /** This ticket is new, and ready to be started. New tickets may be put into - * progress or canceled. - */ - case class Ready(enteredAt: Instant) extends Status: - val name: String = "ready" - - /** This ticket is being worked on actively. In progress tickets can be - * paused, completed, or canceled. - */ - case class InProgress(enteredAt: Instant) extends Status: - val name: String = "in_progress" - - /** This ticket was being worked on, but was temporarily stopped. Paused - * tickets may be put into progress or canceled. - */ - case class Paused(enteredAt: Instant) extends Status: - val name: String = "paused" - - /** This ticket was driven to completion. The work is done. Once in this - * state, the status may no longer change. - */ - case class Complete(enteredAt: Instant) extends Status: - val name: String = "complete" - - /** This ticket was canceled for some reason. Once in this state, the status - * may no longer change. - */ - case class Canceled(enteredAt: Instant) extends Status: - val name: String = "canceled" - -end Status diff --git a/modules/model/src/main/scala/gs/smolban/model/Ticket.scala b/modules/model/src/main/scala/gs/smolban/model/Ticket.scala index 47c82a7..504019e 100644 --- a/modules/model/src/main/scala/gs/smolban/model/Ticket.scala +++ b/modules/model/src/main/scala/gs/smolban/model/Ticket.scala @@ -1,6 +1,8 @@ package gs.smolban.model import cats.Show +import gs.smolban.model.users.User +import java.time.Instant /** Tickets represent some tracked work. * @@ -19,9 +21,11 @@ import cats.Show * @param tags * List of [[Tag]] applied to this ticket. * @param status - * Current [[Status]] of this ticket. + * Current [[Ticket.Status]] of this ticket. * @param statusHistory * Linear history of this ticket in terms of status changes. + * @param assignee + * If set, this ticket is assigned to a specific user. */ case class Ticket( id: Ticket.Id, @@ -31,8 +35,9 @@ case class Ticket( title: String, description: String, tags: List[Tag], - status: Status, - statusHistory: List[Status] + status: Ticket.Status, + statusHistory: List[(Ticket.Status, Instant)], + assignee: Option[User.Id] ) object Ticket: @@ -68,4 +73,47 @@ object Ticket: end Id + /** Enumeration that describes the status of a [[Ticket]] in Smolban. Smolban + * does not yet support custom status/workflow. + */ + sealed abstract class Status(val name: String) + + object Status: + + given CanEqual[Status, Status] = CanEqual.derived + + given Show[Status] = _.name + + /** This ticket is new, and ready to be started. New tickets may be put into + * progress or canceled. + */ + case object Ready extends Status("ready") + + /** This ticket is being worked on actively. In progress tickets can be + * paused, completed, or canceled. + */ + case object InProgress extends Status("in_progress") + + /** This ticket was being worked on, but was temporarily stopped. Paused + * tickets may be put into progress or canceled. + */ + case object Paused extends Status("paused") + + /** This ticket was driven to completion. The work is done. Once in this + * state, the status may no longer change. + */ + case object Complete extends Status("complete") + + /** This ticket was canceled for some reason. Once in this state, the status + * may no longer change. + */ + case object Canceled extends Status("canceled") + + val All: List[Status] = List(Ready, InProgress, Paused, Complete, Canceled) + + def parse(candidate: String): Option[Status] = + All.find(_.name.equalsIgnoreCase(candidate)) + + end Status + end Ticket diff --git a/modules/model/src/main/scala/gs/smolban/model/users/User.scala b/modules/model/src/main/scala/gs/smolban/model/users/User.scala index 24935b9..1c56f8e 100644 --- a/modules/model/src/main/scala/gs/smolban/model/users/User.scala +++ b/modules/model/src/main/scala/gs/smolban/model/users/User.scala @@ -12,17 +12,20 @@ import gs.uuid.v0.UUID * The instant at which this user was created. * @param username * The (unique) [[Username]] of this user. - * @param userType - * The [[UserType]] of this user. + * @param designation + * The [[User.Designation]] of this user. * @param roles * List of [[Role]] assigned to this user. + * @param status + * The current [[User.Status]] of this user. */ case class User( id: User.Id, createdAt: CreatedAt, username: Username, - userType: UserType, - roles: List[Role] + designation: User.Designation, + roles: List[Role], + status: User.Status ) object User: @@ -58,4 +61,36 @@ object User: end Id + /** Enumeration that describes the designation of a [[User]]. + */ + sealed abstract class Designation(val name: String) + + object Designation: + + /** Regular users are typically human, and are expected to be using the Web + * UI and _possibly_ APIs. + */ + case object Regular extends Designation("regular") + + /** Service users are intended for use by API-consuming services. They are + * not suitable for human/UI interactive use. + */ + case object Service extends Designation("service") + + end Designation + + /** Enumeration that describes the status of a [[User]] in Smolban. + */ + sealed abstract class Status(val name: String) + + object Status: + + given CanEqual[Status, Status] = CanEqual.derived + + given Show[Status] = _.name + + case object Active extends Status("active") + case object Suspended extends Status("suspended") + case object Off extends Status("off") + end User diff --git a/modules/model/src/main/scala/gs/smolban/model/users/UserType.scala b/modules/model/src/main/scala/gs/smolban/model/users/UserType.scala deleted file mode 100644 index ec3c8a6..0000000 --- a/modules/model/src/main/scala/gs/smolban/model/users/UserType.scala +++ /dev/null @@ -1,19 +0,0 @@ -package gs.smolban.model.users - -/** Enumeration that describes the type of a [[User]]. - */ -sealed abstract class UserType(val name: String) - -object UserType: - - /** Regular users are typically human, and are expected to be using the Web UI - * and _possibly_ APIs. - */ - case object Regular extends UserType("regular") - - /** Service users are intended for use by API-consuming services. They are not - * suitable for human/UI interactive use. - */ - case object Service extends UserType("service") - -end UserType