generated from Bamdoliro/repository-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[새기능] 어드민 수험표 전체 다운로드
- Loading branch information
Showing
6 changed files
with
207 additions
and
3 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
70 changes: 70 additions & 0 deletions
70
src/main/java/com/bamdoliro/maru/application/form/GenerateAllAdmissionTicketUseCase.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,70 @@ | ||
package com.bamdoliro.maru.application.form; | ||
|
||
import com.bamdoliro.maru.domain.form.domain.Form; | ||
import com.bamdoliro.maru.domain.form.domain.type.FormStatus; | ||
import com.bamdoliro.maru.infrastructure.pdf.GeneratePdfService; | ||
import com.bamdoliro.maru.infrastructure.pdf.MergePdfService; | ||
import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository; | ||
import com.bamdoliro.maru.infrastructure.s3.FileService; | ||
import com.bamdoliro.maru.infrastructure.s3.constants.FolderConstant; | ||
import com.bamdoliro.maru.infrastructure.thymeleaf.ProcessTemplateService; | ||
import com.bamdoliro.maru.infrastructure.thymeleaf.Templates; | ||
import com.bamdoliro.maru.shared.annotation.UseCase; | ||
import com.bamdoliro.maru.shared.constants.Schedule; | ||
import com.itextpdf.kernel.pdf.PdfDocument; | ||
import com.itextpdf.kernel.pdf.PdfWriter; | ||
import com.itextpdf.kernel.utils.PdfMerger; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.core.io.ByteArrayResource; | ||
|
||
import java.util.List; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.util.Map; | ||
|
||
import static com.bamdoliro.maru.shared.constants.Schedule.*; | ||
|
||
@RequiredArgsConstructor | ||
@UseCase | ||
public class GenerateAllAdmissionTicketUseCase { | ||
|
||
private final FormRepository formRepository; | ||
private final ProcessTemplateService processTemplateService; | ||
private final GeneratePdfService generatePdfService; | ||
private final MergePdfService mergePdfService; | ||
private final FileService fileService; | ||
|
||
public ByteArrayResource execute() { | ||
List<Form> formList = formRepository.findByStatus(FormStatus.FIRST_PASSED); | ||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
PdfDocument mergedDocument = new PdfDocument(new PdfWriter(outputStream)); | ||
PdfMerger pdfMerger = new PdfMerger(mergedDocument); | ||
|
||
formList.forEach(form -> mergePdfService.execute(pdfMerger, generateAdmissionTicket(form))); | ||
|
||
mergedDocument.close(); | ||
pdfMerger.close(); | ||
|
||
return new ByteArrayResource(outputStream.toByteArray()); | ||
} | ||
|
||
private ByteArrayOutputStream generateAdmissionTicket(Form form) { | ||
|
||
Map<String, Object> formMap = Map.ofEntries( | ||
Map.entry("form", form), | ||
Map.entry("year", Schedule.getAdmissionYear()), | ||
Map.entry("codingTest", Schedule.toLocaleString(CODING_TEST)), | ||
Map.entry("ncs", Schedule.toLocaleString(NCS)), | ||
Map.entry("depthInterview", Schedule.toLocaleString(DEPTH_INTERVIEW)), | ||
Map.entry("physicalExamination", Schedule.toLocaleString(PHYSICAL_EXAMINATION)), | ||
Map.entry("announcementOfSecondPass", Schedule.toLocaleString(ANNOUNCEMENT_OF_SECOND_PASS)), | ||
Map.entry("meisterTalentEntranceTime", Schedule.toLocaleString(MEISTER_TALENT_ENTRANCE_TIME)), | ||
Map.entry("meisterTalentExclusionEntranceTime", Schedule.toLocaleString(MEISTER_TALENT_EXCLUSION_ENTRANCE_TIME)), | ||
Map.entry("entranceRegistrationTime", Schedule.toLocaleString(ENTRANCE_REGISTRATION_PERIOD_START, ENTRANCE_REGISTRATION_PERIOD_END)), | ||
Map.entry("identificationPictureUri", fileService.getPresignedUrl(FolderConstant.IDENTIFICATION_PICTURE, form.getUser().getUuid().toString()).getDownloadUrl()) | ||
); | ||
String html = processTemplateService.execute(Templates.ADMISSION_TICKET, formMap); | ||
|
||
return generatePdfService.execute(html); | ||
} | ||
} |
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
71 changes: 71 additions & 0 deletions
71
src/test/java/com/bamdoliro/maru/application/form/GenerateAllAdmissionTicketUseCaseTest.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,71 @@ | ||
package com.bamdoliro.maru.application.form; | ||
|
||
import com.bamdoliro.maru.domain.form.domain.Form; | ||
import com.bamdoliro.maru.domain.form.domain.type.FormStatus; | ||
import com.bamdoliro.maru.domain.form.domain.type.FormType; | ||
import com.bamdoliro.maru.infrastructure.pdf.GeneratePdfService; | ||
import com.bamdoliro.maru.infrastructure.pdf.MergePdfService; | ||
import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository; | ||
import com.bamdoliro.maru.infrastructure.s3.FileService; | ||
import com.bamdoliro.maru.infrastructure.thymeleaf.ProcessTemplateService; | ||
import com.bamdoliro.maru.shared.fixture.FormFixture; | ||
import com.bamdoliro.maru.shared.fixture.SharedFixture; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class GenerateAllAdmissionTicketUseCaseTest { | ||
|
||
@InjectMocks | ||
private GenerateAllAdmissionTicketUseCase generateAllAdmissionTicketUseCase; | ||
|
||
@Mock | ||
private ProcessTemplateService processTemplateService; | ||
|
||
@Mock | ||
private GeneratePdfService generatePdfService; | ||
|
||
@Mock | ||
private FileService fileService; | ||
|
||
@Mock | ||
private MergePdfService mergePdfService; | ||
|
||
@Mock | ||
private FormRepository formRepository; | ||
|
||
@Test | ||
void 모든_1차_합격자의_수험표를_생성한다() { | ||
// given | ||
List<Form> formList = new ArrayList<>(); | ||
formList.add(FormFixture.createForm(FormType.REGULAR)); | ||
formList.add(FormFixture.createForm(FormType.MEISTER_TALENT)); | ||
formList.forEach(Form::firstPass); | ||
given(formRepository.findByStatus(FormStatus.FIRST_PASSED)).willReturn(formList); | ||
given(processTemplateService.execute(any(String.class), any(Map.class))).willReturn("html"); | ||
given(fileService.getPresignedUrl(any(String.class), any(String.class))).willReturn(SharedFixture.createFormUrlResponse()); | ||
given(generatePdfService.execute(any(String.class))).willReturn(new ByteArrayOutputStream()); | ||
|
||
// when | ||
generateAllAdmissionTicketUseCase.execute(); | ||
|
||
//then | ||
verify(formRepository, times(1)).findByStatus(FormStatus.FIRST_PASSED); | ||
verify(processTemplateService, times(2)).execute(any(String.class), any(Map.class)); | ||
verify(generatePdfService, times(2)).execute(any(String.class)); | ||
verify(fileService, times(2)).getPresignedUrl(any(String.class), any(String.class)); | ||
} | ||
} |
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