-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from Open-Eye-Im-Developer/develop
MVP1 Sprint 1 마무리에 따른 Develop -> Main Merge
- Loading branch information
Showing
31 changed files
with
669 additions
and
24 deletions.
There are no files selected for viewing
128 changes: 128 additions & 0 deletions
128
src/main/java/io/oeid/mogakgo/common/swagger/template/ProfileCardLikeSwagger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package io.oeid.mogakgo.common.swagger.template; | ||
|
||
import io.oeid.mogakgo.common.base.CursorPaginationInfoReq; | ||
import io.oeid.mogakgo.common.base.CursorPaginationResult; | ||
import io.oeid.mogakgo.core.properties.swagger.error.SwaggerProfileCardLikeErrorExamples; | ||
import io.oeid.mogakgo.core.properties.swagger.error.SwaggerUserErrorExamples; | ||
import io.oeid.mogakgo.domain.profile.presentation.dto.req.UserProfileLikeCreateAPIReq; | ||
import io.oeid.mogakgo.domain.profile.presentation.dto.res.UserProfileLikeAPIRes; | ||
import io.oeid.mogakgo.domain.profile.presentation.dto.res.UserProfileLikeCreateAPIRes; | ||
import io.oeid.mogakgo.domain.profile.presentation.dto.res.UserProfileLikeInfoAPIRes; | ||
import io.oeid.mogakgo.exception.dto.ErrorResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.Parameters; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.ExampleObject; | ||
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.tags.Tag; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
@Tag(name = "Profile Card Like", description = "프로필 카드 찔러보기 관련 API") | ||
public interface ProfileCardLikeSwagger { | ||
|
||
@Operation(summary = "관심 있는 프로필 카드에 대해 찔러보기 요청 생성", description = "사용자가 관심 있는 프로필 카드에 찔러보기 요청을 보낼 때 사용하는 API") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "201", description = "찔러보기 요청 생성 성공", | ||
content = @Content(schema = @Schema(implementation = UserProfileLikeCreateAPIRes.class))), | ||
@ApiResponse(responseCode = "400", description = "요청한 데이터가 유효하지 않음", | ||
content = @Content( | ||
mediaType = "application/json", | ||
schema = @Schema(implementation = ErrorResponse.class), | ||
examples = { | ||
@ExampleObject(name = "E040102", value = SwaggerProfileCardLikeErrorExamples.PROFILE_CARD_LIKE_ALREADY_EXIST), | ||
@ExampleObject(name = "E040103", value = SwaggerProfileCardLikeErrorExamples.INVALID_PROFILE_CARD_LIKE_RECEIVER_INFO) | ||
} | ||
)), | ||
@ApiResponse(responseCode = "403", description = "본인이 아닌 프로필 카드에 대한 찔러보기 요청 권한이 없음", | ||
content = @Content( | ||
mediaType = "application/json", | ||
schema = @Schema(implementation = ErrorResponse.class), | ||
examples = @ExampleObject(name = "E040101", value = SwaggerProfileCardLikeErrorExamples.PROFILE_CARD_LIKE_FORBIDDEN_OPERATION) | ||
)), | ||
@ApiResponse(responseCode = "404", description = "요청한 데이터가 존재하지 않음", | ||
content = @Content( | ||
mediaType = "application/json", | ||
schema = @Schema(implementation = ErrorResponse.class), | ||
examples = @ExampleObject(name = "E020301", value = SwaggerUserErrorExamples.USER_NOT_FOUND) | ||
)), | ||
}) | ||
ResponseEntity<UserProfileLikeCreateAPIRes> create( | ||
@Parameter(hidden = true) Long userId, | ||
UserProfileLikeCreateAPIReq request | ||
); | ||
|
||
@Operation(summary = "사용자가 받은 찔러보기 요청 수 조회", description = "사용자가 자신이 받은 찔러보기 요청 수를 조회할 때 사용하는 API") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "찔러보기 요청 수 조회 성공", | ||
content = @Content(schema = @Schema(implementation = UserProfileLikeAPIRes.class))), | ||
@ApiResponse(responseCode = "403", description = "본인이 아닌 프로필 카드에 대한 찔러보기 요청 권한이 없음", | ||
content = @Content( | ||
mediaType = "application/json", | ||
schema = @Schema(implementation = ErrorResponse.class), | ||
examples = @ExampleObject(name = "E040101", value = SwaggerProfileCardLikeErrorExamples.PROFILE_CARD_LIKE_FORBIDDEN_OPERATION) | ||
)), | ||
@ApiResponse(responseCode = "404", description = "요청한 데이터가 존재하지 않음", | ||
content = @Content( | ||
mediaType = "application/json", | ||
schema = @Schema(implementation = ErrorResponse.class), | ||
examples = @ExampleObject(name = "E020301", value = SwaggerUserErrorExamples.USER_NOT_FOUND) | ||
)), | ||
}) | ||
ResponseEntity<UserProfileLikeAPIRes> getProfileLikeCountByReceiver( | ||
@Parameter(hidden = true) Long userId, | ||
@Parameter(description = "'찔러보기' 요청을 조회하는 사용자 ID", required = true) Long id | ||
); | ||
|
||
@Operation(summary = "사용자가 보낸 찔러보기 요청 수 조회", description = "사용자가 자신이 보낸 찔러보기 요청 수를 조회할 때 사용하는 API") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "찔러보기 요청 수 조회 성공", | ||
content = @Content(schema = @Schema(implementation = UserProfileLikeAPIRes.class))), | ||
@ApiResponse(responseCode = "403", description = "본인이 아닌 프로필 카드에 대한 찔러보기 요청 권한이 없음", | ||
content = @Content( | ||
mediaType = "application/json", | ||
schema = @Schema(implementation = ErrorResponse.class), | ||
examples = @ExampleObject(name = "E040101", value = SwaggerProfileCardLikeErrorExamples.PROFILE_CARD_LIKE_FORBIDDEN_OPERATION) | ||
)), | ||
@ApiResponse(responseCode = "404", description = "요청한 데이터가 존재하지 않음", | ||
content = @Content( | ||
mediaType = "application/json", | ||
schema = @Schema(implementation = ErrorResponse.class), | ||
examples = @ExampleObject(name = "E020301", value = SwaggerUserErrorExamples.USER_NOT_FOUND) | ||
)), | ||
}) | ||
ResponseEntity<UserProfileLikeAPIRes> getProfileLikeCountBySender( | ||
@Parameter(hidden = true) Long userId, | ||
@Parameter(description = "'찔러보기' 요청을 조회하는 사용자 ID", required = true) Long id | ||
); | ||
|
||
@Operation(summary = "사용자가 보낸 찔러보기 요청 상세 리스트 조회", description = "사용자가 자신이 보낸 찔러보기 요청 상세 리스트 정보를 조회할 때 사용하는 API") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "200", description = "찔러보기 요청 상세 리스트 조회 성공", | ||
content = @Content(schema = @Schema(implementation = UserProfileLikeInfoAPIRes.class))), | ||
@ApiResponse(responseCode = "403", description = "본인의 프로필 카드에 대한 찔러보기 요청만 조회할 수 있음", | ||
content = @Content( | ||
mediaType = "application/json", | ||
schema = @Schema(implementation = ErrorResponse.class), | ||
examples = @ExampleObject(name = "E040101", value = SwaggerProfileCardLikeErrorExamples.PROFILE_CARD_LIKE_FORBIDDEN_OPERATION) | ||
)), | ||
@ApiResponse(responseCode = "404", description = "요청한 데이터가 존재하지 않음", | ||
content = @Content( | ||
mediaType = "application/json", | ||
schema = @Schema(implementation = ErrorResponse.class), | ||
examples = @ExampleObject(name = "E020301", value = SwaggerUserErrorExamples.USER_NOT_FOUND) | ||
)), | ||
}) | ||
@Parameters({ | ||
@Parameter(name = "cursorId", description = "기준이 되는 커서 ID", example = "1"), | ||
@Parameter(name = "pageSize", description = "요청할 데이터 크기", example = "5", required = true), | ||
@Parameter(name = "sortOrder", description = "정렬 방향", example = "ASC"), | ||
}) | ||
ResponseEntity<CursorPaginationResult<UserProfileLikeInfoAPIRes>> getProfileLikeInfoBySender( | ||
@Parameter(hidden = true) Long userId, | ||
@Parameter(description = "'찔러보기' 요청을 조회하는 사용자 ID", required = true) Long id, | ||
@Parameter(hidden = true) CursorPaginationInfoReq pageable | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...va/io/oeid/mogakgo/core/properties/swagger/error/SwaggerProfileCardLikeErrorExamples.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.oeid.mogakgo.core.properties.swagger.error; | ||
|
||
public class SwaggerProfileCardLikeErrorExamples { | ||
|
||
public static final String PROFILE_CARD_LIKE_ALREADY_EXIST = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":400,\"code\":\"E040102\",\"message\":\"이미 찔러보기 요청을 전송한 프로필 카드에 찔러보기 요청을 전송할 수 없습니다.\"}"; | ||
public static final String INVALID_PROFILE_CARD_LIKE_RECEIVER_INFO = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":400,\"code\":\"E040103\",\"message\":\"찔러보기 요청의 사용자가 존재하지 않습니다.\"}"; | ||
public static final String PROFILE_CARD_LIKE_FORBIDDEN_OPERATION = "{\"timestamp\":\"2024-02-17T10:07:31.404Z\",\"statusCode\":403,\"code\":\"E040103\",\"message\":\"본인의 프로필 카드 외에 대해 찔러보기 요청 권한이 없습니다.\"}"; | ||
|
||
private SwaggerProfileCardLikeErrorExamples() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/main/java/io/oeid/mogakgo/domain/profile/application/ProfileCardLikeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package io.oeid.mogakgo.domain.profile.application; | ||
|
||
import static io.oeid.mogakgo.exception.code.ErrorCode400.PROFILE_CARD_LIKE_ALREADY_EXIST; | ||
import static io.oeid.mogakgo.exception.code.ErrorCode403.PROFILE_CARD_LIKE_FORBIDDEN_OPERATION; | ||
|
||
import io.oeid.mogakgo.common.base.CursorPaginationInfoReq; | ||
import io.oeid.mogakgo.common.base.CursorPaginationResult; | ||
import io.oeid.mogakgo.domain.profile.domain.entity.ProfileCardLike; | ||
import io.oeid.mogakgo.domain.profile.exception.ProfileCardLikeException; | ||
import io.oeid.mogakgo.domain.profile.infrastructure.ProfileCardLikeJpaRepository; | ||
import io.oeid.mogakgo.domain.profile.presentation.dto.req.UserProfileLikeCreateAPIReq; | ||
import io.oeid.mogakgo.domain.profile.presentation.dto.res.UserProfileLikeInfoAPIRes; | ||
import io.oeid.mogakgo.domain.user.application.UserCommonService; | ||
import io.oeid.mogakgo.domain.user.application.UserProfileService; | ||
import io.oeid.mogakgo.domain.user.domain.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class ProfileCardLikeService { | ||
|
||
private final ProfileCardLikeJpaRepository profileCardLikeRepository; | ||
private final ProfileCardService profileCardService; | ||
private final UserCommonService userCommonService; | ||
private final UserProfileService userProfileService; | ||
|
||
@Transactional | ||
public Long create(Long userId, UserProfileLikeCreateAPIReq request) { | ||
User tokenUser = validateToken(userId); | ||
validateSendor(tokenUser, request.getSenderId()); | ||
validateReceiver(userId); | ||
validateLikeAlreadyExist(request.getSenderId(), request.getReceiverId()); | ||
|
||
User receiver = userCommonService.getUserById(request.getReceiverId()); | ||
ProfileCardLike profileCardLike = request.toEntity(tokenUser, receiver); | ||
profileCardLikeRepository.save(profileCardLike); | ||
|
||
profileCardService.increaseTotalLikeAmount(receiver.getId()); | ||
userProfileService.decreaseAvailableLikeCount(userId); | ||
|
||
return profileCardLike.getId(); | ||
} | ||
|
||
// 나의 찔러보기 요청 수 조회 | ||
public Long getReceivedLikeCountForProfileCard(Long userId, Long id) { | ||
User tokenUser = validateToken(userId); | ||
validateSendor(tokenUser, userId); | ||
|
||
return profileCardLikeRepository.getLikeCount(id); | ||
} | ||
|
||
// 내가 보낸 찔러보기 요청 수 조회 | ||
public Long getSentLikeCountForProfileCard(Long userId, Long id) { | ||
User tokenUser = validateToken(userId); | ||
validateSendor(tokenUser, userId); | ||
|
||
return profileCardLikeRepository.getLikeCountByCondition(id, null); | ||
} | ||
|
||
public CursorPaginationResult<UserProfileLikeInfoAPIRes> getLikeInfoSenderProfile( | ||
Long userId, Long id, CursorPaginationInfoReq pageable) { | ||
User tokenUser = validateToken(userId); | ||
validateSendor(tokenUser, userId); | ||
|
||
return profileCardLikeRepository.getLikeInfoBySender(id, pageable); | ||
} | ||
|
||
private User validateToken(Long userId) { | ||
return userCommonService.getUserById(userId); | ||
} | ||
|
||
private void validateSendor(User tokenUser, Long userId) { | ||
if (!tokenUser.getId().equals(userId)) { | ||
throw new ProfileCardLikeException(PROFILE_CARD_LIKE_FORBIDDEN_OPERATION); | ||
} | ||
} | ||
|
||
private void validateReceiver(Long userId) { | ||
userCommonService.getUserById(userId); | ||
} | ||
|
||
private void validateLikeAlreadyExist(Long userId, Long creatorId) { | ||
if (profileCardLikeRepository.findBySenderAndReceiver(userId, creatorId).isPresent()) { | ||
throw new ProfileCardLikeException(PROFILE_CARD_LIKE_ALREADY_EXIST); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/io/oeid/mogakgo/domain/profile/exception/ProfileCardLikeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.oeid.mogakgo.domain.profile.exception; | ||
|
||
import io.oeid.mogakgo.exception.code.ErrorCode; | ||
import io.oeid.mogakgo.exception.exception_class.CustomException; | ||
|
||
public class ProfileCardLikeException extends CustomException { | ||
|
||
public ProfileCardLikeException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
src/main/java/io/oeid/mogakgo/domain/profile/infrastructure/ProfileCardJpaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package io.oeid.mogakgo.domain.profile.infrastructure; | ||
|
||
import io.oeid.mogakgo.domain.profile.domain.entity.ProfileCard; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ProfileCardJpaRepository extends JpaRepository<ProfileCard, Long>, | ||
ProfileCardRepositoryCustom { | ||
|
||
Optional<ProfileCard> findByUserId(Long userId); | ||
} |
9 changes: 9 additions & 0 deletions
9
...main/java/io/oeid/mogakgo/domain/profile/infrastructure/ProfileCardLikeJpaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.oeid.mogakgo.domain.profile.infrastructure; | ||
|
||
import io.oeid.mogakgo.domain.profile.domain.entity.ProfileCardLike; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ProfileCardLikeJpaRepository extends JpaRepository<ProfileCardLike, Long>, | ||
ProfileCardLikeRepositoryCustom { | ||
|
||
} |
Oops, something went wrong.