동기화
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package com.ga.common.upload;
|
||||
|
||||
import com.ga.common.annotation.RequirePermission;
|
||||
import com.ga.common.model.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/upload-templates")
|
||||
@Tag(name = "업로드 템플릿 관리")
|
||||
@RequiredArgsConstructor
|
||||
public class UploadController {
|
||||
|
||||
private final UploadTemplateService templateService;
|
||||
private final UploadService uploadService;
|
||||
|
||||
/* ==========================================================
|
||||
템플릿 CRUD
|
||||
========================================================== */
|
||||
@GetMapping
|
||||
@RequirePermission(menu = "DATA_UPLOAD", perm = "READ")
|
||||
public ApiResponse<List<UploadTemplateVO>> list(@RequestParam(required = false) String category,
|
||||
@RequestParam(required = false) String companyCode) {
|
||||
return ApiResponse.ok(templateService.list(category, companyCode));
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@RequirePermission(menu = "DATA_UPLOAD", perm = "READ")
|
||||
public ApiResponse<TemplateDetailResp> detail(@PathVariable Long id) {
|
||||
TemplateDetailResp r = new TemplateDetailResp();
|
||||
r.setTemplate(templateService.get(id));
|
||||
r.setColumns(templateService.getColumns(id));
|
||||
return ApiResponse.ok(r);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@RequirePermission(menu = "DATA_UPLOAD", perm = "CREATE")
|
||||
public ApiResponse<Long> create(@Valid @RequestBody TemplateSaveReq req) {
|
||||
return ApiResponse.ok(templateService.create(req.getTemplate(), req.getColumns()));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
@RequirePermission(menu = "DATA_UPLOAD", perm = "UPDATE")
|
||||
public ApiResponse<Void> update(@PathVariable Long id, @Valid @RequestBody TemplateSaveReq req) {
|
||||
templateService.update(id, req.getTemplate(), req.getColumns());
|
||||
return ApiResponse.ok();
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
@RequirePermission(menu = "DATA_UPLOAD", perm = "DELETE")
|
||||
public ApiResponse<Void> delete(@PathVariable Long id) {
|
||||
templateService.delete(id);
|
||||
return ApiResponse.ok();
|
||||
}
|
||||
|
||||
/* ==========================================================
|
||||
업로드 처리
|
||||
========================================================== */
|
||||
@PostMapping("/{templateCode}/upload")
|
||||
@RequirePermission(menu = "DATA_UPLOAD", perm = "CREATE")
|
||||
public ApiResponse<UploadResultResp> upload(@PathVariable String templateCode,
|
||||
@RequestParam MultipartFile file) {
|
||||
return ApiResponse.ok(uploadService.processUpload(templateCode, file));
|
||||
}
|
||||
|
||||
@PostMapping("/{templateCode}/preview")
|
||||
@RequirePermission(menu = "DATA_UPLOAD", perm = "READ")
|
||||
public ApiResponse<List<Map<String, Object>>> preview(@PathVariable String templateCode,
|
||||
@RequestParam MultipartFile file,
|
||||
@RequestParam(defaultValue = "5") int rows) {
|
||||
return ApiResponse.ok(uploadService.preview(templateCode, file, rows));
|
||||
}
|
||||
|
||||
/* ==========================================================
|
||||
요청/응답 DTO
|
||||
========================================================== */
|
||||
@Data
|
||||
public static class TemplateSaveReq {
|
||||
private UploadTemplateVO template;
|
||||
private List<UploadTemplateColumnVO> columns;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TemplateDetailResp {
|
||||
private UploadTemplateVO template;
|
||||
private List<UploadTemplateColumnVO> columns;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user