Skip to content

Commit

Permalink
Merge pull request #87 from Team-Shaka/feature/86
Browse files Browse the repository at this point in the history
✨ Feat: 내가 가입한 트리하우스 목록 조회
  • Loading branch information
koojun99 authored Jul 28, 2024
2 parents 617bb61 + 2fb85b1 commit 55035f6
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import treehouse.server.api.treehouse.presentation.dto.TreehouseResponseDTO;
import treehouse.server.global.entity.treeHouse.TreeHouse;

import java.util.List;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class TreehouseMapper {

Expand All @@ -26,7 +28,13 @@ public static TreehouseResponseDTO.getTreehouseDetails toGetTreehouseDetails(Tre
.treehouseId(treehouse.getId())
.treehouseName(treehouse.getName())
.treehouseSize(treehouse.getMemberList().size())
.treehouseImageUrl(null) //TODO: 이미지 URL 설정
.treehouseImageUrl(treehouse.getTreehouseImageUrl())
.build();
}

public static TreehouseResponseDTO.getTreehouses toGetTreehouses(List<TreehouseResponseDTO.getTreehouseDetails> treehouseDtos) {
return TreehouseResponseDTO.getTreehouses.builder()
.treehouses(treehouseDtos)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import treehouse.server.api.treehouse.implementation.TreehouseQueryAdapter;
import treehouse.server.api.treehouse.presentation.dto.TreehouseRequestDTO;
import treehouse.server.api.treehouse.presentation.dto.TreehouseResponseDTO;
import treehouse.server.global.entity.User.User;
import treehouse.server.global.entity.member.Member;
import treehouse.server.global.entity.treeHouse.TreeHouse;

import java.util.List;

@Service
@RequiredArgsConstructor
@Slf4j
Expand All @@ -35,5 +39,15 @@ public TreehouseResponseDTO.getTreehouseDetails getTreehouseDetails(Long treehou
return TreehouseMapper.toGetTreehouseDetails(treehouse);
}

public TreehouseResponseDTO.getTreehouses getTreehouses(User user) {
List<Member> memberList = user.getMemberList();

List<TreehouseResponseDTO.getTreehouseDetails> treehouseDtos = memberList.stream()
.map(Member::getTreeHouse)
.map(TreehouseMapper::toGetTreehouseDetails)
.toList();

return TreehouseMapper.toGetTreehouses(treehouseDtos);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package treehouse.server.api.treehouse.presentation;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -10,6 +11,8 @@
import treehouse.server.api.treehouse.presentation.dto.TreehouseRequestDTO;
import treehouse.server.api.treehouse.presentation.dto.TreehouseResponseDTO;
import treehouse.server.global.common.CommonResponse;
import treehouse.server.global.entity.User.User;
import treehouse.server.global.security.handler.annotation.AuthMember;

@RestController
@RequiredArgsConstructor
Expand All @@ -36,4 +39,12 @@ public CommonResponse<TreehouseResponseDTO.getTreehouseDetails> getTreehouseDeta
) {
return CommonResponse.onSuccess(treehouseService.getTreehouseDetails(treehouseId));
}

@GetMapping
@Operation(summary = "내 트리하우스 조회 🔑", description = "내가 가입한 트리하우스 목록을 조회합니다.")
public CommonResponse<TreehouseResponseDTO.getTreehouses> getTreehouses(
@AuthMember @Parameter(hidden = true) User user
) {
return CommonResponse.onSuccess(treehouseService.getTreehouses(user));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import lombok.*;

import java.util.List;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class TreehouseResponseDTO {

Expand All @@ -25,4 +27,12 @@ public static class getTreehouseDetails {
private Integer treehouseSize;
private String treehouseImageUrl;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class getTreehouses {
List<getTreehouseDetails> treehouses;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public static UserResponseDTO.checkUserStatus toCheckUserStatus(Boolean isNewUse
public static UserResponseDTO.loginMember toLogin(User user, String accessToken, String refreshToken, List<Long> treehouseIdList){
return UserResponseDTO.loginMember.builder()
.userId(user.getId())
.userName(user.getName())
.profileImageUrl(user.getProfileImageUrl())
.accessToken(accessToken)
.refreshToken(refreshToken)
.treehouseIdList(treehouseIdList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public static class checkUserStatus{
public static class loginMember {

private Long userId;
private String userName;
private String profileImageUrl;
private String accessToken;
private String refreshToken;
private List<Long> treehouseIdList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class TreeHouse extends BaseDateTimeEntity {

private String name;

private String treehouseImageUrl;

@OneToMany(mappedBy = "treeHouse")
private List<Member> memberList;

Expand Down

0 comments on commit 55035f6

Please sign in to comment.