-
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.
Merge branch 'main' of https://github.com/DSM-Repo/Whopper
- Loading branch information
Showing
27 changed files
with
230 additions
and
155 deletions.
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
35 changes: 35 additions & 0 deletions
35
...va/com/example/whopper/domain/document/application/impl/CancelReleaseDocumentService.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,35 @@ | ||
package com.example.whopper.domain.document.application.impl; | ||
|
||
import com.example.whopper.domain.document.application.usecase.CancelReleaseDocumentUseCase; | ||
import com.example.whopper.domain.document.dao.DocumentRepository; | ||
import com.example.whopper.domain.document.domain.DocumentEntity; | ||
import com.example.whopper.domain.document.domain.element.DocumentStatus; | ||
import com.example.whopper.domain.document.exception.DocumentIllegalStatusException; | ||
import com.example.whopper.domain.document.exception.DocumentNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CancelReleaseDocumentService implements CancelReleaseDocumentUseCase { | ||
private final DocumentRepository documentRepository; | ||
|
||
@Override | ||
public void cancel(String documentId) { | ||
var document = validateDocumentIdAndGetDocumentEntity(documentId); | ||
|
||
document.submit(); | ||
|
||
documentRepository.save(document); | ||
} | ||
|
||
private DocumentEntity validateDocumentIdAndGetDocumentEntity(String documentId) { | ||
var document = documentRepository.findById(documentId) | ||
.orElseThrow(() -> DocumentNotFoundException.EXCEPTION); | ||
|
||
if(!document.getStatus().equals(DocumentStatus.RELEASED)) { | ||
throw DocumentIllegalStatusException.EXCEPTION; | ||
} | ||
return document; | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
...ain/java/com/example/whopper/domain/document/application/impl/ReleaseDocumentService.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,43 @@ | ||
package com.example.whopper.domain.document.application.impl; | ||
|
||
import com.example.whopper.domain.document.application.usecase.ReleaseDocumentUseCase; | ||
import com.example.whopper.domain.document.dao.DocumentRepository; | ||
import com.example.whopper.domain.document.domain.DocumentEntity; | ||
import com.example.whopper.domain.document.domain.element.DocumentStatus; | ||
import com.example.whopper.domain.document.exception.DocumentIllegalStatusException; | ||
import com.example.whopper.domain.document.exception.DocumentNotFoundException; | ||
import com.example.whopper.domain.feedback.dao.FeedbackMongoRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReleaseDocumentService implements ReleaseDocumentUseCase { | ||
private final DocumentRepository documentRepository; | ||
private final FeedbackMongoRepository feedbackMongoRepository; | ||
|
||
@Override | ||
public void release(String documentId) { | ||
var document = validateDocumentIdAndGetDocumentEntity(documentId); | ||
|
||
document.release(); | ||
|
||
deleteFeedback(document); | ||
|
||
documentRepository.save(document); | ||
} | ||
|
||
private void deleteFeedback(DocumentEntity document) { | ||
feedbackMongoRepository.deleteAllByDocument(document); | ||
} | ||
|
||
private DocumentEntity validateDocumentIdAndGetDocumentEntity(String documentId) { | ||
var document = documentRepository.findById(documentId) | ||
.orElseThrow(() -> DocumentNotFoundException.EXCEPTION); | ||
|
||
if(!document.getStatus().equals(DocumentStatus.SUBMITTED)) { | ||
throw DocumentIllegalStatusException.EXCEPTION; | ||
} | ||
return document; | ||
} | ||
} |
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
49 changes: 6 additions & 43 deletions
49
...n/java/com/example/whopper/domain/document/application/impl/UpdateProjectListService.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 |
---|---|---|
@@ -1,60 +1,23 @@ | ||
package com.example.whopper.domain.document.application.impl; | ||
|
||
import com.example.whopper.domain.document.application.base.AbstractUpdateElementServiceBase; | ||
import com.example.whopper.domain.document.application.usecase.UpdateProjectListUseCase; | ||
import com.example.whopper.domain.document.dao.DocumentRepository; | ||
import com.example.whopper.domain.document.domain.DocumentEntity; | ||
import com.example.whopper.domain.document.domain.element.DocumentStatus; | ||
import com.example.whopper.domain.document.domain.element.ProjectElement; | ||
import com.example.whopper.domain.document.dto.request.ProjectElementRequest; | ||
import com.example.whopper.domain.document.exception.DocumentModificationException; | ||
import com.example.whopper.domain.document.exception.ImageRequestSizeMismatchException; | ||
import com.example.whopper.global.utils.current.CurrentStudent; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.util.List; | ||
import java.util.stream.IntStream; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UpdateProjectListService implements UpdateProjectListUseCase { | ||
private final DocumentRepository documentRepository; | ||
private final CurrentStudent currentStudent; | ||
|
||
private void updateDocument(DocumentEntity document, List<ProjectElement> list) { | ||
document.updateProjectList(list); | ||
public class UpdateProjectListService extends AbstractUpdateElementServiceBase<List<ProjectElement>> implements UpdateProjectListUseCase { | ||
public UpdateProjectListService(DocumentRepository documentRepository, CurrentStudent currentUser) { | ||
super(documentRepository, currentUser); | ||
} | ||
|
||
@Override | ||
public void update(List<ProjectElementRequest> request, List<MultipartFile> images) { | ||
if (images.size() != request.size()) { | ||
throw ImageRequestSizeMismatchException.EXCEPTION; | ||
} | ||
|
||
var document = currentStudent.getDocument(); | ||
|
||
if (!document.getStatus().equals(DocumentStatus.ONGOING)) { | ||
throw DocumentModificationException.EXCEPTION; | ||
} | ||
|
||
List<String> imagePathList = images.stream() | ||
.map(img -> { | ||
if (img.isEmpty()) { | ||
return ""; | ||
} | ||
return "image path"; // 저장 후 접근 가능한 URL | ||
}).toList(); // TODO: 7/27/24 이미지 저장에 대해 생각해야함 | ||
// if (images.get() == null) => "" | ||
|
||
var projectElementList = IntStream.range(0, request.size()) | ||
.mapToObj(i -> ProjectElement.fromProjectElementRequest( | ||
request.get(i), | ||
imagePathList.get(i)) | ||
) | ||
.toList(); | ||
|
||
updateDocument(document, projectElementList); | ||
documentRepository.save(document); | ||
protected void updateDocument(DocumentEntity document, List<ProjectElement> list) { | ||
document.updateProjectList(list); | ||
} | ||
} |
Oops, something went wrong.