Skip to content

Commit

Permalink
#31 [FEAT] : 룸리스트 get api
Browse files Browse the repository at this point in the history
  • Loading branch information
hye-on committed Sep 11, 2023
1 parent d2e1685 commit f695300
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 68 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,18 @@
@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")
private int id;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,8 @@ public BaseResponse<Status> create(@AuthUser Integer userId, @RequestBody RoomR

public BaseResponse<List<RoomRes>> test(@AuthUser Integer userId ) {

// List<Integer> roomIds= new ArrayList<>();
// roomIds.add(6);
//roomIds.add(7);
//System.out.println("룸아이디" + roomIds.get(0).toString());
// List<MissionLog> missionLogs =missionLogRepository.findMostRecentMissionLogsByRoomIds(roomIds);
//List<MissionLog> 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));

}

Expand Down
42 changes: 4 additions & 38 deletions src/main/java/com/wakeUpTogetUp/togetUp/api/room/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,46 +68,12 @@ public void createRoom(Integer userId, RoomReq roomReq){
alarmRepository.updateRoomIdByAlarmId(alarmId,room.getId());

}
public void getRoomList(Integer userId) {

//모든 룸아이디 가져오기
List<RoomUser> roomList = roomUserRepository.findByUserId(userId);

System.out.println("룸리스트 "+roomList.toString());
List<Integer> roomIds = roomList.stream()
.map(roomUser -> roomUser.getRoom().getId())
.collect(Collectors.toList());
//모든 알람 가져오기
List<Alarm> alarmList = alarmRepository.findAllByRoomIds(roomIds);
System.out.println("알람 "+alarmList.toString());
// RoomRes roomRes= RoomRes.builder()
// .roomId(roomList.get(0).getId())
// .roomIcon(alarmList.get())
// //알람의 미션 가져오기
//
// List<Integer> missionIds = alarmList.stream()
// .map(Alarm -> Alarm.getMission().getId())
// .collect(Collectors.toList());
//
// List<Mission> missionList = missionRepository.findAllById(missionIds);
// System.out.println("미션 "+ missionList.toString());


//미션 로그 가져오기

List<MissionLog> missionLogs= missionLogRepository.findMostRecentMissionLogsByRoomIds(roomIds);
// dto 매핑
/* ArrayList<RoomRes> roomResList = new ArrayList<>();
for(Room room : roomList) {
roomResList.add(GroupMapper.INSTANCE.toGroupRes(room));
}*/

// return roomResList;
}

public List<RoomRes> getRoomList2(Integer userId) {

public List<RoomRes> getRoomList(Integer userId) {
List<Alarm> alarmList = alarmRepository.findAllByUser_IdAndRoom_IdIsNotNull(userId);
return EntityDtoMapper.INSTANCE.toRoomRes(alarmList);

return EntityDtoMapper.INSTANCE.toRoomResList(alarmList);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -45,12 +47,21 @@ public interface EntityDtoMapper {
NotificationRes toNotificationRes(Notification notification);
List<NotificationRes> toNotificationResList(List<Notification> 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<RoomRes> toRoomRes(List<Alarm> 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<RoomRes> toRoomResList(List<Alarm> alarmList);




}

0 comments on commit f695300

Please sign in to comment.