Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat : 스터디룸 삭제 API #14

Merged
merged 39 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9047d59
feat : 스터디룸 삭제 서비스계층까지 작성
Mouon Jul 1, 2024
bdd0e88
feat : deleteStudyroom 메서드 구현 - 예외처리와 로그 강화
Mouon Jul 1, 2024
5a76ffa
feat : 컨트롤러 계층 deleteStudyroom 메서드 예비 구현 - 로그 처리
Mouon Jul 1, 2024
43aa831
fix : findByMemberIdAndStudyroomId 의 쿼리문에서 오타 수정
Mouon Jul 1, 2024
d26411c
fix : 아바타와 맴버가 일대일관계로 되어있는 오류 수정
Mouon Jul 2, 2024
2589118
feat : 맴버 테이블에 색상 속성 추가
Mouon Jul 2, 2024
dbdf4bf
fix : 로컬 yml 파일 pr 미반영
jsilver01 Jun 30, 2024
e21cc87
chore : LoginService 생성
jsilver01 Jul 1, 2024
cffd0cb
feat : LoginResponse 작성
jsilver01 Jul 1, 2024
9d508ae
feat : MemberRepository.existsByGithubIdAndStatus 작성
jsilver01 Jul 1, 2024
90a20a5
feat : isMember -> memberStatus 로 변경
jsilver01 Jul 1, 2024
240ca8d
feat : 소셜로그인 절반구현
jsilver01 Jul 1, 2024
70e93f1
feat : 소셜로그인 절반구현
jsilver01 Jul 1, 2024
8b8bb4f
feat : 토큰 발급 완료
jsilver01 Jul 3, 2024
caf639d
feat : RedisConfig 생성
jsilver01 Jul 3, 2024
5f19124
feat : 레디스 저장하기 구현
jsilver01 Jul 3, 2024
ed9ae6e
feat : 레디스 저장하기 구현
jsilver01 Jul 3, 2024
96e907e
feat : 레디스 저장하기 구현
jsilver01 Jul 3, 2024
3705bdf
feat : 레디스 저장하기 구현
jsilver01 Jul 3, 2024
dbc5646
feat : 레디스 ec2 배포 환경 설정
Mouon Jul 3, 2024
df06434
feat : Authorization 토큰을 통해 memberId 받는 예비 로직 추가해둠
Mouon Jul 4, 2024
a15aaf5
feat : Authorization 토큰을 통해 memberId 받는 예비 로직 추가해둠
Mouon Jul 4, 2024
197e465
feat : @EnableJpaAuditing 통해 생성일 수정일 자동생기도록함
Mouon Jul 4, 2024
b6709d6
feat : 명세서 형식으로 api 반환되도록 반환자료형 수정
Mouon Jul 4, 2024
c1d5cd5
feat : MemberstudyroomRepository에 역할찾는 메서드 추가, 서비스계층 수정으로 예외처리 강화
Mouon Jul 4, 2024
ee1769f
feat : memberId 로 토큰 생성
jsilver01 Jul 3, 2024
254c68c
fix : 깃허브 소셜로그인 security 설정을 위한 코드 수정
jsilver01 Jul 4, 2024
fb5b05b
fix : JwtProvider 코드 수정
jsilver01 Jul 4, 2024
fa6b671
fix : JwtProvider 코드 수정
jsilver01 Jul 4, 2024
a287264
feat : @Autowired로 JwtProvider 주입
Mouon Jul 4, 2024
ed79bae
feat : findRoleByMemberIdAndStudyroomId를 서비스에서 파라매터 잘못 넘겨주는 문제해결 + 스터…
Mouon Jul 4, 2024
f3d086c
feat : @Transactional(readOnly = true) 추가
Mouon Jul 4, 2024
844eea9
feat : @RequestHeader 삭제
Mouon Jul 4, 2024
11bdf81
feat : 스터디룸 삭제시 맴버 스터디룸도 삭제되게 수정
Mouon Jul 4, 2024
ce20573
feat : 조건문 조건에 논리적인 오류가있어서 수정
Mouon Jul 5, 2024
31867dd
Merge remote-tracking branch 'origin/develop' into LINKODE-16-BE-API-…
Mouon Jul 5, 2024
ccea837
Merge branch 'develop' into LINKODE-16-BE-API-스터디룸-삭제-API
Mouon Jul 5, 2024
a88d6cd
chore : dto 폴더 정리
Mouon Jul 5, 2024
d2a86c2
Merge remote-tracking branch 'origin/LINKODE-16-BE-API-스터디룸-삭제-API' i…
Mouon Jul 5, 2024
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 @@ -10,7 +10,7 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{
* 1000: 요청 성공 (OK)
*/
SUCCESS(1000,HttpStatus.OK.value(), "요청에 성공하였습니다."),

FAILURE(2000, HttpStatus.BAD_REQUEST.value(), "요청에 실패하였습니다."),
INVALID_TOKEN(2000, HttpStatus.OK.value(), "유효하지 않은 토큰입니다."),
ALREADY_EXIST_MEMBER(3000, HttpStatus.OK.value(), "이미 존재하는 회원입니다.");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.linkode.api_server.controller;

import com.linkode.api_server.dto.CreateStudyroomRequest;
import com.linkode.api_server.dto.CreateStudyroomResponse;
import com.linkode.api_server.common.response.BaseResponse;
import com.linkode.api_server.common.response.status.BaseExceptionResponseStatus;
import com.linkode.api_server.dto.studyroom.CreateStudyroomRequest;
import com.linkode.api_server.dto.studyroom.CreateStudyroomResponse;
import com.linkode.api_server.service.StudyroomService;
import com.linkode.api_server.util.JwtProvider;
import lombok.RequiredArgsConstructor;
Expand All @@ -21,6 +23,18 @@ public class StudyroomController {
@Autowired
JwtProvider jwtProvider;

@PatchMapping("/removal")
public BaseResponse<BaseExceptionResponseStatus> deleteStudyroom(@RequestHeader("Authorization") String authorization, @RequestParam long studyroomId){

long memberId = jwtProvider.extractIdFromHeader(authorization);
BaseExceptionResponseStatus responseStatus = studyroomService.deleteStudyroom(studyroomId,memberId);
log.info("Run Delete Studyroom API ");
if (responseStatus == BaseExceptionResponseStatus.SUCCESS) {
return new BaseResponse<>(responseStatus);
} else {
return new BaseResponse<>(responseStatus, responseStatus);
} }

@PostMapping("/generation")
public CreateStudyroomResponse createStudyroom(@RequestHeader("Authorization") String authorization, @RequestBody CreateStudyroomRequest request){
log.info("Success createStudyroom API");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.linkode.api_server.dto;
package com.linkode.api_server.dto.studyroom;

import jakarta.persistence.Column;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.linkode.api_server.dto;
package com.linkode.api_server.dto.studyroom;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.linkode.api_server.dto.studyroom;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter @Setter
@AllArgsConstructor
@NoArgsConstructor
public class DeleteStudyroomRequest {

private long studyroomId;

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.linkode.api_server.dto;
package com.linkode.api_server.dto.studyroom;

import com.linkode.api_server.domain.memberstudyroom.MemberRole;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package com.linkode.api_server.repository;

import com.linkode.api_server.domain.Studyroom;
import com.linkode.api_server.domain.memberstudyroom.MemberRole;
import com.linkode.api_server.domain.memberstudyroom.MemberStudyroom;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Repository
@Transactional(readOnly = true)
public interface MemberstudyroomRepository extends JpaRepository<MemberStudyroom, Long> {


}
@Query("SELECT ms.role FROM MemberStudyroom ms WHERE ms.studyroom.studyroomId = :studyroomId AND ms.member.memberId = :memberId")
Optional<MemberRole> findRoleByMemberIdAndStudyroomId(long studyroomId, long memberId);
@Transactional
@Modifying
@Query("UPDATE MemberStudyroom ms SET ms.status = 'DELETE' WHERE ms.studyroom.studyroomId = :studyroomId")
int deleteMemberStudyroom(long studyroomId);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
package com.linkode.api_server.repository;

import com.linkode.api_server.domain.Studyroom;
import com.linkode.api_server.dto.CreateStudyroomResponse;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Repository
@Transactional(readOnly = true)
public interface StudyroomRepository extends JpaRepository<Studyroom, Long> {
@Transactional
@Modifying
@Query("UPDATE Studyroom sr SET sr.status = 'DELETE' WHERE sr.studyroomId = :studyroomId")
int deleteStudyroom(long studyroomId);

}
@Query("SELECT sr From Studyroom sr WHERE sr.studyroomId = :studyroomId AND sr.status = 'ACTIVE'")
Optional<Studyroom> findById(long studyroomId);
}
51 changes: 40 additions & 11 deletions src/main/java/com/linkode/api_server/service/StudyroomService.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package com.linkode.api_server.service;

import com.linkode.api_server.domain.Member;
import com.linkode.api_server.domain.Studyroom;
import com.linkode.api_server.domain.base.BaseStatus;
import com.linkode.api_server.common.response.status.BaseExceptionResponseStatus;
import com.linkode.api_server.domain.memberstudyroom.MemberRole;
import com.linkode.api_server.domain.memberstudyroom.MemberStudyroom;
import com.linkode.api_server.dto.CreateStudyroomRequest;
import com.linkode.api_server.dto.CreateStudyroomResponse;
import com.linkode.api_server.dto.JoinStudyroomRequest;
import com.linkode.api_server.repository.MemberRepository;
import com.linkode.api_server.repository.MemberstudyroomRepository;
import com.linkode.api_server.repository.StudyroomRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Optional;
import com.linkode.api_server.domain.Member;
import com.linkode.api_server.domain.Studyroom;
import com.linkode.api_server.domain.base.BaseStatus;
import com.linkode.api_server.dto.studyroom.CreateStudyroomRequest;
import com.linkode.api_server.dto.studyroom.CreateStudyroomResponse;
import com.linkode.api_server.dto.studyroom.JoinStudyroomRequest;
import com.linkode.api_server.repository.MemberRepository;
import org.springframework.transaction.annotation.Transactional;

@Service
Expand All @@ -27,6 +29,37 @@ public class StudyroomService {
@Autowired
private MemberRepository memberRepository;

public BaseExceptionResponseStatus deleteStudyroom(long studyroomId, long memberId) {


if(!studyroomRepository.findById(studyroomId).isPresent()){
log.info("StudyRoom Id is Invalid");
return BaseExceptionResponseStatus.FAILURE;
}

Optional<MemberRole> optionalMemberRole = memberstudyroomRepository.findRoleByMemberIdAndStudyroomId(studyroomId, memberId);
if (optionalMemberRole.isEmpty()) {
log.info("Member Role not found for memberId: " + memberId + " and studyroomId: " + studyroomId);
return BaseExceptionResponseStatus.FAILURE;
}
MemberRole memberRole = optionalMemberRole.orElseThrow(() -> new IllegalArgumentException("Error because of Invalid Member Id or Invalid StudyRoom Id"));

if (memberRole .equals(MemberRole.CAPTAIN)) {
if(studyroomRepository.deleteStudyroom(studyroomId)==1){
memberstudyroomRepository.deleteMemberStudyroom(studyroomId);
log.info("Success delete studyRoom in Service layer");
return BaseExceptionResponseStatus.SUCCESS;
}else {
log.info("Failure delete studyRoom");
return BaseExceptionResponseStatus.FAILURE;
}
} else {
log.info("Crew Member can't delete studyRoom");
return BaseExceptionResponseStatus.FAILURE;
}

}

@Transactional
public CreateStudyroomResponse createStudyroom(CreateStudyroomRequest request, long memberId) {
log.info("Start createStudyroom method of StudyroomService Class");
Expand Down Expand Up @@ -70,8 +103,4 @@ public void joinStudyroom(JoinStudyroomRequest request){
memberstudyroomRepository.save(memberStudyroom);

}




}
Loading