Skip to content

Commit

Permalink
[FEATURE] 댓글 숨김 ADMIN API (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
yes-ee authored Mar 6, 2024
1 parent e32ca78 commit f7b0b3c
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package gg.admin.repo.comment;

import org.springframework.data.jpa.repository.JpaRepository;

import gg.data.party.Comment;

public interface CommentAdminRepository extends JpaRepository<Comment, Long> {
}
6 changes: 6 additions & 0 deletions gg-data/src/main/java/gg/data/party/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ public Comment(User user, UserRoom userRoom, Room room, String content) {
this.content = content;
this.isHidden = false;
}

public void updateHidden(boolean isHidden) {
this.isHidden = isHidden;
}

}

Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
package gg.pingpong.api.party.admin.comment.controller;
package gg.party.api.admin.comment.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import gg.auth.UserDto;
import gg.auth.argumentresolver.Login;
import gg.party.api.admin.comment.controller.request.CommentUpdateAdminRequestDto;
import gg.party.api.admin.comment.service.CommentAdminService;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/party/admin/comments")
public class CommentAdminController {
private final CommentAdminService commentAdminService;

/**
* 댓글 숨김
* @param commentId 댓글 번호
* @return 숨김 성공 여부
*/
@PatchMapping("/{commentId}")
public ResponseEntity<Void> hideComment(@PathVariable Long commentId,
@RequestBody CommentUpdateAdminRequestDto reqDto, @Login UserDto user) {
commentAdminService.hideComment(commentId, reqDto);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package gg.party.api.admin.comment.controller.request;

import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class CommentUpdateAdminRequestDto {
private Boolean isHidden;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package gg.party.api.admin.comment.service;

import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import gg.admin.repo.comment.CommentAdminRepository;
import gg.data.party.Comment;
import gg.party.api.admin.comment.controller.request.CommentUpdateAdminRequestDto;
import gg.utils.exception.party.CommentNotFoundException;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class CommentAdminService {
private final CommentAdminRepository commentAdminRepository;

@Transactional
public void hideComment(Long commentId, CommentUpdateAdminRequestDto reqDto) {
Comment comment = commentAdminRepository.findById(commentId)
.orElseThrow(CommentNotFoundException::new);
comment.updateHidden(reqDto.getIsHidden());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public class CommentController {
public ResponseEntity<Void> createComment(@PathVariable Long roomId, @RequestBody CommentCreateReqDto reqDto,
@Login UserDto user) {
commentService.createComment(roomId, reqDto, user.getId());
return new ResponseEntity<>(HttpStatus.CREATED);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
}
1 change: 1 addition & 0 deletions gg-utils/src/main/java/gg/utils/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public enum ErrorCode {
USER_NOT_IN_ROOM(404, "PT103", "방에 존재하지 않는 유저입니다."),
ROOM_REPORTED_ERROR(404, "PT104", "신고 상태로 접근이 불가능합니다."),
USER_NOT_EXIST(404, "PT105", "방에 유저가 존재하지 않습니다."),
COMMENT_NOT_FOUND(404, "PT106", "존재하지 않는 댓글입니다."),
COMMENT_TOO_LONG(400, "PT201", "댓글은 100자 이하로 작성해주세요."),
ROOM_FINISHED(403, "PT501", "마감된 방입니다."),
ROOM_NOT_PARTICIPANT(400, "PT202", "해당 방의 참여자가 아닙니다."),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package gg.utils.exception.party;

import gg.utils.exception.ErrorCode;
import gg.utils.exception.custom.NotExistException;

public class CommentNotFoundException extends NotExistException {
public CommentNotFoundException() {
super(ErrorCode.COMMENT_NOT_FOUND.getMessage(), ErrorCode.COMMENT_NOT_FOUND);
}

}

0 comments on commit f7b0b3c

Please sign in to comment.