Skip to content

Commit

Permalink
Merge branch 'dev' into 641-방-시작-API
Browse files Browse the repository at this point in the history
  • Loading branch information
ghyen authored Mar 6, 2024
2 parents 4397cce + f7b0b3c commit 87a6a58
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 6 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;
}

}

4 changes: 4 additions & 0 deletions gg-data/src/main/java/gg/data/party/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,8 @@ public void updateStatus(RoomType status) {
public void updateHost(User host) {
this.host = host;
}

public void updateRoomStatus(RoomType status) {
this.status = status;
}
}
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
@@ -1,7 +1,40 @@
package gg.pingpong.api.party.admin.room.controller;
package gg.party.api.admin.room.controller;

import javax.validation.Valid;

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.data.party.type.RoomType;
import gg.party.api.admin.room.controller.request.RoomShowChangeReqDto;
import gg.party.api.admin.room.service.RoomAdminService;
import gg.utils.exception.ErrorCode;
import gg.utils.exception.party.RoomStatNotFoundException;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/party/admin/rooms")
public class RoomAdminController {

private final RoomAdminService roomAdminService;

@PatchMapping("/{roomId}")
public ResponseEntity<Void> changeRoomVisibility(@PathVariable Long roomId,
@Valid @RequestBody RoomShowChangeReqDto reqDto) throws RoomStatNotFoundException {

RoomType roomType;
try {
roomType = RoomType.valueOf(reqDto.getStatus().toUpperCase());
} catch (IllegalArgumentException e) {
throw new RoomStatNotFoundException();
}

roomAdminService.modifyRoomStatus(roomId, roomType);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package gg.party.api.admin.room.controller.request;

import javax.validation.constraints.NotNull;

import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class RoomShowChangeReqDto {
@NotNull
private String status;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package gg.party.api.admin.room.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import gg.data.party.Room;
import gg.data.party.type.RoomType;
import gg.repo.party.RoomRepository;
import gg.utils.exception.party.RoomAlreadyHiddenException;
import gg.utils.exception.party.RoomNotFoundException;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class RoomAdminService {
private final RoomRepository roomRepository;

@Transactional
public void modifyRoomStatus(Long roomId, RoomType newStatus) {
Room room = roomRepository.findById(roomId)
.orElseThrow(RoomNotFoundException::new);

if (RoomType.HIDDEN == room.getStatus() && RoomType.HIDDEN == newStatus) {
throw new RoomAlreadyHiddenException();
}

room.updateRoomStatus(newStatus);
roomRepository.save(room);
}
}
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();
}
}
9 changes: 6 additions & 3 deletions gg-utils/src/main/java/gg/utils/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,15 @@ 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, "PT002", "해당 방의 참여자가 아닙니다."),
ROOM_NOT_OPEN(400, "PT003", "해당 방의 참여자가 아닙니다."),
ROOM_NOT_ENOUGH_PEOPLE(400, "PT202", "시작할 수 있는 인원이 아닙니다."),
NOT_HOST(400, "PT203", "방장이 아닙니다");
NOT_HOST(400, "PT203", "방장이 아닙니다"),
ROOM_NOT_PARTICIPANT(400, "PT202", "해당 방의 참여자가 아닙니다."),
ROOM_NOT_OPEN(400, "PT203", "준비 상태의 방이 아닙니다."),
ROOM_ALREADY_HIDDEN(400, "PT204", "이미 숨겨진 방입니다."),
ROOMSTAT_NOT_FOUND(404, "PT106", "존재하지 않는 방 status입니다.");

private final int status;
private final String errCode;
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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package gg.utils.exception.party;

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

public class RoomAlreadyHiddenException extends DuplicationException {
public RoomAlreadyHiddenException(String message, ErrorCode errorCode) {
super(message, errorCode);
}

public RoomAlreadyHiddenException() {
super(ErrorCode.ROOM_ALREADY_HIDDEN.getMessage(), ErrorCode.ROOM_ALREADY_HIDDEN);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package gg.utils.exception.party;

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

public class RoomStatNotFoundException extends NotExistException {
public RoomStatNotFoundException(String message, ErrorCode errorCode) {
super(message, errorCode);
}

public RoomStatNotFoundException() {
super(ErrorCode.ROOMSTAT_NOT_FOUND.getMessage(), ErrorCode.ROOMSTAT_NOT_FOUND);
}
}

0 comments on commit 87a6a58

Please sign in to comment.