Skip to content

Commit

Permalink
Merge pull request #138 from KUIT-Space/feat/#135/voiceroom-delete-api
Browse files Browse the repository at this point in the history
Feat/#135/voiceroom delete api
  • Loading branch information
drbug2000 authored Aug 19, 2024
2 parents d3b43fd + 9b2472d commit 1162563
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@ public BaseResponse<String> updateVoiceRoom(
}
//ํ•ด๋‹น ์œ ์ €๊ฐ€ ํ˜„์žฌ space์— ๋Œ€ํ•ด ๊ด€๋ฆฌ์ž ๊ถŒํ•œ์„ ๊ฐ–๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธ
validateManagerPermission(userSpaceAuth);
//ํ•ด๋‹น voiceRoom์ด ํ•ด๋‹น space์— ์†ํ•œ๊ฒƒ์ด ๋งž๋Š”์ง€ ํ™•์ธ

for(PatchVoiceRoom.UpdateRoom updateRoom : patchVoiceRoom.getUpdateRoomList()) {
//ํ•ด๋‹น voiceRoomId๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธ
validateVoiceRoom(updateRoom.getRoomId());
//ํ•ด๋‹น voiceRoom์ด ํ•ด๋‹น space์— ์†ํ•œ๊ฒƒ์ด ๋งž๋Š”์ง€ ํ™•์ธ
validateVoiceRoomInSpace(spaceId, updateRoom.getRoomId());
}

Expand All @@ -181,6 +184,8 @@ public BaseResponse<String> deleteVoiceRoom(

//ํ•ด๋‹น ์œ ์ €๊ฐ€ ํ˜„์žฌ space์— ๋Œ€ํ•ด ๊ด€๋ฆฌ์ž ๊ถŒํ•œ์„ ๊ฐ–๊ณ  ์žˆ๋Š”์ง€ ํ™•์ธ
validateManagerPermission(userSpaceAuth);
//ํ•ด๋‹น ๋ณด์ด์Šค๋ฃธ์ด ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธ
validateVoiceRoom(voiceRoomId);
//ํ•ด๋‹น voiceRoom์ด ํ•ด๋‹น space์— ์†ํ•œ๊ฒƒ์ด ๋งž๋Š”์ง€ ํ™•์ธ
validateVoiceRoomInSpace(spaceId, voiceRoomId);

Expand Down
17 changes: 10 additions & 7 deletions src/main/java/space/space_spring/dao/VoiceRoomRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
@Repository
public interface VoiceRoomRepository extends JpaRepository<VoiceRoom,Long> {

//Todo limit ๊ฐœ์ˆ˜ ๋งŒํผ ๊ฐ€์ ธ์˜ค๋„๋ก ๊ธฐ๋Šฅ๊ณผ ํŒŒ๋ผ๋ฏธํ„ฐ ์ˆ˜์ •
List<VoiceRoom> findBySpace(Space space);
@Query("SELECT MAX(r.order) FROM VoiceRoom r WHERE r.space = :space")
Integer findMaxOrderBySpace(@Param("space") Space space);

boolean existsByVoiceRoomId(long voiceRoomId);
boolean existsByName(String voiceRoomName);
VoiceRoom findById(long Id);
@Query("SELECT v FROM VoiceRoom v WHERE v.space = :space AND v.status = 'ACTIVE'")
List<VoiceRoom> findBySpace(@Param("space")Space space);
@Query("SELECT MAX(r.order) FROM VoiceRoom r WHERE r.space = :space AND r.status = 'ACTIVE'")
Integer findMaxOrderBySpace(@Param("space") Space space);
@Query("SELECT CASE WHEN COUNT(v) > 0 THEN true ELSE false END FROM VoiceRoom v WHERE v.voiceRoomId = :id AND v.status = 'ACTIVE'")
boolean existsByVoiceRoomId(@Param("id")long voiceRoomId);
@Query("SELECT CASE WHEN COUNT(v) > 0 THEN true ELSE false END FROM VoiceRoom v WHERE v.name = :voiceRoomName AND v.status = 'ACTIVE'")
boolean existsByName(@Param("voiceRoomName") String voiceRoomName);
@Query("SELECT v FROM VoiceRoom v WHERE v.voiceRoomId = :id AND v.status = 'ACTIVE'")
VoiceRoom findById(@Param("id") long Id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,22 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons

// URL์—์„œ spaceId ์ถ”์ถœ
Map pathVariables = (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
Long spaceId = Long.parseLong((String) pathVariables.get("spaceId"));
//Long spaceId;
try {
Long spaceId = Long.parseLong((String) pathVariables.get("spaceId"));

if(spaceId==null){
throw new CustomException(SPACE_ID_PATHVARIABLE_NULL);
}
request.setAttribute("userSpaceId",getUserSpace(spaceId,userId));
System.out.print("userSpaceID:"+getUserSpace(spaceId,userId));
return true;

}catch (NumberFormatException e){
throw new CustomException(SPACE_ID_PATHVARIABLE_ERROR);

}

request.setAttribute("userSpaceId",getUserSpace(spaceId,userId));
System.out.print("userSpaceID:"+getUserSpace(spaceId,userId));
return true;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public enum BaseExceptionResponseStatus implements ResponseStatus {
URL_NOT_FOUND(2001, HttpStatus.BAD_REQUEST, "์œ ํšจํ•˜์ง€ ์•Š์€ URL ์ž…๋‹ˆ๋‹ค."),
METHOD_NOT_ALLOWED(2002, HttpStatus.METHOD_NOT_ALLOWED, "ํ•ด๋‹น URL์—์„œ๋Š” ์ง€์›ํ•˜์ง€ ์•Š๋Š” HTTP Method ์ž…๋‹ˆ๋‹ค."),
HTTP_MESSAGE_NOT_READABLE(2003, HttpStatus.BAD_REQUEST,"request body ์–‘์‹์— ๋ฌธ์ œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค"),
SPACE_ID_PATHVARIABLE_ERROR(2004,HttpStatus.BAD_REQUEST,"URL์— ํฌํ•จ๋œ SPACE_ID ๊ฐ’์ด ์ž˜๋ชป๋˜์—ˆ์Šต๋‹ˆ๋‹ค."),
SPACE_ID_PATHVARIABLE_NULL(2005,HttpStatus.BAD_REQUEST,"URL์— ํฌํ•จ๋œ SPACE_ID ๊ฐ’์ด ์—†์Šต๋‹ˆ๋‹ค"),


/**
* 3000: Server, Database ์˜ค๋ฅ˜ (INTERNAL_SERVER_ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ public boolean updateVoiceRoom(List<PatchVoiceRoom.UpdateRoom> updateRoomList){

public void deleteVoiceRoom(long voiceRoomId){
//Todo Base Entity์— ์ผ๊ด„์ ์œผ๋กœ soft Delete๋ฅผ ์ ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋‹ค๊ฐ™์ด ์ •ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์•„๋ณด์ž„
VoiceRoom voiceRoom = voiceRoomRepository.findById(voiceRoomId);
voiceRoom.updateInactive();
voiceRoomRepository.save(voiceRoom);


}

private String findProfileImageByUserId(Long userSpaceId){
Expand Down

0 comments on commit 1162563

Please sign in to comment.