Skip to content

Commit

Permalink
#56 [FEAT] : 그룹디테일 api
Browse files Browse the repository at this point in the history
  • Loading branch information
hye-on committed Oct 16, 2023
1 parent 19a31be commit 9531aa1
Show file tree
Hide file tree
Showing 5 changed files with 424 additions and 36 deletions.
16 changes: 12 additions & 4 deletions src/main/java/com/wakeUpTogetUp/togetUp/api/room/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,20 @@ public RoomDetailRes getRoomDetail(Integer roomId){
List<RoomUser> roomUsers = roomUserRepository.findAllByRoom_Id(roomId);


//dto 매핑
RoomDetailRes roomDetailRes = EntityDtoMapper.INSTANCE.toRoomDetailRes(alarm);
//dto 매핑 mapper 사용
RoomDetailRes roomDetailRes =new RoomDetailRes();
roomDetailRes.setRoomData(EntityDtoMapper.INSTANCE.toRoomDetailResRoomData(alarm));
roomDetailRes.setAlarmData(EntityDtoMapper.INSTANCE.toRoomDetailResAlarmData(alarm));
roomDetailRes.setUserList(EntityDtoMapper.INSTANCE.toUserDataList(roomUsers));

roomDetailRes.setCreatedAtString("개설일 "+timeFormatter.timestampToDotDateFormat(alarm.getRoom().getCreatedAt()));
roomDetailRes.setPersonnelString(roomUsers.size()+"명이 함께해요");
//dto 매핑 - 커스텀 필드
roomDetailRes.getRoomData().setCreatedAtString(timeFormatter.timestampToDotDateFormat(alarm.getRoom().getCreatedAt()));
roomDetailRes.getRoomData().setPersonnelString(roomUsers.size());

// ex) 13:00 -> pm 1:00
roomDetailRes.getAlarmData().setAlarmTime(timeFormatter.timeStringToAMPMFormat(alarm.getAlarmTime()));
// ex) 평일, 주말, 매일, 월요일, (월, 화, 수), 빈칸
roomDetailRes.getAlarmData().setAlarmDay(timeFormatter.formatDaysOfWeek(alarm.getMonday(),alarm.getTuesday(),alarm.getWednesday(),alarm.getThursday(),alarm.getFriday(),alarm.getSaturday(),alarm.getSunday()));

return roomDetailRes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,52 @@
@Builder
public class RoomDetailRes {

@Schema( description = "룸이 가지고 있는 알람의 아이콘",example = "⏰")
private String icon;
@Schema(description = "룸 정보")
private RoomData roomData;

@Schema(description = "room name", example = "설여대 기상방")
private String name;
@Schema(description = "룸 정보")
private AlarmData alarmData;

@Schema(description = "room 소개",example = "소프트웨어융학학과 기상방입니다.")
private String intro;
@Schema(description = "룸의 유저들 정보 리스트")
private List<RoomDetailRes.UserData> userList;
@Builder
@Data
public static class RoomData {

@Schema(description = "room 개설일",example = "개설일 2020.02.03")
private String createdAtString;
@Schema( description = "룸이 가지고 있는 알람의 아이콘",example = "")
private String icon;

// @Schema(description = "룸이 가지고 있는 알람의 미션" , example = "강아지")
// private String mission;
//
// private String a
@Schema(description = "room name", example = "설여대 기상방")
private String name;

@Schema(description = "room 소개",example = "소프트웨어융학학과 기상방입니다.")
private String intro;

@Schema(description = "room 개설일",example = "2020.02.03")
private String createdAtString;

@Schema(description = "함께하는 인원수",example = "6")
private Integer personnelString;


}

@Builder
@Data
public static class AlarmData {
@Schema(description = "미션의 한국말",example = "자동차")
private String missionKr;

@Schema(description = "알람 시간", example = "06:00")
private String alarmTime;

@Schema(description = "그룹알람 울리는 날",example = "주중")
private String alarmDay;


}

@Schema(description = "함께하는 인원수",example = "6명이 함께해요")
private String personnelString;

private List<RoomDetailRes.UserData> userList;

@Builder
@Data
Expand Down
49 changes: 48 additions & 1 deletion src/main/java/com/wakeUpTogetUp/togetUp/utils/TimeFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;
import java.util.Objects;
import java.util.stream.Stream;

@Component
public class TimeFormatter {
Expand Down Expand Up @@ -41,4 +43,49 @@ public LocalDateTime stringToLocalDateTime(String timeString)
return localDateTime;

}

public String timeStringToAMPMFormat(String timeString) {
LocalTime localTime = stringToLocalTime(timeString);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("a h:mm").withLocale(Locale.ENGLISH);
return localTime.format(formatter).toLowerCase();
}




public String formatDaysOfWeek(boolean monday, boolean tuesday, boolean wednesday, boolean thursday, boolean friday, boolean saturday, boolean sunday) {

StringBuilder formattedDays = new StringBuilder();

Boolean[] weekDays= {true, true, true, true, true, false, false };
Boolean[] weekend = {false, false, false, false, false, true, true};
Boolean[] none = {false, false, false, false, false, false, false};
Boolean[] everyDay= {true, true, true, true, true, true, true };


Boolean[] alarmDays = {monday, tuesday, wednesday, thursday, friday, saturday, sunday };

if(Objects.deepEquals(weekDays,alarmDays))
formattedDays.append("주중");
else if(Objects.deepEquals(weekend,alarmDays))
formattedDays.append("주말");
else if (Objects.deepEquals(none,alarmDays))
formattedDays.append("");
else if(Objects.deepEquals(everyDay,alarmDays))
formattedDays.append("매일");
else
{

for (int i = 0; i < alarmDays.length; i++) {
if (alarmDays[i]) {
formattedDays.append(new String[]{"월", "화", "수", "목", "금","토","일"}[i]);
formattedDays.append(",");
}
}
formattedDays.deleteCharAt(formattedDays.length() - 1);
}

return formattedDays.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@ public interface EntityDtoMapper {
@Mapping(target = "icon",source = "icon")
@Mapping(target = "name",source = "room.name")
@Mapping(target = "intro",source = "room.intro")
RoomDetailRes toRoomDetailRes(Alarm alarm);
RoomDetailRes.RoomData toRoomDetailResRoomData(Alarm alarm);

@Mapping(target = "missionKr", source = "missionObject.kr")
RoomDetailRes.AlarmData toRoomDetailResAlarmData(Alarm alarm);
@Mapping(target = "userId",source = "user.id")
@Mapping(target = "userName",source = "user.name")
@Mapping(target = "isHost",source = "isHost")
RoomDetailRes.UserData toUserData(RoomUser roomUser);
RoomDetailRes.UserData toRoomDetailUserData(RoomUser roomUser);

@Mapping(target = "userId",source = "user.id")
@Mapping(target = "userName",source = "user.name")
Expand Down
Loading

0 comments on commit 9531aa1

Please sign in to comment.