55import com .taskmanagerapi .model .Task ;
66import com .taskmanagerapi .model .TaskStatus ;
77import com .taskmanagerapi .repository .TaskRepository ;
8+ import org .slf4j .Logger ;
9+ import org .slf4j .LoggerFactory ;
810import org .springframework .stereotype .Service ;
911import org .springframework .transaction .annotation .Transactional ;
1012
1517@ Service
1618public class TaskService {
1719
20+ private static final Logger log = LoggerFactory .getLogger (TaskService .class );
21+
1822 private final TaskRepository taskRepository ;
1923
2024 public TaskService (TaskRepository taskRepository ) {
@@ -23,11 +27,14 @@ public TaskService(TaskRepository taskRepository) {
2327
2428 public TaskResponse addTask (String name , String description ) {
2529 Task task = new Task (name , description );
26- return TaskResponse .from (taskRepository .save (task ));
30+ TaskResponse response = TaskResponse .from (taskRepository .save (task ));
31+ log .info ("Task created: id={}, name={}" , response .getId (), response .getName ());
32+ return response ;
2733 }
2834
2935 public List <TaskResponse > getAllTasks () {
3036 List <Task > tasks = taskRepository .findAll ();
37+ log .info ("Fetched {} tasks" , tasks .size ());
3138 return tasks .stream ()
3239 .map (TaskResponse ::from )
3340 .toList ();
@@ -47,6 +54,7 @@ public TaskResponse searchTaskByName(String name) {
4754
4855 public List <TaskResponse > searchTaskByStatus (TaskStatus status ) {
4956 List <Task > tasks = taskRepository .findTasksByStatus (status );
57+ log .info ("Fetched {} tasks with status={}" , tasks .size (), status );
5058 return tasks .stream ()
5159 .map (TaskResponse ::from )
5260 .toList ();
@@ -57,6 +65,7 @@ public TaskResponse completeTask(String id) {
5765 Task task = taskRepository .findById (id )
5866 .orElseThrow (() -> new TaskNotFoundException (id ));
5967 task .setStatus (DONE );
68+ log .info ("Task completed: id={}" , id );
6069 return TaskResponse .from (task );
6170 }
6271
@@ -65,6 +74,7 @@ public TaskResponse deleteTask(String id) {
6574 Task task = taskRepository .findById (id )
6675 .orElseThrow (() -> new TaskNotFoundException (id ));
6776 task .setStatus (DELETED );
77+ log .info ("Task deleted: id={}" , id );
6878 return TaskResponse .from (task );
6979 }
7080
@@ -73,6 +83,7 @@ public TaskResponse undoDelete(String id) {
7383 Task task = taskRepository .findById (id )
7484 .orElseThrow (() -> new TaskNotFoundException (id ));
7585 task .setStatus (CREATED );
86+ log .info ("Task restored: id={}" , id );
7687 return TaskResponse .from (task );
7788 }
7889}
0 commit comments