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

feat : 보물 캡슐 찾기 기능 추가 #487

Merged
merged 12 commits into from
Jun 11, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -64,13 +63,13 @@ public class Capsule extends BaseEntity {
private Address address;

@OneToMany(mappedBy = "capsule", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Image> images = new ArrayList<>();
private final List<Image> images = new ArrayList<>();

@OneToMany(mappedBy = "capsule", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Video> videos = new ArrayList<>();
private final List<Video> videos = new ArrayList<>();

@OneToMany(mappedBy = "capsule", cascade = CascadeType.ALL, orphanRemoval = true)
private List<GroupCapsuleOpen> groupCapsuleOpens = new ArrayList<>();
private final List<GroupCapsuleOpen> groupCapsuleOpens = new ArrayList<>();

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "group_id")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.capsule;

import java.util.List;
import org.locationtech.jts.geom.Polygon;
import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.NearbyARCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.NearbyCapsuleSummaryDto;

public interface CapsuleQueryRepository {

List<NearbyARCapsuleSummaryDto> findARCapsuleSummaryDtosByCurrentLocationAndCapsuleType(
final Long memberId,
final Polygon mbr,
final CapsuleType capsuleType
);

List<NearbyCapsuleSummaryDto> findCapsuleSummaryDtosByCurrentLocationAndCapsuleType(
final Long memberId,
final Polygon mbr,
final CapsuleType capsuleType
);

List<NearbyCapsuleSummaryDto> findFriendsCapsuleSummaryDtosByCurrentLocationAndCapsuleType(
final List<Long> friendIds,
final Polygon mbr
);

List<NearbyARCapsuleSummaryDto> findFriendsARCapsulesByCurrentLocation(
final List<Long> friendIds,
final Polygon mbr
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.timecapsulearchive.core.domain.capsule.generic_capsule.repository;
package site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.capsule;

import static site.timecapsulearchive.core.domain.capsule.entity.QCapsule.capsule;
import static site.timecapsulearchive.core.domain.capsuleskin.entity.QCapsuleSkin.capsuleSkin;
Expand All @@ -20,7 +20,7 @@

@Repository
@RequiredArgsConstructor
public class CapsuleQueryRepository {
public class CapsuleQueryRepositoryImpl implements CapsuleQueryRepository {

private final JPAQueryFactory jpaQueryFactory;

Expand Down Expand Up @@ -104,8 +104,8 @@ public List<NearbyCapsuleSummaryDto> findCapsuleSummaryDtosByCurrentLocationAndC
* @return 범위 내에 조회된 캡슐들의 요약 정보들을 반환한다.
*/
public List<NearbyCapsuleSummaryDto> findFriendsCapsuleSummaryDtosByCurrentLocationAndCapsuleType(
List<Long> friendIds,
Polygon mbr
final List<Long> friendIds,
final Polygon mbr
) {
return jpaQueryFactory
.select(
Expand Down Expand Up @@ -136,8 +136,8 @@ private BooleanExpression ST_Contains(Polygon mbr, ComparablePath<Point> point)
* @return 범위 내에 조회된 캡슐들의 요약 정보들을 반환한다.
*/
public List<NearbyARCapsuleSummaryDto> findFriendsARCapsulesByCurrentLocation(
List<Long> friendIds,
Polygon mbr
final List<Long> friendIds,
final Polygon mbr
) {
return jpaQueryFactory
.select(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.timecapsulearchive.core.domain.capsule.generic_capsule.repository;
package site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.capsule;

import java.util.Optional;
import org.springframework.data.jpa.repository.Modifying;
Expand All @@ -7,16 +7,23 @@
import org.springframework.data.repository.query.Param;
import site.timecapsulearchive.core.domain.capsule.entity.Capsule;

public interface CapsuleRepository extends Repository<Capsule, Long> {
public interface CapsuleRepository extends Repository<Capsule, Long>, CapsuleQueryRepository {

Capsule save(Capsule capsule);

void delete(Capsule capsule);

@Query("select c from Capsule c where c.id = :capsuleId and c.member.id = :memberId")
Optional<Capsule> findCapsuleByMemberIdAndCapsuleId(
@Param("memberId") Long memberId,
@Param("capsuleId") Long capsuleId
);

@Query("select c from Capsule c join fetch c.images where c.id = :capsuleId")
Optional<Capsule> findCapsuleWithImageByCapsuleId(
@Param("capsuleId") Long capsuleId
);

@Modifying(clearAutomatically = true)
@Query("UPDATE Capsule c SET c.isOpened = true WHERE c.id = :capsuleId and c.member.id = :memberId")
int updateIsOpenedTrue(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.image;

import java.util.List;
import site.timecapsulearchive.core.domain.capsule.entity.Image;

public interface ImageQueryRepository {

void bulkSave(final List<Image> images);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.timecapsulearchive.core.domain.capsule.generic_capsule.repository;
package site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.image;

import java.sql.PreparedStatement;
import java.sql.SQLException;
Expand All @@ -14,7 +14,7 @@

@Repository
@RequiredArgsConstructor
public class ImageQueryRepository {
public class ImageQueryRepositoryImpl implements ImageQueryRepository {

private final JdbcTemplate jdbcTemplate;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package site.timecapsulearchive.core.domain.capsule.generic_capsule.repository;
package site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.image;

import org.springframework.data.repository.Repository;
import site.timecapsulearchive.core.domain.capsule.entity.Image;

public interface ImageRepository extends Repository<Image, Long> {
public interface ImageRepository extends Repository<Image, Long>, ImageQueryRepository {

void save(Image newImage);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.video;

import java.util.List;
import site.timecapsulearchive.core.domain.capsule.entity.Video;

public interface VideoQueryRepository {

void bulkSave(final List<Video> videos);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.timecapsulearchive.core.domain.capsule.generic_capsule.repository;
package site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.video;

import java.sql.PreparedStatement;
import java.sql.SQLException;
Expand All @@ -14,7 +14,7 @@

@Repository
@RequiredArgsConstructor
public class VideoQueryRepository {
public class VideoQueryRepositoryImpl implements VideoQueryRepository {

private final JdbcTemplate jdbcTemplate;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package site.timecapsulearchive.core.domain.capsule.generic_capsule.repository;
package site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.video;

import org.springframework.data.repository.Repository;
import site.timecapsulearchive.core.domain.capsule.entity.Video;

public interface VideoRepository extends Repository<Video, Long> {
public interface VideoRepository extends Repository<Video, Long>, VideoQueryRepository {

void save(Video video);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.CoordinateRangeDto;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.NearbyARCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.data.dto.NearbyCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.CapsuleQueryRepository;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.CapsuleRepository;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.capsule.CapsuleRepository;
import site.timecapsulearchive.core.domain.capsuleskin.entity.CapsuleSkin;
import site.timecapsulearchive.core.domain.friend.repository.member_friend.MemberFriendRepository;
import site.timecapsulearchive.core.domain.member.entity.Member;
Expand All @@ -25,7 +24,6 @@
@Transactional(readOnly = true)
public class CapsuleService {

private final CapsuleQueryRepository capsuleQueryRepository;
private final CapsuleRepository capsuleRepository;
private final MemberFriendRepository memberFriendRepository;
private final GeoTransformManager geoTransformManager;
Expand All @@ -49,7 +47,7 @@ public List<NearbyARCapsuleSummaryDto> findARCapsuleByCurrentLocationAndCapsuleT

final Polygon mbr = geoTransformManager.getDistanceMBROf3857(point, dto.distance());

return capsuleQueryRepository.findARCapsuleSummaryDtosByCurrentLocationAndCapsuleType(
return capsuleRepository.findARCapsuleSummaryDtosByCurrentLocationAndCapsuleType(
memberId, mbr, capsuleType);
}

Expand All @@ -63,7 +61,7 @@ public List<NearbyCapsuleSummaryDto> findCapsuleByCurrentLocationAndCapsuleType(

final Polygon mbr = geoTransformManager.getDistanceMBROf3857(point, dto.distance());

return capsuleQueryRepository.findCapsuleSummaryDtosByCurrentLocationAndCapsuleType(
return capsuleRepository.findCapsuleSummaryDtosByCurrentLocationAndCapsuleType(
memberId, mbr, capsuleType);
}

Expand Down Expand Up @@ -116,7 +114,7 @@ public List<NearbyCapsuleSummaryDto> findFriendsCapsulesByCurrentLocation(

final List<Long> friendIds = memberFriendRepository.findFriendIdsByOwnerId(memberId);

return capsuleQueryRepository.findFriendsCapsuleSummaryDtosByCurrentLocationAndCapsuleType(
return capsuleRepository.findFriendsCapsuleSummaryDtosByCurrentLocationAndCapsuleType(
friendIds,
mbr
);
Expand All @@ -140,7 +138,7 @@ public List<NearbyARCapsuleSummaryDto> findFriendsARCapsulesByCurrentLocation(

final List<Long> friendIds = memberFriendRepository.findFriendIdsByOwnerId(memberId);

return capsuleQueryRepository.findFriendsARCapsulesByCurrentLocation(
return capsuleRepository.findFriendsARCapsulesByCurrentLocation(
friendIds,
mbr
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import org.springframework.transaction.annotation.Transactional;
import site.timecapsulearchive.core.domain.capsule.entity.Capsule;
import site.timecapsulearchive.core.domain.capsule.entity.Image;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.ImageQueryRepository;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.image.ImageRepository;
import site.timecapsulearchive.core.domain.member.entity.Member;
import site.timecapsulearchive.core.infra.s3.data.dto.S3Directory;

@Service
@RequiredArgsConstructor
public class ImageService {

private final ImageQueryRepository imageQueryRepository;
private final ImageRepository imageRepository;

@Transactional
public void bulkSave(final List<String> fileNames, final Capsule capsule, final Member member) {
Expand All @@ -23,7 +23,7 @@ public void bulkSave(final List<String> fileNames, final Capsule capsule, final
.map(fileName -> S3Directory.CAPSULE.generateFullPath(member.getId(), fileName))
.toList();

imageQueryRepository.bulkSave(Image.createOf(fullFileNames, capsule, member));
imageRepository.bulkSave(Image.createOf(fullFileNames, capsule, member));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import org.springframework.transaction.annotation.Transactional;
import site.timecapsulearchive.core.domain.capsule.entity.Capsule;
import site.timecapsulearchive.core.domain.capsule.entity.Video;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.VideoQueryRepository;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.video.VideoRepository;
import site.timecapsulearchive.core.domain.member.entity.Member;
import site.timecapsulearchive.core.infra.s3.data.dto.S3Directory;

@Service
@RequiredArgsConstructor
public class VideoService {

private final VideoQueryRepository videoQueryRepository;
private final VideoRepository videoRepository;

@Transactional
public void bulkSave(final List<String> fileNames, final Capsule capsule, final Member member) {
Expand All @@ -23,7 +23,7 @@ public void bulkSave(final List<String> fileNames, final Capsule capsule, final
.map(fileName -> S3Directory.CAPSULE.generateFullPath(member.getId(), fileName))
.toList();

videoQueryRepository.bulkSave(Video.createOf(fullFileNames, capsule, member));
videoRepository.bulkSave(Video.createOf(fullFileNames, capsule, member));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import site.timecapsulearchive.core.domain.capsule.entity.Capsule;
import site.timecapsulearchive.core.domain.capsule.entity.CapsuleType;
import site.timecapsulearchive.core.domain.capsule.exception.CapsuleNotFondException;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.CapsuleRepository;
import site.timecapsulearchive.core.domain.capsule.generic_capsule.repository.capsule.CapsuleRepository;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleCreateRequestDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleDetailDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleOpenStateDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.data.dto.GroupCapsuleSummaryDto;
import site.timecapsulearchive.core.domain.capsule.group_capsule.repository.GroupCapsuleQueryRepository;
import site.timecapsulearchive.core.domain.capsuleskin.entity.CapsuleSkin;
import site.timecapsulearchive.core.domain.group.entity.Group;
Expand Down Expand Up @@ -98,7 +98,8 @@ public Slice<CapsuleBasicInfoDto> findMyGroupCapsuleSlice(
*/
@Transactional
public GroupCapsuleOpenStateDto openGroupCapsule(final Long memberId, final Long capsuleId) {
Capsule groupCapsule = capsuleRepository.findNotOpenedGroupCapsuleByMemberIdAndCapsuleId(memberId,
Capsule groupCapsule = capsuleRepository.findNotOpenedGroupCapsuleByMemberIdAndCapsuleId(
memberId,
capsuleId)
.orElseThrow(CapsuleNotFondException::new);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package site.timecapsulearchive.core.domain.capsule.treasure_capsule.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
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 org.springframework.http.ResponseEntity;
import site.timecapsulearchive.core.global.common.response.ApiSpec;
import site.timecapsulearchive.core.global.error.ErrorResponse;

public interface TreasureCapsuleApi {

@Operation(
summary = "보물 캡슐 개봉",
description = "사용자는 보물 캡슐을 개봉할 수 있다.",
security = {@SecurityRequirement(name = "user_token")},
tags = {"secret capsule"}
)
@ApiResponses(value = {
@ApiResponse(
GaBaljaintheroom marked this conversation as resolved.
Show resolved Hide resolved
responseCode = "202",
description = "처리 시작"
),
@ApiResponse(
responseCode = "500",
description = "보물 캡슐 찾기 실패 예외",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
),
@ApiResponse(
responseCode = "500",
description = "외부 API 요청 실패",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))
)
})
ResponseEntity<ApiSpec<String>> openTreasureCapsule(
Long memberId,

@Parameter(in = ParameterIn.PATH, description = "개봉할 보물 캡슐 아이디", required = true)
Long capsuleId
);

}
Loading
Loading