Skip to content

Commit

Permalink
feat: 퍼블릭 스페이스 정보 조회하기
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondanythings committed Aug 24, 2024
1 parent 160c32b commit 69988ba
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void setHttp(HttpSecurity http) throws Exception {
.requestMatchers(new AntPathRequestMatcher("/api/auth/sign-up")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/auth/oauth2/google")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/auth/oauth2/kakao")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/test")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/space/public/*")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/api/auth/test")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/h2-console/**")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/external/image/presigned")).permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ public interface SpaceApi {
})
ResponseEntity<SpaceResponse.SpaceWithMemberCountInfo> getSpaceById(@MemberId Long memberId, @PathVariable Long spaceId);

@Operation(summary = "PUBLIC/ 스페이스 단건 조회하기", method = "GET", description = """
스페이스 아이디를 통해 하나의 스페이스를 조회합니다.
내가 속하지 않은 공간만 조회할 수 있습니다.
""")
@ApiResponses({
@ApiResponse(responseCode = "200", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = SpaceResponse.SpaceWithMemberCountInfo.class))
})
})
ResponseEntity<SpaceResponse.SpaceWithMemberCountInfo> getPublicSpaceById(@PathVariable Long spaceId);


@Operation(summary = "스페이스 입장하기", method = "POST", description = """
공유받은 링크를 통해 스페이스에 입장합니다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ public ResponseEntity<SpaceResponse.SpaceWithMemberCountInfo> getSpaceById(@Memb
return ResponseEntity.ok((foundSpace));
}


@GetMapping("/public/{spaceId}")
public ResponseEntity<SpaceResponse.SpaceWithMemberCountInfo> getPublicSpaceById(@PathVariable Long spaceId) {
var foundSpace = spaceService.getPublicSpaceById(spaceId);
return ResponseEntity.ok((foundSpace));
}

@Override
@PostMapping("/join")
@ResponseStatus(HttpStatus.ACCEPTED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public SpaceResponse.SpaceWithMemberCountInfo getSpaceById(Long memberId, Long s
return SpaceResponse.SpaceWithMemberCountInfo.toResponse(foundSpace);
}

public SpaceResponse.SpaceWithMemberCountInfo getPublicSpaceById(Long spaceId) {
var foundSpace = spaceRepository.findByIdAndJoinedMemberId(spaceId).orElseThrow(() -> new SpaceException(NOT_FOUND_SPACE));

return SpaceResponse.SpaceWithMemberCountInfo.toResponse(foundSpace);
}

@Transactional
public void createMemberSpace(Long memberId, Long spaceId) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public interface SpaceCustomRepository {

Optional<SpaceWithMemberCount> findByIdAndJoinedMemberId(Long spaceId, Long memberId);

Optional<SpaceWithMemberCount> findByIdAndJoinedMemberId(Long spaceId);

Long updateSpace(Long spaceId, SpaceCategory category, List<SpaceField> fieldList, String name, String introduction, String bannerUrl);

List<SpaceMember> findAllSpaceMemberBySpaceIdWithIsLeader(Long spaceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ public Optional<SpaceWithMemberCount> findByIdAndJoinedMemberId(Long spaceId, Lo
return Optional.of(foundSpace);
}

@Override
public Optional<SpaceWithMemberCount> findByIdAndJoinedMemberId(Long spaceId) {

var foundSpace = getSpaceWithMemberCountQuery().where(space.id.eq(spaceId)).fetchOne();


if (foundSpace == null || isSpaceWithMemberCountEmpty(foundSpace)) {
return Optional.empty();
}
// TODO: 커스텀 에러로 변경
return Optional.of(foundSpace);
}

@Override
public Long updateSpace(Long spaceId, SpaceCategory category, List<SpaceField> fieldList, String name, String introduction, String bannerUrl) {
var query = queryFactory.update(space);
Expand Down Expand Up @@ -116,8 +129,8 @@ private JPAQuery<SpaceWithMemberCount> getSpaceWithMemberCountQuery() {
.leftJoin(memberCountRelationTable).on(space.id.eq(memberCountRelationTable.space.id))
.leftJoin(member).on(space.leaderId.eq(member.id))
.leftJoin(form).on(space.formId.eq(form.id))
.orderBy(form.id.desc())
.limit(1);
.orderBy(form.id.desc())
.limit(1);

}

Expand Down

0 comments on commit 69988ba

Please sign in to comment.