-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [Feature] AdminRoom show변경 API (#686)
- Loading branch information
Showing
7 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 34 additions & 1 deletion
35
gg-pingpong-api/src/main/java/gg/party/api/admin/room/controller/RoomAdminController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ng-api/src/main/java/gg/party/api/admin/room/controller/request/RoomShowChangeReqDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
30 changes: 30 additions & 0 deletions
30
gg-pingpong-api/src/main/java/gg/party/api/admin/room/service/RoomAdminService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
gg-utils/src/main/java/gg/utils/exception/party/RoomAlreadyHiddenException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
gg-utils/src/main/java/gg/utils/exception/party/RoomStatNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |