-
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.
* [Feat] FAQ 삽입 로직 구현 * [Feat] FAQ 조회 로직 구현 * [Feat] FAQ 생성 로직 admin 그룹으로 변경
- Loading branch information
Showing
11 changed files
with
187 additions
and
1 deletion.
There are no files selected for viewing
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
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
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,17 @@ | ||
package appjjang.fitpet.domain.question; | ||
|
||
import appjjang.fitpet.domain.question.domain.Question; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class FaqDto { | ||
private String type; | ||
private String question; | ||
private String answer; | ||
|
||
public FaqDto(Question question) { | ||
this.type = question.getType(); | ||
this.question = question.getTitle(); | ||
this.answer = question.getAnswer(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/appjjang/fitpet/domain/question/api/QuestionController.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,23 @@ | ||
package appjjang.fitpet.domain.question.api; | ||
|
||
import appjjang.fitpet.domain.question.application.QuestionService; | ||
import appjjang.fitpet.domain.question.dto.response.FaqQueryResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import org.springframework.web.bind.annotation.*; | ||
|
||
@Tag(name = "FAQ API", description = "FAQ 관련 API입니다.") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/questions") | ||
public class QuestionController { | ||
private final QuestionService questionService; | ||
|
||
@Operation(summary = "FAQ 조회", description = "모든 FAQ를 조회합니다.") | ||
@GetMapping | ||
public FaqQueryResponse addQuestion(@RequestParam(required = false) String keyword) { | ||
return questionService.getQuestionList(keyword); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/appjjang/fitpet/domain/question/application/QuestionService.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,33 @@ | ||
package appjjang.fitpet.domain.question.application; | ||
|
||
import appjjang.fitpet.domain.question.FaqDto; | ||
import appjjang.fitpet.domain.question.dao.QuestionRepository; | ||
import appjjang.fitpet.domain.question.domain.Question; | ||
import appjjang.fitpet.domain.question.dto.request.FaqCreateRequest; | ||
import appjjang.fitpet.domain.question.dto.response.FaqQueryResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class QuestionService { | ||
private final QuestionRepository questionRepository; | ||
|
||
public void addQuestion(FaqCreateRequest request) { | ||
questionRepository.save(Question.createQuestion(request.getType(), request.getTitle(), request.getAnswer())); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public FaqQueryResponse getQuestionList(String keyword) { | ||
List<String> types = questionRepository.findDistinctTypes(); | ||
List<FaqDto> dtoList = questionRepository.findQuestionByType(keyword).stream() | ||
.map(FaqDto::new) | ||
.collect(Collectors.toList()); | ||
return new FaqQueryResponse(types.size(), types, dtoList.size(), dtoList); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/appjjang/fitpet/domain/question/dao/QuestionRepository.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 appjjang.fitpet.domain.question.dao; | ||
|
||
import appjjang.fitpet.domain.question.domain.Question; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface QuestionRepository extends JpaRepository<Question, Long> , QuestionRepositoryCustom{ | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/appjjang/fitpet/domain/question/dao/QuestionRepositoryCustom.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 appjjang.fitpet.domain.question.dao; | ||
|
||
import appjjang.fitpet.domain.question.domain.Question; | ||
|
||
import java.util.List; | ||
|
||
public interface QuestionRepositoryCustom { | ||
List<String> findDistinctTypes(); | ||
List<Question> findQuestionByType(String keyword); | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/appjjang/fitpet/domain/question/dao/QuestionRepositoryImpl.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,37 @@ | ||
package appjjang.fitpet.domain.question.dao; | ||
|
||
import appjjang.fitpet.domain.question.domain.Question; | ||
import com.querydsl.core.BooleanBuilder; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
import static appjjang.fitpet.domain.question.domain.QQuestion.question; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class QuestionRepositoryImpl implements QuestionRepositoryCustom{ | ||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public List<String> findDistinctTypes() { | ||
return queryFactory | ||
.select(question.type) | ||
.distinct() | ||
.from(question) | ||
.fetch(); | ||
} | ||
|
||
@Override | ||
public List<Question> findQuestionByType(String keyword) { | ||
BooleanBuilder builder = new BooleanBuilder(); | ||
if (keyword != null) { | ||
builder.and(question.type.eq(keyword)); | ||
} | ||
return queryFactory.selectFrom(question) | ||
.where(builder) | ||
.fetch(); | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/main/java/appjjang/fitpet/domain/question/dto/request/FaqCreateRequest.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,12 @@ | ||
package appjjang.fitpet.domain.question.dto.request; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class FaqCreateRequest { | ||
private String type; | ||
private String title; | ||
private String answer; | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/appjjang/fitpet/domain/question/dto/response/FaqQueryResponse.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,16 @@ | ||
package appjjang.fitpet.domain.question.dto.response; | ||
|
||
import appjjang.fitpet.domain.question.FaqDto; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class FaqQueryResponse { | ||
private long typeCount; | ||
private List<String> typeList; | ||
private int questionCount; | ||
private List<FaqDto> questionList; | ||
} |