diff --git a/src/main/java/com/api/TaveShot/domain/compiler/domain/BojProblem.java b/src/main/java/com/api/TaveShot/domain/compiler/domain/BojProblem.java index 4c3680b..e507a2f 100644 --- a/src/main/java/com/api/TaveShot/domain/compiler/domain/BojProblem.java +++ b/src/main/java/com/api/TaveShot/domain/compiler/domain/BojProblem.java @@ -18,12 +18,10 @@ public class BojProblem { @Column(name = "Title", columnDefinition = "TEXT") private String title; - @Lob - @Column(name = "Description") + @Column(name = "Description", columnDefinition = "TEXT") private String description; - @Lob - @Column(name = "Input Description") + @Column(name = "Input Description", columnDefinition = "TEXT") private String inputDescription; @Column(name = "Output Description", columnDefinition = "TEXT") diff --git a/src/main/java/com/api/TaveShot/domain/recommend/controller/RecommendController.java b/src/main/java/com/api/TaveShot/domain/recommend/controller/RecommendController.java index 2fd5c2e..2bbada5 100644 --- a/src/main/java/com/api/TaveShot/domain/recommend/controller/RecommendController.java +++ b/src/main/java/com/api/TaveShot/domain/recommend/controller/RecommendController.java @@ -1,27 +1,19 @@ package com.api.TaveShot.domain.recommend.controller; -import com.api.TaveShot.domain.post.post.dto.response.PostResponse; -import com.api.TaveShot.domain.recommend.dto.RecProRequestDto; -import com.api.TaveShot.domain.recommend.dto.RecProResponseDto; import com.api.TaveShot.domain.recommend.dto.RecResponseDto; import com.api.TaveShot.domain.recommend.service.RecommendService; import com.api.TaveShot.global.success.SuccessResponse; import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.parameters.RequestBody; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; +import java.io.IOException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import java.io.IOException; - @RestController @Slf4j @RequiredArgsConstructor @@ -46,7 +38,8 @@ public SuccessResponse getUserBasedProList() throws IOException @ApiResponse(responseCode = "200", description = "추천 성공") }) @GetMapping("/problem") - public SuccessResponse getSolvedProList(@RequestParam(value = "solvedRecentId") int solvedNumber) throws IOException { + public SuccessResponse getSolvedProList(@RequestParam(value = "solvedRecentId") Long solvedNumber) + throws IOException { RecResponseDto responseDto = recommendService.getListByProblem(solvedNumber); return new SuccessResponse<>(responseDto); } diff --git a/src/main/java/com/api/TaveShot/domain/recommend/dto/RecProRequestDto.java b/src/main/java/com/api/TaveShot/domain/recommend/dto/RecProRequestDto.java index b35866d..59cab0b 100644 --- a/src/main/java/com/api/TaveShot/domain/recommend/dto/RecProRequestDto.java +++ b/src/main/java/com/api/TaveShot/domain/recommend/dto/RecProRequestDto.java @@ -1,13 +1,11 @@ package com.api.TaveShot.domain.recommend.dto; -import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; -import lombok.NoArgsConstructor; @Getter @Builder public class RecProRequestDto { - private int solvedRecentId; + private Long solvedRecentId; } diff --git a/src/main/java/com/api/TaveShot/domain/recommend/repository/ProblemElementRepository.java b/src/main/java/com/api/TaveShot/domain/recommend/repository/ProblemElementRepository.java index 4cb0bff..1fad14a 100644 --- a/src/main/java/com/api/TaveShot/domain/recommend/repository/ProblemElementRepository.java +++ b/src/main/java/com/api/TaveShot/domain/recommend/repository/ProblemElementRepository.java @@ -11,6 +11,6 @@ public interface ProblemElementRepository extends JpaRepository { @Query("select p from ProblemElement as p where p.problemId=:problemId") - Optional findByProblemId(Integer problemId); + Optional findByProblemId(Long problemId); } diff --git a/src/main/java/com/api/TaveShot/domain/recommend/service/RecommendService.java b/src/main/java/com/api/TaveShot/domain/recommend/service/RecommendService.java index bf53816..acafba7 100644 --- a/src/main/java/com/api/TaveShot/domain/recommend/service/RecommendService.java +++ b/src/main/java/com/api/TaveShot/domain/recommend/service/RecommendService.java @@ -3,12 +3,21 @@ import com.api.TaveShot.domain.Member.domain.Member; import com.api.TaveShot.domain.Member.repository.MemberRepository; import com.api.TaveShot.domain.recommend.domain.ProblemElement; -import com.api.TaveShot.domain.recommend.dto.*; +import com.api.TaveShot.domain.recommend.dto.RecProDetailResponseDto; +import com.api.TaveShot.domain.recommend.dto.RecProRequestDto; +import com.api.TaveShot.domain.recommend.dto.RecProResponseDto; +import com.api.TaveShot.domain.recommend.dto.RecResponseDto; +import com.api.TaveShot.domain.recommend.dto.UserCrawlingDto; import com.api.TaveShot.domain.recommend.repository.ProblemElementRepository; import com.api.TaveShot.domain.recommend.repository.TierCountRepository; import com.api.TaveShot.global.exception.ApiException; import com.api.TaveShot.global.exception.ErrorType; import com.api.TaveShot.global.util.SecurityUtil; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -16,12 +25,6 @@ import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - @Service @Slf4j @RequiredArgsConstructor @@ -52,10 +55,9 @@ public RecResponseDto getListByUser() throws IOException { .block(); Integer tierCount; - if(dto.getTier().equals("0")){ + if (dto.getTier().equals("0")) { tierCount = 0; - } - else { + } else { tierCount = tierCountRepository.findByTier(Integer.parseInt(dto.getTier())); } log.info("tier:{}", tierCount); @@ -74,7 +76,7 @@ public RecResponseDto getListByUser() throws IOException { } // 문제 기반 추천 서비스 - public RecResponseDto getListByProblem(int solvedRecentId) throws IOException { + public RecResponseDto getListByProblem(Long solvedRecentId) throws IOException { UserCrawlingDto dto = getUserInfo(); @@ -82,7 +84,8 @@ public RecResponseDto getListByProblem(int solvedRecentId) throws IOException { .baseUrl(lambda2) .build(); - ProblemElement problemElement = problemElementRepository.findByProblemId(solvedRecentId).orElseThrow( () -> new ApiException(ErrorType._PROBLEM_NOT_FOUND)); + problemElementRepository.findByProblemId(solvedRecentId) + .orElseThrow(() -> new ApiException(ErrorType._PROBLEM_NOT_FOUND)); RecProRequestDto requestDto = RecProRequestDto.builder() .solvedRecentId(solvedRecentId) @@ -95,10 +98,9 @@ public RecResponseDto getListByProblem(int solvedRecentId) throws IOException { .block(); Integer tierCount; - if(dto.getTier().equals("0")){ + if (dto.getTier().equals("0")) { tierCount = 0; - } - else { + } else { tierCount = tierCountRepository.findByTier(Integer.parseInt(dto.getTier())); } log.info("tier:{}", tierCount); @@ -126,55 +128,59 @@ public UserCrawlingDto getUserInfo() throws IOException { return dto; } - private Member getCurrentMember(){ + private Member getCurrentMember() { Member currentMember = SecurityUtil.getCurrentMember(); Long currentMemberId = currentMember.getId(); return memberRepository.findById(currentMemberId) .orElseThrow(() -> new ApiException(ErrorType._USER_NOT_FOUND_DB)); } - private String getTierName(Integer bojLevel){ + private String getTierName(Integer bojLevel) { String[] tiers = {"BRONZE", "SILVER", "GOLD", "PLATINUM", "DIAMOND", "RUBY", "MASTER"}; - if(bojLevel <= 5) + if (bojLevel <= 5) { return tiers[0]; - else if(bojLevel <= 10) + } else if (bojLevel <= 10) { return tiers[1]; - else if(bojLevel <= 15) + } else if (bojLevel <= 15) { return tiers[2]; - else if(bojLevel <= 20) + } else if (bojLevel <= 20) { return tiers[3]; - else if(bojLevel <= 25) + } else if (bojLevel <= 25) { return tiers[4]; - else if(bojLevel <= 30) + } else if (bojLevel <= 30) { return tiers[5]; + } return tiers[6]; } - private List extractWords(String bojTags){ + private List extractWords(String bojTags) { List tags = new ArrayList<>(); Pattern pattern = Pattern.compile("\\b\\w+\\b"); Matcher matcher = pattern.matcher(bojTags); - while(matcher.find()){ + while (matcher.find()) { tags.add(matcher.group()); } return tags; } - private List getProblemDetail(RecProResponseDto proList){ + private List getProblemDetail(RecProResponseDto proList) { List result = proList.getResult(); List proDetailResponseDto = new ArrayList<>(); // 문제 세부 정보 찾기 - for(int i=0;i<15;i++){ + for (int i = 0; i < 15; i++) { Integer num = Integer.parseInt(result.get(i)); log.info("num:{}", num); try { - ProblemElement problemElement = problemElementRepository.findByProblemId(Integer.parseInt(String.valueOf(num))).orElseThrow( () -> new ApiException(ErrorType._PROBLEM_NOT_FOUND)); - log.info("{}, {}, {}", problemElement.getProblemId(), problemElement.getBojLevel(), problemElement.getBojKey()); + ProblemElement problemElement = problemElementRepository.findByProblemId( + Long.parseLong(String.valueOf(num))) + .orElseThrow(() -> new ApiException(ErrorType._PROBLEM_NOT_FOUND)); + log.info("{}, {}, {}", problemElement.getProblemId(), problemElement.getBojLevel(), + problemElement.getBojKey()); String tierName = getTierName(problemElement.getBojLevel()); List tags = extractWords(problemElement.getBojKey()); RecProDetailResponseDto detailResponseDto = RecProDetailResponseDto.builder() @@ -184,7 +190,7 @@ private List getProblemDetail(RecProResponseDto proList .bojTag(tags) .build(); proDetailResponseDto.add(detailResponseDto); - } catch(Exception e){ + } catch (Exception e) { continue; } diff --git a/src/main/java/com/api/TaveShot/domain/search/service/SearchService.java b/src/main/java/com/api/TaveShot/domain/search/service/SearchService.java index 8bb578a..e1dd7ac 100644 --- a/src/main/java/com/api/TaveShot/domain/search/service/SearchService.java +++ b/src/main/java/com/api/TaveShot/domain/search/service/SearchService.java @@ -1,6 +1,5 @@ package com.api.TaveShot.domain.search.service; -import com.api.TaveShot.domain.recommend.domain.ProblemElement; import com.api.TaveShot.domain.recommend.repository.ProblemElementRepository; import com.api.TaveShot.domain.search.dto.GoogleItemDto; import com.api.TaveShot.domain.search.dto.GoogleListResponseDto; @@ -8,6 +7,8 @@ import com.api.TaveShot.global.exception.ApiException; import com.api.TaveShot.global.exception.ErrorType; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; @@ -32,9 +33,9 @@ public class SearchService { public GoogleListResponseDto findBlog(String query, int index) { - String questionNumber = query.replaceAll("[^0-9]", ""); + Long questionNumber = extractNumberFromBojString(query); - problemElementRepository.findByProblemId(Integer.parseInt(questionNumber)) + problemElementRepository.findByProblemId(questionNumber) .orElseThrow(() -> new ApiException(ErrorType._PROBLEM_NOT_FOUND)); WebClient webClient = WebClient.builder() @@ -66,4 +67,13 @@ public GoogleListResponseDto findBlog(String query, int index) { .build(); } + + public Long extractNumberFromBojString(String input) { + Pattern pattern = Pattern.compile("백준 (\\d+)번"); + Matcher matcher = pattern.matcher(input); + if (matcher.find()) { + return Long.parseLong(matcher.group(1)); + } + throw new ApiException(ErrorType._PROBLEM_NOT_FOUND); + } }