공지사항 수정

This commit is contained in:
주수현
2025-07-11 14:54:35 +09:00
parent 6c78438d7c
commit b4a5f0b14e
6 changed files with 45 additions and 24 deletions

View File

@@ -11,9 +11,14 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
@Controller @Controller
@RequiredArgsConstructor @RequiredArgsConstructor
class CreateNoticeController { class CreateNoticeController {
@@ -23,8 +28,13 @@ class CreateNoticeController {
ResponseEntity<?> operate(@RequestBody @Valid CreateNoticeReqVO reqVO, BindingResult bindingResult) { ResponseEntity<?> operate(@RequestBody @Valid CreateNoticeReqVO reqVO, BindingResult bindingResult) {
if (bindingResult.hasErrors()) { 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) return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
.body(bindingResult.getFieldErrors()); .body(sortedErrors);
} }
CreateNotice article = CreateNotice article =

View File

@@ -15,19 +15,19 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
@EqualsAndHashCode @EqualsAndHashCode
public class CreateNoticeReqVO { public class CreateNoticeReqVO {
@NotBlank(message = "{valid.common.required}") @NotBlank(message = "제목은 필수입력값입니다.")
private String title; private String title;
@NotBlank(message = "{valid.common.required}") @NotBlank(message = "내용은 {valid.common.required}")
private String content; private String content;
@NotNull(message = "{valid.common.required}") @NotNull(message = "노출 여부는 {valid.common.required}")
private Boolean visible; private Boolean visible;
@NotNull(message = "{valid.common.required}") @NotNull(message = "시작일은 {valid.common.required}")
private LocalDateTime startDate; private LocalDateTime startDate;
@NotNull(message = "{valid.common.required}") @NotNull(message = "종료일은 {valid.common.required}")
private LocalDateTime endDate; private LocalDateTime endDate;
private List<String> fileMappingId; private List<String> fileMappingId;

View File

@@ -11,10 +11,15 @@ import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
@RestController @RestController
@RequiredArgsConstructor @RequiredArgsConstructor
class UpdateNoticeController { class UpdateNoticeController {
@@ -26,8 +31,13 @@ class UpdateNoticeController {
if (bindingResult.hasErrors()) { 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) return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
.body(bindingResult.getFieldErrors()); .body(sortedErrors);
} }
updateFilePortIn.operate( updateFilePortIn.operate(

View File

@@ -17,20 +17,20 @@ public class UpdateNoticeReqVO {
@NotNull(message = "{valid.common.required}") @NotNull(message = "{valid.common.required}")
private Long id; private Long id;
@NotBlank(message = "{valid.common.required}") @NotBlank(message = "제목은 {valid.common.required}")
private String title; private String title;
@NotBlank(message = "{valid.common.required}") @NotBlank(message = "내용은 {valid.common.required}")
private String content; private String content;
@NotNull(message = "{valid.common.required}") @NotNull(message = "노출여부는 {valid.common.required}")
private Boolean visible; private Boolean visible;
@NotNull(message = "{valid.common.required}") @NotNull(message = "시작일은 {valid.common.required}")
private LocalDateTime startDate; private LocalDateTime startDate;
@NotNull(message = "{valid.common.required}") @NotNull(message = "종료일은 {valid.common.required}")
private LocalDateTime endDate; private LocalDateTime endDate;
private List<String> fileMappingId; private List<String> fileMappingId;

View File

@@ -29,15 +29,17 @@
<tr> <tr>
<th>첨부파일<i class="ico-required-mark" role="img" aria-label="필수">*</i></th> <th>첨부파일<i class="ico-required-mark" role="img" aria-label="필수">*</i></th>
<td colspan="3"> <td colspan="3">
<div class="btns-row align-left publicFileInputs"> <div class="input-file-group">
<button type="button" class="btn btn-secondary" onclick="addFileInput();"> <label for="file" class="input-file-btn">
<span class="btn-txt">다건 파일 첨부</span> <input type="file" name="multipartAttachments" id="file" onchange="uiUtil.uploadFile('NOTICE', this);" >
</button> <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> </div>
</td> </td>
</tr> </tr>
@@ -74,8 +76,6 @@
<td></td> <td></td>
<td></td> <td></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@@ -164,7 +164,8 @@
}, },
// validation fail // validation fail
422: function (res) { 422: function (res) {
alert("error"); debugger
alert(res.responseJSON[0].defaultMessage);
// $(res.responseJSON).each((idx, oj) => { // $(res.responseJSON).each((idx, oj) => {
// let target = $(f).find('[name=' + oj.field + ']'); // let target = $(f).find('[name=' + oj.field + ']');
// target.addClass('is-invalid'); // target.addClass('is-invalid');

View File

@@ -220,7 +220,7 @@
}, },
// validation fail // validation fail
422: function (res) { 422: function (res) {
alert('error'); alert(res.responseJSON[0].defaultMessage);
// $(res.responseJSON).each((idx, oj) => { // $(res.responseJSON).each((idx, oj) => {
// let target = $(f).find('[name=' + oj.field + ']'); // let target = $(f).find('[name=' + oj.field + ']');
// target.addClass('is-invalid'); // target.addClass('is-invalid');