Skip to content

Commit

Permalink
feat : 게시글 삭제 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
MyunghyunNero committed Nov 21, 2023
1 parent 41b80c7 commit 68104d7
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/main/java/kusitms/gallae/GallaeApplication.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package kusitms.gallae;

import jakarta.annotation.PostConstruct;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.TimeZone;

@SpringBootApplication
public class GallaeApplication {

@PostConstruct
public void started() {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul"));
}

public static void main(String[] args) {
SpringApplication.run(GallaeApplication.class, args);
}
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/kusitms/gallae/controller/ArchiveController.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,31 @@ public ResponseEntity<BaseResponse<ArchiveDetailRes>> getArchivesEditable(
return ResponseEntity.ok(new BaseResponse<>(this.archiveService.checkArchiveEditable(archiveId, principal.getName())));
}

@Operation(summary = "게시물 삭제", description = """
삭제 버튼 눌르면 권한이 있는지 체크해준다.
\n 권한이 없으면 아래 코드 처럼 나옴 \n
{\n
"isSuccess": false,\n
"code": 1002,\n
"message": "작성자가 아닙니다."\n
}
""")
@DeleteMapping("/delete")
public ResponseEntity<BaseResponse> delArchive(
Principal principal,

@Parameter(description = "자료실 아이디")
@RequestParam(value = "archiveId", required = false)
Long archiveId
){
if(principal == null ){
throw new BaseException(BaseResponseStatus.NOT_WRITER);
}
archiveService.deleteArchive(archiveId, principal.getName());
return ResponseEntity.ok(new BaseResponse<>(BaseResponseStatus.SUCCESS));
}

@PostMapping("/saveArchive")
public ResponseEntity<BaseResponse<Long>> saveArchive(
Principal principal,
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/kusitms/gallae/controller/ReviewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,30 @@ public ResponseEntity<BaseResponse<ReviewDetailRes>> getReviewEditable(
return ResponseEntity.ok(new BaseResponse<>(this.reviewService.checkReviewEditable(reviewId, principal.getName())));
}

@Operation(summary = "후기 삭제", description = """
삭제 버튼 눌르면 권한이 있는지 체크해준다.
\n 권한이 없으면 아래 코드 처럼 나옴 \n
{\n
"isSuccess": false,\n
"code": 1002,\n
"message": "작성자가 아닙니다."\n
}
""")
@DeleteMapping("/delete")
public ResponseEntity<BaseResponse> delArchive(
Principal principal,

@Parameter(description = "후기 아이디")
@RequestParam(value = "reviewId", required = false)
Long reviewId
){
if(principal == null ){
throw new BaseException(BaseResponseStatus.NOT_WRITER);
}
reviewService.deleteReivew(reviewId, principal.getName());
return ResponseEntity.ok(new BaseResponse<>(BaseResponseStatus.SUCCESS));
}

@Operation(summary = "지원후기 좋아요순으로 게시판 내용들 가져오기")
@GetMapping("/sorted/likes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,21 @@ private BooleanBuilder createSearchCondition(ProgramSearchReq programSearchReq)
private BooleanBuilder createSimiliarProgramCondition(ProgramSimilarReq programSimilarReq) {
BooleanBuilder booleanBuilder = new BooleanBuilder();

booleanBuilder.and(program.status.eq(Program.ProgramStatus.SAVE));

if(programSimilarReq.getId() != null) {
booleanBuilder.and(program.id.ne(programSimilarReq.getId()));
}

if(programSimilarReq.getLocation() != null) {
booleanBuilder.or(program.location.contains(programSimilarReq.getLocation()));
booleanBuilder.and(program.location.contains(programSimilarReq.getLocation()));
}

if(programSimilarReq.getProgramType() != null) {
booleanBuilder.or(program.programType.eq(programSimilarReq.getProgramType()));
}

if(programSimilarReq.getId() != null) {
booleanBuilder.and(program.id.ne(programSimilarReq.getId()));
}

booleanBuilder.and(program.status.eq(Program.ProgramStatus.SAVE));

return booleanBuilder;
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/kusitms/gallae/service/archive/ArchiveService.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ public ArchiveDetailRes checkArchiveEditable(Long archiveId, String username) {
return convertArchive(archive,user);
}

public void deleteArchive(Long archiveId, String username) {
Archive archive = archiveRepository.findById(archiveId).orElse(null);
User user = userRepository.findById(Long.valueOf(username)).orElse(null);
if(archive.getUser().getId() != user.getId()){
throw new BaseException(BaseResponseStatus.NOT_WRITER);
}
if(archive.getFileUrl() != null ){
s3Service.deleteFile(archive.getFileUrl());
}
archiveRepository.delete(archive);
}

public Long editArchive(ArchiveEditReq archiveEditReq) {
Archive archive = archiveRepository.findById(archiveEditReq.getArchiveId()).orElse(null);
if(archive.getFileUrl() != null ){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ public List<ProgramMainRes> getSimilarPrograms(Long programId,String username) {
ProgramSimilarReq programSimilarReq = new ProgramSimilarReq();
programSimilarReq.setLocation(program.getLocation());
programSimilarReq.setProgramType(program.getProgramType());
programSimilarReq.setId(programId);
User user = null;
if(username != null){
user = userRepository.findById(Long.valueOf(username)).get();
user = userRepository.findById(Long.valueOf(username)).orElse(null);
}
List<Program> temp = programRepositoryCustom.getDynamicSimilar(programSimilarReq);
List<ProgramMainRes> programs = new ArrayList<>();
Expand Down Expand Up @@ -171,6 +172,8 @@ private List<ProgramMainRes> getProgramMainRes(List<Program> programs){
program.getRecruitEndDate().getMonth(),program.getRecruitEndDate().getDayOfMonth());
String strRemainDay = DurationCalcurator.getDuration(localDate);
programMainRes.setRemainDay(strRemainDay);
programMainRes.setRecruitStartDate(program.getRecruitStartDate());
programMainRes.setRecruitEndDate(program.getRecruitEndDate());
programMainRes.setHashTag(Arrays.stream(program.getHashTags().split(","))
.collect(Collectors.toList()));
return programMainRes;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/kusitms/gallae/service/review/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ public Long editReivew(ReviewEditReq reviewEditReq) {
return saveReview.getId();
}

public void deleteReivew(Long reviewId, String username) {
Review review = reviewRepository.findById(reviewId).orElse(null);
User user = userRepository.findById(Long.valueOf(username)).orElse(null);
if(review.getUser().getId() != user.getId()){
throw new BaseException(BaseResponseStatus.NOT_WRITER);
}
if(review.getFileUrl() != null ){
s3Service.deleteFile(review.getFileUrl());
}
reviewRepository.delete(review);
}

public ReviewDetailRes checkReviewEditable(Long reviewId, String username) {
Review review = reviewRepository.findById(reviewId).orElse(null);
User user = userRepository.findById(Long.valueOf(username)).orElse(null);
Expand Down

0 comments on commit 68104d7

Please sign in to comment.