Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#62 [FEAT, FIX] Feature/edit group 그룹 api 수정 및 개발 #72

Merged
merged 8 commits into from
Nov 4, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public interface AlarmRepository extends JpaRepository<Alarm, Integer> {
List<Alarm> findAllByRoomIds(@Param("roomIds") List<Integer> roomIds);


@Query("SELECT a FROM Alarm a WHERE a.room.invitationCode = :invitationCode")
Optional<Alarm> findByInvitationCode(@Param("invitationCode") String invitationCode);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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.RoomDetailRes;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomInfoRes;
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;
Expand Down Expand Up @@ -101,7 +102,7 @@ public BaseResponse changeRoomHost(@Parameter(hidden = true) @AuthUser Integer u

}

@Operation(summary = "그룹 디테일 보기 and 초대 받은 사람에게 보이는 그룹 정보 보기 ",description = "그룹 디테일 보기 (설정 화면) and 초대 받은 사람에게 보이는 앱 내 페이지")
@Operation(summary = "그룹 디테일 보기 ",description = "그룹 디테일 보기 (설정 화면)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: 혹시 코드 컨벤션 적용하셨을까요? 군데군데 적용이 되지 않은 부분이 보이는 것 같습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어떤 코드 컨벤션 말하는 걸까요?
뛰어쓰기 말씀하신건가요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인텔리제이에서 컨트롤 알트 L을 누르면 자동으로 포맷팅 되는 기능이 있습니다! 그걸 적용하셨는지 궁금합니다!
아니면 Save and action에서 저장할 때마다 코드 포맷팅을 하는 기능도 있습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

글 정렬은 따로 pr을 올리는 것이 좋을 것같아서 따로 pr을 올렸다가 이 pr이 머지 된후에 다시 올리려고 close 하였습니다.
다시 알려주셔서 감사합니다😃

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "요청에 성공하였습니다.",
content = @Content(schema = @Schema(implementation = RoomDetailRes.class))),
Expand Down Expand Up @@ -141,6 +142,22 @@ public BaseResponse joinRoom(@Parameter(hidden = true) @AuthUser Integer invite

}

@Operation(summary = "초대 받은 사람에게 보이는 그룹 정보 보기 ",description = "초대 받은 사람에게 보이는 앱 내 페이지")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "요청에 성공하였습니다.",
content = @Content(schema = @Schema(implementation = RoomInfoRes.class))),
@ApiResponse(responseCode = "404" , description = "존재하지 않는 알람 입니다."),
@ApiResponse(responseCode = "404", description = "존재하지 않는 룸입니다.")
})
@GetMapping("/information")
public BaseResponse<RoomInfoRes> getRoomIntro(@RequestParam() String invitationCode) {


return new BaseResponse(Status.SUCCESS,roomService.getRoomInformation(invitationCode));

}




}
68 changes: 53 additions & 15 deletions src/main/java/com/wakeUpTogetUp/togetUp/api/room/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.wakeUpTogetUp.togetUp.api.mission.model.MissionLog;
import com.wakeUpTogetUp.togetUp.api.room.dto.request.RoomReq;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomDetailRes;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomInfoRes;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomRes;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomUserMissionLogRes;
import com.wakeUpTogetUp.togetUp.api.room.model.Room;
Expand All @@ -20,12 +21,15 @@
import com.wakeUpTogetUp.togetUp.exception.BaseException;
import com.wakeUpTogetUp.togetUp.utils.TimeFormatter;
import com.wakeUpTogetUp.togetUp.utils.mapper.EntityDtoMapper;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -86,7 +90,7 @@ public List<RoomRes> getRoomList(Integer userId) {


public RoomUserMissionLogRes getRoomUserLogList(Integer userId, Integer roomId,
String localDateTimeString) {
String localDateTimeString) {

LocalDateTime localDateTime = timeFormatter.stringToLocalDateTime(localDateTimeString);
List<RoomUser> roomUserList = roomUserRepository.findAllByRoom_IdOrderByPreference(roomId,
Expand Down Expand Up @@ -116,7 +120,7 @@ public RoomUserMissionLogRes getRoomUserLogList(Integer userId, Integer roomId,
}

public RoomUserMissionLogRes setUserLogData(RoomUserMissionLogRes roomUserMissionLogRes,
Integer userId, Integer roomId, LocalDateTime localDateTime) {
Integer userId, Integer roomId, LocalDateTime localDateTime) {

boolean isAlarmActive = alarmRepository.findFirstByRoom_Id(roomId)
.getDayOfWeekValue(localDateTime.getDayOfWeek());
Expand Down Expand Up @@ -191,23 +195,25 @@ public RoomUserMissionLogRes setUserLogData(RoomUserMissionLogRes roomUserMissio
public void changeRoomHost(Integer roomId, Integer userId, Integer selectedUserId) {

//host false로 바꾸기
RoomUser roomUser = roomUserRepository.findByRoom_IdAndUser_Id(roomId, userId);
RoomUser roomUser = roomUserRepository.findByRoom_IdAndUser_Id(roomId, userId)
.orElseThrow(() -> new BaseException(Status.ROOM_USER_NOT_FOUND));
if (!roomUser.getIsHost()) {
throw new BaseException(Status.INVALID_ROOM_HOST_ID);
}
roomUser.setIsHost(false);

//선택한 user를 host 지정
RoomUser seletedRoomUser = roomUserRepository.findByRoom_IdAndUser_Id(roomId,
selectedUserId);
RoomUser seletedRoomUser = roomUserRepository.findByRoom_IdAndUser_Id(roomId, selectedUserId)
.orElseThrow(() -> new BaseException(Status.ROOM_USER_NOT_FOUND));
seletedRoomUser.setIsHost(true);

}

@Transactional
public void leaveRoom(Integer roomId, Integer userId) {

RoomUser roomUser = roomUserRepository.findByRoom_IdAndUser_Id(roomId, userId);
RoomUser roomUser = roomUserRepository.findByRoom_IdAndUser_Id(roomId, userId)
.orElseThrow(() -> new BaseException(Status.ROOM_USER_NOT_FOUND));
if (Objects.isNull(roomUser)) {
throw new BaseException(Status.ROOM_USER_NOT_FOUND);
}
Expand Down Expand Up @@ -269,11 +275,10 @@ public RoomDetailRes getRoomDetail(Integer roomId, Integer userId) {
roomDetailRes.setUserList(EntityDtoMapper.INSTANCE.toUserDataList(roomUsers));

//dto 매핑 - 커스텀 필드

//아바타 세팅 (아바타 수정 이후 변경될 예정)
this.setUserTheme(roomDetailRes);
roomDetailRes.getRoomData().setCreatedAt(
timeFormatter.timestampToDotDateFormat(alarm.getRoom().getCreatedAt()));

roomDetailRes.getRoomData().setPersonnel(roomUsers.size());

// ex) 13:00 -> pm 1:00
Expand All @@ -290,11 +295,9 @@ public RoomDetailRes getRoomDetail(Integer roomId, Integer userId) {

public void setUserTheme(RoomDetailRes roomDetailRes) {

//TODO 테이블 바뀌면 수정 해야함
// roomDetailRes.getUserList().forEach(userData -> userData.setTheme(AvatarTheme.valueOf(userAvatarRepository.findByUser_Id(userData.getUserId()).getAvatar().getTheme()).getValue()));
roomDetailRes.getUserList().forEach(userData -> userData.setTheme(
userAvatarRepository.findByUser_IdAndIsActiveIsTrue(userData.getUserId())
.orElseThrow(() -> new BaseException(Status.INTERNAL_SERVER_ERROR))
.orElseThrow(() -> new BaseException(Status.FIND_USER_AVATAR_FAIL))
.getAvatar().getTheme().getValue()));

}
Expand All @@ -303,17 +306,20 @@ public void setUserTheme(RoomDetailRes roomDetailRes) {
@Transactional
public void updateAgreePush(Integer roomId, Integer userId, boolean agreePush) {

RoomUser roomUser = roomUserRepository.findByRoom_IdAndUser_Id(roomId, userId);
if (Objects.isNull(roomUser)) {
throw new BaseException(Status.ROOM_USER_NOT_FOUND);
}
RoomUser roomUser = roomUserRepository.findByRoom_IdAndUser_Id(roomId, userId)
.orElseThrow(() -> new BaseException(Status.ROOM_USER_NOT_FOUND));

roomUser.setAgreePush(agreePush);

}

@Transactional
public void joinRoom(Integer roomId, Integer invitedUserId, boolean isHost) {

if (!isHost && roomUserRepository.existsRoomUserByRoom_IdAndUser_Id(roomId, invitedUserId)) {
throw new BaseException(Status.ROOM_USER_ALREADY_EXIST);
}

User user = userRepository.findById(invitedUserId)
.orElseThrow(() -> new BaseException(Status.USER_NOT_FOUND));

Expand All @@ -332,4 +338,36 @@ public void joinRoom(Integer roomId, Integer invitedUserId, boolean isHost) {
roomUserRepository.save(roomUser);
}

public RoomInfoRes getRoomInformation(String invitationCode) {

Alarm alarm = alarmRepository.findByInvitationCode(invitationCode)
.orElseThrow(() -> new BaseException(Status.ALARM_NOT_FOUND));

Integer roomPersonnel = roomUserRepository.countByRoomId(alarm.getRoom().getId());
if (roomPersonnel < 1)
throw new BaseException(Status.ROOM_NOT_FOUND);

//dto 매핑 mapper 사용
RoomInfoRes roomInfoRes = new RoomInfoRes();
roomInfoRes.setRoomData(EntityDtoMapper.INSTANCE.toRoomInfoResRoomData(alarm));
roomInfoRes.setAlarmData(EntityDtoMapper.INSTANCE.toRoomInfoResAlarmData(alarm));

//dto 매핑 - 커스텀 필드
roomInfoRes.getRoomData().setCreatedAt(
timeFormatter.timestampToDotDateFormat(alarm.getRoom().getCreatedAt()));
roomInfoRes.getRoomData().setPersonnel(roomPersonnel);

// ex) 13:00 -> pm 1:00
roomInfoRes.getAlarmData()
.setAlarmTime(timeFormatter.timeStringToAMPMFormat(alarm.getAlarmTime()));

// ex) 평일, 주말, 매일, 월요일, (월, 화, 수), 빈칸
roomInfoRes.getAlarmData().setAlarmDay(
timeFormatter.formatDaysOfWeek(alarm.getMonday(), alarm.getTuesday(),
alarm.getWednesday(), alarm.getThursday(), alarm.getFriday(),
alarm.getSaturday(), alarm.getSunday()));

return roomInfoRes;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface RoomUserRepository extends JpaRepository<RoomUser, Integer> {
Expand All @@ -32,9 +33,13 @@ public interface RoomUserRepository extends JpaRepository<RoomUser, Integer> {
List<Integer> findAllRoomIdsByUserId(@Param("userId") Integer userId);

Integer countByUserId(Integer userId);

Integer countByRoomId(Integer roomId);
void deleteByUserId(Integer userId);

RoomUser findByRoom_IdAndUser_Id(Integer roomId , Integer userId);
Optional<RoomUser> findByRoom_IdAndUser_Id(Integer roomId , Integer userId);

Boolean existsRoomUserByRoom_IdAndUser_Id(Integer roomId , Integer userId);

void deleteByRoom_IdAndUser_Id(Integer roomId, Integer userId);
List<RoomUser> findAllByRoom_IdOrderByCreatedAt(Integer roomId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public static class RoomData {
@Schema(description = "함께하는 인원수",example = "6")
private Integer personnel;

@Schema(description = "룸 초대코드" ,example = "4c905")
private String invitationCode;


}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.wakeUpTogetUp.togetUp.api.room.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;


@Schema(description = "룸정보 조회 요청 api 응답")
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class RoomInfoRes {

@Schema(description = "룸 정보")
private RoomData roomData;

@Schema(description = "알람 정보")
private AlarmData alarmData;

@Builder
@Data
public static class RoomData {

@Schema(description = "룸아이디" ,example = "1")
private Integer id;

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

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

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

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

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



}

@Builder
@Data
public static class AlarmData {

@Schema(description = "미션의 한국말",example = "자동차")
private String missionKr;

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

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


}


}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class Room {
/**
* todo uuid
*/
@Column(name = "invitation_code",length = 50)
@Column(name = "invitation_code",length = 10)
private String invitationCode;

// @JsonIgnore
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/wakeUpTogetUp/togetUp/common/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public enum Status {

// NOT FOUND
USER_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 유저 입니다."),
ROOM_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 room 입니다."),
ROOM_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 입니다."),
ALARM_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 알람 입니다."),
MISSION_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 미션 입니다."),
AVATAR_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 아바타 입니다."),
Expand All @@ -60,6 +60,7 @@ public enum Status {

// CONFLICT
USER_AVATAR_ALREADY_EXIST(HttpStatus.CONFLICT, "이미 보유한 아바타 입니다."),
ROOM_USER_ALREADY_EXIST(HttpStatus.CONFLICT, "이미 방에 들어간 멤버입니다."),

// UNSUPPORTED MEDIA TYPE
UNSUPPORTED_MEDIA_TYPE(HttpStatus.UNSUPPORTED_MEDIA_TYPE, "지원하지 않는 파일 확장자 입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.wakeUpTogetUp.togetUp.api.mission.model.Mission;
import com.wakeUpTogetUp.togetUp.api.mission.model.MissionLog;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomDetailRes;
import com.wakeUpTogetUp.togetUp.api.room.dto.response.RoomInfoRes;
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;
Expand Down Expand Up @@ -88,6 +89,7 @@ public interface EntityDtoMapper {
@Mapping(target = "icon", source = "icon")
@Mapping(target = "name", source = "room.name")
@Mapping(target = "intro", source = "room.intro")
@Mapping(target = "invitationCode", source = "room.invitationCode")
RoomDetailRes.RoomData toRoomDetailResRoomData(Alarm alarm);

@Mapping(target = "id", source = "id")
Expand All @@ -102,6 +104,17 @@ public interface EntityDtoMapper {

List<RoomDetailRes.UserData> toUserDataList(List<RoomUser> roomUser);


@Mapping(target = "id", source = "room.id")
@Mapping(target = "icon", source = "icon")
@Mapping(target = "name", source = "room.name")
@Mapping(target = "intro", source = "room.intro")
RoomInfoRes.RoomData toRoomInfoResRoomData(Alarm alarm);


@Mapping(target = "missionKr", source = "missionObject.kr")
RoomInfoRes.AlarmData toRoomInfoResAlarmData(Alarm alarm);

// Avatar
@Mapping(source = "avatar.id", target = "avatarId")
@Mapping(source = "avatar.theme.value", target = "theme")
Expand All @@ -116,4 +129,5 @@ default void setIsUnlockedStatus(@MappingTarget UserAvatarData target, Avatar av
target.setIsUnlocked(userAvatarList.stream()
.anyMatch(userAvatar -> userAvatar.getAvatar().getId().equals(avatar.getId())));
}

}
6 changes: 3 additions & 3 deletions src/main/resources/migration/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ INSERT INTO mission_object (id, name, kr, icon, is_active, mission_id) VALUES (7


-- 아바타 (임시)
INSERT INTO togetup_local_cm.avatar (id, theme, price, unlock_level, created_at) VALUES (1, 'NOOB_CHICK', 0, 1, '2023-10-07 20:35:51');
INSERT INTO togetup_local_cm.avatar (id, theme, price, unlock_level, created_at) VALUES (2, 'TWINKLING_TEDDY_BEAR', 1500, 15, '2023-10-21 03:24:06');
INSERT INTO togetup_local_cm.avatar (id, theme, price, unlock_level, created_at) VALUES (3, 'CUTE_BUNNY', 1500, 30, '2023-10-21 03:24:06');
INSERT INTO avatar (id, theme, price, unlock_level, created_at) VALUES (1, 'NOOB_CHICK', 0, 1, '2023-10-07 20:35:51');
INSERT INTO avatar (id, theme, price, unlock_level, created_at) VALUES (2, 'TWINKLING_TEDDY_BEAR', 1500, 15, '2023-10-21 03:24:06');
INSERT INTO avatar (id, theme, price, unlock_level, created_at) VALUES (3, 'CUTE_BUNNY', 1500, 30, '2023-10-21 03:24:06');
2 changes: 1 addition & 1 deletion src/main/resources/migration/togetup-erd.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ create table room
name varchar(10) not null,
intro varchar(30) null,
topic varchar(100) null,
invitation_code varchar(100) null,
invitation_code varchar(10) null,
created_at timestamp default CURRENT_TIMESTAMP not null,
updated_at timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP,
latest_completion_time timestamp null,
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/migration/updates/202031102[room].sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--table : invitation_code 길이 10으로 수정
alter table room
add invitation_code varchar(10) null;