Skip to content

Commit

Permalink
#62 [MERGE] : 그룹게시판 api 수정 (#67)
Browse files Browse the repository at this point in the history
## 작업
- RoomDetailRes에 level,theme 추가
- 나- 방장 - 방 구성원 순으로 정렬해서 반환하게 수정
  • Loading branch information
05AM authored Oct 20, 2023
2 parents 9c357a2 + 90d92f3 commit f43b5c1
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ public BaseResponse changeRoomHost(@Parameter(hidden = true) @AuthUser Integer u
content = @Content(schema = @Schema(implementation = RoomDetailRes.class))),
@ApiResponse(responseCode = "404",description = "존재하지 않는 알람입니다.")})
@GetMapping("/{roomId}")
public BaseResponse<RoomDetailRes> getRoomDetail(@PathVariable Integer roomId) {
public BaseResponse<RoomDetailRes> getRoomDetail(@Parameter(hidden = true) @AuthUser Integer userId,@PathVariable Integer roomId) {


return new BaseResponse(Status.SUCCESS,roomService.getRoomDetail(roomId));
return new BaseResponse(Status.SUCCESS,roomService.getRoomDetail(roomId , userId));

}

Expand Down
17 changes: 13 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 @@ -90,7 +90,7 @@ public List<RoomRes> getRoomList(Integer userId) {
public RoomUserMissionLogRes getRoomUserLogList(Integer userId,Integer roomId,String localDateTimeString ){

LocalDateTime localDateTime = timeFormatter.stringToLocalDateTime(localDateTimeString);
List<RoomUser> roomUserList = roomUserRepository.findAllByRoom_Id(roomId);
List<RoomUser> roomUserList = roomUserRepository.findAllByRoom_IdOrderByPreference(roomId , userId);
//크기가 0이면 예외처리
if(roomUserList.isEmpty())
throw new BaseException(Status.ROOM_USER_NOT_FOUND);
Expand Down Expand Up @@ -243,14 +243,13 @@ public void deleteUnnecessaryRoomAndAlarm(Integer roomId){
}


public RoomDetailRes getRoomDetail(Integer roomId){
public RoomDetailRes getRoomDetail(Integer roomId , Integer userId){
//알람 조회
Alarm alarm = alarmRepository.findFirstByRoom_Id(roomId);
if(Objects.isNull(alarm)) throw new BaseException(Status.ALARM_NOT_FOUND);

//room_user 조회
List<RoomUser> roomUsers = roomUserRepository.findAllByRoom_Id(roomId);

List<RoomUser> roomUsers = roomUserRepository.findAllByRoom_IdOrderByPreference(roomId , userId);

//dto 매핑 mapper 사용
RoomDetailRes roomDetailRes =new RoomDetailRes();
Expand All @@ -259,6 +258,9 @@ public RoomDetailRes getRoomDetail(Integer roomId){
roomDetailRes.setUserList(EntityDtoMapper.INSTANCE.toUserDataList(roomUsers));

//dto 매핑 - 커스텀 필드

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

Expand All @@ -270,6 +272,13 @@ public RoomDetailRes getRoomDetail(Integer roomId){
return roomDetailRes;
}

public void setUserTheme(RoomDetailRes roomDetailRes){

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

}


@Transactional
public void updateAgreePush(Integer roomId,Integer userId, boolean agreePush){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@
public interface RoomUserRepository extends JpaRepository<RoomUser, Integer> {

List<RoomUser> findByUserId(Integer userId);
List<RoomUser> findAllByRoom_Id(Integer roomId);

@Query("SELECT ru FROM RoomUser ru " +
"JOIN User u ON (ru.user.id = u.id) " +
"WHERE ru.room.id = :roomId " +
"ORDER BY " +
"CASE WHEN ru.user.id = :userId THEN 0 " +
"WHEN ru.isHost = true THEN 1 " +
"ELSE 2 " +
"END, u.name")
List<RoomUser> findAllByRoom_IdOrderByPreference(Integer roomId ,Integer userId);


@Query("SELECT ru.room.id " +
"FROM RoomUser ru " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public static class UserData {
@Schema(description = "유저 이름", example = "조혜온")
private String userName;

@Schema(description = "- 신입 병아리 \n - 눈을 반짝이는 곰돌이 \n - 깜찍한 토끼" ,example = "신입 병아리")
private String theme;

@Schema(description = "유저의 레벨" , example = "1")
private Integer level;

@Schema(description = "방장인지 여부", example = "true")
private Boolean isHost;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wakeUpTogetUp.togetUp.api.room.model;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.wakeUpTogetUp.togetUp.common.Constant;
import lombok.*;
import org.hibernate.annotations.DynamicInsert;
Expand All @@ -14,7 +15,7 @@
import java.util.List;
import java.util.UUID;

@ToString

@Entity
@SQLDelete(sql = "UPDATE room SET is_deleted = true WHERE id = ?")
@Where(clause = "is_deleted = false")
Expand Down Expand Up @@ -45,7 +46,7 @@ public class Room {
@Column(name = "invitation_code",length = 50)
private String invitationCode;


// @JsonIgnore
@OneToMany(mappedBy = "room")
private List<RoomUser> roomUsers= new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import java.time.Instant;
@Entity
@Table(name = "room_user")
@Getter
@Setter
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor(force = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ public interface EntityDtoMapper {
@Mapping(target = "userId",source = "user.id")
@Mapping(target = "userName",source = "user.name")
@Mapping(target = "isHost",source = "isHost")
@Mapping(target = "level" , source = "user.level")
RoomDetailRes.UserData toRoomDetailUserData(RoomUser roomUser);

@Mapping(target = "userId",source = "user.id")
@Mapping(target = "userName",source = "user.name")
@Mapping(target = "isHost",source = "isHost")
@Mapping(target = "level" , source = "user.level")
List<RoomDetailRes.UserData> toUserDataList(List<RoomUser> roomUser);


Expand Down

0 comments on commit f43b5c1

Please sign in to comment.