공지사항 수정
This commit is contained in:
@@ -11,9 +11,14 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
class CreateNoticeController {
|
||||
@@ -23,8 +28,13 @@ class CreateNoticeController {
|
||||
ResponseEntity<?> operate(@RequestBody @Valid CreateNoticeReqVO reqVO, BindingResult bindingResult) {
|
||||
|
||||
if (bindingResult.hasErrors()) {
|
||||
List<String> fieldOrder = Arrays.asList("title", "content", "visible", "startDate", "endDate");
|
||||
|
||||
List<FieldError> sortedErrors = bindingResult.getFieldErrors().stream()
|
||||
.sorted(Comparator.comparingInt(error -> fieldOrder.indexOf(error.getField())))
|
||||
.toList();
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||
.body(bindingResult.getFieldErrors());
|
||||
.body(sortedErrors);
|
||||
}
|
||||
|
||||
CreateNotice article =
|
||||
|
||||
@@ -15,19 +15,19 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class CreateNoticeReqVO {
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
@NotBlank(message = "제목은 필수입력값입니다.")
|
||||
private String title;
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
@NotBlank(message = "내용은 {valid.common.required}")
|
||||
private String content;
|
||||
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
@NotNull(message = "노출 여부는 {valid.common.required}")
|
||||
private Boolean visible;
|
||||
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
@NotNull(message = "시작일은 {valid.common.required}")
|
||||
private LocalDateTime startDate;
|
||||
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
@NotNull(message = "종료일은 {valid.common.required}")
|
||||
private LocalDateTime endDate;
|
||||
|
||||
private List<String> fileMappingId;
|
||||
|
||||
@@ -11,10 +11,15 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
class UpdateNoticeController {
|
||||
@@ -26,8 +31,13 @@ class UpdateNoticeController {
|
||||
|
||||
|
||||
if (bindingResult.hasErrors()) {
|
||||
List<String> fieldOrder = Arrays.asList("title", "content", "visible", "startDate", "endDate");
|
||||
|
||||
List<FieldError> sortedErrors = bindingResult.getFieldErrors().stream()
|
||||
.sorted(Comparator.comparingInt(error -> fieldOrder.indexOf(error.getField())))
|
||||
.toList();
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||
.body(bindingResult.getFieldErrors());
|
||||
.body(sortedErrors);
|
||||
}
|
||||
|
||||
updateFilePortIn.operate(
|
||||
|
||||
@@ -17,20 +17,20 @@ public class UpdateNoticeReqVO {
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
private Long id;
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
@NotBlank(message = "제목은 {valid.common.required}")
|
||||
private String title;
|
||||
|
||||
@NotBlank(message = "{valid.common.required}")
|
||||
@NotBlank(message = "내용은 {valid.common.required}")
|
||||
private String content;
|
||||
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
@NotNull(message = "노출여부는 {valid.common.required}")
|
||||
private Boolean visible;
|
||||
|
||||
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
@NotNull(message = "시작일은 {valid.common.required}")
|
||||
private LocalDateTime startDate;
|
||||
|
||||
@NotNull(message = "{valid.common.required}")
|
||||
@NotNull(message = "종료일은 {valid.common.required}")
|
||||
private LocalDateTime endDate;
|
||||
|
||||
private List<String> fileMappingId;
|
||||
|
||||
@@ -29,15 +29,17 @@
|
||||
<tr>
|
||||
<th>첨부파일<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
|
||||
<td colspan="3">
|
||||
<div class="btns-row align-left publicFileInputs">
|
||||
<button type="button" class="btn btn-secondary" onclick="addFileInput();">
|
||||
<span class="btn-txt">다건 파일 첨부</span>
|
||||
</button>
|
||||
<div class="input-file-group">
|
||||
<label for="file" class="input-file-btn">
|
||||
<input type="file" name="multipartAttachments" id="file" onchange="uiUtil.uploadFile('NOTICE', this);" >
|
||||
<span class="file-txt">파일첨부</span>
|
||||
</label>
|
||||
<p class="desc">첨부 가능 파일 형식: 문서(pdf, docx, xlsx, pptx, hwp), 이미지(jpg, jpeg, png, gif), 기타(zip,
|
||||
csv, txt) / 파일당 최대 5MB까지 등록 가능합니다.</p>
|
||||
<ul class="file-list input-group" id="noticeAttachments">
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -74,8 +76,6 @@
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -164,7 +164,8 @@
|
||||
},
|
||||
// validation fail
|
||||
422: function (res) {
|
||||
alert("error");
|
||||
debugger
|
||||
alert(res.responseJSON[0].defaultMessage);
|
||||
// $(res.responseJSON).each((idx, oj) => {
|
||||
// let target = $(f).find('[name=' + oj.field + ']');
|
||||
// target.addClass('is-invalid');
|
||||
|
||||
@@ -220,7 +220,7 @@
|
||||
},
|
||||
// validation fail
|
||||
422: function (res) {
|
||||
alert('error');
|
||||
alert(res.responseJSON[0].defaultMessage);
|
||||
// $(res.responseJSON).each((idx, oj) => {
|
||||
// let target = $(f).find('[name=' + oj.field + ']');
|
||||
// target.addClass('is-invalid');
|
||||
|
||||
Reference in New Issue
Block a user