Skip to content

Commit

Permalink
Merge pull request #396 from tukcomCD2024/ARCH-87-B-feat/group_list
Browse files Browse the repository at this point in the history
feat : 그룹 목록, 상세 조회 추가 #360
  • Loading branch information
GaBaljaintheroom authored May 6, 2024
2 parents 385fa33 + d8cf5bd commit 34dab2c
Show file tree
Hide file tree
Showing 27 changed files with 703 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public record CapsuleDetailResponse(
dueDate = dueDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}

createdDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
if (createdDate != null) {
createdDate = createdDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}
}

public static CapsuleDetailResponse createOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public record CapsuleSummaryResponse(
dueDate = dueDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}

createdAt = createdAt.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
if (createdAt != null) {
createdAt = createdAt.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}
}

public static CapsuleSummaryResponse createOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public record NearbyARCapsuleSummaryResponse(
@Schema(description = "캡슐 타입")
CapsuleType capsuleType
) {

public NearbyARCapsuleSummaryResponse {
if (dueDate != null) {
dueDate = dueDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ public PublicCapsuleDetailResponse toResponse(
final List<String> preSignedImageUrls = multiplePreSignUrlFunction.apply(images);
final List<String> preSignedVideoUrls = multiplePreSignUrlFunction.apply(videos);

return new PublicCapsuleDetailResponse(
capsuleId,
singlePreSignUrlFunction.apply(capsuleSkinUrl),
dueDate,
nickname,
profileUrl,
createdAt,
changePoint.getX(),
changePoint.getY(),
address,
roadName,
title,
content,
preSignedImageUrls,
preSignedVideoUrls,
isOpened,
capsuleType
);
return PublicCapsuleDetailResponse.builder()
.capsuleId(capsuleId)
.capsuleSkinUrl(singlePreSignUrlFunction.apply(capsuleSkinUrl))
.dueDate(dueDate)
.nickname(nickname)
.profileUrl(profileUrl)
.createdDate(createdAt)
.latitude(changePoint.getX())
.longitude(changePoint.getY())
.address(address)
.roadName(roadName)
.title(title)
.content(content)
.imageUrls(preSignedImageUrls)
.videoUrls(preSignedVideoUrls)
.isOpened(isOpened)
.capsuleType(capsuleType)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.function.Function;
import lombok.Builder;
import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType;
import site.timecapsulearchive.core.domain.capsule.public_capsule.data.dto.PublicCapsuleDetailDto;
import site.timecapsulearchive.core.global.common.response.ResponseMappingConstant;

@Schema(description = "공개 캡슐 상세 정보")
Expand Down Expand Up @@ -67,36 +65,8 @@ public record PublicCapsuleDetailResponse(
dueDate = dueDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}

createdDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}

public static PublicCapsuleDetailResponse createOf(
final PublicCapsuleDetailDto detailDto,
final Function<String, String> singlePreSignUrlFunction,
final Function<String, List<String>> multiplePreSignUrlFunction
) {
final List<String> preSignedImageUrls = multiplePreSignUrlFunction.apply(
detailDto.images());
final List<String> preSignedVideoUrls = multiplePreSignUrlFunction.apply(
detailDto.videos());

return new PublicCapsuleDetailResponse(
detailDto.capsuleId(),
singlePreSignUrlFunction.apply(detailDto.capsuleSkinUrl()),
detailDto.dueDate(),
detailDto.nickname(),
detailDto.profileUrl(),
detailDto.createdAt(),
detailDto.point().getX(),
detailDto.point().getY(),
detailDto.address(),
detailDto.roadName(),
detailDto.title(),
detailDto.content(),
preSignedImageUrls,
preSignedVideoUrls,
detailDto.isOpened(),
detailDto.capsuleType()
);
if (createdDate != null) {
createdDate = createdDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ public record MySecreteCapsuleDto(
CapsuleType type
) {

public MySecreteCapsuleDto {
if (dueDate != null) {
dueDate = dueDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}

createdAt = createdAt.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}

public MySecreteCapsuleResponse toResponse(
final Function<String, String> preSignUrlFunction
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.time.ZonedDateTime;
import lombok.Builder;
import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType;
import site.timecapsulearchive.core.global.common.response.ResponseMappingConstant;

@Builder
@Schema(description = "내 비밀 캡슐 응답")
Expand All @@ -30,4 +31,13 @@ public record MySecreteCapsuleResponse(
CapsuleType type
) {

public MySecreteCapsuleResponse {
if (dueDate != null) {
dueDate = dueDate.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}

if (createdAt != null) {
createdAt = createdAt.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import java.time.ZonedDateTime;
import lombok.Builder;
import site.timecapsulearchive.core.global.common.response.ResponseMappingConstant;

@Schema(description = "캡슐 스킨 요약 정보")
@Builder
Expand All @@ -20,4 +21,9 @@ public record CapsuleSkinSummaryResponse(
ZonedDateTime createdAt
) {

public CapsuleSkinSummaryResponse {
if (createdAt != null) {
createdAt = createdAt.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public record FriendSummaryResponse(

public FriendSummaryResponse {
if (createdAt != null) {
createdAt.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
createdAt = createdAt.withZoneSameInstant(ResponseMappingConstant.ZONE_ID);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.time.ZonedDateTime;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import site.timecapsulearchive.core.domain.group.data.reqeust.GroupCreateRequest;
import site.timecapsulearchive.core.domain.group.data.reqeust.GroupUpdateRequest;
import site.timecapsulearchive.core.domain.group.data.response.GroupDetailResponse;
import site.timecapsulearchive.core.domain.group.data.response.GroupsPageResponse;
import site.timecapsulearchive.core.domain.group.data.response.GroupsSliceResponse;
import site.timecapsulearchive.core.global.common.response.ApiSpec;

public interface GroupApi {
Expand Down Expand Up @@ -133,15 +130,21 @@ ResponseEntity<Void> denyGroupInvitation(
@ApiResponse(
responseCode = "200",
description = "ok"
),
@ApiResponse(
responseCode = "400",
description = "잘못된 파라미터를 받았을 때 발생하는 오류"
),
@ApiResponse(
responseCode = "403",
description = "그룹에 포함된 사용자가 아닌 경우 발생하는 오류"
)
})
@GetMapping(
value = "/groups/{group_id}",
produces = {"application/json"}
)
ResponseEntity<GroupDetailResponse> findGroupById(
ResponseEntity<ApiSpec<GroupDetailResponse>> findGroupDetailById(
Long memberId,

@Parameter(in = ParameterIn.PATH, description = "조회할 그룹 아이디", required = true, schema = @Schema())
@PathVariable("group_id") Long groupId
Long groupId
);

@Operation(
Expand All @@ -156,16 +159,14 @@ ResponseEntity<GroupDetailResponse> findGroupById(
description = "ok"
)
})
@GetMapping(
value = "/groups",
produces = {"application/json"}
)
ResponseEntity<GroupsPageResponse> findGroups(
@Parameter(in = ParameterIn.QUERY, description = "페이지 크기", required = true, schema = @Schema())
@NotNull @Valid @RequestParam(value = "size") Long size,
ResponseEntity<ApiSpec<GroupsSliceResponse>> findGroups(
Long memberId,

@Parameter(in = ParameterIn.QUERY, description = "페이지 크기", required = true)
int size,

@Parameter(in = ParameterIn.QUERY, description = "마지막 그룹 아이디", required = true, schema = @Schema())
@NotNull @Valid @RequestParam(value = "group_id") Long groupId
@Parameter(in = ParameterIn.QUERY, description = "마지막 데이터의 시간", required = true)
ZonedDateTime createdAt
);

@Operation(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package site.timecapsulearchive.core.domain.group.api;

import jakarta.validation.Valid;
import java.time.ZonedDateTime;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Slice;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import site.timecapsulearchive.core.domain.group.data.dto.GroupCreateDto;
import site.timecapsulearchive.core.domain.group.data.dto.GroupDetailDto;
import site.timecapsulearchive.core.domain.group.data.dto.GroupSummaryDto;
import site.timecapsulearchive.core.domain.group.data.reqeust.GroupCreateRequest;
import site.timecapsulearchive.core.domain.group.data.reqeust.GroupUpdateRequest;
import site.timecapsulearchive.core.domain.group.data.response.GroupDetailResponse;
import site.timecapsulearchive.core.domain.group.data.response.GroupsPageResponse;
import site.timecapsulearchive.core.domain.group.data.response.GroupsSliceResponse;
import site.timecapsulearchive.core.domain.group.service.GroupService;
import site.timecapsulearchive.core.global.common.response.ApiSpec;
import site.timecapsulearchive.core.global.common.response.SuccessCode;
import site.timecapsulearchive.core.infra.s3.manager.S3PreSignedUrlManager;
import site.timecapsulearchive.core.infra.s3.manager.S3UrlGenerator;


Expand All @@ -26,6 +34,7 @@ public class GroupApiController implements GroupApi {

private final GroupService groupService;
private final S3UrlGenerator s3UrlGenerator;
private final S3PreSignedUrlManager s3PreSignedUrlManager;

@Override
public ResponseEntity<Void> acceptGroupInvitation(Long groupId, Long memberId) {
Expand Down Expand Up @@ -66,14 +75,47 @@ public ResponseEntity<Void> denyGroupInvitation(Long groupId, Long memberId) {
return null;
}

@GetMapping(
value = "/{group_id}",
produces = {"application/json"}
)
@Override
public ResponseEntity<GroupDetailResponse> findGroupById(Long groupId) {
return null;
public ResponseEntity<ApiSpec<GroupDetailResponse>> findGroupDetailById(
@AuthenticationPrincipal final Long memberId,
@PathVariable("group_id") final Long groupId
) {
final GroupDetailDto groupDetailDto = groupService.findGroupDetailByGroupId(memberId, groupId);

return ResponseEntity.ok(
ApiSpec.success(
SuccessCode.SUCCESS,
groupDetailDto.toResponse(s3PreSignedUrlManager::getS3PreSignedUrlForGet)
)
);
}

@GetMapping(
produces = {"application/json"}
)
@Override
public ResponseEntity<GroupsPageResponse> findGroups(Long size, Long groupId) {
return null;
public ResponseEntity<ApiSpec<GroupsSliceResponse>> findGroups(
@AuthenticationPrincipal final Long memberId,
@RequestParam(defaultValue = "20", value = "size") final int size,
@RequestParam(value = "created_at") final ZonedDateTime createdAt
) {
final Slice<GroupSummaryDto> groupsSlice = groupService.findGroupsSlice(memberId, size,
createdAt);

return ResponseEntity.ok(
ApiSpec.success(
SuccessCode.SUCCESS,
GroupsSliceResponse.createOf(
groupsSlice.getContent(),
groupsSlice.hasNext(),
s3PreSignedUrlManager::getS3PreSignedUrlForGet
)
)
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package site.timecapsulearchive.core.domain.group.data.dto;

import java.time.ZonedDateTime;
import java.util.List;
import java.util.function.Function;
import site.timecapsulearchive.core.domain.group.data.response.GroupDetailResponse;
import site.timecapsulearchive.core.domain.group.data.response.GroupMemberResponse;
import site.timecapsulearchive.core.domain.group.data.response.GroupMemberSummaryResponse;

public record GroupDetailDto(
String groupName,
String groupDescription,
String groupProfileUrl,
ZonedDateTime createdAt,
List<GroupMemberDto> members
) {

public GroupDetailResponse toResponse(Function<String, String> singlePreSignUrlFunction) {
List<GroupMemberResponse> members = this.members.stream()
.map(GroupMemberDto::toResponse)
.toList();

return GroupDetailResponse.builder()
.groupName(groupName)
.groupDescription(groupDescription)
.groupProfileUrl(singlePreSignUrlFunction.apply(groupProfileUrl))
.createdAt(createdAt)
.members(members)
.build();
}
}
Loading

0 comments on commit 34dab2c

Please sign in to comment.