Skip to content

Commit

Permalink
Merge pull request #62 from Review-zip/feat/#58-post-delete
Browse files Browse the repository at this point in the history
[Feat] ๊ฒŒ์‹œ๊ธ€ ์‚ญ์ œํ•˜๊ธฐ
  • Loading branch information
yoondaeng authored Jan 29, 2024
2 parents 2af1204 + b1bbe3d commit a92f142
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/example/ReviewZIP/domain/post/Posts.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import com.example.ReviewZIP.domain.postLike.PostLikes;
import com.example.ReviewZIP.domain.scrab.Scrabs;
import com.example.ReviewZIP.domain.store.Stores;
import com.example.ReviewZIP.domain.user.Status;
import com.example.ReviewZIP.domain.user.Users;
import com.example.ReviewZIP.global.entity.BaseEntity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public ApiResponse<PostResponseDto.PostPreviewListDto> searchPostsByHashtagId(@P
})
@Parameters({
@Parameter(name = "postId", description = "๊ฒŒ์‹œ๊ธ€์˜ ์•„์ด๋””"),
@Parameter(name = "page", description = "ํŽ˜์ด์ง€ ๋ฒˆํ˜ธ"),
@Parameter(name = "size", description = "ํŽ˜์ด์ง• ์‚ฌ์ด์ฆˆ")
})
public ApiResponse<PostResponseDto.PostInfoDto> getPostInfo(@PathVariable(name = "postId") Long postId){

Expand Down Expand Up @@ -87,4 +85,18 @@ public ApiResponse<List<PostResponseDto.PostInfoDto>> getRandomPosts(@RequestPar

return ApiResponse.onSuccess(randomPostInfoDtos);
}

@DeleteMapping("/{postId}")
@Operation(summary = "๊ฒŒ์‹œ๊ธ€ ์‚ญ์ œ API", description = "๊ฒŒ์‹œ๊ธ€์˜ id๋ฅผ ๋ฐ›์•„ ํ•ด๋‹นํ•˜๋Š” ๊ฒŒ์‹œ๊ธ€ ์‚ญ์ œ")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200",description = "OK, ์„ฑ๊ณต"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "POST401", description = "๊ฒŒ์‹œ๊ธ€์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค",content = @Content(schema = @Schema(implementation = ApiResponse.class))),
})
@Parameters({
@Parameter(name = "postId", description = "๊ฒŒ์‹œ๊ธ€์˜ ์•„์ด๋””"),
})
public ApiResponse<Void> deletePost(@PathVariable(name = "postId") Long postId){
postsService.deletePost(postId);
return ApiResponse.onSuccess(null);
}
}
29 changes: 12 additions & 17 deletions src/main/java/com/example/ReviewZIP/domain/post/PostsService.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
package com.example.ReviewZIP.domain.post;

import com.example.ReviewZIP.domain.postHashtag.PostHashtags;
import com.example.ReviewZIP.domain.postHashtag.PostHashtagsRepository;
import com.example.ReviewZIP.domain.postHashtag.PostHashtagsService;
import com.example.ReviewZIP.global.response.code.resultCode.ErrorStatus;
import com.example.ReviewZIP.global.response.exception.handler.PostHashtagsHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;


import com.example.ReviewZIP.domain.image.Images;
import com.example.ReviewZIP.domain.image.ImagesRepository;
import com.example.ReviewZIP.domain.post.dto.request.PostRequestDto;
import com.example.ReviewZIP.domain.post.dto.response.PostResponseDto;
import com.example.ReviewZIP.domain.postHashtag.PostHashtags;
import com.example.ReviewZIP.domain.postHashtag.PostHashtagsRepository;
import com.example.ReviewZIP.domain.postLike.PostLikesRepository;
import com.example.ReviewZIP.domain.scrab.ScrabsRepository;
import com.example.ReviewZIP.domain.user.Users;
import com.example.ReviewZIP.domain.user.UsersRepository;
import com.example.ReviewZIP.global.response.code.resultCode.ErrorStatus;
import com.example.ReviewZIP.global.response.exception.handler.ImagesHandler;
import com.example.ReviewZIP.global.response.exception.handler.PostHashtagsHandler;
import com.example.ReviewZIP.global.response.exception.handler.PostsHandler;
import com.example.ReviewZIP.global.response.exception.handler.UsersHandler;

import lombok.RequiredArgsConstructor;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -38,6 +26,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -132,5 +121,11 @@ public PostResponseDto.PostInfoDto getPostInfoDto(Long postId){
return PostsConverter.toPostInfoResultDto(post, checkLike, checkScrab);
}

@Transactional
public void deletePost(Long postId){
Posts post = postsRepository.findById(postId).orElseThrow(()-> new PostsHandler(ErrorStatus.POST_NOT_FOUND));

}
postsRepository.deleteById(post.getId());

}
}

0 comments on commit a92f142

Please sign in to comment.