Skip to content

Commit

Permalink
#49 [CHORE] : 리뷰반영
Browse files Browse the repository at this point in the history
  • Loading branch information
hye-on committed Sep 21, 2023
1 parent b4d4ea7 commit 4de908b
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,6 @@ public int deleteAlarm(Integer alarmId) {

return alarm.getId();
}
//String 인 alarmTime을 LocalTime으로 변경
public LocalTime alarmTimeStringToLocalTime(String alarmTime)
{
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
LocalTime localTime = LocalTime.parse(alarmTime, formatter);
return localTime;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@Schema(description = "소셜로그인 요펑")
@Schema(description = "소셜로그인 요청")
@Setter
@Getter
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.wakeUpTogetUp.togetUp.api.room.model.Room;
import com.wakeUpTogetUp.togetUp.api.users.model.User;
import com.wakeUpTogetUp.togetUp.utils.TimestampFormatter;
import com.wakeUpTogetUp.togetUp.utils.TimeFormatter;
import lombok.*;
import org.hibernate.annotations.DynamicInsert;

Expand Down Expand Up @@ -35,7 +35,7 @@ public class MissionLog {
private String missionPicLink;

@Column(name = "created_at",columnDefinition = "Timestamp")
private String createdAt = TimestampFormatter.format(new Timestamp(System.currentTimeMillis()));
private String createdAt = TimeFormatter.timestampFormat(new Timestamp(System.currentTimeMillis()));

@Column(name = "is_deleted")
private Boolean isDeleted = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.wakeUpTogetUp.togetUp.api.room.model.Room;
import com.wakeUpTogetUp.togetUp.api.users.fcmToken.FcmToken;
import com.wakeUpTogetUp.togetUp.utils.TimestampFormatter;
import com.wakeUpTogetUp.togetUp.utils.TimeFormatter;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -41,7 +41,7 @@ public Notification(String title, String content, Room room, FcmToken fcmToken)
private String content;

@Column(columnDefinition = "timestamp")
private String createdAt = TimestampFormatter.format(new Timestamp(System.currentTimeMillis()));
private String createdAt = TimeFormatter.timestampFormat(new Timestamp(System.currentTimeMillis()));

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "roomId",columnDefinition = "INT UNSIGNED")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.wakeUpTogetUp.togetUp.api.auth.AuthUser;
import com.wakeUpTogetUp.togetUp.api.mission.MissionLogRepository;
import com.wakeUpTogetUp.togetUp.api.room.dto.request.RoomUserLogReq;
import com.wakeUpTogetUp.togetUp.api.room.dto.request.RoomUserLogMissionReq;
import com.wakeUpTogetUp.togetUp.api.room.dto.request.RoomReq;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomUserLogRes;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomUserMissionLogRes;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomRes;
import com.wakeUpTogetUp.togetUp.common.dto.BaseResponse;
import com.wakeUpTogetUp.togetUp.common.Status;
Expand Down Expand Up @@ -58,11 +58,11 @@ public BaseResponse<List<RoomRes>> getList(@Parameter(hidden = true) @AuthUser I

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "요청에 성공하였습니다.",
content = @Content(schema = @Schema(implementation = RoomUserLogRes.class))),
content = @Content(schema = @Schema(implementation = RoomUserMissionLogRes.class))),
@ApiResponse(responseCode = "404", description = "그룹의 멤버가 없습니다.")})
@Operation(description = "그룹의 멤버의 미션기록 보기")
@GetMapping("/user/mission-log")
public BaseResponse<RoomUserLogRes> getRoomDetailByDate(@Parameter(hidden = true) @AuthUser Integer userId, @RequestBody RoomUserLogReq roomLogReq) {
public BaseResponse<RoomUserMissionLogRes> getRoomDetailByDate(@Parameter(hidden = true) @AuthUser Integer userId, @RequestBody RoomUserLogMissionReq roomLogReq) {


return new BaseResponse(Status.SUCCESS,roomService.getRoomUserLogList(userId,roomLogReq));
Expand Down
34 changes: 18 additions & 16 deletions src/main/java/com/wakeUpTogetUp/togetUp/api/room/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.wakeUpTogetUp.togetUp.api.alarm.model.Alarm;
import com.wakeUpTogetUp.togetUp.api.mission.MissionLogRepository;
import com.wakeUpTogetUp.togetUp.api.mission.model.MissionLog;
import com.wakeUpTogetUp.togetUp.api.room.dto.request.RoomUserLogReq;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomUserLogRes;
import com.wakeUpTogetUp.togetUp.api.room.dto.request.RoomUserLogMissionReq;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomUserMissionLogRes;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomRes;
import com.wakeUpTogetUp.togetUp.api.room.model.Room;
import com.wakeUpTogetUp.togetUp.api.room.model.RoomUser;
Expand All @@ -16,6 +16,7 @@
import com.wakeUpTogetUp.togetUp.common.Status;
import com.wakeUpTogetUp.togetUp.exception.BaseException;
import com.wakeUpTogetUp.togetUp.api.room.dto.request.RoomReq;
import com.wakeUpTogetUp.togetUp.utils.TimeFormatter;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -39,6 +40,7 @@ public class RoomService {
private final RoomUserRepository roomUserRepository;
private final AlarmRepository alarmRepository;
private final MissionLogRepository missionLogRepository;
private final TimeFormatter timeFormatter;
@Transactional
public void createRoom(Integer userId, RoomReq roomReq){

Expand Down Expand Up @@ -78,29 +80,29 @@ public List<RoomRes> getRoomList(Integer userId) {
}


public RoomUserLogRes getRoomUserLogList(Integer userId, RoomUserLogReq roomUserLogReq){
Integer roomId = roomUserLogReq.getRoomId();
LocalDateTime localDateTime = roomUserLogReq.getLocalDateTime();
boolean isAlarmActive = roomUserLogReq.getIsAlarmActive();
public RoomUserMissionLogRes getRoomUserLogList(Integer userId, RoomUserLogMissionReq roomUserLogMissionReq){
Integer roomId = roomUserLogMissionReq.getRoomId();
LocalDateTime localDateTime = roomUserLogMissionReq.getLocalDateTime();
boolean isAlarmActive = roomUserLogMissionReq.getIsAlarmActive();

List<RoomUser> roomUserList = roomUserRepository.findAllByRoom_Id(roomId);
//크기가 0이면 예외처리
if(roomUserList.isEmpty())
throw new BaseException(Status.ROOM_USER_NOT_FOUND);
//룸이름, userId,userName 매핑 (항상 반환하는 정보)
RoomUserLogRes roomUserLogRes =new RoomUserLogRes();
roomUserLogRes.setName(roomUserList.get(0).getRoom().getName());
roomUserLogRes.setUserLogList(EntityDtoMapper.INSTANCE.toUserLogDataList(roomUserList));
RoomUserMissionLogRes roomUserMissionLogRes =new RoomUserMissionLogRes();
roomUserMissionLogRes.setName(roomUserList.get(0).getRoom().getName());
roomUserMissionLogRes.setUserLogList(EntityDtoMapper.INSTANCE.toUserLogDataList(roomUserList));

//isMyLog, missionPicLink, userCompleteType 는 각케이스에 맞게 설정
return setUserLogData(roomUserLogRes, userId, roomId, isAlarmActive, localDateTime);
return setUserLogData(roomUserMissionLogRes, userId, roomId, isAlarmActive, localDateTime);

}

public RoomUserLogRes setUserLogData(RoomUserLogRes roomUserLogRes,Integer userId,Integer roomId,boolean isAlarmActive,LocalDateTime localDateTime){
public RoomUserMissionLogRes setUserLogData(RoomUserMissionLogRes roomUserMissionLogRes, Integer userId, Integer roomId, boolean isAlarmActive, LocalDateTime localDateTime){
if(!isAlarmActive)
{
for (RoomUserLogRes.UserLogData userLogData : roomUserLogRes.getUserLogList()) {
for (RoomUserMissionLogRes.UserLogData userLogData : roomUserMissionLogRes.getUserLogList()) {
userLogData.setUserCompleteType(UserCompleteType.NOT_MISSION);
userLogData.setMissionPicLink(Constant.ROOM_USER_MISSION_IMG_NOT_MISSION);
if(userLogData.getUserId()==userId)
Expand All @@ -109,15 +111,15 @@ public RoomUserLogRes setUserLogData(RoomUserLogRes roomUserLogRes,Integer userI
}

}
return roomUserLogRes;
return roomUserMissionLogRes;
}
//missionLog에서 날짜로 가져옴 .
List<MissionLog> missionLogList = missionLogRepository.findAllByRoom_IdAndCreatedAtContaining(roomId,localDateTime.toLocalDate());
//오늘인지 아닌지
boolean isToday = localDateTime.toLocalDate().isEqual(LocalDate.now());

// for 문돌면서 : 유저 Id로 비교 :
for (RoomUserLogRes.UserLogData userLogData : roomUserLogRes.getUserLogList()) {
for (RoomUserMissionLogRes.UserLogData userLogData : roomUserMissionLogRes.getUserLogList()) {
// 유저 Id가 있으면 (미션 수행한 기록이 있으면) -> 미션 수행사진 매핑
if(userLogData.getUserId()==userId)
{
Expand All @@ -138,7 +140,7 @@ public RoomUserLogRes setUserLogData(RoomUserLogRes roomUserLogRes,Integer userI
{
//알람의 다시 울림 시간을 계산함.
Alarm alarm = alarmRepository.findFirstByRoom_Id(roomId);
LocalTime alarmLocalTime = alarmService.alarmTimeStringToLocalTime(alarm.getAlarmTime());
LocalTime alarmLocalTime = timeFormatter.stringToLocalTime(alarm.getAlarmTime());
LocalTime alarmOffTime = alarmLocalTime.withMinute(alarmLocalTime.getMinute() + alarm.getSnoozeCnt()*alarm.getSnoozeInterval());
//알람이 끝나기 전인지 여부
boolean isBeforeAlarmEnd = localDateTime.toLocalTime().isBefore(alarmOffTime);
Expand All @@ -163,7 +165,7 @@ public RoomUserLogRes setUserLogData(RoomUserLogRes roomUserLogRes,Integer userI



return roomUserLogRes;
return roomUserMissionLogRes;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class RoomUserLogReq {
public class RoomUserLogMissionReq {

@Schema( description = "룸 id",requiredMode = Schema.RequiredMode.REQUIRED ,example = "1")
@NotBlank(message = "룸 id는 공백일 수 없습니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import javax.validation.constraints.NotBlank;

@Schema(description = "룸리스트 요청 api 응답")
@Getter
Expand All @@ -16,7 +15,7 @@ public class RoomRes {
@Schema( description = "룸 id" ,example = "1")
private Integer roomId;

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

@Schema( description = "룸 이름",example = "일찍 일어나는 새들의 방")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RoomUserLogRes {
public class RoomUserMissionLogRes {

@Schema(description = "room name",example = "설여대 기상방")
private String name;
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/wakeUpTogetUp/togetUp/utils/TimeFormatter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.wakeUpTogetUp.togetUp.utils;


import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

@Component
public class TimeFormatter {
public static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static String timestampFormat(Timestamp timestamp) {
return simpleDateFormat.format(timestamp);
}


public LocalTime stringToLocalTime(String timeString)
{
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
LocalTime localTime = LocalTime.parse(timeString, formatter);
return localTime;

}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.wakeUpTogetUp.togetUp.api.mission.dto.response.GetMissionLogRes;
import com.wakeUpTogetUp.togetUp.api.mission.model.Mission;
import com.wakeUpTogetUp.togetUp.api.mission.model.MissionLog;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomUserLogRes;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomUserMissionLogRes;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomRes;
import com.wakeUpTogetUp.togetUp.api.room.model.RoomUser;
import org.mapstruct.Mapper;
Expand Down Expand Up @@ -71,11 +71,11 @@ public interface EntityDtoMapper {

@Mapping(target = "userId", source = "user.id")
@Mapping(target = "userName",source = "user.name")
RoomUserLogRes.UserLogData toUserLogData(RoomUser roomUser);
RoomUserMissionLogRes.UserLogData toUserLogData(RoomUser roomUser);

@Mapping(target = "userId", source = "user.id")
@Mapping(target = "userName",source = "user.name")
List<RoomUserLogRes.UserLogData> toUserLogDataList(List<RoomUser> roomUser);
List<RoomUserMissionLogRes.UserLogData> toUserLogDataList(List<RoomUser> roomUser);



Expand Down
22 changes: 11 additions & 11 deletions src/main/resources/migration/mock.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@



INSERT INTO togetUp_local.room (id, name, intro, topic, invitation_code, created_at, updated_at, is_deleted) VALUES (1, 'test room1', 'test room 1 입니다', 'kdfja39r83', 'dfjasdlf', '2023-09-19 11:01:11', '2023-09-19 11:02:24', 0);
INSERT INTO togetUp_local.room (id, name, intro, topic, invitation_code, created_at, updated_at, is_deleted) VALUES (2, 'test room2', 'test room 2 입니다', 'adsfadf', 'asdfade', '2023-09-19 11:03:15', '2023-09-19 11:03:15', 0);
INSERT INTO togetUp_local.room (id, name, intro, topic, invitation_code, created_at, updated_at, is_deleted) VALUES (3, 'test room3', 'test room 3입니다', 'egaaegg', 'egageg', '2023-09-19 11:03:45', '2023-09-19 11:03:48', 0);
INSERT INTO room (id, name, intro, topic, invitation_code, created_at, updated_at, is_deleted) VALUES (1, 'test room1', 'test room 1 입니다', 'kdfja39r83', 'dfjasdlf', '2023-09-19 11:01:11', '2023-09-19 11:02:24', 0);
INSERT INTO room (id, name, intro, topic, invitation_code, created_at, updated_at, is_deleted) VALUES (2, 'test room2', 'test room 2 입니다', 'adsfadf', 'asdfade', '2023-09-19 11:03:15', '2023-09-19 11:03:15', 0);
INSERT INTO room (id, name, intro, topic, invitation_code, created_at, updated_at, is_deleted) VALUES (3, 'test room3', 'test room 3입니다', 'egaaegg', 'egageg', '2023-09-19 11:03:45', '2023-09-19 11:03:48', 0);


INSERT INTO togetUp_local.alarm (id, name, icon, snooze_interval, snooze_cnt, alarm_time, monday, tuesday, wednesday, thursday, friday, saturday, sunday, is_snooze_activated, is_vibrate, is_activated, user_id, mission_id, mission_object_id, room_id) VALUES (1, 'room 1알람', '', 5, 3, '11:10:23', 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1);
INSERT INTO togetUp_local.alarm (id, name, icon, snooze_interval, snooze_cnt, alarm_time, monday, tuesday, wednesday, thursday, friday, saturday, sunday, is_snooze_activated, is_vibrate, is_activated, user_id, mission_id, mission_object_id, room_id) VALUES (2, 'room 2알람', '', 5, 3, '12:10:23', 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2);
INSERT INTO togetUp_local.alarm (id, name, icon, snooze_interval, snooze_cnt, alarm_time, monday, tuesday, wednesday, thursday, friday, saturday, sunday, is_snooze_activated, is_vibrate, is_activated, user_id, mission_id, mission_object_id, room_id) VALUES (3, 'room 3알람', '', 5, 3, '10:10:23', 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 3);
INSERT INTO alarm (id, name, icon, snooze_interval, snooze_cnt, alarm_time, monday, tuesday, wednesday, thursday, friday, saturday, sunday, is_snooze_activated, is_vibrate, is_activated, user_id, mission_id, mission_object_id, room_id) VALUES (1, 'room 1알람', '', 5, 3, '11:10:23', 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1);
INSERT INTO alarm (id, name, icon, snooze_interval, snooze_cnt, alarm_time, monday, tuesday, wednesday, thursday, friday, saturday, sunday, is_snooze_activated, is_vibrate, is_activated, user_id, mission_id, mission_object_id, room_id) VALUES (2, 'room 2알람', '', 5, 3, '12:10:23', 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2);
INSERT INTO alarm (id, name, icon, snooze_interval, snooze_cnt, alarm_time, monday, tuesday, wednesday, thursday, friday, saturday, sunday, is_snooze_activated, is_vibrate, is_activated, user_id, mission_id, mission_object_id, room_id) VALUES (3, 'room 3알람', '', 5, 3, '10:10:23', 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 3);


INSERT INTO togetUp_local.room_user (id, created_at, room_id, user_id) VALUES (1, '2023-09-16 11:08:38', 1, 1);
INSERT INTO togetUp_local.room_user (id, created_at, room_id, user_id) VALUES (2, '2023-09-17 11:08:38', 1, 2);
INSERT INTO togetUp_local.room_user (id, created_at, room_id, user_id) VALUES (3, '2023-09-18 11:08:38', 2, 1);
INSERT INTO togetUp_local.room_user (id, created_at, room_id, user_id) VALUES (4, '2023-09-19 11:08:38', 2, 2);
INSERT INTO togetUp_local.room_user (id, created_at, room_id, user_id) VALUES (5, '2023-09-19 11:08:38', 3, 1);
INSERT INTO room_user (id, created_at, room_id, user_id) VALUES (1, '2023-09-16 11:08:38', 1, 1);
INSERT INTO room_user (id, created_at, room_id, user_id) VALUES (2, '2023-09-17 11:08:38', 1, 2);
INSERT INTO room_user (id, created_at, room_id, user_id) VALUES (3, '2023-09-18 11:08:38', 2, 1);
INSERT INTO room_user (id, created_at, room_id, user_id) VALUES (4, '2023-09-19 11:08:38', 2, 2);
INSERT INTO room_user (id, created_at, room_id, user_id) VALUES (5, '2023-09-19 11:08:38', 3, 1);

0 comments on commit 4de908b

Please sign in to comment.