-
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 #14 from Findy-org/feat/유튜브-즐겨찾기에-장소-저장
[FINDY-15] feat: 유튜브 즐겨찾기에 장소 저장
- Loading branch information
Showing
59 changed files
with
1,393 additions
and
243 deletions.
There are no files selected for viewing
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
17 changes: 16 additions & 1 deletion
17
src/main/java/org/findy/findy_be/bookmark/api/BookmarkController.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,12 +1,27 @@ | ||
package org.findy.findy_be.bookmark.api; | ||
|
||
import org.findy.findy_be.bookmark.api.swagger.BookmarkAPIPresentation; | ||
import org.findy.findy_be.bookmark.application.register.RegisterYoutubeBookmark; | ||
import org.findy.findy_be.bookmark.dto.request.YoutubeBookmarkRequest; | ||
import org.findy.findy_be.common.meta.LoginUser; | ||
import org.findy.findy_be.user.domain.User; | ||
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.RestController; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/bookmarks") | ||
public class BookmarkController { | ||
public class BookmarkController implements BookmarkAPIPresentation { | ||
|
||
private final RegisterYoutubeBookmark registerYoutubeBookmark; | ||
|
||
@PostMapping("/youtube") | ||
public void registerPlace(@LoginUser User user, @Valid @RequestBody YoutubeBookmarkRequest request) { | ||
registerYoutubeBookmark.invoke(user.getUserId(), request); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/org/findy/findy_be/bookmark/api/swagger/BookmarkAPIPresentation.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,28 @@ | ||
package org.findy.findy_be.bookmark.api.swagger; | ||
|
||
import org.findy.findy_be.bookmark.dto.request.YoutubeBookmarkRequest; | ||
import org.findy.findy_be.common.meta.CustomApiResponse; | ||
import org.findy.findy_be.common.meta.CustomApiResponses; | ||
import org.findy.findy_be.common.meta.LoginUser; | ||
import org.findy.findy_be.user.domain.User; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
|
||
@Tag(name = "Bookmark API", description = "북마크 관련 API") | ||
public interface BookmarkAPIPresentation { | ||
|
||
@Operation(summary = "유튜브 북마크 등록", description = "유저가 유튜브 북마크를 등록하는 API", responses = { | ||
@ApiResponse(responseCode = "200", description = "유튜브 북마크 등록 성공"), | ||
}) | ||
@CustomApiResponses({ | ||
@CustomApiResponse(error = "IllegalArgumentException", status = 400, message = "유튜브 즐겨찾기는 장소를 추가할 수 없습니다.", description = "유튜브 북마크에 잘못된 요청이 있는 경우"), | ||
@CustomApiResponse(error = "ForbiddenAccessException", status = 403, message = "해당 즐겨찾기에 접근할 권한이 없습니다.", description = "권한이 없는 유저가 즐겨찾기에 접근할 경우"), | ||
@CustomApiResponse(error = "EntityNotFoundException", status = 404, message = "해당 id : {id}의 즐겨찾기가 존재하지 않습니다.", description = "존재하지 않는 즐겨찾기에 접근할 경우"), | ||
@CustomApiResponse(error = "InternalServerError", status = 500, message = "내부 서버 오류가 발생했습니다.", description = "서버 내부에서 예기치 않은 오류가 발생한 경우") | ||
}) | ||
void registerPlace(@LoginUser User user, @Valid @RequestBody YoutubeBookmarkRequest request); | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/main/java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmark.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,7 @@ | ||
package org.findy.findy_be.bookmark.application.register; | ||
|
||
import org.findy.findy_be.bookmark.dto.request.YoutubeBookmarkRequest; | ||
|
||
public interface RegisterYoutubeBookmark { | ||
void invoke(final String userId, final YoutubeBookmarkRequest request); | ||
} |
56 changes: 56 additions & 0 deletions
56
...java/org/findy/findy_be/bookmark/application/register/RegisterYoutubeBookmarkService.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,56 @@ | ||
package org.findy.findy_be.bookmark.application.register; | ||
|
||
import static org.findy.findy_be.common.exception.ErrorCode.*; | ||
|
||
import java.util.List; | ||
|
||
import org.findy.findy_be.bookmark.domain.Bookmark; | ||
import org.findy.findy_be.bookmark.dto.request.YoutubeBookmarkRequest; | ||
import org.findy.findy_be.bookmark.repository.BookmarkRepository; | ||
import org.findy.findy_be.common.exception.custom.ForbiddenAccessException; | ||
import org.findy.findy_be.place.application.register.BatchRegisterPlace; | ||
import org.findy.findy_be.place.dto.request.RegisterPlaceRequest; | ||
import org.findy.findy_be.user.application.UserService; | ||
import org.findy.findy_be.user.domain.User; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class RegisterYoutubeBookmarkService implements RegisterYoutubeBookmark { | ||
|
||
private final UserService userService; | ||
private final BookmarkRepository bookmarkRepository; | ||
private final BatchRegisterPlace batchRegisterPlace; | ||
|
||
@Override | ||
public void invoke(final String userId, final YoutubeBookmarkRequest request) { | ||
User user = userService.findUser(userId); | ||
List<RegisterPlaceRequest> placeRequests = request.places(); | ||
bookmarkRepository.findByUserAndYoutuberId(user, request.youtuberId()).ifPresentOrElse( | ||
existingBookmark -> { | ||
validateBookmarkOwner(userId, existingBookmark); | ||
batchRegisterPlace.invoke(existingBookmark, placeRequests); | ||
}, | ||
() -> { | ||
log.info("새로운 북마크에 저장합니다."); | ||
Bookmark bookmark = Bookmark.createYoutubeType(request.youtuberName(), request.youtuberId(), | ||
request.youtuberProfile(), user); | ||
bookmarkRepository.save(bookmark); | ||
batchRegisterPlace.invoke(bookmark, placeRequests); | ||
} | ||
); | ||
} | ||
|
||
private void validateBookmarkOwner(String userId, Bookmark bookmark) { | ||
String bookmarkUserId = bookmark.getUser().getUserId(); | ||
if (!bookmarkUserId.equals(userId)) { | ||
throw new ForbiddenAccessException(FORBIDDEN_BOOKMARK_ACCESS.getMessage()); | ||
} | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/main/java/org/findy/findy_be/bookmark/dto/request/CategoryRequest.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,17 @@ | ||
package org.findy.findy_be.bookmark.dto.request; | ||
|
||
import org.findy.findy_be.place.domain.MajorCategory; | ||
import org.findy.findy_be.place.domain.MiddleCategory; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record CategoryRequest( | ||
@NotNull(message = "대분류는 비어있을 수 없습니다.") | ||
@Schema(description = "대분류", example = "RESTAURANT") | ||
MajorCategory majorCategory, | ||
|
||
@Schema(description = "중분류", example = "KOREAN") | ||
MiddleCategory middleCategory | ||
) { | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/org/findy/findy_be/bookmark/dto/request/YoutubeBookmarkRequest.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,30 @@ | ||
package org.findy.findy_be.bookmark.dto.request; | ||
|
||
import java.util.List; | ||
|
||
import org.findy.findy_be.common.validation.ValidYoutuberId; | ||
import org.findy.findy_be.place.dto.request.RegisterPlaceRequest; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
@Schema(description = "유튜브 즐겨찾기 DTO") | ||
public record YoutubeBookmarkRequest( | ||
|
||
@ValidYoutuberId(message = "유튜버 ID는 @으로 시작해야합니다.") | ||
@Schema(description = "유튜버 ID", example = "@iammingki") | ||
String youtuberId, | ||
|
||
@NotNull(message = "유튜버 이름은 비어있을 수 없습니다.") | ||
@Schema(description = "유튜버 이름", example = "걍밍경") | ||
String youtuberName, | ||
|
||
@Schema(description = "유튜버 프로필 link", example = "https://yt3.googleusercontent.com/ytc/AIdro_mieTH2WSE4oBMmczfLHB3HhikzOg1nz9tFD-MLad93Xnw=s160-c-k-c0x00ffffff-no-rj") | ||
String youtuberProfile, | ||
|
||
@Schema(description = "유튜브 링크", example = "https://www.youtube.com/watch?v=hE2wMo5Coco") | ||
String youtubeLink, | ||
|
||
List<RegisterPlaceRequest> places | ||
) { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/org/findy/findy_be/bookmark/repository/BookmarkRepository.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,7 +1,11 @@ | ||
package org.findy.findy_be.bookmark.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.findy.findy_be.bookmark.domain.Bookmark; | ||
import org.findy.findy_be.user.domain.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface BookmarkRepository extends JpaRepository<Bookmark, Long> { | ||
Optional<Bookmark> findByUserAndYoutuberId(final User user, final String youtuberId); | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/org/findy/findy_be/common/config/QueryDslConfig.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,21 @@ | ||
package org.findy.findy_be.common.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
|
||
@Configuration | ||
public class QueryDslConfig { | ||
|
||
@PersistenceContext | ||
private EntityManager entityManager; | ||
|
||
@Bean | ||
public JPAQueryFactory jpaQueryFactory() { | ||
return new JPAQueryFactory(entityManager); | ||
} | ||
} |
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
Oops, something went wrong.