Skip to content

Commit

Permalink
[#16] refactor : dto 이름 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
sangminee committed May 21, 2023
1 parent f1f19d9 commit 0e0a361
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import com.mju.course.domain.service.LectureDomainService;
import com.mju.course.domain.service.ResponseService;
import com.mju.course.presentation.dto.request.LectureQuestionCreateDto;
import com.mju.course.presentation.dto.request.LectureReadAnswerDto;
import com.mju.course.presentation.dto.request.LectureReadQAndADto;
import com.mju.course.presentation.dto.response.LectureAnswerReadDto;
import com.mju.course.presentation.dto.response.LectureQAndAReadDto;
import com.mju.course.presentation.dto.response.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -84,20 +84,20 @@ public CommonResult readQAndA(Long question_index) {
lectureQuestionRepository.save(lectureQuestion);

// 질문 dto
LectureReadQuestionDto lectureReadQuestionDto = LectureReadQuestionDto.of(lectureQuestion);
LectureQuestionReadDto lectureQuestionReadDto = LectureQuestionReadDto.of(lectureQuestion);

// 답변들
List<LectureReadAnswerDto> list = new ArrayList<>();
List<LectureAnswerReadDto> list = new ArrayList<>();
if(lectureQuestion.getLectureAnswerList() != null && lectureQuestion.getLectureAnswerList().size() != 0){
lectureQuestion.getLectureAnswerList()
.forEach(s ->{
list.add(LectureReadAnswerDto.of(s));
list.add(LectureAnswerReadDto.of(s));
});
}

return responseService.getSingleResult(LectureReadQAndADto.builder()
.lectureReadQuestionDto(lectureReadQuestionDto)
.lectureReadAnswerDtos(list)
return responseService.getSingleResult(LectureQAndAReadDto.builder()
.lectureQuestionReadDto(lectureQuestionReadDto)
.lectureAnswerReadDtos(list)
.build());
}

Expand All @@ -109,7 +109,7 @@ public CommonResult readQAndA(Long question_index) {
public CommonResult readQuestions(Long lecture_index, Pageable pageable) {
Lecture lecture = lectureRepository.findById(lecture_index)
.orElseThrow(() -> new CourseException(NOT_EXISTENT_LECTURE));
Page<LectureReadQuestionDto> result = lectureRepository.readQuestions(lecture, pageable);
Page<LectureQuestionReadDto> result = lectureRepository.readQuestions(lecture, pageable);
return responseService.getSingleResult(result);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.mju.course.domain.repository.lecture;

import com.mju.course.domain.model.lecture.Lecture;
import com.mju.course.presentation.dto.response.LectureReadQuestionDto;
import com.mju.course.presentation.dto.response.LectureQuestionReadDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface LectureRepositoryCustom {
Page<LectureReadQuestionDto> readQuestions(Lecture lecture, Pageable pageable);
Page<LectureQuestionReadDto> readQuestions(Lecture lecture, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.mju.course.domain.model.lecture.Lecture;
import com.mju.course.domain.model.lecture.LectureQuestion;
import com.mju.course.domain.model.lecture.QLectureQuestion;
import com.mju.course.presentation.dto.response.LectureReadQuestionDto;
import com.mju.course.presentation.dto.response.LectureQuestionReadDto;
import com.querydsl.jpa.JPQLQuery;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand All @@ -24,7 +24,7 @@ public LectureRepositoryImpl(EntityManager em) {
}

@Override
public Page<LectureReadQuestionDto> readQuestions(Lecture lecture, Pageable pageable) {
public Page<LectureQuestionReadDto> readQuestions(Lecture lecture, Pageable pageable) {
QLectureQuestion lectureQuestion = QLectureQuestion.lectureQuestion1;

JPQLQuery<LectureQuestion> query = queryFactory.selectFrom(lectureQuestion)
Expand All @@ -34,9 +34,9 @@ public Page<LectureReadQuestionDto> readQuestions(Lecture lecture, Pageable page

List<LectureQuestion> lectureQuestionList = query.fetch();

List<LectureReadQuestionDto> content = new ArrayList<>();
List<LectureQuestionReadDto> content = new ArrayList<>();
lectureQuestionList.forEach(s->{
content.add(LectureReadQuestionDto.of(s));
content.add(LectureQuestionReadDto.of(s));
});

JPAQuery<LectureQuestion> countQuery = queryFactory.selectFrom(lectureQuestion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ public CommonResult deleteQuestion(@PathVariable Long question_index){
return lectureService.deleteQuestion(question_index);
}

// 강의 답변 CUD


// 강의 질문 북마크, 북마크 취소
@Operation(summary = "강의 질문 북마크, 북마크 취소", description = "강의 질문 북마크, 북마크 취소 API 입니다. ")
@GetMapping("/{question_index}/bookmark")
Expand All @@ -83,4 +80,13 @@ public CommonResult lectureQuestionBookmark(@PathVariable Long question_index,
return lectureService.lectureQuestionBookmark(question_index,userId);
}

// // 강의 답변 CUD
// @Operation(summary = "강의 답변 작성하기", description = "강의 답변 작성하기 API 입니다. ")
// @PostMapping("/{question_index}/answer")
// public CommonResult createAnswer(@PathVariable Long question_index,
// @RequestPart(value="images", required=false) List<MultipartFile> images,
// @RequestPart(value="lectureQuestionDto") @Validated LectureQuestionCreateDto lectureQuestionCreateDto){
// return lectureService.createAnswer(question_index, images, lectureQuestionCreateDto);
// }

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mju.course.presentation.dto.request;
package com.mju.course.presentation.dto.response;

import com.mju.course.domain.model.lecture.LectureAnswer;
import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -13,7 +13,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class LectureReadAnswerDto {
public class LectureAnswerReadDto {
@Schema(description = "질문 답변 index")
private Long lectureAnswerIndex;

Expand All @@ -26,8 +26,8 @@ public class LectureReadAnswerDto {
@Schema(description = "답변 시간")
private LocalDateTime createdAt;

public static LectureReadAnswerDto of(LectureAnswer lectureAnswer) {
return LectureReadAnswerDto.builder()
public static LectureAnswerReadDto of(LectureAnswer lectureAnswer) {
return LectureAnswerReadDto.builder()
.lectureAnswerIndex(lectureAnswer.getId())
.username("답변자")
.lectureAnswer(lectureAnswer.getLectureAnswer())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.mju.course.presentation.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class LectureQAndAReadDto {
private LectureQuestionReadDto lectureQuestionReadDto;
private List<LectureAnswerReadDto> lectureAnswerReadDtos;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class LectureReadQuestionDto {
public class LectureQuestionReadDto {
@Schema(description = "강의 질문 index")
private Long lectureQuestionIndex;

Expand All @@ -38,8 +38,8 @@ public class LectureReadQuestionDto {
@Schema(description = "답변 수")
private long answerSum;

public static LectureReadQuestionDto of(LectureQuestion lectureQuestion) {
return LectureReadQuestionDto.builder()
public static LectureQuestionReadDto of(LectureQuestion lectureQuestion) {
return LectureQuestionReadDto.builder()
.lectureQuestionIndex(lectureQuestion.getId())
.lectureQuestionTitle(lectureQuestion.getLectureQuestionTitle())
.lectureQuestion(lectureQuestion.getLectureQuestion())
Expand Down

0 comments on commit 0e0a361

Please sign in to comment.