Skip to content

Commit

Permalink
Merge pull request #41 from DSM-Repo/find-document-update
Browse files Browse the repository at this point in the history
pr :: Update Find Full Document
  • Loading branch information
dkflfkd53 authored Aug 4, 2024
2 parents b0c4608 + 51c47d2 commit 228eefb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,23 @@

import com.example.whopper.domain.document.application.usecase.FindDocumentUseCase;
import com.example.whopper.domain.document.dao.DocumentRepository;
import com.example.whopper.domain.document.domain.DocumentEntity;
import com.example.whopper.domain.document.domain.detail.CompletionElementLevel;
import com.example.whopper.domain.document.dto.request.SearchDocumentRequest;
import com.example.whopper.domain.document.dto.response.DocumentResponse;
import com.example.whopper.domain.document.dto.response.FullDocumentResponse;
import com.example.whopper.domain.document.dto.response.SearchDocumentResponse;
import com.example.whopper.domain.document.exception.DocumentNotFoundException;
import com.example.whopper.domain.feedback.dao.FeedbackMongoRepository;
import com.example.whopper.domain.major.dao.MajorRepository;
import com.example.whopper.global.utils.current.CurrentStudent;
import com.example.whopper.global.utils.DataResponseInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class FindDocumentService implements FindDocumentUseCase {
private final FeedbackMongoRepository feedbackRepository;
private final DocumentRepository documentRepository;
private final MajorRepository majorRepository;
private final CurrentStudent currentStudent;
Expand All @@ -42,12 +36,10 @@ public DocumentResponse getCurrentStudentDocumentMainPageResponse() {
@Override
public FullDocumentResponse getCurrentStudentDocument() {
var currentStudentDocument = currentStudent.getDocument();
var currentStudent = currentStudentDocument.getStudent();
var major = majorRepository.getById(currentStudent.getMajorId());

var feedbackMap = getFeedbackResponseMap(currentStudentDocument);
var student = currentStudentDocument.getStudent();
var major = majorRepository.getById(student.getMajorId());

return FullDocumentResponse.of(currentStudentDocument, currentStudent, major.name(), feedbackMap);
return FullDocumentResponse.of(currentStudentDocument, student, major.name());
}

@Override
Expand All @@ -58,19 +50,7 @@ public FullDocumentResponse getSubmittedDocument(String documentId) {
var student = document.getStudent();
var major = majorRepository.getById(student.getMajorId());

var feedbackMap = getFeedbackResponseMap(document);

return FullDocumentResponse.of(document, student, major.name(), feedbackMap);
}

private Map<String, List<FullDocumentResponse.FeedbackResponse>> getFeedbackResponseMap(DocumentEntity document) {
return feedbackRepository.findAllByDocument(document)
.stream()
.map(FullDocumentResponse.FeedbackResponse::of)
.collect(Collectors.groupingBy(
FullDocumentResponse.FeedbackResponse::elementId,
Collectors.toList()
));
return FullDocumentResponse.of(document, student, major.name());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class ProjectElement extends AbstractElement {
private final String endDate;
private final Set<String> skillSet;
private final String description;
private final Set<String> urls;
private final String url;

public ProjectElement(String elementId, String name, String imagePath, ProjectType type, String startDate, String endDate, Set<String> skillSet, String description, Set<String> urls) {
public ProjectElement(String elementId, String name, String imagePath, ProjectType type, String startDate, String endDate, Set<String> skillSet, String description, String url) {
super(elementId);
this.name = name;
this.imagePath = imagePath;
Expand All @@ -27,7 +27,7 @@ public ProjectElement(String elementId, String name, String imagePath, ProjectTy
this.endDate = endDate;
this.skillSet = skillSet;
this.description = description;
this.urls = urls;
this.url = url;
}

public static ProjectElement fromProjectElementRequest(ProjectElementRequest request, String imagePath) {
Expand All @@ -40,7 +40,7 @@ public static ProjectElement fromProjectElementRequest(ProjectElementRequest req
request.endDate(),
request.skillSet(),
request.description(),
request.urls()
request.url()
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public class WriterInfoElement extends AbstractElement {
private final String email;
private final String profileImagePath;
private final Set<String> skillSet;
private final Set<String> url;
private final String url;

private static final int ONE_GEN_YEAR = 2015;

@Builder
public WriterInfoElement(String elementId, Integer generation, String email, String profileImagePath, Set<String> skillSet, Set<String> url) {
public WriterInfoElement(String elementId, Integer generation, String email, String profileImagePath, Set<String> skillSet, String url) {
super(elementId);
this.generation = generation;
this.email = email;
Expand All @@ -36,7 +36,7 @@ public static WriterInfoElement createEmptyElement(StudentEntity student) {
"",
student.getProfileImagePath(),
Collections.emptySet(),
Collections.emptySet()
""
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public record ProjectElementRequest(
String endDate,
Set<String> skillSet,
String description,
Set<String> urls
String url
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.example.whopper.domain.document.domain.element.type.AchievementType;
import com.example.whopper.domain.document.domain.element.type.ProjectType;
import com.example.whopper.domain.feedback.domain.FeedbackEntity;
import com.example.whopper.domain.student.domain.ClassInfo;
import com.example.whopper.domain.student.domain.StudentEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;

Expand All @@ -17,139 +18,44 @@ public record FullDocumentResponse(
String id,
DocumentWriterResponse writer,
DocumentStatus status,
IntroduceElementResponse introduce,
Set<String> skillSet,
Set<String> links,
List<ProjectElementResponse>projectList,
List<AchievementElementResponse> awardList,
List<ActivityElementResponse> activityList
IntroduceElement introduce,
List<ProjectElement>projectList,
List<AchievementElement> awardList,
List<ActivityElement> activityList
) {
public static FullDocumentResponse of(DocumentEntity document, StudentEntity student, String majorName, Map<String, List<FeedbackResponse>> feedbackMap) {
final var introduce = document.getIntroduce();

public static FullDocumentResponse of(DocumentEntity document, StudentEntity student, String majorName) {
return new FullDocumentResponse(
document.getId(),
DocumentWriterResponse.of(student, document, majorName),
document.getStatus(),
IntroduceElementResponse.of(introduce, feedbackMap.get(introduce.getElementId())),
document.getWriter().getSkillSet(),
document.getWriter().getUrl(),
document.getProjectList().stream().map(project -> ProjectElementResponse.of(project, feedbackMap.get(project.getElementId()))).toList(),
document.getAchievementList().stream().map(achievement -> AchievementElementResponse.of(achievement, feedbackMap.get(achievement.getElementId()))).toList(),
document.getActivityList().stream().map(activity -> ActivityElementResponse.of(activity, feedbackMap.get(activity.getElementId()))).toList()
document.getIntroduce(),
document.getProjectList(),
document.getAchievementList(),
document.getActivityList()
);
}

public record FeedbackResponse(@JsonIgnore String elementId, String comment, String writerName) {
public static FeedbackResponse of(FeedbackEntity entity) {
return new FeedbackResponse(entity.getElementId(), entity.getComment(), entity.getWriterName());
}
}

record IntroduceElementResponse(
String elementId,
String heading,
String introduce,
List<FeedbackResponse> feedback
) {
public static IntroduceElementResponse of(IntroduceElement element, List<FeedbackResponse> feedbackList) {
return new IntroduceElementResponse(
element.getElementId(),
element.getHeading(),
element.getIntroduce(),
feedbackList
);
}
}

record ProjectElementResponse(
String elementId,
String name,
String imagePath,
ProjectType type,
String startDate,
String endDate,
Set<String> skillSet,
String description,
Set<String> urls,
List<FeedbackResponse> feedback
) {
public static ProjectElementResponse of(ProjectElement element, List<FeedbackResponse> feedbackList) {
return new ProjectElementResponse(
element.getElementId(),
element.getName(),
element.getImagePath(),
element.getType(),
element.getStartDate(),
element.getEndDate(),
element.getSkillSet(),
element.getDescription(),
element.getUrls(),
feedbackList
);
}
}

record AchievementElementResponse(
String elementId,
String name,
String institution,
String date,
AchievementType type,
List<FeedbackResponse> feedback
) {
public static AchievementElementResponse of(AchievementElement element, List<FeedbackResponse> feedbackList) {
return new AchievementElementResponse(
element.getElementId(),
element.getName(),
element.getInstitution(),
element.getDate(),
element.getType(),
feedbackList
);
}
}

record ActivityElementResponse(
String elementId,
String name,
String date,
String endDate,
boolean isPeriod,
String description,
List<FeedbackResponse> feedback
) {
public static ActivityElementResponse of(ActivityElement element, List<FeedbackResponse> feedbackList) {
return new ActivityElementResponse(
element.getElementId(),
element.getName(),
element.getDate(),
element.getEndDate(),
element.isPeriod(),
element.getDescription(),
feedbackList
);
}
}

record DocumentWriterResponse(
String name,
String email,
String majorName,
String schoolNumber,
ClassInfo classInfo,
String department,
String profileImage
String url,
Set<String> skillSet
) {
public static DocumentWriterResponse of(StudentEntity student, DocumentEntity document, String majorName) {
final var schoolNumber = student.getClassInfo().schoolNumber();
final var classInfo = student.getClassInfo();
final var schoolNumber = classInfo.schoolNumber();

return new DocumentWriterResponse(
student.getName(),
document.getWriter().getEmail(),
majorName,
schoolNumber,
classInfo,
SchoolDepartmentEnum.getBySchoolNumber(schoolNumber),
student.getProfileImagePath()
document.getWriter().getUrl(),
document.getWriter().getSkillSet()
);
}

Expand Down

0 comments on commit 228eefb

Please sign in to comment.