diff --git a/Match-Api/src/main/generated/com/example/matchapi/admin/notice/mapper/AdminNoticeMapperImpl.java b/Match-Api/src/main/generated/com/example/matchapi/admin/notice/mapper/AdminNoticeMapperImpl.java index c0bd334d..0bd2a686 100644 --- a/Match-Api/src/main/generated/com/example/matchapi/admin/notice/mapper/AdminNoticeMapperImpl.java +++ b/Match-Api/src/main/generated/com/example/matchapi/admin/notice/mapper/AdminNoticeMapperImpl.java @@ -10,7 +10,7 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2024-02-14T17:44:03+0900", + date = "2024-01-17T19:31:30+0900", comments = "version: 1.5.3.Final, compiler: javac, environment: Java 11.0.19 (Oracle Corporation)" ) public class AdminNoticeMapperImpl implements AdminNoticeMapper { diff --git a/Match-Api/src/main/java/com/example/matchapi/admin/notice/controller/AdminNoticeController.java b/Match-Api/src/main/java/com/example/matchapi/admin/notice/controller/AdminNoticeController.java index 2f7d1fd4..172dfd28 100644 --- a/Match-Api/src/main/java/com/example/matchapi/admin/notice/controller/AdminNoticeController.java +++ b/Match-Api/src/main/java/com/example/matchapi/admin/notice/controller/AdminNoticeController.java @@ -1,6 +1,7 @@ package com.example.matchapi.admin.notice.controller; import com.example.matchapi.admin.event.dto.EventUploadReq; +import com.example.matchapi.admin.notice.dto.NoticeUpdateReq; import com.example.matchapi.admin.notice.dto.NoticeUploadReq; import com.example.matchapi.admin.notice.mapper.AdminNoticeMapper; import com.example.matchapi.admin.notice.service.AdminNoticeService; @@ -47,4 +48,11 @@ public CommonResponse deleteNotice(@PathVariable Long noticeId){ adminNoticeService.deleteNotice(noticeId); return CommonResponse.onSuccess("삭제 성공"); } + + @PatchMapping("/{noticeId}") + @Operation(summary = "ADMIN-10-03 공지사항 수정") + public CommonResponse updateNotice(@PathVariable Long noticeId, @Valid @RequestBody NoticeUpdateReq noticeUploadReq){ + adminNoticeService.updateNotice(noticeId, noticeUploadReq); + return CommonResponse.onSuccess("수정 성공"); + } } diff --git a/Match-Api/src/main/java/com/example/matchapi/admin/notice/dto/NoticeUpdateReq.java b/Match-Api/src/main/java/com/example/matchapi/admin/notice/dto/NoticeUpdateReq.java new file mode 100644 index 00000000..6bf87a08 --- /dev/null +++ b/Match-Api/src/main/java/com/example/matchapi/admin/notice/dto/NoticeUpdateReq.java @@ -0,0 +1,50 @@ +package com.example.matchapi.admin.notice.dto; + +import java.util.List; + + +import com.example.matchapi.common.model.ContentsList; +import com.example.matchdomain.notice.enums.NoticeType; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ToString +public class NoticeUpdateReq { + @Schema(description = "공지사항 제목", required = true, example = "공지사항 제목입니다.") + private String title; + + @Schema(description = "공지사항 타입", required = true, example = "EVENT") + private NoticeType noticeType; + + @Schema(description = "공지사항 내용 수정 리스트", required = false) + private List noticeContents; + + @Schema(description = "추가할 컨텐츠 리스트", required = false) + private List contentsList; + + @Schema(description = "삭제할 컨텐츠 ID 리스트", required = false) + private List deleteContentsList; + + @Getter + @Setter + @Builder + @AllArgsConstructor + @NoArgsConstructor + @ToString + public static class NoticeContent{ + private Long contentId; + + private String contents; + } +} diff --git a/Match-Api/src/main/java/com/example/matchapi/admin/notice/mapper/AdminNoticeMapper.java b/Match-Api/src/main/java/com/example/matchapi/admin/notice/mapper/AdminNoticeMapper.java index ae0793a0..6ec548e6 100644 --- a/Match-Api/src/main/java/com/example/matchapi/admin/notice/mapper/AdminNoticeMapper.java +++ b/Match-Api/src/main/java/com/example/matchapi/admin/notice/mapper/AdminNoticeMapper.java @@ -16,4 +16,6 @@ public interface AdminNoticeMapper { List toEntityNoticeContents(List contentsList); Notice toEntityNotice(NoticeUploadReq noticeUploadReq); + + NoticeContent toEntityNoticeContent(ContentsList contentsList, Long noticeId); } diff --git a/Match-Api/src/main/java/com/example/matchapi/admin/notice/service/AdminNoticeService.java b/Match-Api/src/main/java/com/example/matchapi/admin/notice/service/AdminNoticeService.java index 8eab39e1..c7af55ea 100644 --- a/Match-Api/src/main/java/com/example/matchapi/admin/notice/service/AdminNoticeService.java +++ b/Match-Api/src/main/java/com/example/matchapi/admin/notice/service/AdminNoticeService.java @@ -1,5 +1,8 @@ package com.example.matchapi.admin.notice.service; +import com.example.matchapi.admin.notice.dto.NoticeUpdateReq; +import com.example.matchapi.admin.notice.mapper.AdminNoticeMapper; +import com.example.matchapi.common.model.ContentsList; import com.example.matchapi.notice.converter.NoticeConverter; import com.example.matchapi.notice.dto.NoticeRes; import com.example.matchcommon.reponse.PageResponse; @@ -7,8 +10,6 @@ import com.example.matchdomain.notice.adaptor.NoticeContentAdaptor; import com.example.matchdomain.notice.entity.Notice; import com.example.matchdomain.notice.entity.NoticeContent; -import com.example.matchdomain.notice.repository.NoticeContentRepository; -import com.example.matchdomain.notice.repository.NoticeRepository; import com.example.matchinfrastructure.config.s3.S3UploadService; import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.CacheEvict; @@ -16,6 +17,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; import static com.example.matchdomain.common.model.ContentsType.IMG; @@ -28,6 +30,8 @@ public class AdminNoticeService { private final NoticeAdapter noticeAdapter; private final S3UploadService s3UploadService; private final NoticeConverter noticeConverter; + private final AdminNoticeMapper mapper = AdminNoticeMapper.INSTANCE; + @CacheEvict(value = "noticeCache", allEntries = true, cacheManager = "ehcacheManager") public void uploadNoticeList(List noticeContents, Notice notice) { @@ -53,4 +57,32 @@ public PageResponse> getNoticeList(int page, int size Page notices = noticeAdapter.getNoticeList(page,size); return new PageResponse<>(notices.isLast(), notices.getTotalElements(), noticeConverter.convertToNoticeList(notices.getContent())); } + + @Transactional + public void updateNotice(Long noticeId, NoticeUpdateReq noticeUploadReq) { + Notice notice = noticeAdapter.findNoticeDetail(noticeId); + notice.updateNotice(noticeUploadReq.getTitle(), noticeUploadReq.getNoticeType()); + updateNoticeContent(noticeUploadReq, noticeId); + } + + private void updateNoticeContent(NoticeUpdateReq noticeUploadReq, Long noticeId) { + if(noticeUploadReq.getDeleteContentsList() != null){ + noticeContentAdaptor.deleteNoticeContent(noticeUploadReq.getDeleteContentsList()); + } + if(noticeUploadReq.getContentsList() != null){ + List noticeContents = new ArrayList<>(); + for(ContentsList contentsList : noticeUploadReq.getContentsList()){ + noticeContents.add(mapper.toEntityNoticeContent(contentsList, noticeId)); + } + noticeContentAdaptor.saveAll(noticeContents); + } + if(noticeUploadReq.getNoticeContents() != null){ + for(NoticeUpdateReq.NoticeContent noticeContent : noticeUploadReq.getNoticeContents()){ + NoticeContent content = noticeContentAdaptor.findById(noticeContent.getContentId()); + content.updateContents(noticeContent.getContents()); + noticeContentAdaptor.save(content); + } + } + + } } diff --git a/Match-Domain/src/main/java/com/example/matchdomain/common/model/ContentsEntity.java b/Match-Domain/src/main/java/com/example/matchdomain/common/model/ContentsEntity.java index 8bbc687e..eb76b91a 100644 --- a/Match-Domain/src/main/java/com/example/matchdomain/common/model/ContentsEntity.java +++ b/Match-Domain/src/main/java/com/example/matchdomain/common/model/ContentsEntity.java @@ -34,4 +34,8 @@ public abstract class ContentsEntity { @Enumerated(EnumType.STRING) private Status status = Status.ACTIVE; + + public void updateContents(String contents) { + this.contents = contents; + } } diff --git a/Match-Domain/src/main/java/com/example/matchdomain/notice/adaptor/NoticeAdapter.java b/Match-Domain/src/main/java/com/example/matchdomain/notice/adaptor/NoticeAdapter.java index fdffb469..1a1db01c 100644 --- a/Match-Domain/src/main/java/com/example/matchdomain/notice/adaptor/NoticeAdapter.java +++ b/Match-Domain/src/main/java/com/example/matchdomain/notice/adaptor/NoticeAdapter.java @@ -3,6 +3,7 @@ import com.example.matchcommon.annotation.Adaptor; import com.example.matchcommon.exception.BadRequestException; import com.example.matchdomain.notice.entity.Notice; +import com.example.matchdomain.notice.repository.NoticeContentRepository; import com.example.matchdomain.notice.repository.NoticeRepository; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -11,6 +12,8 @@ import static com.example.matchdomain.notice.exception.GetNoticeErrorCode.NOT_EXIST_NOTICE; +import java.util.List; + @Adaptor @RequiredArgsConstructor public class NoticeAdapter { @@ -32,4 +35,5 @@ public Notice save(Notice notice) { public void delete(Notice notice) { noticeRepository.deleteById(notice.getId()); } + } diff --git a/Match-Domain/src/main/java/com/example/matchdomain/notice/adaptor/NoticeContentAdaptor.java b/Match-Domain/src/main/java/com/example/matchdomain/notice/adaptor/NoticeContentAdaptor.java index 53580232..7bd2adbc 100644 --- a/Match-Domain/src/main/java/com/example/matchdomain/notice/adaptor/NoticeContentAdaptor.java +++ b/Match-Domain/src/main/java/com/example/matchdomain/notice/adaptor/NoticeContentAdaptor.java @@ -1,6 +1,9 @@ package com.example.matchdomain.notice.adaptor; +import static com.example.matchdomain.notice.exception.GetNoticeErrorCode.*; + import com.example.matchcommon.annotation.Adaptor; +import com.example.matchcommon.exception.BadRequestException; import com.example.matchdomain.notice.entity.NoticeContent; import com.example.matchdomain.notice.repository.NoticeContentRepository; import lombok.RequiredArgsConstructor; @@ -15,4 +18,17 @@ public class NoticeContentAdaptor { public void saveAll(List noticeContents) { contentRepository.saveAll(noticeContents); } + + public void deleteNoticeContent(List deleteContentsList) { + contentRepository.deleteAllByIdInBatch(deleteContentsList); + } + + public NoticeContent findById(Long contentId) { + return contentRepository.findById(contentId).orElseThrow(()-> + new BadRequestException(NOT_EXIST_NOTICE_CONTENT)); + } + + public NoticeContent save(NoticeContent content) { + return contentRepository.save(content); + } } diff --git a/Match-Domain/src/main/java/com/example/matchdomain/notice/entity/Notice.java b/Match-Domain/src/main/java/com/example/matchdomain/notice/entity/Notice.java index 3af2d3b8..18f1f176 100644 --- a/Match-Domain/src/main/java/com/example/matchdomain/notice/entity/Notice.java +++ b/Match-Domain/src/main/java/com/example/matchdomain/notice/entity/Notice.java @@ -37,4 +37,8 @@ public class Notice extends BaseEntity { private String title; + public void updateNotice(String title, NoticeType noticeType) { + this.title = title; + this.noticeType = noticeType; + } } diff --git a/Match-Domain/src/main/java/com/example/matchdomain/notice/exception/GetNoticeErrorCode.java b/Match-Domain/src/main/java/com/example/matchdomain/notice/exception/GetNoticeErrorCode.java index aa6432a9..f3a950b3 100644 --- a/Match-Domain/src/main/java/com/example/matchdomain/notice/exception/GetNoticeErrorCode.java +++ b/Match-Domain/src/main/java/com/example/matchdomain/notice/exception/GetNoticeErrorCode.java @@ -15,7 +15,8 @@ public enum GetNoticeErrorCode implements BaseErrorCode { @ExplainError("해당 공지사항이 존재하지 않습니다.") - NOT_EXIST_NOTICE(HttpStatus.BAD_REQUEST,false,"NOTICE_001","해당 공지사항이 존재하지 않습니다.."); + NOT_EXIST_NOTICE(HttpStatus.BAD_REQUEST,false,"NOTICE_001","해당 공지사항이 존재하지 않습니다..") + ,NOT_EXIST_NOTICE_CONTENT(HttpStatus.BAD_REQUEST,false,"NOTICE_002","해당 공지사항의 컨텐츠가 존재하지 않습니다."); private final HttpStatus httpStatus; private final boolean isSuccess;