diff --git a/infrastructure/src/main/java/com/btg/infrastructure/web/auth/AuthController.java b/infrastructure/src/main/java/com/btg/infrastructure/web/auth/AuthController.java index ac0f65d..257bbd0 100644 --- a/infrastructure/src/main/java/com/btg/infrastructure/web/auth/AuthController.java +++ b/infrastructure/src/main/java/com/btg/infrastructure/web/auth/AuthController.java @@ -6,6 +6,7 @@ import com.btg.infrastructure.web.auth.dto.request.SignupRequest; import com.btg.infrastructure.web.auth.dto.response.LoginResponse; import com.btg.infrastructure.web.auth.dto.response.TokenResponse; +import com.btg.infrastructure.web.mapper.AuthResponseMapper; import com.btg.infrastructure.web.user.dto.response.UserResponse; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -22,6 +23,7 @@ public class AuthController { private final LoginUseCase loginUseCase; private final RefreshTokenUseCase refreshTokenUseCase; private final LogoutUseCase logoutUseCase; + private final AuthResponseMapper authResponseMapper; @PostMapping("/signup") public ResponseEntity signup(@Valid @RequestBody SignupRequest request) { @@ -33,14 +35,8 @@ public ResponseEntity signup(@Valid @RequestBody SignupRequest req SignupUseCase.UserResult result = signupUseCase.signup(command); - UserResponse response = new UserResponse( - result.id(), - result.email(), - result.name(), - result.createdAt() - ); - - return ResponseEntity.status(HttpStatus.CREATED).body(response); + return ResponseEntity.status(HttpStatus.CREATED) + .body(authResponseMapper.toUserResponse(result)); } @PostMapping("/login") @@ -52,20 +48,7 @@ public ResponseEntity login(@Valid @RequestBody LoginRequest requ LoginUseCase.LoginResult result = loginUseCase.login(command); - UserResponse userResponse = new UserResponse( - result.user().id(), - result.user().email(), - result.user().name(), - result.user().createdAt() - ); - - LoginResponse response = new LoginResponse( - result.accessToken(), - result.refreshToken(), - userResponse - ); - - return ResponseEntity.ok(response); + return ResponseEntity.ok(authResponseMapper.toLoginResponse(result)); } @PostMapping("/refresh") @@ -73,9 +56,7 @@ public ResponseEntity refreshToken(@Valid @RequestBody RefreshTok RefreshTokenUseCase.RefreshTokenCommand command = new RefreshTokenUseCase.RefreshTokenCommand(request.refreshToken()); RefreshTokenUseCase.TokenResult result = refreshTokenUseCase.refreshToken(command); - TokenResponse response = new TokenResponse(result.accessToken()); - - return ResponseEntity.ok(response); + return ResponseEntity.ok(authResponseMapper.toTokenResponse(result)); } @PostMapping("/logout") diff --git a/infrastructure/src/main/java/com/btg/infrastructure/web/dailyprogress/DailyProgressController.java b/infrastructure/src/main/java/com/btg/infrastructure/web/dailyprogress/DailyProgressController.java index c292b8a..954a6db 100644 --- a/infrastructure/src/main/java/com/btg/infrastructure/web/dailyprogress/DailyProgressController.java +++ b/infrastructure/src/main/java/com/btg/infrastructure/web/dailyprogress/DailyProgressController.java @@ -1,19 +1,17 @@ package com.btg.infrastructure.web.dailyprogress; import com.btg.core.application.port.in.dailyprogress.GetDailyProgressUseCase; +import com.btg.core.application.port.in.dailyprogress.UpdateDailyProgressUseCase; import com.btg.infrastructure.web.dailyprogress.dto.request.UpdateDailyProgressRequest; import com.btg.infrastructure.web.dailyprogress.dto.response.DailyProgressResponse; import com.btg.infrastructure.web.dailyprogress.dto.response.DailyProgressSummaryResponse; -import com.btg.infrastructure.web.dailyprogress.dto.response.DailyStatResponse; import com.btg.infrastructure.web.dailyprogress.dto.response.MyDailyProgressResponse; -import com.btg.core.application.port.in.dailyprogress.UpdateDailyProgressUseCase; +import com.btg.infrastructure.web.mapper.DailyProgressResponseMapper; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.stream.Collectors; - @RestController @RequestMapping("/tasks/{taskId}/daily-progress") @RequiredArgsConstructor @@ -21,27 +19,14 @@ public class DailyProgressController { private final GetDailyProgressUseCase getDailyProgressUseCase; private final UpdateDailyProgressUseCase updateDailyProgressUseCase; + private final DailyProgressResponseMapper dailyProgressResponseMapper; @GetMapping public ResponseEntity getDailyProgressSummary(@PathVariable Long taskId) { GetDailyProgressUseCase.DailyProgressSummaryResult result = getDailyProgressUseCase.getDailyProgressSummary(taskId); - DailyProgressSummaryResponse response = new DailyProgressSummaryResponse( - result.taskId(), - result.startDate(), - result.endDate(), - result.dailyStats().stream() - .map(stat -> new DailyStatResponse( - stat.date(), - stat.completedCount(), - stat.totalParticipants(), - stat.completionRate() - )) - .collect(Collectors.toList()) - ); - - return ResponseEntity.ok(response); + return ResponseEntity.ok(dailyProgressResponseMapper.toSummaryResponse(result)); } @GetMapping("/me") @@ -52,19 +37,7 @@ public ResponseEntity getMyDailyProgress(@PathVariable GetDailyProgressUseCase.MyDailyProgressResult result = getDailyProgressUseCase.getMyDailyProgress(taskId, userId); - MyDailyProgressResponse response = new MyDailyProgressResponse( - result.taskId(), - result.userId(), - result.dailyRecords().stream() - .map(record -> new DailyProgressResponse( - record.date(), - record.completed(), - record.completedAt() - )) - .collect(Collectors.toList()) - ); - - return ResponseEntity.ok(response); + return ResponseEntity.ok(dailyProgressResponseMapper.toMyProgressResponse(result)); } @PatchMapping("/{date}") @@ -87,12 +60,6 @@ public ResponseEntity updateDailyProgress( UpdateDailyProgressUseCase.DailyProgressResult result = updateDailyProgressUseCase.updateDailyProgress(command); - DailyProgressResponse response = new DailyProgressResponse( - result.date(), - result.completed(), - result.completedAt() - ); - - return ResponseEntity.ok(response); + return ResponseEntity.ok(dailyProgressResponseMapper.toProgressResponse(result)); } } diff --git a/infrastructure/src/main/java/com/btg/infrastructure/web/group/GroupController.java b/infrastructure/src/main/java/com/btg/infrastructure/web/group/GroupController.java index 0bf469e..31e077c 100644 --- a/infrastructure/src/main/java/com/btg/infrastructure/web/group/GroupController.java +++ b/infrastructure/src/main/java/com/btg/infrastructure/web/group/GroupController.java @@ -4,14 +4,13 @@ import com.btg.infrastructure.web.group.dto.request.CreateGroupRequest; import com.btg.infrastructure.web.group.dto.request.UpdateGroupRequest; import com.btg.infrastructure.web.group.dto.response.*; +import com.btg.infrastructure.web.mapper.GroupResponseMapper; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.stream.Collectors; - @RestController @RequestMapping("/groups") @RequiredArgsConstructor @@ -23,6 +22,8 @@ public class GroupController { private final DeleteGroupUseCase deleteGroupUseCase; private final ListGroupsUseCase listGroupsUseCase; + private final GroupResponseMapper groupResponseMapper; + @PostMapping public ResponseEntity createGroup(@Valid @RequestBody CreateGroupRequest request) { // TODO: Get authenticated user ID from SecurityContext @@ -37,21 +38,8 @@ public ResponseEntity createGroup(@Valid @RequestBody CreateGroup CreateGroupUseCase.GroupResult result = createGroupUseCase.createGroup(command); - GroupResponse response = new GroupResponse( - result.id(), - result.name(), - result.description(), - result.memberCount(), - result.maxMembers(), - new UserResponse( - result.createdBy().id(), - result.createdBy().email(), - result.createdBy().name() - ), - result.createdAt() - ); - - return ResponseEntity.status(HttpStatus.CREATED).body(response); + return ResponseEntity.status(HttpStatus.CREATED) + .body(groupResponseMapper.toResponse(result)); } // TODO: GET /groups/search - 그룹 검색 @@ -74,52 +62,14 @@ public ResponseEntity listGroups( ListGroupsUseCase.PagedGroupResult result = listGroupsUseCase.listGroups(query); - PagedGroupResponse response = new PagedGroupResponse( - result.content().stream() - .map(group -> new GroupResponse( - group.id(), - group.name(), - group.description(), - group.memberCount(), - group.maxMembers(), - new UserResponse( - group.createdBy().id(), - group.createdBy().email(), - group.createdBy().name() - ), - group.createdAt() - )) - .collect(Collectors.toList()), - result.totalElements(), - result.totalPages(), - result.page(), - result.size() - ); - - return ResponseEntity.ok(response); + return ResponseEntity.ok(groupResponseMapper.toPagedResponse(result)); } @GetMapping("/{groupId}") public ResponseEntity getGroup(@PathVariable Long groupId) { GetGroupUseCase.GroupDetailResult result = getGroupUseCase.getGroup(groupId); - GroupDetailResponse response = new GroupDetailResponse( - result.id(), - result.name(), - result.description(), - result.memberCount(), - result.maxMembers(), - new UserResponse( - result.createdBy().id(), - result.createdBy().email(), - result.createdBy().name() - ), - result.createdAt(), - result.myRole(), - result.taskCount() - ); - - return ResponseEntity.ok(response); + return ResponseEntity.ok(groupResponseMapper.toDetailResponse(result)); } @PutMapping("/{groupId}") @@ -140,21 +90,7 @@ public ResponseEntity updateGroup( UpdateGroupUseCase.GroupResult result = updateGroupUseCase.updateGroup(command); - GroupResponse response = new GroupResponse( - result.id(), - result.name(), - result.description(), - result.memberCount(), - result.maxMembers(), - new UserResponse( - result.createdBy().id(), - result.createdBy().email(), - result.createdBy().name() - ), - result.createdAt() - ); - - return ResponseEntity.ok(response); + return ResponseEntity.ok(groupResponseMapper.toResponse(result)); } @DeleteMapping("/{groupId}") diff --git a/infrastructure/src/main/java/com/btg/infrastructure/web/mapper/AuthResponseMapper.java b/infrastructure/src/main/java/com/btg/infrastructure/web/mapper/AuthResponseMapper.java new file mode 100644 index 0000000..1da573d --- /dev/null +++ b/infrastructure/src/main/java/com/btg/infrastructure/web/mapper/AuthResponseMapper.java @@ -0,0 +1,27 @@ +package com.btg.infrastructure.web.mapper; + +import com.btg.core.application.port.in.auth.LoginUseCase; +import com.btg.core.application.port.in.auth.RefreshTokenUseCase; +import com.btg.core.application.port.in.auth.SignupUseCase; +import com.btg.infrastructure.web.auth.dto.response.LoginResponse; +import com.btg.infrastructure.web.auth.dto.response.TokenResponse; +import com.btg.infrastructure.web.user.dto.response.UserResponse; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +@Mapper( + componentModel = "spring", + unmappedTargetPolicy = ReportingPolicy.ERROR +) +public interface AuthResponseMapper { + + // SignupUseCase 변환 + UserResponse toUserResponse(SignupUseCase.UserResult result); + + // LoginUseCase 변환 + LoginResponse toLoginResponse(LoginUseCase.LoginResult result); + UserResponse toUserResponse(LoginUseCase.LoginResult.UserInfo userInfo); + + // RefreshTokenUseCase 변환 + TokenResponse toTokenResponse(RefreshTokenUseCase.TokenResult result); +} diff --git a/infrastructure/src/main/java/com/btg/infrastructure/web/mapper/DailyProgressResponseMapper.java b/infrastructure/src/main/java/com/btg/infrastructure/web/mapper/DailyProgressResponseMapper.java new file mode 100644 index 0000000..1fa7077 --- /dev/null +++ b/infrastructure/src/main/java/com/btg/infrastructure/web/mapper/DailyProgressResponseMapper.java @@ -0,0 +1,31 @@ +package com.btg.infrastructure.web.mapper; + +import com.btg.core.application.port.in.dailyprogress.GetDailyProgressUseCase; +import com.btg.core.application.port.in.dailyprogress.UpdateDailyProgressUseCase; +import com.btg.infrastructure.web.dailyprogress.dto.response.DailyProgressResponse; +import com.btg.infrastructure.web.dailyprogress.dto.response.DailyProgressSummaryResponse; +import com.btg.infrastructure.web.dailyprogress.dto.response.DailyStatResponse; +import com.btg.infrastructure.web.dailyprogress.dto.response.MyDailyProgressResponse; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +import java.util.List; + +@Mapper( + componentModel = "spring", + unmappedTargetPolicy = ReportingPolicy.ERROR +) +public interface DailyProgressResponseMapper { + + // GetDailyProgressUseCase 변환 + DailyProgressSummaryResponse toSummaryResponse(GetDailyProgressUseCase.DailyProgressSummaryResult result); + DailyStatResponse toStatResponse(GetDailyProgressUseCase.DailyStat stat); + List toStatResponseList(List stats); + + MyDailyProgressResponse toMyProgressResponse(GetDailyProgressUseCase.MyDailyProgressResult result); + DailyProgressResponse toProgressResponse(GetDailyProgressUseCase.DailyRecord record); + List toProgressResponseList(List records); + + // UpdateDailyProgressUseCase 변환 + DailyProgressResponse toProgressResponse(UpdateDailyProgressUseCase.DailyProgressResult result); +} diff --git a/infrastructure/src/main/java/com/btg/infrastructure/web/mapper/GroupResponseMapper.java b/infrastructure/src/main/java/com/btg/infrastructure/web/mapper/GroupResponseMapper.java new file mode 100644 index 0000000..38d5cbd --- /dev/null +++ b/infrastructure/src/main/java/com/btg/infrastructure/web/mapper/GroupResponseMapper.java @@ -0,0 +1,61 @@ +package com.btg.infrastructure.web.mapper; + +import com.btg.core.application.port.in.group.CreateGroupUseCase; +import com.btg.core.application.port.in.group.GetGroupUseCase; +import com.btg.core.application.port.in.group.ListGroupsUseCase; +import com.btg.core.application.port.in.group.UpdateGroupUseCase; +import com.btg.infrastructure.web.group.dto.response.GroupDetailResponse; +import com.btg.infrastructure.web.group.dto.response.GroupResponse; +import com.btg.infrastructure.web.group.dto.response.PagedGroupResponse; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +import java.util.List; + +/** + * Group 관련 UseCase Result → Response DTO 변환 Mapper + * MapStruct가 중첩 객체(UserInfo → UserResponse)를 자동으로 처리합니다. + */ +@Mapper( + componentModel = "spring", + uses = {UserResponseMapper.class}, // 중첩 변환용 UserResponseMapper 연결 + unmappedTargetPolicy = ReportingPolicy.ERROR // 매핑 누락 시 컴파일 에러 발생 +) +public interface GroupResponseMapper { + + /** + * CreateGroupUseCase.GroupResult → GroupResponse + * createGroup 메서드에서 사용 + */ + GroupResponse toResponse(CreateGroupUseCase.GroupResult result); + + /** + * UpdateGroupUseCase.GroupResult → GroupResponse + * updateGroup 메서드에서 사용 + */ + GroupResponse toResponse(UpdateGroupUseCase.GroupResult result); + + /** + * GetGroupUseCase.GroupDetailResult → GroupDetailResponse + * getGroup 메서드에서 사용 + */ + GroupDetailResponse toDetailResponse(GetGroupUseCase.GroupDetailResult result); + + /** + * ListGroupsUseCase.GroupSummary → GroupResponse + * List 변환의 기본 단위 + */ + GroupResponse toResponse(ListGroupsUseCase.GroupSummary summary); + + /** + * List → List + * listGroups의 content 변환용 + */ + List toResponseList(List summaries); + + /** + * ListGroupsUseCase.PagedGroupResult → PagedGroupResponse + * listGroups 메서드에서 사용 (content List 자동 변환 포함) + */ + PagedGroupResponse toPagedResponse(ListGroupsUseCase.PagedGroupResult result); +} diff --git a/infrastructure/src/main/java/com/btg/infrastructure/web/mapper/TaskResponseMapper.java b/infrastructure/src/main/java/com/btg/infrastructure/web/mapper/TaskResponseMapper.java new file mode 100644 index 0000000..e6526b6 --- /dev/null +++ b/infrastructure/src/main/java/com/btg/infrastructure/web/mapper/TaskResponseMapper.java @@ -0,0 +1,39 @@ +package com.btg.infrastructure.web.mapper; + +import com.btg.core.application.port.in.task.CreateTaskUseCase; +import com.btg.core.application.port.in.task.GetTaskUseCase; +import com.btg.core.application.port.in.task.ListTasksUseCase; +import com.btg.core.application.port.in.task.UpdateTaskUseCase; +import com.btg.infrastructure.web.task.dto.response.PagedTaskResponse; +import com.btg.infrastructure.web.task.dto.response.TaskDetailResponse; +import com.btg.infrastructure.web.task.dto.response.TaskResponse; +import com.btg.infrastructure.web.task.dto.response.UserResponse; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +import java.util.List; + +@Mapper( + componentModel = "spring", + unmappedTargetPolicy = ReportingPolicy.ERROR +) +public interface TaskResponseMapper { + + // CreateTaskUseCase 변환 + TaskResponse toResponse(CreateTaskUseCase.TaskResult result); + UserResponse toUserResponse(CreateTaskUseCase.UserInfo userInfo); + + // UpdateTaskUseCase 변환 + TaskResponse toResponse(UpdateTaskUseCase.TaskResult result); + UserResponse toUserResponse(UpdateTaskUseCase.UserInfo userInfo); + + // GetTaskUseCase 변환 + TaskDetailResponse toDetailResponse(GetTaskUseCase.TaskDetailResult result); + UserResponse toUserResponse(GetTaskUseCase.UserInfo userInfo); + + // ListTasksUseCase 변환 + TaskResponse toResponse(ListTasksUseCase.TaskSummary summary); + UserResponse toUserResponse(ListTasksUseCase.UserInfo userInfo); + List toResponseList(List summaries); + PagedTaskResponse toPagedResponse(ListTasksUseCase.PagedTaskResult result); +} diff --git a/infrastructure/src/main/java/com/btg/infrastructure/web/mapper/UserResponseMapper.java b/infrastructure/src/main/java/com/btg/infrastructure/web/mapper/UserResponseMapper.java new file mode 100644 index 0000000..6fed990 --- /dev/null +++ b/infrastructure/src/main/java/com/btg/infrastructure/web/mapper/UserResponseMapper.java @@ -0,0 +1,38 @@ +package com.btg.infrastructure.web.mapper; + +import com.btg.core.application.port.in.group.*; +import com.btg.core.application.port.in.user.GetUserProfileUseCase; +import com.btg.core.application.port.in.user.UpdateUserProfileUseCase; +import com.btg.infrastructure.web.user.dto.response.UserResponse; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.ReportingPolicy; + + +@Mapper( + componentModel = "spring", + unmappedTargetPolicy = ReportingPolicy.ERROR +) +public interface UserResponseMapper { + + // Group 도메인용 UserInfo 변환 (createdAt 없음) + @Mapping(target = "createdAt", ignore = true) + UserResponse toResponse(CreateGroupUseCase.UserInfo userInfo); + + @Mapping(target = "createdAt", ignore = true) + UserResponse toResponse(GetGroupUseCase.UserInfo userInfo); + + @Mapping(target = "createdAt", ignore = true) + UserResponse toResponse(ListGroupsUseCase.UserInfo userInfo); + + @Mapping(target = "createdAt", ignore = true) + UserResponse toResponse(UpdateGroupUseCase.UserInfo userInfo); + + @Mapping(target = "createdAt", ignore = true) + UserResponse toResponse(JoinGroupUseCase.UserInfo userInfo); + + // User 도메인용 UserProfileResult 변환 + UserResponse toResponse(GetUserProfileUseCase.UserProfileResult result); + + UserResponse toResponse(UpdateUserProfileUseCase.UserProfileResult result); +} diff --git a/infrastructure/src/main/java/com/btg/infrastructure/web/task/TaskController.java b/infrastructure/src/main/java/com/btg/infrastructure/web/task/TaskController.java index 722b88f..9fa99c1 100644 --- a/infrastructure/src/main/java/com/btg/infrastructure/web/task/TaskController.java +++ b/infrastructure/src/main/java/com/btg/infrastructure/web/task/TaskController.java @@ -1,6 +1,7 @@ package com.btg.infrastructure.web.task; import com.btg.core.application.port.in.task.*; +import com.btg.infrastructure.web.mapper.TaskResponseMapper; import com.btg.infrastructure.web.task.dto.request.CreateTaskRequest; import com.btg.infrastructure.web.task.dto.request.UpdateTaskRequest; import com.btg.infrastructure.web.task.dto.response.*; @@ -10,8 +11,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.stream.Collectors; - @RestController @RequestMapping("/tasks") @RequiredArgsConstructor @@ -22,6 +21,7 @@ public class TaskController { private final UpdateTaskUseCase updateTaskUseCase; private final DeleteTaskUseCase deleteTaskUseCase; private final ListTasksUseCase listTasksUseCase; + private final TaskResponseMapper taskResponseMapper; @PostMapping public ResponseEntity createTask(@Valid @RequestBody CreateTaskRequest request) { @@ -40,28 +40,8 @@ public ResponseEntity createTask(@Valid @RequestBody CreateTaskReq CreateTaskUseCase.TaskResult result = createTaskUseCase.createTask(command); - TaskResponse response = new TaskResponse( - result.id(), - result.groupId(), - result.title(), - result.description(), - result.status(), - result.startDate(), - result.endDate(), - result.totalDays(), - result.participantCount(), - result.maxParticipants(), - result.overallCompletionRate(), - new UserResponse( - result.createdBy().id(), - result.createdBy().email(), - result.createdBy().name() - ), - result.createdAt(), - result.updatedAt() - ); - - return ResponseEntity.status(HttpStatus.CREATED).body(response); + return ResponseEntity.status(HttpStatus.CREATED) + .body(taskResponseMapper.toResponse(result)); } @GetMapping @@ -84,36 +64,7 @@ public ResponseEntity listTasks( ListTasksUseCase.PagedTaskResult result = listTasksUseCase.listTasks(query); - PagedTaskResponse response = new PagedTaskResponse( - result.content().stream() - .map(task -> new TaskResponse( - task.id(), - task.groupId(), - task.title(), - task.description(), - task.status(), - task.startDate(), - task.endDate(), - task.totalDays(), - task.participantCount(), - task.maxParticipants(), - task.overallCompletionRate(), - new UserResponse( - task.createdBy().id(), - task.createdBy().email(), - task.createdBy().name() - ), - task.createdAt(), - task.updatedAt() - )) - .collect(Collectors.toList()), - result.totalElements(), - result.totalPages(), - result.page(), - result.size() - ); - - return ResponseEntity.ok(response); + return ResponseEntity.ok(taskResponseMapper.toPagedResponse(result)); } @GetMapping("/{taskId}") @@ -123,30 +74,7 @@ public ResponseEntity getTask(@PathVariable Long taskId) { GetTaskUseCase.TaskDetailResult result = getTaskUseCase.getTask(taskId, userId); - TaskDetailResponse response = new TaskDetailResponse( - result.id(), - result.groupId(), - result.title(), - result.description(), - result.status(), - result.startDate(), - result.endDate(), - result.totalDays(), - result.participantCount(), - result.maxParticipants(), - result.overallCompletionRate(), - new UserResponse( - result.createdBy().id(), - result.createdBy().email(), - result.createdBy().name() - ), - result.createdAt(), - result.updatedAt(), - result.isParticipating(), - result.myCompletionRate() - ); - - return ResponseEntity.ok(response); + return ResponseEntity.ok(taskResponseMapper.toDetailResponse(result)); } // TODO: PATCH /tasks/{taskId}/status - Task 상태 변경 @@ -169,28 +97,7 @@ public ResponseEntity updateTask( UpdateTaskUseCase.TaskResult result = updateTaskUseCase.updateTask(command); - TaskResponse response = new TaskResponse( - result.id(), - result.groupId(), - result.title(), - result.description(), - result.status(), - result.startDate(), - result.endDate(), - result.totalDays(), - result.participantCount(), - result.maxParticipants(), - result.overallCompletionRate(), - new UserResponse( - result.createdBy().id(), - result.createdBy().email(), - result.createdBy().name() - ), - result.createdAt(), - result.updatedAt() - ); - - return ResponseEntity.ok(response); + return ResponseEntity.ok(taskResponseMapper.toResponse(result)); } @DeleteMapping("/{taskId}") diff --git a/infrastructure/src/main/java/com/btg/infrastructure/web/user/UserController.java b/infrastructure/src/main/java/com/btg/infrastructure/web/user/UserController.java index 6f97c59..6b8e2f0 100644 --- a/infrastructure/src/main/java/com/btg/infrastructure/web/user/UserController.java +++ b/infrastructure/src/main/java/com/btg/infrastructure/web/user/UserController.java @@ -2,6 +2,7 @@ import com.btg.core.application.port.in.user.GetUserProfileUseCase; import com.btg.core.application.port.in.user.UpdateUserProfileUseCase; +import com.btg.infrastructure.web.mapper.UserResponseMapper; import com.btg.infrastructure.web.user.dto.request.UpdateUserRequest; import com.btg.infrastructure.web.user.dto.response.UserResponse; import jakarta.validation.Valid; @@ -16,6 +17,7 @@ public class UserController { private final GetUserProfileUseCase getUserProfileUseCase; private final UpdateUserProfileUseCase updateUserProfileUseCase; + private final UserResponseMapper userResponseMapper; @GetMapping("/me") public ResponseEntity getMyProfile() { @@ -24,14 +26,7 @@ public ResponseEntity getMyProfile() { GetUserProfileUseCase.UserProfileResult result = getUserProfileUseCase.getUserProfile(userId); - UserResponse response = new UserResponse( - result.id(), - result.email(), - result.name(), - result.createdAt() - ); - - return ResponseEntity.ok(response); + return ResponseEntity.ok(userResponseMapper.toResponse(result)); } @PutMapping("/me") @@ -47,13 +42,6 @@ public ResponseEntity updateMyProfile(@Valid @RequestBody UpdateUs UpdateUserProfileUseCase.UserProfileResult result = updateUserProfileUseCase.updateUserProfile(command); - UserResponse response = new UserResponse( - result.id(), - result.email(), - result.name(), - result.createdAt() - ); - - return ResponseEntity.ok(response); + return ResponseEntity.ok(userResponseMapper.toResponse(result)); } }