refactor(task): replace mechanical boilerplate with Lombok
This commit is contained in:
@@ -12,6 +12,7 @@ import com.lab.labtimesheet.feature.task.service.TaskService;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
@@ -31,19 +32,11 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
* successful mutations use redirects to prevent duplicate submissions.
|
||||
*/
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class TaskController {
|
||||
|
||||
private final TaskService taskService;
|
||||
|
||||
/**
|
||||
* Creates the MVC adapter for the Task application service.
|
||||
*
|
||||
* @param taskService authorized Task use cases
|
||||
*/
|
||||
public TaskController(TaskService taskService) {
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
@GetMapping("/projects/{projectId}/tasks")
|
||||
String list(Authentication authentication, @PathVariable long projectId, Model model) {
|
||||
TaskListView taskList = taskService.list(authentication.getName(), projectId);
|
||||
|
||||
@@ -12,6 +12,9 @@ import jakarta.persistence.Table;
|
||||
import jakarta.persistence.Version;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Persisted Task aggregate row with one current same-Project assignee.
|
||||
@@ -22,6 +25,8 @@ import java.time.LocalDate;
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "tasks")
|
||||
@Getter
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public class Task {
|
||||
|
||||
@Id
|
||||
@@ -60,20 +65,20 @@ public class Task {
|
||||
private Instant deletedAt;
|
||||
|
||||
@Column(name = "deleted_by_membership_id")
|
||||
@Getter(AccessLevel.NONE)
|
||||
private Long deletedByMembershipId;
|
||||
|
||||
@Column(name = "created_at", nullable = false)
|
||||
private Instant createdAt;
|
||||
|
||||
@Column(name = "updated_at", nullable = false)
|
||||
@Getter(AccessLevel.NONE)
|
||||
private Instant updatedAt;
|
||||
|
||||
@Version
|
||||
@Getter(AccessLevel.NONE)
|
||||
private long version;
|
||||
|
||||
/** Constructor reserved for JPA materialization. */
|
||||
protected Task() {}
|
||||
|
||||
/**
|
||||
* Creates a TODO Task and records the creating membership as both creator and assigner.
|
||||
*
|
||||
@@ -121,111 +126,4 @@ public class Task {
|
||||
updatedAt = now;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the persistence identity.
|
||||
*
|
||||
* @return Task identifier, or {@code null} before insertion
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the aggregate identity.
|
||||
*
|
||||
* @return owning Project identifier
|
||||
*/
|
||||
public long getProjectId() {
|
||||
return projectId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current assignment identity.
|
||||
*
|
||||
* @return current same-Project assignee membership identifier
|
||||
*/
|
||||
public long getAssigneeMembershipId() {
|
||||
return assigneeMembershipId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the display title.
|
||||
*
|
||||
* @return normalized Task title
|
||||
*/
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the descriptive text.
|
||||
*
|
||||
* @return optional normalized description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the workflow state.
|
||||
*
|
||||
* @return current fixed workflow status
|
||||
*/
|
||||
public TaskStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the business deadline.
|
||||
*
|
||||
* @return optional validated due date
|
||||
*/
|
||||
public LocalDate getDueDate() {
|
||||
return dueDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current assignment timing.
|
||||
*
|
||||
* @return instant when the current assignment was established
|
||||
*/
|
||||
public Instant getAssignedAt() {
|
||||
return assignedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns original creator attribution.
|
||||
*
|
||||
* @return immutable creating membership identifier
|
||||
*/
|
||||
public long getCreatorMembershipId() {
|
||||
return creatorMembershipId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current assignment attribution.
|
||||
*
|
||||
* @return membership identifier responsible for the current assignment
|
||||
*/
|
||||
public long getAssignerMembershipId() {
|
||||
return assignerMembershipId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns lifecycle visibility state.
|
||||
*
|
||||
* @return soft-deletion instant, or {@code null} while current
|
||||
*/
|
||||
public Instant getDeletedAt() {
|
||||
return deletedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns creation timing.
|
||||
*
|
||||
* @return immutable creation instant
|
||||
*/
|
||||
public Instant getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import java.time.Instant;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Persisted append-only Task comment.
|
||||
@@ -16,6 +19,8 @@ import java.time.Instant;
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "task_comments")
|
||||
@Getter
|
||||
@NoArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public class TaskComment {
|
||||
|
||||
@Id
|
||||
@@ -34,9 +39,6 @@ public class TaskComment {
|
||||
@Column(name = "created_at", nullable = false)
|
||||
private Instant createdAt;
|
||||
|
||||
/** Constructor reserved for JPA materialization. */
|
||||
protected TaskComment() {}
|
||||
|
||||
/**
|
||||
* Creates an immutable comment from server-authorized values.
|
||||
*
|
||||
@@ -52,48 +54,4 @@ public class TaskComment {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the persistence identity.
|
||||
*
|
||||
* @return comment identifier, or {@code null} before insertion
|
||||
*/
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the owning record identity.
|
||||
*
|
||||
* @return owning Task identifier
|
||||
*/
|
||||
public long getTaskId() {
|
||||
return taskId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns historical authorship.
|
||||
*
|
||||
* @return immutable historical author user identifier
|
||||
*/
|
||||
public long getAuthorUserId() {
|
||||
return authorUserId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns comment content.
|
||||
*
|
||||
* @return normalized comment text
|
||||
*/
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns creation timing.
|
||||
*
|
||||
* @return immutable creation instant
|
||||
*/
|
||||
public Instant getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.lab.labtimesheet.feature.task.repository.TaskRepository;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -23,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* priorities cover current assignments only where the actor still has an active membership.
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TaskDashboardService {
|
||||
|
||||
private static final TaskDashboardView EMPTY_DASHBOARD = new TaskDashboardView(0, 0, List.of());
|
||||
@@ -30,17 +32,6 @@ public class TaskDashboardService {
|
||||
private final TaskRepository tasks;
|
||||
private final ProjectQueryService projects;
|
||||
|
||||
/**
|
||||
* Creates the dashboard query service.
|
||||
*
|
||||
* @param tasks Task persistence boundary
|
||||
* @param projects authorized Project query boundary
|
||||
*/
|
||||
public TaskDashboardService(TaskRepository tasks, ProjectQueryService projects) {
|
||||
this.tasks = tasks;
|
||||
this.projects = projects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the role-scoped Task dashboard for one authenticated account.
|
||||
*
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.lab.labtimesheet.feature.task.service;
|
||||
|
||||
import com.lab.labtimesheet.feature.task.repository.TaskRepository;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -9,19 +10,11 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* Public Task query boundary used by other features without exposing Task entities or repositories.
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TaskQueryService {
|
||||
|
||||
private final TaskRepository tasks;
|
||||
|
||||
/**
|
||||
* Creates the cross-feature Task query service.
|
||||
*
|
||||
* @param tasks Task persistence boundary
|
||||
*/
|
||||
public TaskQueryService(TaskRepository tasks) {
|
||||
this.tasks = tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts current Tasks assigned outside the supplied active membership set.
|
||||
*
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -42,6 +43,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* to a non-disclosing Task 404, while authenticated business-rule failures use Task validation.
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TaskService {
|
||||
|
||||
private final TaskRepository tasks;
|
||||
@@ -51,31 +53,6 @@ public class TaskService {
|
||||
private final CalendarApplicationService calendar;
|
||||
private final Clock clock;
|
||||
|
||||
/**
|
||||
* Creates the Task application service and its feature boundaries.
|
||||
*
|
||||
* @param tasks Task persistence boundary
|
||||
* @param comments append-only comment persistence boundary
|
||||
* @param projects authorized Project read boundary
|
||||
* @param projectMutations Project-first locking mutation boundary
|
||||
* @param calendar authoritative global day-off query boundary
|
||||
* @param clock server time source for persisted instants
|
||||
*/
|
||||
public TaskService(
|
||||
TaskRepository tasks,
|
||||
TaskCommentRepository comments,
|
||||
ProjectQueryService projects,
|
||||
ProjectService projectMutations,
|
||||
CalendarApplicationService calendar,
|
||||
Clock clock) {
|
||||
this.tasks = tasks;
|
||||
this.comments = comments;
|
||||
this.projects = projects;
|
||||
this.projectMutations = projectMutations;
|
||||
this.calendar = calendar;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a TODO Task in a PLANNED or ACTIVE Project.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user