diff --git a/src/main/java/com/umc/owncast/domain/cast/controller/CastController.java b/src/main/java/com/umc/owncast/domain/cast/controller/CastController.java index 350214a..fd4f6f4 100644 --- a/src/main/java/com/umc/owncast/domain/cast/controller/CastController.java +++ b/src/main/java/com/umc/owncast/domain/cast/controller/CastController.java @@ -91,7 +91,7 @@ public ApiResponse deleteCast(@PathVariable("castId") Long castId @GetMapping("/home") @Operation(summary = "홈 화면 키워드 6개 받아오기") - public ApiResponse> getHomeKeyword(@AuthUser Member member) { + public ApiResponse getHomeKeyword(@AuthUser Member member) { System.out.println("GET api/cast/home"); return ApiResponse.onSuccess(keywordService.createKeyword(member)); } diff --git a/src/main/java/com/umc/owncast/domain/cast/dto/HomeDTO.java b/src/main/java/com/umc/owncast/domain/cast/dto/HomeDTO.java new file mode 100644 index 0000000..cc63da5 --- /dev/null +++ b/src/main/java/com/umc/owncast/domain/cast/dto/HomeDTO.java @@ -0,0 +1,18 @@ +package com.umc.owncast.domain.cast.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class HomeDTO { + private String nickName; + private String subCategory; + private List keywords; +} diff --git a/src/main/java/com/umc/owncast/domain/cast/repository/CastRepository.java b/src/main/java/com/umc/owncast/domain/cast/repository/CastRepository.java index 166a6cf..377aa75 100644 --- a/src/main/java/com/umc/owncast/domain/cast/repository/CastRepository.java +++ b/src/main/java/com/umc/owncast/domain/cast/repository/CastRepository.java @@ -1,9 +1,8 @@ package com.umc.owncast.domain.cast.repository; - import com.umc.owncast.domain.cast.entity.Cast; -import com.umc.owncast.domain.category.entity.MainCategory; import com.umc.owncast.domain.enums.Language; +import com.umc.owncast.domain.enums.MainCategory; import com.umc.owncast.domain.member.entity.Member; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -12,7 +11,6 @@ import org.springframework.data.repository.query.Param; import java.util.List; -import java.util.Optional; public interface CastRepository extends JpaRepository { @@ -29,11 +27,15 @@ List castSearch(@Param("text") String text, @Param("language") String language); @Query("SELECT c FROM Cast c " + - "JOIN MainPrefer m ON m.member = c.member " + - "WHERE m.mainCategory = :mainCategory " + + "JOIN SubPrefer s ON s.member = c.member " + + "JOIN SubCategory sub ON sub = s.subCategory " + + "WHERE sub.mainCategory = :mainCategory " + "AND c.isPublic = true " + "AND c.member != :member " + "AND c.language = :language " + - "ORDER BY c.hits DESC ") - Page findTop5ByMainCategoryIdOrderByHitsDesc(@Param("mainCategory") MainCategory mainCategory, @Param("member") Member member, @Param("language") Language language, Pageable pageable); + "ORDER BY c.hits DESC") + Page findTop5ByMainCategoryOrderByHitsDesc(@Param("mainCategory") MainCategory mainCategory, + @Param("member") Member member, + @Param("language") Language language, + Pageable pageable); } diff --git a/src/main/java/com/umc/owncast/domain/cast/service/CastServiceImpl.java b/src/main/java/com/umc/owncast/domain/cast/service/CastServiceImpl.java index 14629ad..5fadf3d 100644 --- a/src/main/java/com/umc/owncast/domain/cast/service/CastServiceImpl.java +++ b/src/main/java/com/umc/owncast/domain/cast/service/CastServiceImpl.java @@ -9,11 +9,12 @@ import com.umc.owncast.domain.cast.service.chatGPT.script.ScriptService; import com.umc.owncast.domain.castplaylist.entity.CastPlaylist; import com.umc.owncast.domain.castplaylist.repository.CastPlaylistRepository; -import com.umc.owncast.domain.category.entity.MainCategory; +import com.umc.owncast.domain.category.entity.SubCategory; import com.umc.owncast.domain.enums.Language; +import com.umc.owncast.domain.enums.MainCategory; import com.umc.owncast.domain.member.entity.Member; -import com.umc.owncast.domain.memberprefer.entity.MainPrefer; -import com.umc.owncast.domain.memberprefer.repository.MemberPreferRepository; +import com.umc.owncast.domain.memberprefer.entity.SubPrefer; +import com.umc.owncast.domain.memberprefer.repository.SubPreferRepository; import com.umc.owncast.domain.playlist.entity.Playlist; import com.umc.owncast.domain.playlist.repository.PlaylistRepository; import com.umc.owncast.domain.sentence.dto.SentenceResponseDTO; @@ -44,11 +45,10 @@ public class CastServiceImpl implements CastService { private final FileService fileService; private final SentenceService sentenceService; private final ChatGptScriptDivider scriptDivider; - private final CastRepository castRepository; private final PlaylistRepository playlistRepository; private final CastPlaylistRepository castPlaylistRepository; - private final MemberPreferRepository memberPreferRepository; + private final SubPreferRepository subPreferRepository; @Value("${app.image.default-path}") private String CAST_DEFAULT_IMAGE_PATH; @@ -227,10 +227,9 @@ public SimpleCastDTO deleteCast(Long castId, Member member) { return new SimpleCastDTO(cast); } - private MainPrefer getMemberPrefer(Member member) { - return memberPreferRepository.findByMember(member) - .orElseThrow(() -> new UserHandler(ErrorCode.CAST_NOT_FOUND)); - + private MainCategory getMemberPrefer(Member member) { + SubPrefer subPrefer = subPreferRepository.findByMember(member).orElseThrow(() -> new UserHandler(ErrorCode.CAST_NOT_FOUND)); + return subPrefer.getSubCategory().getMainCategory(); } @Override @@ -239,10 +238,10 @@ public List getHomeCast(Member member) { final int TOP_CASTS_LIMIT = 5; Pageable pageable = PageRequest.of(0, TOP_CASTS_LIMIT); - MainCategory userCategory = getMemberPrefer(member).getMainCategory(); + MainCategory userCategory = getMemberPrefer(member); Language userLanguage = member.getLanguage(); - List castMainCategories = castRepository.findTop5ByMainCategoryIdOrderByHitsDesc(userCategory, member, userLanguage, pageable).getContent(); + List castMainCategories = castRepository.findTop5ByMainCategoryOrderByHitsDesc(userCategory, member, userLanguage, pageable).getContent(); return convertToCastHomeDTO(castMainCategories); } diff --git a/src/main/java/com/umc/owncast/domain/cast/service/chatGPT/keyword/KeywordService.java b/src/main/java/com/umc/owncast/domain/cast/service/chatGPT/keyword/KeywordService.java index 4bfdd2d..aef28e2 100644 --- a/src/main/java/com/umc/owncast/domain/cast/service/chatGPT/keyword/KeywordService.java +++ b/src/main/java/com/umc/owncast/domain/cast/service/chatGPT/keyword/KeywordService.java @@ -1,9 +1,10 @@ package com.umc.owncast.domain.cast.service.chatGPT.keyword; +import com.umc.owncast.domain.cast.dto.HomeDTO; import com.umc.owncast.domain.member.entity.Member; import java.util.List; public interface KeywordService { - List createKeyword(Member member); + HomeDTO createKeyword(Member member); } diff --git a/src/main/java/com/umc/owncast/domain/cast/service/chatGPT/keyword/KeywordServiceImpl.java b/src/main/java/com/umc/owncast/domain/cast/service/chatGPT/keyword/KeywordServiceImpl.java index 86ad662..5ef6272 100644 --- a/src/main/java/com/umc/owncast/domain/cast/service/chatGPT/keyword/KeywordServiceImpl.java +++ b/src/main/java/com/umc/owncast/domain/cast/service/chatGPT/keyword/KeywordServiceImpl.java @@ -5,9 +5,10 @@ import com.theokanning.openai.completion.chat.ChatCompletionRequest; import com.umc.owncast.common.exception.handler.UserHandler; import com.umc.owncast.common.response.status.ErrorCode; +import com.umc.owncast.domain.cast.dto.HomeDTO; import com.umc.owncast.domain.cast.service.chatGPT.ChatGptAnswerGenerator; import com.umc.owncast.domain.cast.service.chatGPT.ChatGptPromptGenerator; -import com.umc.owncast.domain.category.repository.MainCategoryRepository; +import com.umc.owncast.domain.category.entity.SubCategory; import com.umc.owncast.domain.category.repository.SubCategoryRepository; import com.umc.owncast.domain.member.entity.Member; import lombok.RequiredArgsConstructor; @@ -15,7 +16,6 @@ import java.lang.reflect.Type; import java.util.List; -import java.util.Optional; @Service @RequiredArgsConstructor @@ -23,17 +23,17 @@ public class KeywordServiceImpl implements KeywordService { private final ChatGptPromptGenerator chatGPTPromptGenerator; private final ChatGptAnswerGenerator answerGenerator; - private final MainCategoryRepository mainCategoryRepository; private final SubCategoryRepository subCategoryRepository; @Override - public List createKeyword(Member member) { + public HomeDTO createKeyword(Member member) { String script = ""; List keywords = null; - String mainCategoryName = mainCategoryRepository.getMainCategoryNameByMember(member).orElseThrow(()->new UserHandler(ErrorCode.CATEGORY_NOT_EXIST)); - String subCategoryName = subCategoryRepository.getSubCategoryNameByMember(member).orElseThrow(()->new UserHandler(ErrorCode.CATEGORY_NOT_EXIST)); + SubCategory subCategory = subCategoryRepository.getSubCategoryNameByMember(member).orElseThrow(()->new UserHandler(ErrorCode.CATEGORY_NOT_EXIST)); + String subCategoryName = subCategory.getName(); + String mainCategoryName = subCategory.getMainCategory().getKrSubCategory(); System.out.println("입력 받은 키워드 1: " + mainCategoryName); System.out.println("입력 받은 키워드 2: " + subCategoryName); @@ -55,6 +55,10 @@ public List createKeyword(Member member) { System.out.println("Exception cause : " + e.getCause()); throw e; } - return keywords; + return HomeDTO.builder() + .nickName(member.getNickname()) + .subCategory(subCategoryName) + .keywords(keywords) + .build(); } } diff --git a/src/main/java/com/umc/owncast/domain/castcategory/entity/CastMainCategory.java b/src/main/java/com/umc/owncast/domain/castcategory/entity/CastMainCategory.java deleted file mode 100644 index ed2da85..0000000 --- a/src/main/java/com/umc/owncast/domain/castcategory/entity/CastMainCategory.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.umc.owncast.domain.castcategory.entity; - -import com.umc.owncast.common.entity.BaseTimeEntity; -import com.umc.owncast.domain.cast.entity.Cast; -import com.umc.owncast.domain.category.entity.MainCategory; -import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@Builder -@NoArgsConstructor -@Entity -@Table(name = "cast_main_category") -@AllArgsConstructor -public class CastMainCategory extends BaseTimeEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "cast_id") - private Cast cast; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "main_category_id") - private MainCategory mainCategory; -} diff --git a/src/main/java/com/umc/owncast/domain/castcategory/entity/CastSubCategory.java b/src/main/java/com/umc/owncast/domain/castcategory/entity/CastSubCategory.java deleted file mode 100644 index 2898596..0000000 --- a/src/main/java/com/umc/owncast/domain/castcategory/entity/CastSubCategory.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.umc.owncast.domain.castcategory.entity; - -import com.umc.owncast.common.entity.BaseTimeEntity; -import com.umc.owncast.domain.cast.entity.Cast; -import com.umc.owncast.domain.category.entity.SubCategory; -import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@Builder -@NoArgsConstructor -@Entity -@Table(name = "cast_sub_category") -@AllArgsConstructor -public class CastSubCategory extends BaseTimeEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "cast_id") - private Cast cast; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "sub_category_id") - private SubCategory subCategory; -} \ No newline at end of file diff --git a/src/main/java/com/umc/owncast/domain/castcategory/repository/CastMainCategoryRepository.java b/src/main/java/com/umc/owncast/domain/castcategory/repository/CastMainCategoryRepository.java deleted file mode 100644 index 5e3c7b5..0000000 --- a/src/main/java/com/umc/owncast/domain/castcategory/repository/CastMainCategoryRepository.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.umc.owncast.domain.castcategory.repository; - -import com.umc.owncast.domain.castcategory.entity.CastMainCategory; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import java.util.List; - -public interface CastMainCategoryRepository extends JpaRepository { - - @Query("SELECT cmc FROM CastMainCategory cmc " + - "JOIN cmc.cast c " + - "WHERE cmc.mainCategory.id = :mainCategoryId " + - "ORDER BY c.hits DESC") - List findTop5ByMainCategoryIdOrderByHitsDesc(Long mainCategoryId, Pageable pageable); - - CastMainCategory findByCastId(Long castId); -} diff --git a/src/main/java/com/umc/owncast/domain/category/Initializer/MainCategoryInitializer.java b/src/main/java/com/umc/owncast/domain/category/Initializer/MainCategoryInitializer.java deleted file mode 100644 index 757305f..0000000 --- a/src/main/java/com/umc/owncast/domain/category/Initializer/MainCategoryInitializer.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.umc.owncast.domain.category.Initializer; - -import com.umc.owncast.domain.category.entity.MainCategory; -import com.umc.owncast.domain.category.repository.MainCategoryRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.stereotype.Component; - -@Component -@RequiredArgsConstructor -public class MainCategoryInitializer implements CommandLineRunner { - - private final MainCategoryRepository mainCategoryRepository; - - @Override - public void run(String... args) throws Exception { - if (mainCategoryRepository.count() == 0) { // 데이터가 없는 경우만 추가 - mainCategoryRepository.save(new MainCategory(1L, "스포츠")); - mainCategoryRepository.save(new MainCategory(2L, "음악")); - mainCategoryRepository.save(new MainCategory(3L, "책")); - mainCategoryRepository.save(new MainCategory(4L, "미술")); - mainCategoryRepository.save(new MainCategory(5L, "드라마/영화")); - mainCategoryRepository.save(new MainCategory(6L, "음식")); - mainCategoryRepository.save(new MainCategory(7L, "시사/뉴스")); - mainCategoryRepository.save(new MainCategory(8L, "직접 입력")); - } - } - -} diff --git a/src/main/java/com/umc/owncast/domain/category/Initializer/SubCategoryInitializer.java b/src/main/java/com/umc/owncast/domain/category/Initializer/SubCategoryInitializer.java index f5d13a7..ff68066 100644 --- a/src/main/java/com/umc/owncast/domain/category/Initializer/SubCategoryInitializer.java +++ b/src/main/java/com/umc/owncast/domain/category/Initializer/SubCategoryInitializer.java @@ -1,13 +1,10 @@ package com.umc.owncast.domain.category.Initializer; -import com.umc.owncast.domain.category.entity.MainCategory; import com.umc.owncast.domain.category.entity.SubCategory; -import com.umc.owncast.domain.category.repository.MainCategoryRepository; import com.umc.owncast.domain.category.repository.SubCategoryRepository; +import com.umc.owncast.domain.enums.MainCategory; import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; -import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; @Service @@ -15,75 +12,65 @@ public class SubCategoryInitializer implements CommandLineRunner { private final SubCategoryRepository subCategoryRepository; - private final MainCategoryRepository mainCategoryRepository; @Override public void run(String... args) throws Exception { if (subCategoryRepository.count() == 0) { // 데이터가 없는 경우만 추가 - - MainCategory sports = mainCategoryRepository.findById(1L).orElse(new MainCategory(1L, "스포츠")); - MainCategory music = mainCategoryRepository.findById(2L).orElse(new MainCategory(2L, "음악")); - MainCategory books = mainCategoryRepository.findById(3L).orElse(new MainCategory(3L, "책")); - MainCategory arts = mainCategoryRepository.findById(4L).orElse(new MainCategory(4L, "미술")); - MainCategory movie = mainCategoryRepository.findById(5L).orElse(new MainCategory(5L, "드라마/영화")); - MainCategory foods = mainCategoryRepository.findById(6L).orElse(new MainCategory(6L, "음식")); - MainCategory news = mainCategoryRepository.findById(7L).orElse(new MainCategory(7L, "시사/뉴스")); - // 스포츠 - subCategoryRepository.save(new SubCategory(1L, "축구", sports, false)); - subCategoryRepository.save(new SubCategory(2L, "야구", sports, false)); - subCategoryRepository.save(new SubCategory(3L, "농구", sports, false)); - subCategoryRepository.save(new SubCategory(4L, "테니스", sports, false)); - subCategoryRepository.save(new SubCategory(5L, "골프", sports, false)); - subCategoryRepository.save(new SubCategory(6L, "수영", sports, false)); + subCategoryRepository.save(new SubCategory(1L, "축구", MainCategory.SPORTS, false)); + subCategoryRepository.save(new SubCategory(2L, "야구", MainCategory.SPORTS, false)); + subCategoryRepository.save(new SubCategory(3L, "농구", MainCategory.SPORTS, false)); + subCategoryRepository.save(new SubCategory(4L, "테니스", MainCategory.SPORTS, false)); + subCategoryRepository.save(new SubCategory(5L, "골프", MainCategory.SPORTS, false)); + subCategoryRepository.save(new SubCategory(6L, "수영", MainCategory.SPORTS, false)); // 음악 - subCategoryRepository.save(new SubCategory(7L, "팝", music, false)); - subCategoryRepository.save(new SubCategory(8L, "재즈", music, false)); - subCategoryRepository.save(new SubCategory(9L, "힙합", music, false)); - subCategoryRepository.save(new SubCategory(10L, "클래식", music, false)); - subCategoryRepository.save(new SubCategory(11L, "K-POP", music, false)); - subCategoryRepository.save(new SubCategory(12L, "록", music, false)); + subCategoryRepository.save(new SubCategory(7L, "팝", MainCategory.MUSIC, false)); + subCategoryRepository.save(new SubCategory(8L, "재즈", MainCategory.MUSIC, false)); + subCategoryRepository.save(new SubCategory(9L, "힙합", MainCategory.MUSIC, false)); + subCategoryRepository.save(new SubCategory(10L, "클래식", MainCategory.MUSIC, false)); + subCategoryRepository.save(new SubCategory(11L, "K-POP", MainCategory.MUSIC, false)); + subCategoryRepository.save(new SubCategory(12L, "록", MainCategory.MUSIC, false)); // 책 - subCategoryRepository.save(new SubCategory(13L, "소설", books, false)); - subCategoryRepository.save(new SubCategory(14L, "자기개발", books, false)); - subCategoryRepository.save(new SubCategory(15L, "판타지", books, false)); - subCategoryRepository.save(new SubCategory(16L, "철학", books, false)); - subCategoryRepository.save(new SubCategory(17L, "역사", books, false)); - subCategoryRepository.save(new SubCategory(18L, "과학", books, false)); + subCategoryRepository.save(new SubCategory(13L, "소설", MainCategory.BOOK, false)); + subCategoryRepository.save(new SubCategory(14L, "자기개발", MainCategory.BOOK, false)); + subCategoryRepository.save(new SubCategory(15L, "판타지", MainCategory.BOOK, false)); + subCategoryRepository.save(new SubCategory(16L, "철학", MainCategory.BOOK, false)); + subCategoryRepository.save(new SubCategory(17L, "역사", MainCategory.BOOK, false)); + subCategoryRepository.save(new SubCategory(18L, "과학", MainCategory.BOOK, false)); // 미술 - subCategoryRepository.save(new SubCategory(19L, "사진", arts, false)); - subCategoryRepository.save(new SubCategory(20L, "현대미술", arts, false)); - subCategoryRepository.save(new SubCategory(21L, "회화", arts, false)); - subCategoryRepository.save(new SubCategory(22L, "조각", arts, false)); - subCategoryRepository.save(new SubCategory(23L, "일러스트", arts, false)); - subCategoryRepository.save(new SubCategory(24L, "그래픽디자인", arts, false)); + subCategoryRepository.save(new SubCategory(19L, "사진", MainCategory.ART, false)); + subCategoryRepository.save(new SubCategory(20L, "현대미술", MainCategory.ART, false)); + subCategoryRepository.save(new SubCategory(21L, "회화", MainCategory.ART, false)); + subCategoryRepository.save(new SubCategory(22L, "조각", MainCategory.ART, false)); + subCategoryRepository.save(new SubCategory(23L, "일러스트", MainCategory.ART, false)); + subCategoryRepository.save(new SubCategory(24L, "그래픽디자인", MainCategory.ART, false)); // 드라마/영화 - subCategoryRepository.save(new SubCategory(25L, "로맨스", movie, false)); - subCategoryRepository.save(new SubCategory(26L, "액션", movie, false)); - subCategoryRepository.save(new SubCategory(27L, "코미디", movie, false)); - subCategoryRepository.save(new SubCategory(28L, "공포", movie, false)); - subCategoryRepository.save(new SubCategory(29L, "애니메이션", movie, false)); - subCategoryRepository.save(new SubCategory(30L, "스릴러", movie, false)); + subCategoryRepository.save(new SubCategory(25L, "로맨스", MainCategory.DRAMA, false)); + subCategoryRepository.save(new SubCategory(26L, "액션", MainCategory.DRAMA, false)); + subCategoryRepository.save(new SubCategory(27L, "코미디", MainCategory.DRAMA, false)); + subCategoryRepository.save(new SubCategory(28L, "공포", MainCategory.DRAMA, false)); + subCategoryRepository.save(new SubCategory(29L, "애니메이션", MainCategory.DRAMA, false)); + subCategoryRepository.save(new SubCategory(30L, "스릴러", MainCategory.DRAMA, false)); // 음식 - subCategoryRepository.save(new SubCategory(31L, "한식", foods, false)); - subCategoryRepository.save(new SubCategory(32L, "양식", foods, false)); - subCategoryRepository.save(new SubCategory(33L, "중식", foods, false)); - subCategoryRepository.save(new SubCategory(34L, "일식", foods, false)); - subCategoryRepository.save(new SubCategory(35L, "베이커리", foods, false)); - subCategoryRepository.save(new SubCategory(36L, "채식", foods, false)); + subCategoryRepository.save(new SubCategory(31L, "한식", MainCategory.FOOD, false)); + subCategoryRepository.save(new SubCategory(32L, "양식", MainCategory.FOOD, false)); + subCategoryRepository.save(new SubCategory(33L, "중식", MainCategory.FOOD, false)); + subCategoryRepository.save(new SubCategory(34L, "일식", MainCategory.FOOD, false)); + subCategoryRepository.save(new SubCategory(35L, "베이커리", MainCategory.FOOD, false)); + subCategoryRepository.save(new SubCategory(36L, "채식", MainCategory.FOOD, false)); // 시사/뉴스 - subCategoryRepository.save(new SubCategory(37L, "정치", news, false)); - subCategoryRepository.save(new SubCategory(38L, "경제", news, false)); - subCategoryRepository.save(new SubCategory(39L, "국제", news, false)); - subCategoryRepository.save(new SubCategory(40L, "사회", news, false)); - subCategoryRepository.save(new SubCategory(41L, "기술", news, false)); - subCategoryRepository.save(new SubCategory(42L, "환경", news, false)); + subCategoryRepository.save(new SubCategory(37L, "정치", MainCategory.NEWS, false)); + subCategoryRepository.save(new SubCategory(38L, "경제", MainCategory.NEWS, false)); + subCategoryRepository.save(new SubCategory(39L, "국제", MainCategory.NEWS, false)); + subCategoryRepository.save(new SubCategory(40L, "사회", MainCategory.NEWS, false)); + subCategoryRepository.save(new SubCategory(41L, "기술", MainCategory.NEWS, false)); + subCategoryRepository.save(new SubCategory(42L, "환경", MainCategory.NEWS, false)); } } } diff --git a/src/main/java/com/umc/owncast/domain/category/entity/MainCategory.java b/src/main/java/com/umc/owncast/domain/category/entity/MainCategory.java deleted file mode 100644 index 36ba12e..0000000 --- a/src/main/java/com/umc/owncast/domain/category/entity/MainCategory.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.umc.owncast.domain.category.entity; - -import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@Builder -@NoArgsConstructor -@Entity -@Table(name = "main_category") -@AllArgsConstructor -public class MainCategory { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(nullable = false, length = 50) - private String name; - - /*@OneToMany(mappedBy = "mainCategory", cascade = CascadeType.ALL) - private List subCategoryList = new ArrayList<>(); - - @OneToMany(mappedBy = "mainCategory", cascade = CascadeType.ALL) - private List memberPreferList = new ArrayList<>();*/ -} \ No newline at end of file diff --git a/src/main/java/com/umc/owncast/domain/category/entity/SubCategory.java b/src/main/java/com/umc/owncast/domain/category/entity/SubCategory.java index 25f55ed..e08795f 100644 --- a/src/main/java/com/umc/owncast/domain/category/entity/SubCategory.java +++ b/src/main/java/com/umc/owncast/domain/category/entity/SubCategory.java @@ -1,5 +1,6 @@ package com.umc.owncast.domain.category.entity; +import com.umc.owncast.domain.enums.MainCategory; import jakarta.persistence.*; import lombok.AllArgsConstructor; import lombok.Builder; @@ -20,8 +21,7 @@ public class SubCategory { @Column(nullable = false, length = 50) private String name; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "category_id") + @Enumerated(EnumType.STRING) private MainCategory mainCategory; @Column(nullable = false) diff --git a/src/main/java/com/umc/owncast/domain/category/repository/MainCategoryRepository.java b/src/main/java/com/umc/owncast/domain/category/repository/MainCategoryRepository.java deleted file mode 100644 index 5c9c6b2..0000000 --- a/src/main/java/com/umc/owncast/domain/category/repository/MainCategoryRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.umc.owncast.domain.category.repository; - -import com.umc.owncast.domain.category.entity.MainCategory; -import com.umc.owncast.domain.member.entity.Member; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import java.util.Optional; - -public interface MainCategoryRepository extends JpaRepository { - @Query(" SELECT m.name " + - " FROM MainCategory m " + - " JOIN MainPrefer mp ON m.id = mp.mainCategory.id " + - " WHERE mp.member = :member ") - Optional getMainCategoryNameByMember(@Param("member") Member member); - - Optional findByName(String name); -} diff --git a/src/main/java/com/umc/owncast/domain/category/repository/SubCategoryRepository.java b/src/main/java/com/umc/owncast/domain/category/repository/SubCategoryRepository.java index cc759c0..b53a986 100644 --- a/src/main/java/com/umc/owncast/domain/category/repository/SubCategoryRepository.java +++ b/src/main/java/com/umc/owncast/domain/category/repository/SubCategoryRepository.java @@ -10,11 +10,11 @@ public interface SubCategoryRepository extends JpaRepository { - @Query(" SELECT s.name " + + @Query(" SELECT s " + " FROM SubCategory s " + " JOIN SubPrefer sp ON s.id =sp.subCategory.id " + " WHERE sp.member = :member ") - Optional getSubCategoryNameByMember(@Param("member") Member member); + Optional getSubCategoryNameByMember(@Param("member") Member member); Optional findByName(String name); } diff --git a/src/main/java/com/umc/owncast/domain/enums/MainCategory.java b/src/main/java/com/umc/owncast/domain/enums/MainCategory.java new file mode 100644 index 0000000..4ff294e --- /dev/null +++ b/src/main/java/com/umc/owncast/domain/enums/MainCategory.java @@ -0,0 +1,23 @@ +package com.umc.owncast.domain.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum MainCategory { + SPORTS("스포츠"), + MUSIC("음악"), + BOOK("책"), + ART("미술"), + DRAMA("드라마/영화"), + FOOD("음식"), + NEWS("시사/뉴스"), + ETC("직접 입력"); + + private final String subCategory; + + public String getKrSubCategory() { + return this.subCategory; + } +} diff --git a/src/main/java/com/umc/owncast/domain/member/controller/MemberController.java b/src/main/java/com/umc/owncast/domain/member/controller/MemberController.java index e197a35..20925f5 100644 --- a/src/main/java/com/umc/owncast/domain/member/controller/MemberController.java +++ b/src/main/java/com/umc/owncast/domain/member/controller/MemberController.java @@ -5,6 +5,8 @@ import com.umc.owncast.common.response.status.SuccessCode; import com.umc.owncast.domain.member.annotation.AuthUser; import com.umc.owncast.domain.member.dto.*; +import com.umc.owncast.domain.member.dto.MemberRequest.JoinLoginIdDto; +import com.umc.owncast.domain.member.dto.MemberRequest.LoginDto; import com.umc.owncast.domain.member.entity.Member; import com.umc.owncast.domain.member.service.MemberMapper; import com.umc.owncast.domain.member.service.MemberService; @@ -18,7 +20,6 @@ import static com.umc.owncast.common.response.status.SuccessCode._SIGNUP_SUCCESS; - @Tag(name = "유저 관련 API", description = "유저 관련 API입니다") @RequiredArgsConstructor @RequestMapping("/api/users") @@ -30,13 +31,13 @@ public class MemberController { @Operation(summary = "회원가입 API") @PostMapping("/signup") public ApiResponse joinByLoginId(HttpServletResponse response, - @Valid @RequestBody MemberRequest.joinLoginIdDto requestDto) { + @Valid @RequestBody JoinLoginIdDto requestDto) { return ApiResponse.of(_SIGNUP_SUCCESS, memberService.insertMember(response, requestDto)); } @Operation(summary = "로그인 API") @PostMapping("/login") - public ApiResponse login(@Valid @RequestBody MemberRequest.loginDto request) { + public ApiResponse login(@Valid @RequestBody LoginDto request) { //Filter에서 작동, swagger 틀만 작성 return ApiResponse.onSuccess(new LoginResponseDTO("mockup", "for swagger")); } diff --git a/src/main/java/com/umc/owncast/domain/member/dto/MemberRequest.java b/src/main/java/com/umc/owncast/domain/member/dto/MemberRequest.java index 2ad6f53..9d70ff4 100644 --- a/src/main/java/com/umc/owncast/domain/member/dto/MemberRequest.java +++ b/src/main/java/com/umc/owncast/domain/member/dto/MemberRequest.java @@ -8,7 +8,7 @@ public class MemberRequest { @Getter - public static class joinLoginIdDto { + public static class JoinLoginIdDto { @NotBlank @Size(max = 10, message = "닉네임은 10자 이내여야 합니다.") @@ -41,18 +41,8 @@ public static class joinLoginIdDto { } @Getter - public static class loginDto { + public static class LoginDto { String loginId; String password; } - - @Getter - public static class memberPreferDto { - @NotBlank - String language; - @NotBlank - Long mainCategoryId; - Long subCategoryId; - String etc; - } } diff --git a/src/main/java/com/umc/owncast/domain/member/service/MemberService.java b/src/main/java/com/umc/owncast/domain/member/service/MemberService.java index 26d14a1..6799863 100644 --- a/src/main/java/com/umc/owncast/domain/member/service/MemberService.java +++ b/src/main/java/com/umc/owncast/domain/member/service/MemberService.java @@ -4,18 +4,15 @@ import com.umc.owncast.common.jwt.JwtUtil; import com.umc.owncast.common.jwt.LoginService; import com.umc.owncast.common.response.status.ErrorCode; -import com.umc.owncast.domain.category.entity.MainCategory; import com.umc.owncast.domain.category.entity.SubCategory; -import com.umc.owncast.domain.category.repository.MainCategoryRepository; import com.umc.owncast.domain.category.repository.SubCategoryRepository; import com.umc.owncast.domain.enums.Language; +import com.umc.owncast.domain.enums.MainCategory; import com.umc.owncast.domain.member.dto.*; -import com.umc.owncast.domain.member.dto.MemberRequest.joinLoginIdDto; +import com.umc.owncast.domain.member.dto.MemberRequest.JoinLoginIdDto; import com.umc.owncast.domain.member.entity.Member; import com.umc.owncast.domain.member.repository.MemberRepository; -import com.umc.owncast.domain.memberprefer.entity.MainPrefer; import com.umc.owncast.domain.memberprefer.entity.SubPrefer; -import com.umc.owncast.domain.memberprefer.repository.MainPreferRepository; import com.umc.owncast.domain.memberprefer.repository.SubPreferRepository; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @@ -35,14 +32,12 @@ public class MemberService { private final LoginService loginService; private final JwtUtil jwtUtil; private final PasswordEncoder passwordEncoder; - private final MainPreferRepository mainPreferRepository; private final SubPreferRepository subPreferRepository; - private final MainCategoryRepository mainCategoryRepository; private final SubCategoryRepository subCategoryRepository; @Transactional - public RefreshTokenDto insertMember(HttpServletResponse response, joinLoginIdDto requestDto) { + public RefreshTokenDto insertMember(HttpServletResponse response, JoinLoginIdDto requestDto) { if (memberRepository.existsByNickname(requestDto.getNickname())) { throw new UserHandler(ErrorCode.NICKNAME_ALREADY_EXIST); @@ -113,9 +108,7 @@ public MemberSettingResponseDTO languageSetting(Member member, String language) } public MemberSettingResponseDTO preferSetting(Member member, MemberPreferRequestDTO memberPreferRequestDTO) { - MainCategory mainCategory = mainCategoryRepository.findByName(memberPreferRequestDTO.getMainCategory()) - .orElseThrow(() -> new UserHandler(ErrorCode.CATEGORY_NOT_EXIST)); - + MainCategory mainCategory = MainCategory.valueOf(memberPreferRequestDTO.getMainCategory().toUpperCase(Locale.ROOT)); SubCategory subCategory = subCategoryRepository.findByName(memberPreferRequestDTO.getSubCategory()) .orElseGet(() -> { if (memberPreferRequestDTO.getSubCategory() == null) { @@ -130,19 +123,6 @@ public MemberSettingResponseDTO preferSetting(Member member, MemberPreferRequest return newSubCategory; }); - Optional mainPrefer = mainPreferRepository.findByMember(member); - - if(mainPrefer.isPresent()) { - mainPrefer.get().setMainCategory(mainCategory); - mainPreferRepository.save(mainPrefer.get()); - } else { - MainPrefer newMainPrefer = MainPrefer.builder() - .member(member) - .mainCategory(mainCategory) - .build(); - mainPreferRepository.save(newMainPrefer); - } - Optional subPrefer = subPreferRepository.findByMember(member); if(subPrefer.isPresent()) { subPrefer.get().setSubCategory(subCategory); diff --git a/src/main/java/com/umc/owncast/domain/memberprefer/entity/MainPrefer.java b/src/main/java/com/umc/owncast/domain/memberprefer/entity/MainPrefer.java deleted file mode 100644 index 3492566..0000000 --- a/src/main/java/com/umc/owncast/domain/memberprefer/entity/MainPrefer.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.umc.owncast.domain.memberprefer.entity; - -import com.umc.owncast.common.entity.BaseTimeEntity; -import com.umc.owncast.domain.category.entity.MainCategory; -import com.umc.owncast.domain.member.entity.Member; -import jakarta.persistence.*; -import lombok.*; - -@Getter -@Builder -@NoArgsConstructor -@Entity -@Table(name = "main_prefer") -@AllArgsConstructor -public class MainPrefer extends BaseTimeEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "member_id") - private Member member; - - @Setter - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "main_category_id") - private MainCategory mainCategory; - -} diff --git a/src/main/java/com/umc/owncast/domain/memberprefer/repository/MainPreferRepository.java b/src/main/java/com/umc/owncast/domain/memberprefer/repository/MainPreferRepository.java deleted file mode 100644 index d944c54..0000000 --- a/src/main/java/com/umc/owncast/domain/memberprefer/repository/MainPreferRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.umc.owncast.domain.memberprefer.repository; - -import com.umc.owncast.domain.member.entity.Member; -import com.umc.owncast.domain.memberprefer.entity.MainPrefer; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.repository.query.Param; - -import java.util.Optional; - -public interface MainPreferRepository extends JpaRepository { - Optional findByMember(@Param("member") Member member); -} diff --git a/src/main/java/com/umc/owncast/domain/memberprefer/repository/MemberPreferRepository.java b/src/main/java/com/umc/owncast/domain/memberprefer/repository/MemberPreferRepository.java deleted file mode 100644 index 179dd49..0000000 --- a/src/main/java/com/umc/owncast/domain/memberprefer/repository/MemberPreferRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.umc.owncast.domain.memberprefer.repository; - -import com.umc.owncast.domain.member.entity.Member; -import com.umc.owncast.domain.memberprefer.entity.MainPrefer; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.repository.query.Param; - -import java.util.Optional; - -public interface MemberPreferRepository extends JpaRepository { - Optional findByMember(@Param("member") Member member); -}