From f695300cb7cd4872886b1107795aed0c3e66cecb Mon Sep 17 00:00:00 2001 From: hye-on Date: Mon, 11 Sep 2023 13:43:58 +0900 Subject: [PATCH] =?UTF-8?q?#31=20[FEAT]=20:=20=EB=A3=B8=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20get=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 +- .../togetUp/api/mission/model/Mission.java | 16 +++---- .../togetUp/api/room/RoomController.java | 10 +---- .../togetUp/api/room/RoomService.java | 42 ++----------------- .../api/room/dto/response/RoomRes.java | 8 ++-- .../togetUp/utils/mapper/EntityDtoMapper.java | 21 +++++++--- 6 files changed, 32 insertions(+), 68 deletions(-) diff --git a/build.gradle b/build.gradle index 046b3404..6a0010c4 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,8 @@ dependencies { // model struct implementation 'org.mapstruct:mapstruct:1.5.4.Final' annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.4.Final' - + testAnnotationProcessor("org.mapstruct:mapstruct-processor:1.5.3.Final") + implementation("org.projectlombok:lombok-mapstruct-binding:0.2.0") // security implementation('org.springframework.boot:spring-boot-starter-security') diff --git a/src/main/java/com/wakeUpTogetUp/togetUp/api/mission/model/Mission.java b/src/main/java/com/wakeUpTogetUp/togetUp/api/mission/model/Mission.java index 9cc3945c..95c00c1e 100644 --- a/src/main/java/com/wakeUpTogetUp/togetUp/api/mission/model/Mission.java +++ b/src/main/java/com/wakeUpTogetUp/togetUp/api/mission/model/Mission.java @@ -16,11 +16,11 @@ @Setter @NoArgsConstructor public class Mission { -// @Builder -// public Mission(String name, String object) { -// this.name = name; -// this.object = object; -// } + @Builder + public Mission(String name, String object) { + this.name = name; + this.object = object; + } @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(columnDefinition = "INT UNSIGNED") @@ -28,12 +28,6 @@ public class Mission { private String name; private String object; - @Builder - public Mission(int id, String name, String object) { - this.id = id; - this.name = name; - this.object = object; - } @Column(name ="created_at",columnDefinition = "Timestamp") private String createdAt; diff --git a/src/main/java/com/wakeUpTogetUp/togetUp/api/room/RoomController.java b/src/main/java/com/wakeUpTogetUp/togetUp/api/room/RoomController.java index fc9e81a3..1e819e36 100644 --- a/src/main/java/com/wakeUpTogetUp/togetUp/api/room/RoomController.java +++ b/src/main/java/com/wakeUpTogetUp/togetUp/api/room/RoomController.java @@ -48,16 +48,8 @@ public BaseResponse create(@AuthUser Integer userId, @RequestBody RoomR public BaseResponse> test(@AuthUser Integer userId ) { - // List roomIds= new ArrayList<>(); - // roomIds.add(6); - //roomIds.add(7); - //System.out.println("룸아이디" + roomIds.get(0).toString()); - // List missionLogs =missionLogRepository.findMostRecentMissionLogsByRoomIds(roomIds); - //List missionLogs =missionLogRepository.findMostRecentMissionLogsByRoomIds(roomIds); - // System.out.println(missionLogs.toString() +" 여기"); - - return new BaseResponse(Status.SUCCESS,roomService.getRoomList2(userId)); + return new BaseResponse(Status.SUCCESS,roomService.getRoomList(userId)); } diff --git a/src/main/java/com/wakeUpTogetUp/togetUp/api/room/RoomService.java b/src/main/java/com/wakeUpTogetUp/togetUp/api/room/RoomService.java index 9cdc1166..47149f74 100644 --- a/src/main/java/com/wakeUpTogetUp/togetUp/api/room/RoomService.java +++ b/src/main/java/com/wakeUpTogetUp/togetUp/api/room/RoomService.java @@ -68,46 +68,12 @@ public void createRoom(Integer userId, RoomReq roomReq){ alarmRepository.updateRoomIdByAlarmId(alarmId,room.getId()); } - public void getRoomList(Integer userId) { - - //모든 룸아이디 가져오기 - List roomList = roomUserRepository.findByUserId(userId); - - System.out.println("룸리스트 "+roomList.toString()); - List roomIds = roomList.stream() - .map(roomUser -> roomUser.getRoom().getId()) - .collect(Collectors.toList()); - //모든 알람 가져오기 - List alarmList = alarmRepository.findAllByRoomIds(roomIds); - System.out.println("알람 "+alarmList.toString()); -// RoomRes roomRes= RoomRes.builder() -// .roomId(roomList.get(0).getId()) -// .roomIcon(alarmList.get()) -// //알람의 미션 가져오기 -// -// List missionIds = alarmList.stream() -// .map(Alarm -> Alarm.getMission().getId()) -// .collect(Collectors.toList()); -// -// List missionList = missionRepository.findAllById(missionIds); - // System.out.println("미션 "+ missionList.toString()); - - - //미션 로그 가져오기 - - List missionLogs= missionLogRepository.findMostRecentMissionLogsByRoomIds(roomIds); - // dto 매핑 - /* ArrayList roomResList = new ArrayList<>(); - for(Room room : roomList) { - roomResList.add(GroupMapper.INSTANCE.toGroupRes(room)); - }*/ - - // return roomResList; - } - public List getRoomList2(Integer userId) { + + public List getRoomList(Integer userId) { List alarmList = alarmRepository.findAllByUser_IdAndRoom_IdIsNotNull(userId); - return EntityDtoMapper.INSTANCE.toRoomRes(alarmList); + + return EntityDtoMapper.INSTANCE.toRoomResList(alarmList); } @Transactional diff --git a/src/main/java/com/wakeUpTogetUp/togetUp/api/room/dto/response/RoomRes.java b/src/main/java/com/wakeUpTogetUp/togetUp/api/room/dto/response/RoomRes.java index e482d379..e0008e3c 100644 --- a/src/main/java/com/wakeUpTogetUp/togetUp/api/room/dto/response/RoomRes.java +++ b/src/main/java/com/wakeUpTogetUp/togetUp/api/room/dto/response/RoomRes.java @@ -4,15 +4,15 @@ @Getter @Setter -@Builder -@NoArgsConstructor @AllArgsConstructor +@NoArgsConstructor +@Builder public class RoomRes { private Integer roomId; //룸 - private String roomIcon; //알람 + private String icon; //알람 private String name; //룸 - // private String mission; //알람 + private String mission; //알람 // private String recentlyMissionLog; //private boolean isRead; } diff --git a/src/main/java/com/wakeUpTogetUp/togetUp/utils/mapper/EntityDtoMapper.java b/src/main/java/com/wakeUpTogetUp/togetUp/utils/mapper/EntityDtoMapper.java index 24d31620..f65a63e0 100644 --- a/src/main/java/com/wakeUpTogetUp/togetUp/utils/mapper/EntityDtoMapper.java +++ b/src/main/java/com/wakeUpTogetUp/togetUp/utils/mapper/EntityDtoMapper.java @@ -9,12 +9,14 @@ import com.wakeUpTogetUp.togetUp.api.mission.model.Mission; import com.wakeUpTogetUp.togetUp.api.mission.model.MissionLog; import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomRes; +import org.mapstruct.Mapper; import org.mapstruct.Mapping; +import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; import java.util.List; -@org.mapstruct.Mapper(componentModel = "spring") +@Mapper(componentModel = "spring") public interface EntityDtoMapper { EntityDtoMapper INSTANCE = Mappers.getMapper(EntityDtoMapper.class); @@ -45,12 +47,21 @@ public interface EntityDtoMapper { NotificationRes toNotificationRes(Notification notification); List toNotificationResList(List notificationList); - //Room + @Mapping(target = "roomId",source = "room.id") - @Mapping(target = "roomIcon",source = "icon") + @Mapping(target = "icon",source = "icon") @Mapping(target = "name",source = "room.name") - // @Mapping(target = "mission",source = "room.intro") - List toRoomRes(List alarmList); + @Mapping(target = "mission",source = "mission.name") + RoomRes toRoomRes(Alarm alarm); + + //Room + @Mapping(target = "id",source = "room") + @Mapping(target = "icon",source = "icon") + @Mapping(target = ".",source = "room") + @Mapping(target = "mission",source = "mission.name") + List toRoomResList(List alarmList); + + }