View Javadoc
1   package com.guinetik.hexafun.examples.tasks;
2   
3   import java.util.UUID;
4   
5   /**
6    * Immutable Task domain model with Kanban workflow status.
7    */
8   public record Task(
9       String id,
10      String title,
11      String description,
12      TaskStatus status
13  ) {
14      /**
15       * Create a new task with generated ID in TODO status.
16       */
17      public static Task create(String title, String description) {
18          return new Task(UUID.randomUUID().toString(), title, description, TaskStatus.TODO);
19      }
20  
21      /**
22       * Check if this task is completed.
23       */
24      public boolean completed() {
25          return status == TaskStatus.DONE;
26      }
27  
28      /**
29       * Start working on this task (move to DOING).
30       */
31      public Task start() {
32          return new Task(id, title, description, TaskStatus.DOING);
33      }
34  
35      /**
36       * Mark this task as completed (move to DONE).
37       */
38      public Task complete() {
39          return new Task(id, title, description, TaskStatus.DONE);
40      }
41  
42      /**
43       * Move task back to TODO.
44       */
45      public Task reopen() {
46          return new Task(id, title, description, TaskStatus.TODO);
47      }
48  
49      /**
50       * Update the title.
51       */
52      public Task withTitle(String newTitle) {
53          return new Task(id, newTitle, description, status);
54      }
55  
56      /**
57       * Update the description.
58       */
59      public Task withDescription(String newDescription) {
60          return new Task(id, title, newDescription, status);
61      }
62  
63      /**
64       * Update the status.
65       */
66      public Task withStatus(TaskStatus newStatus) {
67          return new Task(id, title, description, newStatus);
68      }
69  }