Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat :: 검색 기능 강화 #73

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package Minari.cheongForDo.domain.term.controller;

import Minari.cheongForDo.domain.term.dto.TermOneLikeLoadRes;
import Minari.cheongForDo.domain.term.dto.TermRequestDTO;
import Minari.cheongForDo.domain.term.dto.TermResponseDTO;
import Minari.cheongForDo.domain.term.dto.TermCommandReq;
import Minari.cheongForDo.domain.term.dto.TermLoadRes;
import Minari.cheongForDo.domain.term.model.service.TermService;
import Minari.cheongForDo.global.response.Response;
import Minari.cheongForDo.global.response.ResponseData;
Expand All @@ -25,7 +25,7 @@ public class TermController {
@GetMapping
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "용어 전체 조회", description = "아무것도 안 넣으면 20개씩 보여줍니다.")
public ResponseData<List<TermResponseDTO>> getTerms(
public ResponseData<List<TermLoadRes>> getTerms(
@RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "size", defaultValue = "20") int size
) {
Expand All @@ -36,30 +36,30 @@ public ResponseData<List<TermResponseDTO>> getTerms(
@GetMapping("/level/{level}")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "용어 난이도 별 조회")
public ResponseData<List<TermResponseDTO>> getLevelTerms(@PathVariable Long level) {
public ResponseData<List<TermLoadRes>> getLevelTerms(@PathVariable Long level) {
return termService.getLevelTerms(level);
}

@GetMapping("/keyword")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "키워드가 포함된 용어 조회", description = "키워드를 포함한 모든 용어들을 리스트로 보여줍니다.")
public ResponseData<List<TermResponseDTO>> getTermsByKeyword(@RequestParam String keyword) {
public ResponseData<List<TermLoadRes>> getTermsByKeyword(@RequestParam String keyword) {
return termService.getTermsByKeyword(keyword);
}

// 용어 등록
@PostMapping
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "용어 등록")
public Response createTerm(@RequestBody TermRequestDTO requestDTO) {
public Response createTerm(@RequestBody TermCommandReq requestDTO) {
return termService.createTerm(requestDTO);
}

// 용어 하나 조회
@GetMapping("{termId}")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "용어 일일 조회")
public ResponseData<TermResponseDTO> getTerm(@PathVariable Long termId) {
public ResponseData<TermLoadRes> getTerm(@PathVariable Long termId) {
return termService.findOneTerm(termId);
}

Expand All @@ -75,7 +75,7 @@ public ResponseData<TermOneLikeLoadRes> getTermWithNm(@PathVariable String termN
@PatchMapping
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "용어 업데이트")
public ResponseData<String> updateTerm(@RequestParam Long termId, @RequestBody TermRequestDTO requestDTO) {
public ResponseData<String> updateTerm(@RequestParam Long termId, @RequestBody TermCommandReq requestDTO) {
return termService.update(termId, requestDTO);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class TermRequestDTO {
public class TermCommandReq {

@NotBlank
private String termNm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
import lombok.Builder;
import lombok.Getter;

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

@Getter
@Builder
@AllArgsConstructor
public class TermResponseDTO {
public class TermLoadRes {

@NotBlank
private Long termId;
Expand All @@ -27,8 +24,8 @@ public class TermResponseDTO {
@NotBlank
private TermDifficulty termDifficulty;

public static TermResponseDTO of(Term term) {
return TermResponseDTO.builder()
public static TermLoadRes of(Term term) {
return TermLoadRes.builder()
.termId(term.getTermId())
.termNm(term.getTermNm())
.termExplain(term.getTermExplain())
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Minari/cheongForDo/domain/term/entity/Term.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package Minari.cheongForDo.domain.term.entity;

import Minari.cheongForDo.domain.term.dto.TermRequestDTO;
import Minari.cheongForDo.domain.term.dto.TermCommandReq;
import Minari.cheongForDo.domain.term.model.enums.TermDifficulty;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down Expand Up @@ -39,7 +39,7 @@ public class Term {
@Enumerated(EnumType.STRING)
private TermDifficulty termDifficulty;

public void update(TermRequestDTO termRequestDTO) {
public void update(TermCommandReq termRequestDTO) {
this.termNm = termRequestDTO.getTermNm();
this.termExplain = termRequestDTO.getTermExplain();
this.termDifficulty = termRequestDTO.getTermDifficulty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import Minari.cheongForDo.domain.member.authority.MemberAccountType;
import Minari.cheongForDo.domain.member.entity.MemberEntity;
import Minari.cheongForDo.domain.term.dto.TermOneLikeLoadRes;
import Minari.cheongForDo.domain.term.dto.TermRequestDTO;
import Minari.cheongForDo.domain.term.dto.TermResponseDTO;
import Minari.cheongForDo.domain.term.dto.TermCommandReq;
import Minari.cheongForDo.domain.term.dto.TermLoadRes;
import Minari.cheongForDo.domain.term.entity.Term;
import Minari.cheongForDo.domain.term.model.enums.TermDifficulty;
import Minari.cheongForDo.domain.term.repository.TermRepository;
Expand Down Expand Up @@ -38,25 +38,25 @@ public class TermService {
private final UserSessionHolder userSessionHolder;

// 용어 전체 조회
public ResponseData<List<TermResponseDTO>> getTerms(int page, int size) {
public ResponseData<List<TermLoadRes>> getTerms(int page, int size) {
Pageable pageable = PageRequest.of(page, size);

Page<Term> termLists = termRepository.findAll(pageable);

return ResponseData.of(HttpStatus.OK, "용어 전체 조회 성공!",
termLists.stream().map(
TermResponseDTO::of
TermLoadRes::of
).toList());
}

// 용어 난이도 별 조회
public ResponseData<List<TermResponseDTO>> getLevelTerms(Long level) {
public ResponseData<List<TermLoadRes>> getLevelTerms(Long level) {

List<Term> termList = checkQuestionLevel(level);

return ResponseData.of(HttpStatus.OK, "용어 난이도 별 조회 성공!",
termList.stream().map(
TermResponseDTO::of
TermLoadRes::of
).toList());
}

Expand All @@ -76,18 +76,18 @@ public ResponseData<TermOneLikeLoadRes> getTermsWithNm(String termNm) {
}

// 키워드가 포함된 모든 용어 조회
public ResponseData<List<TermResponseDTO>> getTermsByKeyword(String keyword) {
public ResponseData<List<TermLoadRes>> getTermsByKeyword(String keyword) {
List<Term> termList = termRepository.findByTermNmContaining(keyword);

return ResponseData.of(HttpStatus.OK, "키워드가 포함된 모든 단어 조회 성공!",
termList.stream().map(
TermResponseDTO::of
TermLoadRes::of
).toList());
}


// 용어 생성
public Response createTerm(TermRequestDTO requestDTO) {
public Response createTerm(TermCommandReq requestDTO) {
MemberEntity curMember = userSessionHolder.current();

checkMemberAuthority(curMember);
Expand All @@ -104,15 +104,15 @@ public Response createTerm(TermRequestDTO requestDTO) {
}

// 용어 하나 조회
public ResponseData<TermResponseDTO> findOneTerm(Long termId) {
public ResponseData<TermLoadRes> findOneTerm(Long termId) {
Term getTerm = getTerm(termId);

return ResponseData.of(HttpStatus.OK, "용어 조회 성공!", TermResponseDTO.of(getTerm));
return ResponseData.of(HttpStatus.OK, "용어 조회 성공!", TermLoadRes.of(getTerm));

}

// 용어 수정
public ResponseData<String> update(Long termId, TermRequestDTO requestDTO) {
public ResponseData<String> update(Long termId, TermCommandReq requestDTO) {
MemberEntity curMember = userSessionHolder.current();

checkMemberAuthority(curMember);
Expand Down
Loading