Skip to content

Commit

Permalink
fix: main category enum 작업 (#92)
Browse files Browse the repository at this point in the history
* add: home api에 회원 정보 포함

* fix: main category enum 화

---------

Co-authored-by: yuuddin <[email protected]>
  • Loading branch information
yuuddin and yuuddin authored Aug 29, 2024
1 parent 4dfc4ea commit 1133736
Show file tree
Hide file tree
Showing 22 changed files with 131 additions and 336 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public ApiResponse<SimpleCastDTO> deleteCast(@PathVariable("castId") Long castId

@GetMapping("/home")
@Operation(summary = "홈 화면 키워드 6개 받아오기")
public ApiResponse<List<String>> getHomeKeyword(@AuthUser Member member) {
public ApiResponse<HomeDTO> getHomeKeyword(@AuthUser Member member) {
System.out.println("GET api/cast/home");
return ApiResponse.onSuccess(keywordService.createKeyword(member));
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/umc/owncast/domain/cast/dto/HomeDTO.java
Original file line number Diff line number Diff line change
@@ -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<String> keywords;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +11,6 @@
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;

public interface CastRepository extends JpaRepository<Cast, Long> {

Expand All @@ -29,11 +27,15 @@ List<Cast> 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<Cast> findTop5ByMainCategoryIdOrderByHitsDesc(@Param("mainCategory") MainCategory mainCategory, @Param("member") Member member, @Param("language") Language language, Pageable pageable);
"ORDER BY c.hits DESC")
Page<Cast> findTop5ByMainCategoryOrderByHitsDesc(@Param("mainCategory") MainCategory mainCategory,
@Param("member") Member member,
@Param("language") Language language,
Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -239,10 +238,10 @@ public List<CastHomeDTO> 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<Cast> castMainCategories = castRepository.findTop5ByMainCategoryIdOrderByHitsDesc(userCategory, member, userLanguage, pageable).getContent();
List<Cast> castMainCategories = castRepository.findTop5ByMainCategoryOrderByHitsDesc(userCategory, member, userLanguage, pageable).getContent();

return convertToCastHomeDTO(castMainCategories);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> createKeyword(Member member);
HomeDTO createKeyword(Member member);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@
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;
import org.springframework.stereotype.Service;

import java.lang.reflect.Type;
import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
public class KeywordServiceImpl implements KeywordService {

private final ChatGptPromptGenerator chatGPTPromptGenerator;
private final ChatGptAnswerGenerator answerGenerator;
private final MainCategoryRepository mainCategoryRepository;
private final SubCategoryRepository subCategoryRepository;

@Override
public List<String> createKeyword(Member member) {
public HomeDTO createKeyword(Member member) {

String script = "";
List<String> 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);
Expand All @@ -55,6 +55,10 @@ public List<String> 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();
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 1133736

Please sign in to comment.