Skip to content

Commit

Permalink
Merge pull request #75 from DSM-Repo/document-search
Browse files Browse the repository at this point in the history
pr: 학생 문제 목록 조회에서 피드백 반환
  • Loading branch information
dkflfkd53 authored Aug 24, 2024
2 parents bba859e + 7620476 commit e263c18
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.example.whopper.application.resume.service;

import com.example.whopper.application.resume.usecase.FindDocumentUseCase;
import com.example.whopper.application.teacher.component.TeacherComponent;
import com.example.whopper.domain.feedback.FeedbackEntity;
import com.example.whopper.domain.resume.DocumentEntity;
import com.example.whopper.domain.resume.DocumentRepository;
import com.example.whopper.domain.resume.detail.CompletionElementLevel;
import com.example.whopper.interfaces.resume.dto.response.DocumentResponse;
Expand All @@ -18,6 +21,11 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand All @@ -26,6 +34,7 @@ class FindDocumentService implements FindDocumentUseCase {
private final FeedbackMongoRepository feedbackMongoRepository;
private final LibraryMongoRepository libraryMongoRepository;
private final CurrentStudent currentStudent;
private final TeacherComponent teacherComponent;

@Override
public DocumentResponse getIntroduceRecentlySharedDocuments() {
Expand Down Expand Up @@ -62,14 +71,26 @@ public FullDocumentResponse getSubmittedDocument(String documentId) {

@Override
public DataResponseInfo<SearchDocumentResponse> searchDocument(String name, Integer grade, Integer classNumber, String majorId, String status) {
return DataResponseInfo.of(
documentRepository.searchDocuments(name, grade, classNumber, majorId, status)
.map(document -> SearchDocumentResponse.of(
document,
feedbackMongoRepository.countByDocumentId(document.getId())
))
.toList()
);
var teacherId = teacherComponent.currentTeacher().getId();

var documents = documentRepository.searchDocuments(name, grade, classNumber, majorId, status).toList();
var documentIds = documents.stream().map(DocumentEntity::getId).toList();

Map<String, List<FeedbackEntity>> feedbackMap = feedbackMongoRepository.findAllByDocumentIdInAndTeacherId(documentIds, teacherId)
.collect(Collectors.groupingBy(FeedbackEntity::getDocumentId));


var responses = documents.stream()
.map(document -> SearchDocumentResponse.of(
document,
feedbackMap.getOrDefault(document.getId(), Collections.emptyList())
.stream()
.map(SearchDocumentResponse.Feedback::fromFeedback)
.toList()
))
.toList();

return DataResponseInfo.of(responses);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public interface FeedbackMongoRepository extends MongoRepository<FeedbackEntity,
void deleteAllByDocumentId(String documentId);
Stream<FeedbackEntity> findAllByTeacherId(String teacherId);
Stream<FeedbackEntity> findAllByDocumentIdAndTeacherId(String documentId, String teacherId);
Stream<FeedbackEntity> findAllByDocumentIdInAndTeacherId(List<String> documentIds, String teacherId);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package com.example.whopper.interfaces.resume.dto.response;

import com.example.whopper.domain.feedback.FeedbackEntity;
import com.example.whopper.domain.resume.DocumentEntity;
import com.example.whopper.domain.resume.element.DocumentStatus;
import com.example.whopper.domain.student.StudentInfo;

import java.util.List;

public record SearchDocumentResponse(
String documentId,
StudentInfo studentInfo,
DocumentStatus status,
int numberOfFeedback
List<Feedback> feedbackList
) {
public static SearchDocumentResponse of(DocumentEntity document, int numberOfFeedback) {
return new SearchDocumentResponse(document.getId(), StudentInfo.of(document.getStudent()), document.getStatus(), numberOfFeedback);
public record Feedback(String id, String comment, String type, String status, boolean rejected) {
public static Feedback fromFeedback(FeedbackEntity feedback) {
return new Feedback(feedback.getId(), feedback.getComment(), feedback.getType().name(), feedback.getStatus().name(), feedback.getRejected());
}
}
public static SearchDocumentResponse of(DocumentEntity document, List<Feedback> feedbackList) {
return new SearchDocumentResponse(document.getId(), StudentInfo.of(document.getStudent()), document.getStatus(), feedbackList);
}
}

0 comments on commit e263c18

Please sign in to comment.