-
Notifications
You must be signed in to change notification settings - Fork 0
[Onboarding][Feat] 온보딩 CRUD 구현 #196
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3a1a807
[Onboarding][Feat] 온보딩 CRUD 구현
AlphaBs 53f98db
[Onboarding][Test] 테스트코드 추가
AlphaBs 1983367
[Onboarding][Refactor] 예외코드 따로 정의
AlphaBs a51ffae
[Onboarding][Refactor] 이미 온보딩 한 유저가 수정할때는 delete 대신 update
AlphaBs e89787e
[Onboarding][Test] 테스트 단순화
AlphaBs 04bf7a8
[Onboarding][Refactor] 오류코드 수정
AlphaBs b80819f
[Onboarding][Fix] category null checking
AlphaBs 004b159
[Onboarding][Test] service layer
AlphaBs fac5d3d
[Onboarding][Feat] 관리자 계정만 온보딩 설정 가능하도록
AlphaBs 038dda3
[Onboarding][Refactor] 양방향 참조 제거
AlphaBs 5f3a81c
[Onboarding][Fix] 잘못된 쿼리 수정
AlphaBs 27cb81f
[Onboarding][Fix] N+1
AlphaBs 2079c5d
Update src/main/java/book/book/common/ErrorCode.java
AlphaBs ea21d79
[Onboarding][Fix] fetch join 단순화
AlphaBs 1a596da
Merge branch 'feat/onboarding' of https://github.com/ssu-capstone-boo…
AlphaBs d49d8ff
[Onboarding][Fix] 키워드 입력값 검증
AlphaBs 970b211
[Onboarding][Fix] QueryDSL JPA 단순화
AlphaBs 739adc2
Update src/main/java/book/book/onboarding/repository/MemberOnboarding…
AlphaBs 777ad29
[Onboarding][Feat] API 명세 단순화
AlphaBs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,74 @@ | ||
| package book.book.onboarding.api; | ||
|
|
||
| import book.book.common.response.ResponseForm; | ||
| import book.book.onboarding.dto.OnboardingCategoryDto; | ||
| import book.book.onboarding.dto.OnboardingKeywordDto; | ||
| import book.book.onboarding.dto.OnboardingResultRequest; | ||
| import book.book.onboarding.dto.OnboardingResultResponse; | ||
| import book.book.onboarding.service.OnboardingService; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.access.prepost.PreAuthorize; | ||
| 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.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @Tag(name = "onboarding", description = "온보딩 관련 API") | ||
| public class OnboardingApi { | ||
| private final OnboardingService onboardingService; | ||
|
|
||
| @Operation(summary = "온보딩 책 분야 목록 가져오기") | ||
| @GetMapping("/api/v2/onboarding/categories") | ||
| public ResponseForm<List<OnboardingCategoryDto>> getOnboardingCategories() { | ||
| return new ResponseForm<>(onboardingService.getOnboardingCategories()); | ||
| } | ||
|
|
||
| @PreAuthorize("hasRole('ADMIN')") | ||
| @Operation(summary = "온보딩 책 분야 목록 추가하기") | ||
| @PostMapping("/api/v2/onboarding/categories") | ||
| public ResponseForm<Void> postOnboardingCategories( | ||
| @RequestBody List<OnboardingCategoryDto> request) { | ||
| onboardingService.postOnboardingCategories(request); | ||
| return ResponseForm.ok(); | ||
| } | ||
|
|
||
| @Operation(summary = "온보딩 키워드 목록 가져오기") | ||
| @GetMapping("/api/v2/onboarding/categories/{categoryId}/keywords") | ||
| public ResponseForm<List<OnboardingKeywordDto>> getOnboardingKeywords(@PathVariable String categoryId) { | ||
| return new ResponseForm<>(onboardingService.getOnboardingKeywords(categoryId)); | ||
| } | ||
|
|
||
| @PreAuthorize("hasRole('ADMIN')") | ||
| @Operation(summary = "온보딩 키워드 목록 추가하기") | ||
| @PostMapping("/api/v2/onboarding/categories/{categoryId}/keywords") | ||
| public ResponseForm<Void> postOnboardingKeywords( | ||
| @PathVariable String categoryId, | ||
| @RequestBody List<String> keywords) { | ||
| onboardingService.postOnboardingKeywords(categoryId, keywords); | ||
| return ResponseForm.ok(); | ||
| } | ||
|
|
||
| @Operation(summary = "로그인한 멤버가 온보딩때 입력한 정보 확인하기") | ||
| @GetMapping("/api/v2/onboarding") | ||
| public ResponseForm<OnboardingResultResponse> getMemberPreferences( | ||
| @AuthenticationPrincipal Long memberId) { | ||
| return new ResponseForm<>(onboardingService.getMemberPreferences(memberId)); | ||
| } | ||
|
|
||
| @Operation(summary = "온보딩 결과 저장하기") | ||
| @PutMapping("/api/v2/onboarding") | ||
| public ResponseForm<Void> putMemberPreferences( | ||
| @AuthenticationPrincipal Long memberId, | ||
| @RequestBody OnboardingResultRequest request) { | ||
| onboardingService.saveMemberPreferences(memberId, request); | ||
| return ResponseForm.ok(); | ||
| } | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
src/main/java/book/book/onboarding/dto/OnboardingCategoryDto.java
This file contains hidden or 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,15 @@ | ||
| package book.book.onboarding.dto; | ||
|
|
||
| import book.book.onboarding.entity.OnboardingCategory; | ||
|
|
||
| public record OnboardingCategoryDto( | ||
| String id, | ||
| String name | ||
| ) { | ||
| public static OnboardingCategoryDto from(OnboardingCategory entity) { | ||
| if (entity == null) { | ||
| return null; | ||
| } | ||
| return new OnboardingCategoryDto(entity.getId(), entity.getName()); | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
src/main/java/book/book/onboarding/dto/OnboardingKeywordDto.java
This file contains hidden or 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,15 @@ | ||
| package book.book.onboarding.dto; | ||
|
|
||
| import book.book.onboarding.entity.OnboardingKeyword; | ||
|
|
||
| public record OnboardingKeywordDto( | ||
| Long id, | ||
| String name | ||
| ) { | ||
| public static OnboardingKeywordDto from(OnboardingKeyword entity) { | ||
| if (entity == null) { | ||
| return null; | ||
| } | ||
| return new OnboardingKeywordDto(entity.getId(), entity.getName()); | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/main/java/book/book/onboarding/dto/OnboardingResultRequest.java
This file contains hidden or 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,14 @@ | ||
| package book.book.onboarding.dto; | ||
|
|
||
| import java.util.List; | ||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| public record OnboardingResultRequest( | ||
| String category, | ||
| List<Long> keywords, | ||
| String favoriteAuthor, | ||
| String favoriteBook | ||
| ) { | ||
| } | ||
|
|
14 changes: 14 additions & 0 deletions
14
src/main/java/book/book/onboarding/dto/OnboardingResultResponse.java
This file contains hidden or 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,14 @@ | ||
| package book.book.onboarding.dto; | ||
|
|
||
| import java.util.List; | ||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| public record OnboardingResultResponse( | ||
| OnboardingCategoryDto category, | ||
| List<OnboardingKeywordDto> keywords, | ||
| String favoriteAuthor, | ||
| String favoriteBook | ||
| ) { | ||
| } | ||
|
|
55 changes: 55 additions & 0 deletions
55
src/main/java/book/book/onboarding/entity/MemberOnboarding.java
This file contains hidden or 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,55 @@ | ||
| package book.book.onboarding.entity; | ||
|
|
||
| import book.book.common.BaseTimeEntity; | ||
| import book.book.member.entity.Member; | ||
| import jakarta.persistence.*; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Table(name = "member_onboarding") | ||
| @Getter | ||
| @Builder | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class MemberOnboarding extends BaseTimeEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @OneToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "member_id", unique = true, nullable = false) | ||
| private Member member; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "category_id") | ||
| private OnboardingCategory category; | ||
|
|
||
| @OneToMany(mappedBy = "memberOnboarding", fetch = FetchType.LAZY) | ||
| @Builder.Default | ||
| private List<MemberOnboardingKeyword> memberOnboardingKeywords = new ArrayList<>(); | ||
|
|
||
| @Column(length = 200) | ||
| private String favoriteAuthor; | ||
|
|
||
| @Column(length = 200) | ||
| private String favoriteBook; | ||
|
|
||
| public void updateCategory(OnboardingCategory category) { | ||
| this.category = category; | ||
| } | ||
|
|
||
| public void updateFavoriteAuthor(String favoriteAuthor) { | ||
| this.favoriteAuthor = favoriteAuthor; | ||
| } | ||
|
|
||
| public void updateFavoriteBook(String favoriteBook) { | ||
| this.favoriteBook = favoriteBook; | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
src/main/java/book/book/onboarding/entity/MemberOnboardingKeyword.java
This file contains hidden or 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,39 @@ | ||
| package book.book.onboarding.entity; | ||
|
|
||
| import book.book.common.BaseTimeEntity; | ||
| import jakarta.persistence.*; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Table( | ||
| name = "member_onboarding_keyword", | ||
| uniqueConstraints = { | ||
| @UniqueConstraint( | ||
| name = "member_onboarding_keyword_uk", | ||
| columnNames = {"member_onboarding_id", "keyword_id"} | ||
| ) | ||
| } | ||
| ) | ||
| @Getter | ||
| @Builder | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class MemberOnboardingKeyword extends BaseTimeEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "member_onboarding_id", nullable = false) | ||
| private MemberOnboarding memberOnboarding; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "keyword_id", nullable = false) | ||
| private OnboardingKeyword keyword; | ||
| } | ||
|
|
19 changes: 19 additions & 0 deletions
19
src/main/java/book/book/onboarding/entity/OnboardingCategory.java
This file contains hidden or 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,19 @@ | ||
| package book.book.onboarding.entity; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| @Entity | ||
| @Table(name = "onboarding_category") | ||
| @Getter | ||
| @Builder | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class OnboardingCategory { | ||
|
|
||
| @Id | ||
| private String id; | ||
|
|
||
| @Column(nullable = false) | ||
| private String name; | ||
| } |
32 changes: 32 additions & 0 deletions
32
src/main/java/book/book/onboarding/entity/OnboardingKeyword.java
This file contains hidden or 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,32 @@ | ||
| package book.book.onboarding.entity; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| @Entity | ||
| @Table( | ||
| name = "onboarding_keyword", | ||
| uniqueConstraints = { | ||
| @UniqueConstraint( | ||
| name = "onboarding_keyword_uk", | ||
| columnNames = {"name", "category_id"} | ||
| ) | ||
| } | ||
| ) | ||
| @Getter | ||
| @Builder | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class OnboardingKeyword { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(nullable = false) | ||
| private String name; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY) | ||
| @JoinColumn(name = "category_id", nullable = false) | ||
| private OnboardingCategory category; | ||
| } |
18 changes: 18 additions & 0 deletions
18
src/main/java/book/book/onboarding/repository/MemberOnboardingKeywordRepository.java
This file contains hidden or 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,18 @@ | ||
| package book.book.onboarding.repository; | ||
|
|
||
| import book.book.onboarding.entity.MemberOnboarding; | ||
| import book.book.onboarding.entity.MemberOnboardingKeyword; | ||
| import java.util.List; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Modifying; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| public interface MemberOnboardingKeywordRepository extends JpaRepository<MemberOnboardingKeyword, Long> { | ||
|
|
||
| List<MemberOnboardingKeyword> findAllByMemberOnboarding(MemberOnboarding member); | ||
|
|
||
| @Modifying(clearAutomatically = true) | ||
| @Query("DELETE FROM MemberOnboardingKeyword mok WHERE mok.memberOnboarding.id = :memberOnboardingId") | ||
| void deleteAllByMemberOnboardingId(@Param("memberOnboardingId") Long memberOnboardingId); | ||
| } |
19 changes: 19 additions & 0 deletions
19
src/main/java/book/book/onboarding/repository/MemberOnboardingRepository.java
This file contains hidden or 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,19 @@ | ||
| package book.book.onboarding.repository; | ||
|
|
||
| import book.book.onboarding.entity.MemberOnboarding; | ||
| import java.util.Optional; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| public interface MemberOnboardingRepository extends JpaRepository<MemberOnboarding, Long> { | ||
|
|
||
| Optional<MemberOnboarding> findByMemberId(Long memberId); | ||
|
|
||
| @Query("SELECT DISTINCT mo FROM MemberOnboarding mo " + | ||
| "LEFT JOIN FETCH mo.category " + | ||
| "LEFT JOIN FETCH mo.memberOnboardingKeywords mok " + | ||
| "LEFT JOIN FETCH mok.keyword " + | ||
| "WHERE mo.member.id = :memberId") | ||
| Optional<MemberOnboarding> findByMemberIdWithCategory(@Param("memberId") Long memberId); | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/main/java/book/book/onboarding/repository/OnboardingCategoryRepository.java
This file contains hidden or 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 book.book.onboarding.repository; | ||
|
|
||
| import book.book.onboarding.entity.OnboardingCategory; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface OnboardingCategoryRepository extends JpaRepository<OnboardingCategory, String> { | ||
|
|
||
| } | ||
|
|
11 changes: 11 additions & 0 deletions
11
src/main/java/book/book/onboarding/repository/OnboardingKeywordRepository.java
This file contains hidden or 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 book.book.onboarding.repository; | ||
|
|
||
| import book.book.onboarding.entity.OnboardingKeyword; | ||
| import java.util.List; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface OnboardingKeywordRepository extends JpaRepository<OnboardingKeyword, Long> { | ||
|
|
||
| List<OnboardingKeyword> findAllByCategoryId(String categoryId); | ||
| } | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.