Skip to content

Commit

Permalink
Merge pull request #23 from kusitms-28th-Meetup-E/14-mainpage-api
Browse files Browse the repository at this point in the history
feat(#14):Issue Detail + Topic api
  • Loading branch information
eojinny authored Nov 20, 2023
2 parents 8c9de17 + 1dc5a03 commit f2028a5
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gwangjang.server.domain.Issue.application.dto.res;

import lombok.*;

@Getter
@Builder
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class IssueDetailTopicRes {
private Long issueId;
private String issueTitle;
private String issueDetail;
private String imgUrl;
private Long topicId;
private String topicTitle;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package gwangjang.server.domain.Issue.domain.repository;

import gwangjang.server.domain.Issue.application.dto.res.IssueDetailTopicRes;
import gwangjang.server.domain.Issue.application.dto.res.IssueRes;
import gwangjang.server.domain.Issue.application.dto.res.KeywordRes;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
@Repository
public interface IssueCustomRepository {
Optional<IssueRes> findIssueAndTopicById(Long issueId);
public Optional<KeywordRes> findKeywordsByIssueId(Long issueId);
Optional<KeywordRes> findKeywordsByIssueId(Long issueId);
List<IssueDetailTopicRes> getAllIssueDetailTopicRes();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
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.IssueDetailTopicRes;
import gwangjang.server.domain.Issue.application.dto.res.IssueRes;
import gwangjang.server.domain.Issue.application.dto.res.KeywordRes;
import gwangjang.server.domain.Issue.domain.entity.Issue;
import gwangjang.server.domain.Issue.domain.entity.Keyword;
import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import static gwangjang.server.domain.Issue.domain.entity.QIssue.issue;

Expand Down Expand Up @@ -79,6 +82,29 @@ public Optional<KeywordRes> findKeywordsByIssueId(Long issueId) {

return Optional.ofNullable(keywordRes);
}

public List<IssueDetailTopicRes> getAllIssueDetailTopicRes() {
return jpaQueryFactory
.select(
issue.id,
issue.issueTitle,
issue.issueDetail,
issue.imgUrl,
topic.id,
topic.topicTitle
)
.from(issue)
.leftJoin(issue.topic, topic)
.fetch()
.stream()
.map(tuple -> new IssueDetailTopicRes(
tuple.get(issue.id),
tuple.get(issue.issueTitle),
tuple.get(issue.issueDetail),
tuple.get(issue.imgUrl),
tuple.get(topic.id),
tuple.get(topic.topicTitle)
))
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,9 @@ public List<IssueDetailRes> getAllIssue() {
))
.collect(Collectors.toList());
}
public List<IssueDetailTopicRes> getAllIssueDetailTopicRes(){
List<IssueDetailTopicRes> list = issueRepository.getAllIssueDetailTopicRes();
return list;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@ public ResponseEntity<SuccessResponse<List<IssueDetailRes>>> getIssueDetailAll()
return ResponseEntity.ok(SuccessResponse.create(IssueResponseMessage.GET_ISSUE_SUCCESS.getMessage(),this.issueService.getAllIssue()));
}

@GetMapping("/topic/issueDetail/all")
public ResponseEntity<SuccessResponse<List<IssueDetailTopicRes>>> getIssueDetailAndTopicAll() {
return ResponseEntity.ok(SuccessResponse.create(IssueResponseMessage.GET_ISSUE_SUCCESS.getMessage(),this.issueService.getAllIssueDetailTopicRes()));
}

}

0 comments on commit f2028a5

Please sign in to comment.