View Javadoc
1   package com.guinetik.hexafun.examples.tasks;
2   
3   import java.util.List;
4   import java.util.Optional;
5   
6   /**
7    * Output port for task persistence.
8    *
9    * <p>This is the interface that use cases depend on.
10   * Implementations (adapters) provide the actual storage mechanism.
11   */
12  public interface TaskRepository {
13  
14      /**
15       * Save a task (create or update).
16       * @param task The task to save
17       * @return The saved task
18       */
19      Task save(Task task);
20  
21      /**
22       * Find a task by ID.
23       * @param id The task ID
24       * @return The task if found
25       */
26      Optional<Task> findById(String id);
27  
28      /**
29       * Find all tasks.
30       * @return List of all tasks
31       */
32      List<Task> findAll();
33  
34      /**
35       * Delete a task by ID.
36       * @param id The task ID
37       * @return true if deleted, false if not found
38       */
39      boolean delete(String id);
40  
41      /**
42       * Check if a task exists.
43       * @param id The task ID
44       * @return true if exists
45       */
46      default boolean exists(String id) {
47          return findById(id).isPresent();
48      }
49  }