260806_01_ENH: 파일첨부 발송 추가

This commit is contained in:
2026-08-06 14:36:13 +09:00
parent c4c57654da
commit de67433539
17 changed files with 616 additions and 69 deletions

View File

@@ -2,7 +2,7 @@ package com.kri.notihub.server.controller;
import com.kri.common.feature.web.RequestUserContext;
import com.kri.notihub.server.common.enums.ChannelType;
import com.kri.notihub.server.common.enums.SendType;
import com.kri.notihub.server.dto.email.EmailAttachmentDto;
import com.kri.notihub.server.dto.template.TemplateBasicDto;
import com.kri.notihub.server.dto.template.TemplateDto;
import com.kri.notihub.server.dto.template.TemplateSummaryDto;
@@ -11,16 +11,21 @@ import com.kri.notihub.server.service.TemplateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@@ -48,27 +53,38 @@ public class TemplateController {
return templateService.getTemplate(tmplatIdx);
}
@Operation(summary = "템플릿 생성")
@PutMapping
@Operation(summary = "템플릿 첨부파일 개별 다운로드")
@GetMapping("/{tmplatIdx}/attachment")
public ResponseEntity<byte[]> downloadAttachment(
@PathVariable long tmplatIdx,
@RequestParam String fileName
) {
EmailAttachmentDto attachment = templateService.downloadAttachment(tmplatIdx, fileName);
String encodedFileName = URLEncoder.encode(attachment.fileName(), StandardCharsets.UTF_8)
.replace("+", "%20");
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION,
"attachment; filename*=UTF-8''" + encodedFileName)
.header(HttpHeaders.CACHE_CONTROL, "no-store")
.contentType(MediaType.parseMediaType(attachment.contentType()))
.contentLength(attachment.content().length)
.body(attachment.content());
}
@Operation(summary = "첨부파일을 포함한 템플릿 생성")
@PutMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public TemplateDto createTemplate(
@Valid @RequestBody TemplateBasicDto template,
@Valid @RequestPart("template") TemplateBasicDto template,
@RequestPart(value = "files", required = false) List<MultipartFile> files,
RequestUserContext ctx
) {
TemplateDto newTmplat = templateService.createTemplate(template.getItrntPrjctCd(), template,
ctx.getUserId());
if (template.getTmplatTy() == SendType.EMAIL) {
String newHtml = fileService.syncOnSave(
newTmplat.getItrntPrjctCd(),
newTmplat.getTmplatIdx(),
newTmplat.getTmplatBody()
);
newTmplat.setTmplatBody(newHtml);
templateService.updateTemplateBodyWithCreate(newTmplat);
}
return newTmplat;
return templateService.createTemplate(
template.getItrntPrjctCd(),
template,
files,
ctx.getUserId()
);
}
@Operation(summary = "바디에 사용하는 이미지 업로드")
@@ -78,22 +94,20 @@ public class TemplateController {
return fileService.storeTempFile(itrntPrjctCd, file);
}
@Operation(summary = "템플릿 수정")
@PatchMapping
@Operation(summary = "첨부파일 변경을 포함한 템플릿 수정")
@PatchMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public TemplateDto updateTemplate(
@Valid @RequestBody TemplateDto template,
@Valid @RequestPart("template") TemplateDto template,
@RequestPart(value = "files", required = false) List<MultipartFile> files,
@RequestParam(value = "deleteFileNames", required = false) List<String> deleteFileNames,
RequestUserContext ctx
) {
if (template.getTmplatTy() == SendType.EMAIL) {
String newHtml = fileService.syncOnSave(
template.getItrntPrjctCd(),
template.getTmplatIdx(),
template.getTmplatBody()
);
template.setTmplatBody(newHtml);
}
return templateService.updateTemplate(template, ctx.getUserId());
return templateService.updateTemplate(
template,
files,
deleteFileNames,
ctx.getUserId()
);
}
@Operation(summary = "템플릿 삭제(소프트 삭제)")