-
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.
- Loading branch information
Showing
16 changed files
with
291 additions
and
40 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/main/java/gwangjang/server/domain/Issue/application/dto/res/IssueRes.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,14 @@ | ||
package gwangjang.server.domain.Issue.application.dto.res; | ||
|
||
import lombok.*; | ||
|
||
@Getter | ||
@Builder | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class IssueRes { | ||
private String issueTitle; | ||
private String topicTitle; | ||
private String imgUrl; | ||
} |
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
2 changes: 1 addition & 1 deletion
2
.../domain/morpheme/domain/entity/Topic.java → ...ver/domain/Issue/domain/entity/Topic.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
10 changes: 10 additions & 0 deletions
10
src/main/java/gwangjang/server/domain/Issue/domain/repository/IssueCustomRepository.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,10 @@ | ||
package gwangjang.server.domain.Issue.domain.repository; | ||
|
||
import gwangjang.server.domain.Issue.application.dto.res.IssueRes; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
@Repository | ||
public interface IssueCustomRepository { | ||
Optional<IssueRes> findIssueAndTopicById(Long issueId); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/gwangjang/server/domain/Issue/domain/repository/IssueRepository.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,9 @@ | ||
package gwangjang.server.domain.Issue.domain.repository; | ||
|
||
import gwangjang.server.domain.Issue.domain.entity.Issue; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface IssueRepository extends JpaRepository<Issue, Long>, IssueCustomRepository{ | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/gwangjang/server/domain/Issue/domain/repository/IssueRepositoryImpl.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,58 @@ | ||
package gwangjang.server.domain.Issue.domain.repository; | ||
|
||
import com.querydsl.core.Tuple; | ||
import com.querydsl.core.types.Projections; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
|
||
import gwangjang.server.domain.Issue.application.dto.res.IssueRes; | ||
import gwangjang.server.domain.Issue.domain.entity.Issue; | ||
import gwangjang.server.domain.Issue.domain.entity.QIssue; | ||
|
||
import gwangjang.server.domain.Issue.domain.entity.QTopic; | ||
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
import static gwangjang.server.domain.Issue.domain.entity.QIssue.issue; | ||
import static gwangjang.server.domain.Issue.domain.entity.QTopic.topic; | ||
|
||
@Repository | ||
public class IssueRepositoryImpl extends QuerydslRepositorySupport { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
public IssueRepositoryImpl (JPAQueryFactory jpaQueryFactory){ | ||
super(Issue.class); | ||
this.jpaQueryFactory = jpaQueryFactory; | ||
} | ||
public Optional<IssueRes> findIssueAndTopicById(Long issueId) { | ||
// First query to get issueTitle and imgUrl | ||
Tuple issueTuple = jpaQueryFactory | ||
.select( | ||
issue.issueTitle, | ||
issue.imgUrl | ||
) | ||
.from(issue) | ||
.where(issue.id.eq(issueId)) | ||
.fetchOne(); | ||
|
||
if (issueTuple != null) { | ||
String issueTitle = issueTuple.get(issue.issueTitle); | ||
String imgUrl = issueTuple.get(issue.imgUrl); | ||
|
||
// Second query to get topicTitle based on topicId associated with the issue | ||
String topicTitle = jpaQueryFactory | ||
.select(topic.topicTitle) | ||
.from(issue) | ||
.leftJoin(issue.topic, topic) | ||
.where(issue.id.eq(issueId)) | ||
.fetchOne(); | ||
|
||
return Optional.of(new IssueRes(issueTitle, topicTitle, imgUrl)); | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/gwangjang/server/domain/Issue/domain/service/IssueService.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,18 @@ | ||
package gwangjang.server.domain.Issue.domain.service; | ||
|
||
import gwangjang.server.domain.Issue.application.dto.res.IssueRes; | ||
import gwangjang.server.domain.Issue.domain.repository.IssueCustomRepository; | ||
import gwangjang.server.domain.Issue.exception.NotFoundIssueException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class IssueService { | ||
private final IssueCustomRepository issueQueryRepository; | ||
|
||
|
||
public IssueRes findIssueAndTopicById(Long issueId) { | ||
return issueQueryRepository.findIssueAndTopicById(issueId).orElseThrow(NotFoundIssueException::new); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/gwangjang/server/domain/Issue/exception/IssueException.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,13 @@ | ||
package gwangjang.server.domain.Issue.exception; | ||
|
||
import gwangjang.server.global.exception.ApplicationException; | ||
import gwangjang.server.global.response.ErrorCode; | ||
import org.springframework.http.HttpStatus; | ||
|
||
|
||
public abstract class IssueException extends ApplicationException { | ||
|
||
protected IssueException(ErrorCode errorCode, HttpStatus httpStatus) { | ||
super(errorCode, httpStatus); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/gwangjang/server/domain/Issue/exception/NotFoundIssueException.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,10 @@ | ||
package gwangjang.server.domain.Issue.exception; | ||
|
||
import gwangjang.server.global.response.ErrorCode; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public class NotFoundIssueException extends IssueException{ | ||
public NotFoundIssueException() { | ||
super(ErrorCode.NOT_FOUND_ISSUE_ERROR, HttpStatus.NOT_FOUND); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/gwangjang/server/domain/Issue/presentation/IssueController.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,24 @@ | ||
package gwangjang.server.domain.Issue.presentation; | ||
|
||
import gwangjang.server.domain.Issue.application.dto.res.IssueRes; | ||
import gwangjang.server.domain.Issue.domain.service.IssueService; | ||
import gwangjang.server.domain.Issue.exception.NotFoundIssueException; | ||
import gwangjang.server.domain.Issue.presentation.constant.IssueResponseMessage; | ||
import gwangjang.server.global.response.SuccessResponse; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@AllArgsConstructor | ||
public class IssueController { | ||
private final IssueService issueService; | ||
|
||
@GetMapping("/issue/{issueId}") | ||
public ResponseEntity<SuccessResponse<IssueRes>> getIssueById(@PathVariable Long issueId) { | ||
return ResponseEntity.ok(SuccessResponse.create(IssueResponseMessage.GET_ISSUE_SUCCESS.getMessage(),this.issueService.findIssueAndTopicById(issueId) )); | ||
|
||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/gwangjang/server/domain/Issue/presentation/constant/IssueResponseMessage.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,14 @@ | ||
package gwangjang.server.domain.Issue.presentation.constant; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum IssueResponseMessage { | ||
|
||
GET_ISSUE_SUCCESS("이슈 조회 완료"); | ||
|
||
private final String message; | ||
|
||
} |
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
32 changes: 32 additions & 0 deletions
32
src/main/java/gwangjang/server/domain/morpheme/domain/repository/MorphemeRepositoryImpl.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,32 @@ | ||
package gwangjang.server.domain.morpheme.domain.repository; | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import gwangjang.server.domain.morpheme.domain.entity.Morpheme; | ||
import gwangjang.server.domain.morpheme.domain.entity.QMorpheme; | ||
import jakarta.persistence.EntityManager; | ||
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public class MorphemeRepositoryImpl extends QuerydslRepositorySupport { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
public MorphemeRepositoryImpl (JPAQueryFactory jpaQueryFactory){ | ||
super(Morpheme.class); | ||
this.jpaQueryFactory = jpaQueryFactory; | ||
} | ||
|
||
public List<String> findTop5KeywordsExcluding(String excludedKeyword) { | ||
return jpaQueryFactory | ||
.select(QMorpheme.morpheme.word) | ||
.from(QMorpheme.morpheme) | ||
.where(QMorpheme.morpheme.word.ne(excludedKeyword)) | ||
.orderBy(QMorpheme.morpheme.count().desc()) | ||
.limit(5) | ||
.fetch(); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
src/main/java/gwangjang/server/domain/morpheme/domain/service/AsyncService.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,47 @@ | ||
package gwangjang.server.domain.morpheme.domain.service; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import jakarta.transaction.Transactional; | ||
import kr.co.shineware.nlp.komoran.model.Token; | ||
import lombok.RequiredArgsConstructor; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class AsyncService { | ||
private final Logger logger = LoggerFactory.getLogger(AsyncService.class); | ||
private final NewsAPIService newsAPIService; | ||
|
||
private final MorphemeService morphemeService; | ||
@Async | ||
public CompletableFuture<Void> asyncMethodNews(String newsList1) throws JsonProcessingException { | ||
logger.debug("ASYNC Start 1"); | ||
List<Token> newsAnalysis1 =newsAPIService.analysis(newsList1); | ||
logger.debug("ASYNC Start"); | ||
morphemeService.saveOrUpdateWord(newsAnalysis1, 100 ); | ||
return null; | ||
} | ||
@Async | ||
public CompletableFuture<Void> asyncMethodNews2(String newsList2) throws JsonProcessingException { | ||
logger.debug("ASYNC Start 2"); | ||
List<Token> newsAnalysis2 =newsAPIService.analysis(newsList2); | ||
logger.debug("ASYNC Start 3"); | ||
morphemeService.saveOrUpdateWord(newsAnalysis2, 200); | ||
return null; | ||
} | ||
@Async | ||
public CompletableFuture<Void> asyncMethodNews3(String newsList3) throws JsonProcessingException { | ||
logger.debug("ASYNC Start 4 "); | ||
List<Token> newsAnalysis3 =newsAPIService.analysis(newsList3); | ||
logger.debug("ASYNC Start 5"); | ||
morphemeService.saveOrUpdateWord(newsAnalysis3, 300); | ||
return null; | ||
} | ||
} |
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.