11package clap .server .application .service .task ;
22
3- import clap .server .adapter .inbound .web .dto .task .request .UpdateTaskLabelRequest ;
43import clap .server .adapter .inbound .web .dto .task .request .UpdateTaskProcessorRequest ;
5- import clap .server .adapter .inbound .web .dto .task .request .UpdateTaskRequest ;
64import clap .server .adapter .outbound .persistense .entity .member .constant .MemberRole ;
75import clap .server .adapter .outbound .persistense .entity .notification .constant .NotificationType ;
86import clap .server .adapter .outbound .persistense .entity .task .constant .TaskHistoryType ;
97import clap .server .adapter .outbound .persistense .entity .task .constant .TaskStatus ;
10- import clap .server .application .mapper .AttachmentMapper ;
118import clap .server .application .port .inbound .domain .CategoryService ;
12- import clap .server .application .port .inbound .domain .LabelService ;
139import clap .server .application .port .inbound .domain .MemberService ;
1410import clap .server .application .port .inbound .domain .TaskService ;
15- import clap .server .application .port .inbound .task .UpdateTaskLabelUsecase ;
1611import clap .server .application .port .inbound .task .UpdateTaskProcessorUsecase ;
1712import clap .server .application .port .inbound .task .UpdateTaskStatusUsecase ;
1813import clap .server .application .port .inbound .task .UpdateTaskUsecase ;
2217import clap .server .application .port .outbound .taskhistory .CommandTaskHistoryPort ;
2318import clap .server .application .service .webhook .SendNotificationService ;
2419import clap .server .common .annotation .architecture .ApplicationService ;
25- import clap .server .common .constants .FilePathConstants ;
2620import clap .server .domain .model .member .Member ;
27- import clap .server .domain .model .task .*;
21+ import clap .server .domain .model .task .Task ;
22+ import clap .server .domain .model .task .TaskHistory ;
2823import clap .server .exception .ApplicationException ;
2924import clap .server .exception .code .TaskErrorCode ;
3025import lombok .RequiredArgsConstructor ;
3126import lombok .extern .slf4j .Slf4j ;
3227import org .springframework .transaction .annotation .Transactional ;
33- import org .springframework .web .multipart .MultipartFile ;
3428
3529import java .util .List ;
3630
37- import static clap .server .domain .policy .task .TaskPolicyConstants .*;
31+ import static clap .server .domain .policy .task .TaskPolicyConstants .REMAINING_TASK_STATUS ;
32+ import static clap .server .domain .policy .task .TaskPolicyConstants .TASK_UPDATABLE_STATUS ;
3833
3934
4035@ ApplicationService
4136@ RequiredArgsConstructor
4237@ Slf4j
43- public class UpdateTaskService implements UpdateTaskUsecase , UpdateTaskStatusUsecase , UpdateTaskProcessorUsecase , UpdateTaskLabelUsecase {
44-
38+ public class UpdateTaskService implements UpdateTaskStatusUsecase , UpdateTaskProcessorUsecase {
4539 private final MemberService memberService ;
46- private final CategoryService categoryService ;
4740 private final TaskService taskService ;
4841 private final SendNotificationService sendNotificationService ;
4942 private final UpdateProcessorTaskCountService updateProcessorTaskCountService ;
50-
51- private final LoadAttachmentPort loadAttachmentPort ;
52- private final LabelService labelService ;
53- private final CommandAttachmentPort commandAttachmentPort ;
5443 private final CommandTaskHistoryPort commandTaskHistoryPort ;
55- private final S3UploadPort s3UploadPort ;
5644
57- @ Override
58- @ Transactional
59- public void updateTask (Long requesterId , Long taskId , UpdateTaskRequest request , List <MultipartFile > files ) {
60- memberService .findActiveMember (requesterId );
61- Category category = categoryService .findById (request .categoryId ());
62- Task task = taskService .findById (taskId );
63- int attachmentCount = getAttachmentCount (request , files , task );
6445
65- if (!request .attachmentsToDelete ().isEmpty ()) {
66- List <Attachment > attachmentsToDelete = validateAndGetAttachments (request .attachmentsToDelete (), task );
67- attachmentsToDelete .stream ()
68- .peek (Attachment ::softDelete )
69- .forEach (commandAttachmentPort ::save );
70- }
71- if (files != null ) {
72- updateAttachments (files , task );
73- }
74- task .updateTask (requesterId , category , request .title (), request .description (), attachmentCount );
75- taskService .upsert (task );
76- }
7746
7847 @ Override
7948 @ Transactional
@@ -90,8 +59,7 @@ public void updateTaskStatus(Long memberId, Long taskId, TaskStatus targetTaskSt
9059 task .updateTaskStatus (targetTaskStatus );
9160 Task updatedTask = taskService .upsert (task );
9261
93- TaskHistory taskHistory = TaskHistory .createTaskHistory (TaskHistoryType .STATUS_SWITCHED , task , targetTaskStatus .getDescription (), null , null );
94- commandTaskHistoryPort .save (taskHistory );
62+ saveTaskHistory (TaskHistory .createTaskHistory (TaskHistoryType .STATUS_SWITCHED , task , targetTaskStatus .getDescription (), null , null ));
9563
9664 List <Member > receivers = List .of (task .getRequester ());
9765 publishNotification (receivers , updatedTask , NotificationType .STATUS_SWITCHED , String .valueOf (updatedTask .getTaskStatus ()));
@@ -113,46 +81,14 @@ public void updateTaskProcessor(Long taskId, Long memberId, UpdateTaskProcessorR
11381 task .updateProcessor (processor );
11482 Task updatedTask = taskService .upsert (task );
11583
116- TaskHistory taskHistory = TaskHistory .createTaskHistory (TaskHistoryType .PROCESSOR_CHANGED , task , null , processor , null );
117- commandTaskHistoryPort .save (taskHistory );
84+ saveTaskHistory (TaskHistory .createTaskHistory (TaskHistoryType .PROCESSOR_CHANGED , task , null , processor , null ));
11885
11986 List <Member > receivers = List .of (updatedTask .getRequester ());
12087 publishNotification (receivers , updatedTask , NotificationType .PROCESSOR_CHANGED , processor .getNickname ());
12188 }
12289
123- @ Transactional
124- @ Override
125- public void updateTaskLabel (Long taskId , Long memberId , UpdateTaskLabelRequest request ) {
126- memberService .findActiveMember (memberId );
127- memberService .findReviewer (memberId );
128- Task task = taskService .findById (taskId );
129- Label label = labelService .findById (request .labelId ());
130-
131- task .updateLabel (label );
132- taskService .upsert (task );
133- }
134-
135- private void updateAttachments (List <MultipartFile > files , Task task ) {
136- List <String > fileUrls = s3UploadPort .uploadFiles (FilePathConstants .TASK_FILE , files );
137- List <Attachment > attachments = AttachmentMapper .toTaskAttachments (task , files , fileUrls );
138- commandAttachmentPort .saveAll (attachments );
139- }
140-
141- private static int getAttachmentCount (UpdateTaskRequest request , List <MultipartFile > files , Task task ) {
142- int attachmentToAdd = files == null ? 0 : files .size ();
143- int attachmentCount = task .getAttachmentCount () - request .attachmentsToDelete ().size () + attachmentToAdd ;
144- if (attachmentCount > TASK_MAX_FILE_COUNT ) {
145- throw new ApplicationException (TaskErrorCode .FILE_COUNT_EXCEEDED );
146- }
147- return attachmentCount ;
148- }
149-
150- private List <Attachment > validateAndGetAttachments (List <Long > attachmentIdsToDelete , Task task ) {
151- List <Attachment > attachmentsOfTask = loadAttachmentPort .findAllByTaskIdAndAttachmentId (task .getTaskId (), attachmentIdsToDelete );
152- if (attachmentsOfTask .size () != attachmentIdsToDelete .size ()) {
153- throw new ApplicationException (TaskErrorCode .TASK_ATTACHMENT_NOT_FOUND );
154- }
155- return attachmentsOfTask ;
90+ private void saveTaskHistory (TaskHistory taskHistory ) {
91+ commandTaskHistoryPort .save (taskHistory );
15692 }
15793
15894 private void publishNotification (List <Member > receivers , Task task , NotificationType notificationType , String message ) {
0 commit comments