Skip to content

Commit

Permalink
Merge pull request #114 from IDEA-CAMPUS/develop
Browse files Browse the repository at this point in the history
release 2.4.6
  • Loading branch information
jisujeong0 authored Jan 15, 2024
2 parents 0959958 + 821bca8 commit 9b91248
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,7 +86,7 @@ public ClubPostDetailRes getDetailClubPosts(Long clubId) {
}

@Transactional
public Long createClubPost(Long userId, ClubPostReq clubPostReq, List<MultipartFile> images) throws IOException {
public Long createClubPost(Long userId, ClubPostReq clubPostReq) throws IOException {
User user = userRepository.findById(userId)
.orElseThrow(() -> new DefaultException(ErrorCode.USER_NOT_FOUND));

Expand All @@ -99,7 +98,7 @@ public Long createClubPost(Long userId, ClubPostReq clubPostReq, List<MultipartF
.user(user)
.build();

this.uploadFile(clubPost, images);
this.uploadFile(clubPost, clubPostReq.getImages());

clubPostRepository.save(clubPost);

Expand All @@ -108,7 +107,7 @@ public Long createClubPost(Long userId, ClubPostReq clubPostReq, List<MultipartF

// 글 수정
@Transactional
public void updateClubPost(Long clubPostId, Long userId, UpdateClubPostReq updateClubPostReq, List<MultipartFile> images) throws IOException {
public void updateClubPost(Long clubPostId, Long userId, ClubPostReq updateClubPostReq) throws IOException {
if (!isAdminOrWriter(clubPostId, userId)) {
throw new AccessDeniedException("해당 게시글에 대한 권한이 없습니다.");
}
Expand All @@ -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());
}

// 글 삭제
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "제목을 입력해야 합니다.")
Expand All @@ -22,4 +27,6 @@ public class ClubPostReq {

private String url2;

private List<MultipartFile> images;

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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<MultipartFile> 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)
Expand All @@ -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<MultipartFile> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ProjectPostService {
private final RedisTemplate<String, String> redisTemplate;

@Transactional
public Long postProject(Long userId, PostProjectReq postProjectReq, List<MultipartFile> 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, "키워드는 하나 이상 표시해야 합니다.");
Expand All @@ -61,7 +61,7 @@ public Long postProject(Long userId, PostProjectReq postProjectReq, List<Multipa
.hits(0L)
.user(user)
.build();
this.uploadFile(projectPost, images);
this.uploadFile(projectPost, postProjectReq.getImages());
projectPostRepository.save(projectPost);
return projectPost.getId();
}
Expand Down Expand Up @@ -171,7 +171,7 @@ public ProjectDetailRes getProjectDetail(Long projectId) {
}

@Transactional
public void updateProject(Long userId, Long projectId, PostProjectReq updateProjectReq, List<MultipartFile> images) throws IOException {
public void updateProject(Long userId, Long projectId, PostProjectReq updateProjectReq) throws IOException {
if (!isAdminOrWriter(projectId, userId)) {
throw new DefaultException(ErrorCode.UNAUTHORIZED, "수정 권한이 없습니다.");
}
Expand All @@ -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());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -26,5 +31,5 @@ public class PostProjectReq {
private boolean booleanWeb;
private boolean booleanApp;
private boolean booleanAi;

private List<MultipartFile> images;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MultipartFile> 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)
Expand Down Expand Up @@ -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<MultipartFile> 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();
}

Expand Down

0 comments on commit 9b91248

Please sign in to comment.