Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
LANGUAGE_NOT_MATCHING(HttpStatus.NOT_FOUND, "CENTER4003", "해당 언어의 상담사가 없습니다."),
//글 관련 응답
COMMUNITY_NOT_FOUND(HttpStatus.NOT_FOUND,"COMMUNITY4001","글을 찾을 수 없습니다"),
COMMUNITY_NOT_OWNER(HttpStatus.NOT_ACCEPTABLE,"COMMUNITY4002","해당 글의 소유자가 아닙니다."),

//언어 관련 응답
LANGUAGE_NOT_EXIST(HttpStatus.NOT_FOUND, "LANGUAGE4001", "해당 언어가 없습니다.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,11 @@ public static Long toCategoryId(CommunityCategory category) {
}
}

public static CommunityResponseDTO.DeletedPostDTO toDeletedPostDTO(Community community){
return CommunityResponseDTO.DeletedPostDTO.builder()
.categoryName(community.getCommunityCategory().name())
.post_id(community.getId())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface CommunityService {
CommunityResponseDTO.CreatedPostDTO createCommunityPost(String userId, Long categoryId, CommunityRequestDTO.CreatePostDTO request);
CommunityResponseDTO.PostListDTO getCommunityList(String userId, Long categoryId, Integer page, Integer size);
CommunityResponseDTO.PostDetailDTO getCommunityDetail(String userId, Long communityId, Integer page, Integer size);
CommunityResponseDTO.DeletedPostDTO deleteCommunityPost(String userId, Long categoryId, Long communityId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;



@Service
@RequiredArgsConstructor
@Transactional
Expand Down Expand Up @@ -66,4 +67,15 @@ public CommunityResponseDTO.PostDetailDTO getCommunityDetail(String userId, Long
Page<Comment> commentPage = new PageImpl<>(subList, pageRequest, commentList.size());
return CommunityConverter.toPostDetailDTO(community, commentPage);
}

@Override
public CommunityResponseDTO.DeletedPostDTO deleteCommunityPost(String userId, Long categoryId, Long communityId) {
User user = userRepository.findByEmail(userId).orElseThrow(() -> new GeneralException(ErrorStatus.USER_NOT_FOUND));
Community community = communityRepository.findById(communityId).orElseThrow(() -> new GeneralException(ErrorStatus.COMMUNITY_POST_NOT_FOUND));
if(!community.getUser().getId().equals(user.getId())){
throw new GeneralException(ErrorStatus.COMMUNITY_NOT_OWNER);
}
communityRepository.deleteById(community.getId());
return CommunityConverter.toDeletedPostDTO(community);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,22 @@ public ApiResponse<CommentResponseDTO.commentCreateRes> createComment(@RequestHe
}

}

@DeleteMapping(value = "/{category_id}/{community_id}/delete")
@Operation(summary = "커뮤니티 글 삭제 API", description = "커뮤니티 게시판에 글을 삭제하는 API입니다.")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "USER4001", description = "사용자를 찾을수 없습니다.")
})
@Parameters({
@Parameter(name = "Authorization", description = "RequestHeader - 로그인한 사용자 토큰"),
@Parameter(name = "category_id", description = "PathVariable - 게시글 카테고리 아이디"),
@Parameter(name = "community_id", description = "PathVariable - 게시글 아이디"),
})
public ApiResponse<CommunityResponseDTO.DeletedPostDTO> deleteCommunity(@RequestHeader(name = "Authorization") String accessToken,
@PathVariable(name = "category_id") Long categoryId,
@PathVariable(name = "community_id") Long communityId) {
String gmail = jwtTokenProvider.getGoogleEmail(accessToken);
return ApiResponse.onSuccess(communityService.deleteCommunityPost(gmail, categoryId, communityId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,13 @@ public static class CommentDTO{
LocalDateTime created_at;
String content;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class DeletedPostDTO{
String categoryName;
Long post_id;
}
}
Loading