diff --git a/ideac-user/src/main/java/depth/main/ideac/domain/club_post/application/ClubPostService.java b/ideac-user/src/main/java/depth/main/ideac/domain/club_post/application/ClubPostService.java index bf0245d..b4a1863 100644 --- a/ideac-user/src/main/java/depth/main/ideac/domain/club_post/application/ClubPostService.java +++ b/ideac-user/src/main/java/depth/main/ideac/domain/club_post/application/ClubPostService.java @@ -7,7 +7,6 @@ import depth.main.ideac.domain.club_post.repository.ClubPostImageRepository; import depth.main.ideac.domain.club_post.repository.ClubPostRepository; import depth.main.ideac.domain.club_post.dto.response.ClubPostDetailRes; -import depth.main.ideac.domain.club_post.dto.request.UpdateClubPostReq; import depth.main.ideac.domain.user.domain.Role; import depth.main.ideac.domain.user.domain.User; import depth.main.ideac.global.error.DefaultException; @@ -87,7 +86,7 @@ public ClubPostDetailRes getDetailClubPosts(Long clubId) { } @Transactional - public Long createClubPost(Long userId, ClubPostReq clubPostReq, List images) throws IOException { + public Long createClubPost(Long userId, ClubPostReq clubPostReq) throws IOException { User user = userRepository.findById(userId) .orElseThrow(() -> new DefaultException(ErrorCode.USER_NOT_FOUND)); @@ -99,7 +98,7 @@ public Long createClubPost(Long userId, ClubPostReq clubPostReq, List images) throws IOException { + public void updateClubPost(Long clubPostId, Long userId, ClubPostReq updateClubPostReq) throws IOException { if (!isAdminOrWriter(clubPostId, userId)) { throw new AccessDeniedException("해당 게시글에 대한 권한이 없습니다."); } @@ -121,7 +120,7 @@ public void updateClubPost(Long clubPostId, Long userId, UpdateClubPostReq updat clubPost.setUrl2(updateClubPostReq.getUrl2()); this.deleteFile(clubPostId); - this.uploadFile(clubPost, images); + this.uploadFile(clubPost, updateClubPostReq.getImages()); } // 글 삭제 diff --git a/ideac-user/src/main/java/depth/main/ideac/domain/club_post/dto/request/ClubPostReq.java b/ideac-user/src/main/java/depth/main/ideac/domain/club_post/dto/request/ClubPostReq.java index c17d760..c2cde91 100644 --- a/ideac-user/src/main/java/depth/main/ideac/domain/club_post/dto/request/ClubPostReq.java +++ b/ideac-user/src/main/java/depth/main/ideac/domain/club_post/dto/request/ClubPostReq.java @@ -5,10 +5,15 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; @Getter @NoArgsConstructor @AllArgsConstructor +@Setter public class ClubPostReq { @NotBlank(message = "제목을 입력해야 합니다.") @@ -22,4 +27,6 @@ public class ClubPostReq { private String url2; + private List images; + } diff --git a/ideac-user/src/main/java/depth/main/ideac/domain/club_post/dto/request/UpdateClubPostReq.java b/ideac-user/src/main/java/depth/main/ideac/domain/club_post/dto/request/UpdateClubPostReq.java deleted file mode 100644 index 8416908..0000000 --- a/ideac-user/src/main/java/depth/main/ideac/domain/club_post/dto/request/UpdateClubPostReq.java +++ /dev/null @@ -1,26 +0,0 @@ -package depth.main.ideac.domain.club_post.dto.request; - -import jakarta.validation.constraints.NotBlank; -import jakarta.validation.constraints.Size; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; - - -@NoArgsConstructor -@AllArgsConstructor -@Getter -public class UpdateClubPostReq { - - @NotBlank(message = "제목을 입력해야 합니다.") - @Size(max = 100, message = "제목은 최대 100자까지 입력 가능합니다.") - private String title; - - @NotBlank(message = "내용을 입력해야 합니다.") - private String description; - - private String url1; - - private String url2; - -} diff --git a/ideac-user/src/main/java/depth/main/ideac/domain/club_post/presentation/ClubPostController.java b/ideac-user/src/main/java/depth/main/ideac/domain/club_post/presentation/ClubPostController.java index ee7decb..34732e1 100644 --- a/ideac-user/src/main/java/depth/main/ideac/domain/club_post/presentation/ClubPostController.java +++ b/ideac-user/src/main/java/depth/main/ideac/domain/club_post/presentation/ClubPostController.java @@ -1,10 +1,9 @@ package depth.main.ideac.domain.club_post.presentation; import depth.main.ideac.domain.club_post.application.ClubPostService; -import depth.main.ideac.domain.club_post.dto.response.ClubPostDetailRes; import depth.main.ideac.domain.club_post.dto.request.ClubPostReq; +import depth.main.ideac.domain.club_post.dto.response.ClubPostDetailRes; import depth.main.ideac.domain.club_post.dto.response.ClubPostRes; -import depth.main.ideac.domain.club_post.dto.request.UpdateClubPostReq; import depth.main.ideac.global.config.security.token.CurrentUser; import depth.main.ideac.global.config.security.token.UserPrincipal; import depth.main.ideac.global.payload.ApiResponse; @@ -17,14 +16,11 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.http.ResponseEntity; -import org.springframework.security.access.AccessDeniedException; import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; import java.io.IOException; import java.net.URI; -import java.util.List; @Tag(name = "ClubPost API", description = "동아리/학회 관련 API입니다.") @RequiredArgsConstructor @@ -70,9 +66,8 @@ public ResponseEntity getDetailClubPosts(@PathVariable Long id) { @Operation(summary = "글 등록", description = "동아리/학회 글을 등록하는 API입니다.") @PostMapping public ResponseEntity createClubPost(@CurrentUser UserPrincipal userPrincipal, - @Valid @RequestPart ClubPostReq clubPostReq, - @RequestPart("images") List images) throws IOException { - Long clubPostId = clubPostService.createClubPost(userPrincipal.getId(), clubPostReq, images); + @Valid @ModelAttribute ClubPostReq clubPostReq) throws IOException { + Long clubPostId = clubPostService.createClubPost(userPrincipal.getId(), clubPostReq); URI location = ServletUriComponentsBuilder.fromCurrentRequest() .path("/{id}") .buildAndExpand(clubPostId) @@ -84,9 +79,8 @@ public ResponseEntity createClubPost(@CurrentUser UserPrincipal userPrincipal @Operation(summary = "글 수정", description = "동아리/학회 글을 수정하는 API입니다.") @PutMapping("/{id}") public ResponseEntity updateClubPost(@CurrentUser UserPrincipal userPrincipal, @PathVariable Long id, - @Valid @RequestPart UpdateClubPostReq updateClubPostReq, - @RequestPart("images") List images) throws IOException { - clubPostService.updateClubPost(id, userPrincipal.getId(), updateClubPostReq, images); + @Valid @ModelAttribute ClubPostReq updateClubPostReq) throws IOException { + clubPostService.updateClubPost(id, userPrincipal.getId(), updateClubPostReq); return ResponseEntity.ok().build(); } diff --git a/ideac-user/src/main/java/depth/main/ideac/domain/project_post/application/ProjectPostService.java b/ideac-user/src/main/java/depth/main/ideac/domain/project_post/application/ProjectPostService.java index 4a86383..3ede612 100644 --- a/ideac-user/src/main/java/depth/main/ideac/domain/project_post/application/ProjectPostService.java +++ b/ideac-user/src/main/java/depth/main/ideac/domain/project_post/application/ProjectPostService.java @@ -41,7 +41,7 @@ public class ProjectPostService { private final RedisTemplate redisTemplate; @Transactional - public Long postProject(Long userId, PostProjectReq postProjectReq, List images) throws IOException { + public Long postProject(Long userId, PostProjectReq postProjectReq) throws IOException { User user = userRepository.findById(userId).orElseThrow(() -> new DefaultException(ErrorCode.USER_NOT_FOUND)); if (!postProjectReq.isBooleanWeb() && !postProjectReq.isBooleanApp() && !postProjectReq.isBooleanAi()) { throw new DefaultException(ErrorCode.INVALID_PARAMETER, "키워드는 하나 이상 표시해야 합니다."); @@ -61,7 +61,7 @@ public Long postProject(Long userId, PostProjectReq postProjectReq, List images) throws IOException { + public void updateProject(Long userId, Long projectId, PostProjectReq updateProjectReq) throws IOException { if (!isAdminOrWriter(projectId, userId)) { throw new DefaultException(ErrorCode.UNAUTHORIZED, "수정 권한이 없습니다."); } @@ -188,7 +188,7 @@ public void updateProject(Long userId, Long projectId, PostProjectReq updateProj projectPost.setBooleanApp(updateProjectReq.isBooleanApp()); projectPost.setBooleanAi(updateProjectReq.isBooleanAi()); this.deleteFile(projectId); - this.uploadFile(projectPost, images); + this.uploadFile(projectPost, updateProjectReq.getImages()); } diff --git a/ideac-user/src/main/java/depth/main/ideac/domain/project_post/dto/request/PostProjectReq.java b/ideac-user/src/main/java/depth/main/ideac/domain/project_post/dto/request/PostProjectReq.java index 184c8a0..7ee8378 100644 --- a/ideac-user/src/main/java/depth/main/ideac/domain/project_post/dto/request/PostProjectReq.java +++ b/ideac-user/src/main/java/depth/main/ideac/domain/project_post/dto/request/PostProjectReq.java @@ -5,8 +5,13 @@ import jakarta.validation.constraints.Size; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.Setter; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; @Getter +@Setter @RequiredArgsConstructor @Schema(description = "프로젝트 게시 Request") public class PostProjectReq { @@ -26,5 +31,5 @@ public class PostProjectReq { private boolean booleanWeb; private boolean booleanApp; private boolean booleanAi; - + private List images; } diff --git a/ideac-user/src/main/java/depth/main/ideac/domain/project_post/presentation/ProjectPostController.java b/ideac-user/src/main/java/depth/main/ideac/domain/project_post/presentation/ProjectPostController.java index cbbd0c1..6eb5fc0 100644 --- a/ideac-user/src/main/java/depth/main/ideac/domain/project_post/presentation/ProjectPostController.java +++ b/ideac-user/src/main/java/depth/main/ideac/domain/project_post/presentation/ProjectPostController.java @@ -38,9 +38,8 @@ public class ProjectPostController { @Operation(summary = "프로젝트 게시", description = "프로젝트 게시글을 생성하는 API입니다.") @PostMapping(path= "", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public ResponseEntity postProject(@CurrentUser UserPrincipal userPrincipal, - @Valid @RequestPart PostProjectReq postProjectReq, - @RequestPart("images") List images) throws IOException { - Long createdProjectId = projectPostService.postProject(userPrincipal.getId(), postProjectReq, images); + @Valid @ModelAttribute PostProjectReq postProjectReq) throws IOException { + Long createdProjectId = projectPostService.postProject(userPrincipal.getId(), postProjectReq); URI location = ServletUriComponentsBuilder.fromCurrentRequest() .path("/{project-id}") .buildAndExpand(createdProjectId) @@ -101,9 +100,8 @@ public ResponseEntity getProjectDetail(@PathVariable("project-id") Long proje @PutMapping("/{project-id}") public ResponseEntity updateProject(@CurrentUser UserPrincipal userPrincipal, @PathVariable("project-id") Long projectId, - @Valid @RequestPart PostProjectReq updateProjectReq, - @RequestPart("images") List images) throws IOException { - projectPostService.updateProject(userPrincipal.getId(), projectId, updateProjectReq, images); + @Valid @ModelAttribute PostProjectReq updateProjectReq) throws IOException { + projectPostService.updateProject(userPrincipal.getId(), projectId, updateProjectReq); return ResponseEntity.ok().build(); }