From 9047d59ecf2eeeb7f482dc4849c9beb6d5bd9030 Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Mon, 1 Jul 2024 18:03:46 +0900 Subject: [PATCH 01/36] =?UTF-8?q?feat=20:=20=EC=8A=A4=ED=84=B0=EB=94=94?= =?UTF-8?q?=EB=A3=B8=20=EC=82=AD=EC=A0=9C=20=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=EA=B3=84=EC=B8=B5=EA=B9=8C=EC=A7=80=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 추후 회원 기능 구현 완료되면 바뀔사항 많아서 대략 틀만 작성 --- .../status/BaseExceptionResponseStatus.java | 4 ++- .../dto/DeleteStudyroomRequest.java | 15 ++++++++ .../repository/MemberstudyroomRepository.java | 17 ++++++++++ .../repository/StudyroomRepository.java | 18 ++++++++++ .../api_server/sercice/StudyroomService.java | 34 +++++++++++++++++++ 5 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/linkode/api_server/dto/DeleteStudyroomRequest.java create mode 100644 src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java create mode 100644 src/main/java/com/linkode/api_server/repository/StudyroomRepository.java create mode 100644 src/main/java/com/linkode/api_server/sercice/StudyroomService.java diff --git a/src/main/java/com/linkode/api_server/common/response/status/BaseExceptionResponseStatus.java b/src/main/java/com/linkode/api_server/common/response/status/BaseExceptionResponseStatus.java index 1af320e..8e4f0aa 100644 --- a/src/main/java/com/linkode/api_server/common/response/status/BaseExceptionResponseStatus.java +++ b/src/main/java/com/linkode/api_server/common/response/status/BaseExceptionResponseStatus.java @@ -9,7 +9,9 @@ public enum BaseExceptionResponseStatus implements ResponseStatus{ /** * 1000: 요청 성공 (OK) */ - SUCCESS(1000,HttpStatus.OK.value(), "요청에 성공하였습니다."); + SUCCESS(1000,HttpStatus.OK.value(), "요청에 성공하였습니다."), + FAILURE(2000, HttpStatus.BAD_REQUEST.value(), "요청에 실패하였습니다."); + private final int code; private final int status; diff --git a/src/main/java/com/linkode/api_server/dto/DeleteStudyroomRequest.java b/src/main/java/com/linkode/api_server/dto/DeleteStudyroomRequest.java new file mode 100644 index 0000000..92c3f74 --- /dev/null +++ b/src/main/java/com/linkode/api_server/dto/DeleteStudyroomRequest.java @@ -0,0 +1,15 @@ +package com.linkode.api_server.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter @Setter +@AllArgsConstructor +@NoArgsConstructor +public class DeleteStudyroomRequest { + + private long studyroomId; + +} diff --git a/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java b/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java new file mode 100644 index 0000000..eafd40c --- /dev/null +++ b/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java @@ -0,0 +1,17 @@ +package com.linkode.api_server.repository; + +import com.linkode.api_server.domain.memberstudyroom.MemberStudyroom; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface MemberstudyroomRepository extends JpaRepository { + + @Query("SELECT ms FROM Memberstudyroom ms WHERE ms.member.id = :memberId AND ms.studyroom.id = :studyroomId") + Optional findByMemberIdAndStudyroomId(long studyroomId, long memberId); + + +} \ No newline at end of file diff --git a/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java b/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java new file mode 100644 index 0000000..9b386e8 --- /dev/null +++ b/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java @@ -0,0 +1,18 @@ +package com.linkode.api_server.repository; + +import com.linkode.api_server.domain.Studyroom; +import com.linkode.api_server.dto.DeleteStudyroomRequest; +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; + +@Repository +public interface StudyroomRepository extends JpaRepository { + @Transactional + @Modifying + @Query("UPDATE Studyroom sr SET sr.status = 'DELETE' WHERE sr.studyroomId = :#{#request.studyroomId}") + int deleteStudyroom(DeleteStudyroomRequest request); + +} \ No newline at end of file diff --git a/src/main/java/com/linkode/api_server/sercice/StudyroomService.java b/src/main/java/com/linkode/api_server/sercice/StudyroomService.java new file mode 100644 index 0000000..eab9cb3 --- /dev/null +++ b/src/main/java/com/linkode/api_server/sercice/StudyroomService.java @@ -0,0 +1,34 @@ +package com.linkode.api_server.sercice; + +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.DeleteStudyroomRequest; +import com.linkode.api_server.repository.MemberstudyroomRepository; +import com.linkode.api_server.repository.StudyroomRepository; +import lombok.AllArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +@AllArgsConstructor +public class StudyroomService { + + @Autowired + MemberstudyroomRepository memberstudyroomRepository; + + @Autowired + StudyroomRepository studyroomRepository; + + public BaseExceptionResponseStatus deleteStudyroom(DeleteStudyroomRequest request, long memberId){ + + MemberStudyroom memberStudyroom = memberstudyroomRepository.findByMemberIdAndStudyroomId(memberId,request.getStudyroomId()) + .orElseThrow(()->new IllegalArgumentException("Error because of Invalid Member Id or Invalid StudyRoom Id")); + + if(studyroomRepository.deleteStudyroom(request)==1&&memberStudyroom.getRole().equals(MemberRole.CAPTAIN)){ + return BaseExceptionResponseStatus.SUCCESS; + }else { + return BaseExceptionResponseStatus.FAILURE; + } + } +} From bdd0e887723e03d1a7bc85019eef99ae38deee03 Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Tue, 2 Jul 2024 01:27:09 +0900 Subject: [PATCH 02/36] =?UTF-8?q?feat=20:=20deleteStudyroom=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84=20-=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=EC=B2=98=EB=A6=AC=EC=99=80=20=EB=A1=9C=EA=B7=B8=20?= =?UTF-8?q?=EA=B0=95=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/StudyroomRepository.java | 4 +- .../api_server/sercice/StudyroomService.java | 34 --------------- .../api_server/service/StudyroomService.java | 43 +++++++++++++++++++ 3 files changed, 45 insertions(+), 36 deletions(-) delete mode 100644 src/main/java/com/linkode/api_server/sercice/StudyroomService.java create mode 100644 src/main/java/com/linkode/api_server/service/StudyroomService.java diff --git a/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java b/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java index 9b386e8..3116fac 100644 --- a/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java +++ b/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java @@ -12,7 +12,7 @@ public interface StudyroomRepository extends JpaRepository { @Transactional @Modifying - @Query("UPDATE Studyroom sr SET sr.status = 'DELETE' WHERE sr.studyroomId = :#{#request.studyroomId}") - int deleteStudyroom(DeleteStudyroomRequest request); + @Query("UPDATE Studyroom sr SET sr.status = 'DELETE' WHERE sr.studyroomId = :studyroomId") + int deleteStudyroom(long studyroomId); } \ No newline at end of file diff --git a/src/main/java/com/linkode/api_server/sercice/StudyroomService.java b/src/main/java/com/linkode/api_server/sercice/StudyroomService.java deleted file mode 100644 index eab9cb3..0000000 --- a/src/main/java/com/linkode/api_server/sercice/StudyroomService.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.linkode.api_server.sercice; - -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.DeleteStudyroomRequest; -import com.linkode.api_server.repository.MemberstudyroomRepository; -import com.linkode.api_server.repository.StudyroomRepository; -import lombok.AllArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -@AllArgsConstructor -public class StudyroomService { - - @Autowired - MemberstudyroomRepository memberstudyroomRepository; - - @Autowired - StudyroomRepository studyroomRepository; - - public BaseExceptionResponseStatus deleteStudyroom(DeleteStudyroomRequest request, long memberId){ - - MemberStudyroom memberStudyroom = memberstudyroomRepository.findByMemberIdAndStudyroomId(memberId,request.getStudyroomId()) - .orElseThrow(()->new IllegalArgumentException("Error because of Invalid Member Id or Invalid StudyRoom Id")); - - if(studyroomRepository.deleteStudyroom(request)==1&&memberStudyroom.getRole().equals(MemberRole.CAPTAIN)){ - return BaseExceptionResponseStatus.SUCCESS; - }else { - return BaseExceptionResponseStatus.FAILURE; - } - } -} diff --git a/src/main/java/com/linkode/api_server/service/StudyroomService.java b/src/main/java/com/linkode/api_server/service/StudyroomService.java new file mode 100644 index 0000000..4be2c7b --- /dev/null +++ b/src/main/java/com/linkode/api_server/service/StudyroomService.java @@ -0,0 +1,43 @@ +package com.linkode.api_server.service; + +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.repository.MemberstudyroomRepository; +import com.linkode.api_server.repository.StudyroomRepository; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +@AllArgsConstructor +@Slf4j +public class StudyroomService { + + @Autowired + MemberstudyroomRepository memberstudyroomRepository; + + @Autowired + StudyroomRepository studyroomRepository; + + public BaseExceptionResponseStatus deleteStudyroom(long studyroomId, long memberId) { + + MemberStudyroom memberStudyroom = memberstudyroomRepository.findByMemberIdAndStudyroomId(memberId, studyroomId) + .orElseThrow(() -> new IllegalArgumentException("Error because of Invalid Member Id or Invalid StudyRoom Id")); + + + if (memberStudyroom.getRole().equals(MemberRole.CAPTAIN)) { + if(studyroomRepository.deleteStudyroom(studyroomId)==1){ + log.info("Success delete studyRoom"); + return BaseExceptionResponseStatus.SUCCESS; + }else { + log.info("Failure delete studyRoom"); + return BaseExceptionResponseStatus.FAILURE; + } + } else { + log.info("Crew Member can't delete studyRoom"); + return BaseExceptionResponseStatus.FAILURE; + } + } +} From 5a76ffaa0ef55b04d6d4709b54b397350b4c8a42 Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Tue, 2 Jul 2024 01:44:23 +0900 Subject: [PATCH 03/36] =?UTF-8?q?feat=20:=20=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EA=B3=84=EC=B8=B5=20deleteStudyroom=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=98=88=EB=B9=84=20=EA=B5=AC=ED=98=84=20?= =?UTF-8?q?-=20=EB=A1=9C=EA=B7=B8=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/StudyroomController.java | 30 +++++++++++++++++++ .../api_server/service/StudyroomService.java | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/linkode/api_server/controller/StudyroomController.java diff --git a/src/main/java/com/linkode/api_server/controller/StudyroomController.java b/src/main/java/com/linkode/api_server/controller/StudyroomController.java new file mode 100644 index 0000000..27afe16 --- /dev/null +++ b/src/main/java/com/linkode/api_server/controller/StudyroomController.java @@ -0,0 +1,30 @@ +package com.linkode.api_server.controller; + +import com.linkode.api_server.common.response.status.BaseExceptionResponseStatus; +import com.linkode.api_server.service.StudyroomService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@Slf4j +@RequiredArgsConstructor +@RequestMapping("/studyroom") +public class StudyroomController { + + @Autowired + StudyroomService studyroomService; + + @PatchMapping("/removal") + public ResponseEntity deleteStudyroom(@RequestParam long studyroomId, @RequestParam long memberId){ + BaseExceptionResponseStatus responseStatus = studyroomService.deleteStudyroom(studyroomId,memberId); + log.info("Success Delete Studyroom API "); + HttpStatus httpStatus = HttpStatus.OK; + return new ResponseEntity<>(responseStatus,httpStatus); + } + +} diff --git a/src/main/java/com/linkode/api_server/service/StudyroomService.java b/src/main/java/com/linkode/api_server/service/StudyroomService.java index 4be2c7b..6f5d7b2 100644 --- a/src/main/java/com/linkode/api_server/service/StudyroomService.java +++ b/src/main/java/com/linkode/api_server/service/StudyroomService.java @@ -29,7 +29,7 @@ public BaseExceptionResponseStatus deleteStudyroom(long studyroomId, long member if (memberStudyroom.getRole().equals(MemberRole.CAPTAIN)) { if(studyroomRepository.deleteStudyroom(studyroomId)==1){ - log.info("Success delete studyRoom"); + log.info("Success delete studyRoom in Service layer"); return BaseExceptionResponseStatus.SUCCESS; }else { log.info("Failure delete studyRoom"); From 43aa83126cbc05edd91fac7cc24fad750392b5cd Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Tue, 2 Jul 2024 01:53:30 +0900 Subject: [PATCH 04/36] =?UTF-8?q?fix=20:=20=20findByMemberIdAndStudyroomId?= =?UTF-8?q?=20=EC=9D=98=20=EC=BF=BC=EB=A6=AC=EB=AC=B8=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api_server/repository/MemberstudyroomRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java b/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java index eafd40c..8997384 100644 --- a/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java +++ b/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java @@ -10,7 +10,7 @@ @Repository public interface MemberstudyroomRepository extends JpaRepository { - @Query("SELECT ms FROM Memberstudyroom ms WHERE ms.member.id = :memberId AND ms.studyroom.id = :studyroomId") + @Query("SELECT ms FROM MemberStudyroom ms WHERE ms.member.id = :memberId AND ms.studyroom.id = :studyroomId") Optional findByMemberIdAndStudyroomId(long studyroomId, long memberId); From d26411c1af7f88e822f950e680129eeee8360506 Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Tue, 2 Jul 2024 18:29:50 +0900 Subject: [PATCH 05/36] =?UTF-8?q?fix=20:=20=20=EC=95=84=EB=B0=94=ED=83=80?= =?UTF-8?q?=EC=99=80=20=EB=A7=B4=EB=B2=84=EA=B0=80=20=EC=9D=BC=EB=8C=80?= =?UTF-8?q?=EC=9D=BC=EA=B4=80=EA=B3=84=EB=A1=9C=20=EB=90=98=EC=96=B4?= =?UTF-8?q?=EC=9E=88=EB=8A=94=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 일대다 관계여야하는데 오류가있어서 수정했습니다. --- .../java/com/linkode/api_server/domain/Avatar.java | 13 +++++++++++-- .../java/com/linkode/api_server/domain/Member.java | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/linkode/api_server/domain/Avatar.java b/src/main/java/com/linkode/api_server/domain/Avatar.java index 98dc149..5caf801 100644 --- a/src/main/java/com/linkode/api_server/domain/Avatar.java +++ b/src/main/java/com/linkode/api_server/domain/Avatar.java @@ -7,6 +7,9 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.ArrayList; +import java.util.List; + @Entity @Getter @NoArgsConstructor @@ -25,7 +28,13 @@ public class Avatar extends BaseTime { @Column(nullable = false, columnDefinition = "VARCHAR(10)") private BaseStatus status; - @OneToOne(mappedBy = "avatar") - private Member member; + @OneToMany(mappedBy = "avatar") + private List members = new ArrayList<>(); + + public Avatar(Long avatarId, String avatarImg, BaseStatus status) { + this.avatarId = avatarId; + this.avatarImg = avatarImg; + this.status = status; + } } diff --git a/src/main/java/com/linkode/api_server/domain/Member.java b/src/main/java/com/linkode/api_server/domain/Member.java index 481cff4..a27456d 100644 --- a/src/main/java/com/linkode/api_server/domain/Member.java +++ b/src/main/java/com/linkode/api_server/domain/Member.java @@ -47,7 +47,7 @@ public class Member extends BaseTime { /** 캐릭터와의 연관관계의 주인 */ - @OneToOne + @ManyToOne @JoinColumn(name = "avatar_id") private Avatar avatar; From 2589118bb5e676de943fc8fc4df91e70e9fb1678 Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Tue, 2 Jul 2024 19:06:42 +0900 Subject: [PATCH 06/36] =?UTF-8?q?feat=20:=20=EB=A7=B4=EB=B2=84=20=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EB=B8=94=EC=97=90=20=EC=83=89=EC=83=81=20=EC=86=8D?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 테이블 설계시 색상 속성이 누락된것 같아 추가했습니다. --- src/main/java/com/linkode/api_server/domain/Member.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/linkode/api_server/domain/Member.java b/src/main/java/com/linkode/api_server/domain/Member.java index a27456d..63ff369 100644 --- a/src/main/java/com/linkode/api_server/domain/Member.java +++ b/src/main/java/com/linkode/api_server/domain/Member.java @@ -32,6 +32,9 @@ public class Member extends BaseTime { @Column(nullable = false) private String nickname; + @Column(nullable = false) + private String color; + @Enumerated(EnumType.STRING) @Column(nullable = false, columnDefinition = "VARCHAR(10)") private BaseStatus status; @@ -51,10 +54,11 @@ public class Member extends BaseTime { @JoinColumn(name = "avatar_id") private Avatar avatar; - public Member(Long memberId, String githubId, String nickname, BaseStatus status, Avatar avatar) { + public Member(Long memberId, String githubId, String nickname, String color,BaseStatus status, Avatar avatar) { this.memberId = memberId; this.githubId = githubId; this.nickname = nickname; + this.color=color; this.status = status; this.avatar = avatar; } From dbdf4bfc63ecae006dd30fd9cd52542986159f03 Mon Sep 17 00:00:00 2001 From: jungeun Date: Sun, 30 Jun 2024 13:07:51 +0900 Subject: [PATCH 07/36] =?UTF-8?q?fix=20:=20=EB=A1=9C=EC=BB=AC=20yml=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20pr=20=EB=AF=B8=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gitignore 에 application-local.yml 추가 --- .gitignore | 1 + src/main/resources/application-local.yml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index fa83153..0ce3690 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ bin/ out/ !**/src/main/**/out/ !**/src/test/**/out/ +application-local.yml ### NetBeans ### /nbproject/private/ diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 43a39a9..aab2ccf 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -1,8 +1,8 @@ spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/linkode?characterEncoding=UTF-8&serverTimezone=UTC - username: root + url: jdbc:mysql://127.0.0.1:3306/linkode?characterEncoding=UTF-8&serverTimezone=UTC + username: linkode password: ${DB_LOCAL_PASSWD} From e21cc879e1f2ac107bad7abe4971e45f2686b023 Mon Sep 17 00:00:00 2001 From: jungeun Date: Mon, 1 Jul 2024 23:55:27 +0900 Subject: [PATCH 08/36] =?UTF-8?q?chore=20:=20LoginService=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LoginController 에 있던 getAccessToken,getUserInfo 메소드 서비스로 옮김 --- .../controller/LoginController.java | 81 ++----------------- .../api_server/service/LoginService.java | 67 +++++++++++++++ 2 files changed, 75 insertions(+), 73 deletions(-) create mode 100644 src/main/java/com/linkode/api_server/service/LoginService.java diff --git a/src/main/java/com/linkode/api_server/controller/LoginController.java b/src/main/java/com/linkode/api_server/controller/LoginController.java index e0f38cc..f71e523 100644 --- a/src/main/java/com/linkode/api_server/controller/LoginController.java +++ b/src/main/java/com/linkode/api_server/controller/LoginController.java @@ -1,94 +1,29 @@ package com.linkode.api_server.controller; +import com.linkode.api_server.service.LoginService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.json.JSONObject; -import org.springframework.beans.factory.annotation.Value; import org.springframework.http.*; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.util.UriComponentsBuilder; - -import java.util.Collections; @Controller @Slf4j @RequiredArgsConstructor public class LoginController { - @Value("${SOCIAL_CLIENT_ID}") - private String clientId; - @Value("${SOCIAL_CLIENT_SECRET}") - private String clientSecret; + private final LoginService loginService; + + /** + * 소셜 로그인 + */ @GetMapping("/oauth2/redirect") public ResponseEntity githubLogin(@RequestParam String code) { - String accessToken = getAccessToken(code); - String userInfo = getUserInfo(accessToken); + String accessToken = loginService.getAccessToken(code); + String userInfo = loginService.getUserInfo(accessToken); // 깃허브에서 받은 엑세스토큰으로 사용자 정보 요청하기 return new ResponseEntity<>(userInfo, HttpStatus.OK); } - private String getAccessToken(String code) { - UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("https://github.com/login/oauth/access_token") - .queryParam("client_id", clientId) - .queryParam("client_secret", clientSecret) - .queryParam("code", code); - - RestTemplate restTemplate = new RestTemplate(); - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); - HttpEntity entity = new HttpEntity<>(headers); - - ResponseEntity response = restTemplate.exchange( - builder.toUriString(), - HttpMethod.POST, - entity, - String.class - ); - log.info(response.getBody()); - JSONObject jsonObject = new JSONObject(response.getBody()); - // 토큰 저장 하는 redis 구현 해야하는 곳 - return jsonObject.getString("access_token"); // access_token 값만 반환 - } - - private String getUserInfo(String accessToken) { - String userInfoUri = "https://api.github.com/user"; - - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", "token " + accessToken); - HttpEntity entity = new HttpEntity<>(headers); - - RestTemplate restTemplate = new RestTemplate(); - - ResponseEntity response = restTemplate.exchange( - userInfoUri, - HttpMethod.GET, - entity, - String.class - ); - - JSONObject jsonObject = new JSONObject(response.getBody()); - return jsonObject.getString("login"); - } - - private String getUserEmailInfo(String accessToken) { - String userEmailInfoUri = "https://api.github.com/user/emails"; - - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", "token " + accessToken); - HttpEntity entity = new HttpEntity<>(headers); - - RestTemplate restTemplate = new RestTemplate(); - - ResponseEntity response = restTemplate.exchange( - userEmailInfoUri, - HttpMethod.GET, - entity, - String.class - ); - - return response.getBody(); - } } \ No newline at end of file diff --git a/src/main/java/com/linkode/api_server/service/LoginService.java b/src/main/java/com/linkode/api_server/service/LoginService.java new file mode 100644 index 0000000..c193c16 --- /dev/null +++ b/src/main/java/com/linkode/api_server/service/LoginService.java @@ -0,0 +1,67 @@ +package com.linkode.api_server.service; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.*; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; + +import java.util.Collections; + +@Slf4j +@Service +@RequiredArgsConstructor +public class LoginService { + @Value("${SOCIAL_CLIENT_ID}") + private String clientId; + @Value("${SOCIAL_CLIENT_SECRET}") + private String clientSecret; + + /** + * 소셜로그인 + */ + public String getAccessToken(String code) { + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("https://github.com/login/oauth/access_token") + .queryParam("client_id", clientId) + .queryParam("client_secret", clientSecret) + .queryParam("code", code); + + RestTemplate restTemplate = new RestTemplate(); + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + HttpEntity entity = new HttpEntity<>(headers); + + ResponseEntity response = restTemplate.exchange( + builder.toUriString(), + HttpMethod.POST, + entity, + String.class + ); + log.info(response.getBody()); + JSONObject jsonObject = new JSONObject(response.getBody()); + return jsonObject.getString("access_token"); // access_token 값만 반환 + } + + public String getUserInfo(String accessToken) { + String userInfoUri = "https://api.github.com/user"; + + HttpHeaders headers = new HttpHeaders(); + headers.set("Authorization", "token " + accessToken); + HttpEntity entity = new HttpEntity<>(headers); + + RestTemplate restTemplate = new RestTemplate(); + + ResponseEntity response = restTemplate.exchange( + userInfoUri, + HttpMethod.GET, + entity, + String.class + ); + + JSONObject jsonObject = new JSONObject(response.getBody()); + return jsonObject.getString("login"); + } +} From cffd0cbe790f908fadda62aef884084f1b6a5022 Mon Sep 17 00:00:00 2001 From: jungeun Date: Tue, 2 Jul 2024 00:15:39 +0900 Subject: [PATCH 09/36] =?UTF-8?q?feat=20:=20LoginResponse=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/linkode/api_server/dto/member/LoginResponse.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/com/linkode/api_server/dto/member/LoginResponse.java diff --git a/src/main/java/com/linkode/api_server/dto/member/LoginResponse.java b/src/main/java/com/linkode/api_server/dto/member/LoginResponse.java new file mode 100644 index 0000000..0469c54 --- /dev/null +++ b/src/main/java/com/linkode/api_server/dto/member/LoginResponse.java @@ -0,0 +1,9 @@ +package com.linkode.api_server.dto.member; + +public class LoginResponse { + /** + * 깃허브 소셜로그인 + */ + private boolean isMember; + private String githubId; +} From 9d508aea9e0ccb906b3564d863461ad8ab815499 Mon Sep 17 00:00:00 2001 From: jungeun Date: Tue, 2 Jul 2024 01:34:02 +0900 Subject: [PATCH 10/36] =?UTF-8?q?feat=20:=20MemberRepository.existsByGithu?= =?UTF-8?q?bIdAndStatus=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api_server/repository/MemberRepository.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/java/com/linkode/api_server/repository/MemberRepository.java diff --git a/src/main/java/com/linkode/api_server/repository/MemberRepository.java b/src/main/java/com/linkode/api_server/repository/MemberRepository.java new file mode 100644 index 0000000..c0770fb --- /dev/null +++ b/src/main/java/com/linkode/api_server/repository/MemberRepository.java @@ -0,0 +1,10 @@ +package com.linkode.api_server.repository; + +import com.linkode.api_server.domain.Member; +import com.linkode.api_server.domain.base.BaseStatus; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface MemberRepository extends JpaRepository { + + boolean existsByGithubIdAndStatus(String githubId, BaseStatus ACTIVE); +} From 90a20a5ab32d8bb8fa7be33f7d02b80dbbd8e305 Mon Sep 17 00:00:00 2001 From: jungeun Date: Tue, 2 Jul 2024 01:36:55 +0900 Subject: [PATCH 11/36] =?UTF-8?q?feat=20:=20isMember=20->=20memberStatus?= =?UTF-8?q?=20=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit isMember 로 하니까 인식을 잘못하는 오류발생 --- .../com/linkode/api_server/dto/member/LoginResponse.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/linkode/api_server/dto/member/LoginResponse.java b/src/main/java/com/linkode/api_server/dto/member/LoginResponse.java index 0469c54..58d0450 100644 --- a/src/main/java/com/linkode/api_server/dto/member/LoginResponse.java +++ b/src/main/java/com/linkode/api_server/dto/member/LoginResponse.java @@ -1,9 +1,15 @@ package com.linkode.api_server.dto.member; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor public class LoginResponse { /** * 깃허브 소셜로그인 */ - private boolean isMember; + private boolean memberStatus; private String githubId; } From 240ca8d5589d428dedc25abc42c085b4ae961732 Mon Sep 17 00:00:00 2001 From: jungeun Date: Tue, 2 Jul 2024 01:43:49 +0900 Subject: [PATCH 12/36] =?UTF-8?q?feat=20:=20=EC=86=8C=EC=85=9C=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EC=A0=88=EB=B0=98=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 아직 jwt 반환은 미완성 --- .../controller/LoginController.java | 29 ------------------ .../controller/MemberController.java | 30 +++++++++++++++++++ .../api_server/service/LoginService.java | 24 +++++++++++++-- 3 files changed, 52 insertions(+), 31 deletions(-) delete mode 100644 src/main/java/com/linkode/api_server/controller/LoginController.java create mode 100644 src/main/java/com/linkode/api_server/controller/MemberController.java diff --git a/src/main/java/com/linkode/api_server/controller/LoginController.java b/src/main/java/com/linkode/api_server/controller/LoginController.java deleted file mode 100644 index f71e523..0000000 --- a/src/main/java/com/linkode/api_server/controller/LoginController.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.linkode.api_server.controller; - -import com.linkode.api_server.service.LoginService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.*; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; - -@Controller -@Slf4j -@RequiredArgsConstructor -public class LoginController { - - private final LoginService loginService; - - /** - * 소셜 로그인 - */ - @GetMapping("/oauth2/redirect") - public ResponseEntity githubLogin(@RequestParam String code) { - String accessToken = loginService.getAccessToken(code); - String userInfo = loginService.getUserInfo(accessToken); // 깃허브에서 받은 엑세스토큰으로 사용자 정보 요청하기 - - return new ResponseEntity<>(userInfo, HttpStatus.OK); - } - -} \ No newline at end of file diff --git a/src/main/java/com/linkode/api_server/controller/MemberController.java b/src/main/java/com/linkode/api_server/controller/MemberController.java new file mode 100644 index 0000000..b25cace --- /dev/null +++ b/src/main/java/com/linkode/api_server/controller/MemberController.java @@ -0,0 +1,30 @@ +package com.linkode.api_server.controller; + +import com.linkode.api_server.common.response.BaseResponse; +import com.linkode.api_server.dto.member.LoginResponse; +import com.linkode.api_server.service.LoginService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@Slf4j +@RequiredArgsConstructor +public class MemberController { + + private final LoginService loginService; + + /** + * 소셜 로그인 + */ + @GetMapping("/oauth2/redirect") + public BaseResponse githubLogin(@RequestParam String code) { + log.info("[MemberController.githubLogin]"); + return new BaseResponse<>(loginService.githubLogin(code)); + } + + + +} \ No newline at end of file diff --git a/src/main/java/com/linkode/api_server/service/LoginService.java b/src/main/java/com/linkode/api_server/service/LoginService.java index c193c16..86df28a 100644 --- a/src/main/java/com/linkode/api_server/service/LoginService.java +++ b/src/main/java/com/linkode/api_server/service/LoginService.java @@ -1,5 +1,8 @@ package com.linkode.api_server.service; +import com.linkode.api_server.domain.base.BaseStatus; +import com.linkode.api_server.dto.member.LoginResponse; +import com.linkode.api_server.repository.MemberRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.json.JSONObject; @@ -20,10 +23,20 @@ public class LoginService { @Value("${SOCIAL_CLIENT_SECRET}") private String clientSecret; + private final MemberRepository memberRepository; + /** * 소셜로그인 */ - public String getAccessToken(String code) { + public LoginResponse githubLogin(String code){ + log.info("[LoginService.githubLogin]"); + String accessToken = getAccessToken(code); + String githubId = getUserInfo(accessToken); + boolean memberStatus = checkMember(githubId); + return new LoginResponse(memberStatus,githubId); + } + private String getAccessToken(String code) { + log.info("[LoginService.githubLogin.getAccessToken]"); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("https://github.com/login/oauth/access_token") .queryParam("client_id", clientId) .queryParam("client_secret", clientSecret) @@ -45,7 +58,8 @@ public String getAccessToken(String code) { return jsonObject.getString("access_token"); // access_token 값만 반환 } - public String getUserInfo(String accessToken) { + private String getUserInfo(String accessToken) { + log.info("[LoginService.githubLogin.getUserInfo]"); String userInfoUri = "https://api.github.com/user"; HttpHeaders headers = new HttpHeaders(); @@ -64,4 +78,10 @@ public String getUserInfo(String accessToken) { JSONObject jsonObject = new JSONObject(response.getBody()); return jsonObject.getString("login"); } + + private boolean checkMember(String githubId){ + log.info("[LoginService.githubLogin.checkMember]"); + boolean memberStatus = memberRepository.existsByGithubIdAndStatus(githubId, BaseStatus.ACTIVE); + return memberStatus; + } } From 70e93f10a3568077cbdf7c267847408e8b6dcca8 Mon Sep 17 00:00:00 2001 From: jungeun Date: Tue, 2 Jul 2024 01:47:31 +0900 Subject: [PATCH 13/36] =?UTF-8?q?feat=20:=20=EC=86=8C=EC=85=9C=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EC=A0=88=EB=B0=98=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 아직 jwt 반환은 미완성 --- src/main/java/com/linkode/api_server/OAuthInfo.java | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 src/main/java/com/linkode/api_server/OAuthInfo.java diff --git a/src/main/java/com/linkode/api_server/OAuthInfo.java b/src/main/java/com/linkode/api_server/OAuthInfo.java deleted file mode 100644 index 42e80f5..0000000 --- a/src/main/java/com/linkode/api_server/OAuthInfo.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.linkode.api_server; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class OAuthInfo { - @JsonProperty("access_token") - private String accessToken; -} From 8b8bb4f2e210dbb5ac26055a58dd1f3fe985fc55 Mon Sep 17 00:00:00 2001 From: jungeun Date: Wed, 3 Jul 2024 13:07:17 +0900 Subject: [PATCH 14/36] =?UTF-8?q?feat=20:=20=ED=86=A0=ED=81=B0=20=EB=B0=9C?= =?UTF-8?q?=EA=B8=89=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 6 ++ .../com/linkode/api_server/JwtProvider.java | 65 +++++++++++++++++++ .../api_server/dto/member/LoginResponse.java | 2 + .../api_server/service/LoginService.java | 14 +++- src/main/resources/application.yml | 5 ++ 5 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/linkode/api_server/JwtProvider.java diff --git a/build.gradle b/build.gradle index dc43774..8ba0a43 100644 --- a/build.gradle +++ b/build.gradle @@ -34,6 +34,12 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.json:json:20210307' implementation group: 'org.kohsuke', name: 'github-api', version: '1.125' + implementation 'jakarta.xml.bind:jakarta.xml.bind-api:3.0.1' + implementation 'org.glassfish.jaxb:jaxb-runtime:3.0.1' + implementation 'io.jsonwebtoken:jjwt-api:0.11.5' + implementation 'io.jsonwebtoken:jjwt-impl:0.11.5' + implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5' // JSON 처리용 추가 라이브러리 + } tasks.named('test') { diff --git a/src/main/java/com/linkode/api_server/JwtProvider.java b/src/main/java/com/linkode/api_server/JwtProvider.java new file mode 100644 index 0000000..f4eb66d --- /dev/null +++ b/src/main/java/com/linkode/api_server/JwtProvider.java @@ -0,0 +1,65 @@ +package com.linkode.api_server; + +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; +import io.jsonwebtoken.Claims; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.util.Date; + +@Component +public class JwtProvider { + + @Value("${jwt.secret}") + private String secretKey; + + @Value("${jwt.access-token-expiration}") + private long accessTokenExpiration; + + @Value("${jwt.refresh-token-expiration}") + private long refreshTokenExpiration; + + // Access Token 생성 + public String createAccessToken(String githubId) { + Claims claims = Jwts.claims().setSubject(githubId); + Date now = new Date(); + Date validity = new Date(now.getTime() + accessTokenExpiration); + + return Jwts.builder() + .setClaims(claims) + .setIssuedAt(now) + .setExpiration(validity) + .signWith(SignatureAlgorithm.HS256, secretKey) + .compact(); + } + + // Refresh Token 생성 + public String createRefreshToken(String githubId) { + Claims claims = Jwts.claims().setSubject(githubId); + Date now = new Date(); + Date validity = new Date(now.getTime() + refreshTokenExpiration); + + return Jwts.builder() + .setClaims(claims) + .setIssuedAt(now) + .setExpiration(validity) + .signWith(SignatureAlgorithm.HS256, secretKey) + .compact(); + } + + // Access Token 검증 + public boolean validateToken(String token) { + try { + Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token); + return true; + } catch (Exception e) { + return false; + } + } + + // 토큰에서 사용자 정보 추출 + public String getGithubId(String token) { + return Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token).getBody().getSubject(); + } +} diff --git a/src/main/java/com/linkode/api_server/dto/member/LoginResponse.java b/src/main/java/com/linkode/api_server/dto/member/LoginResponse.java index 58d0450..00c0b83 100644 --- a/src/main/java/com/linkode/api_server/dto/member/LoginResponse.java +++ b/src/main/java/com/linkode/api_server/dto/member/LoginResponse.java @@ -12,4 +12,6 @@ public class LoginResponse { */ private boolean memberStatus; private String githubId; + private String accessToken; + private String refreshToken; } diff --git a/src/main/java/com/linkode/api_server/service/LoginService.java b/src/main/java/com/linkode/api_server/service/LoginService.java index 86df28a..40f0a60 100644 --- a/src/main/java/com/linkode/api_server/service/LoginService.java +++ b/src/main/java/com/linkode/api_server/service/LoginService.java @@ -1,5 +1,6 @@ package com.linkode.api_server.service; +import com.linkode.api_server.JwtProvider; import com.linkode.api_server.domain.base.BaseStatus; import com.linkode.api_server.dto.member.LoginResponse; import com.linkode.api_server.repository.MemberRepository; @@ -24,16 +25,24 @@ public class LoginService { private String clientSecret; private final MemberRepository memberRepository; + private final JwtProvider jwtProvider; /** - * 소셜로그인 + * 소셜 로그인 */ public LoginResponse githubLogin(String code){ log.info("[LoginService.githubLogin]"); String accessToken = getAccessToken(code); String githubId = getUserInfo(accessToken); boolean memberStatus = checkMember(githubId); - return new LoginResponse(memberStatus,githubId); + String jwtAccessToken = null; + String jwtRefreshToken = null; + if(memberStatus){ + jwtAccessToken = jwtProvider.createAccessToken(githubId); + jwtRefreshToken = jwtProvider.createRefreshToken(githubId); + } + + return new LoginResponse(memberStatus,githubId,jwtAccessToken,jwtRefreshToken); } private String getAccessToken(String code) { log.info("[LoginService.githubLogin.getAccessToken]"); @@ -84,4 +93,5 @@ private boolean checkMember(String githubId){ boolean memberStatus = memberRepository.existsByGithubIdAndStatus(githubId, BaseStatus.ACTIVE); return memberStatus; } + } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 286fe37..48afc17 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -33,3 +33,8 @@ logging: org: springframework: web: DEBUG + +jwt: + secret: ${JWT_SECRET} + access-token-expiration: 3600000 # 1 hour in milliseconds + refresh-token-expiration: 86400000 # 1 day in milliseconds From caf639d90fd5b183a68cbdc3a24b2449e0fa012c Mon Sep 17 00:00:00 2001 From: jungeun Date: Wed, 3 Jul 2024 13:23:40 +0900 Subject: [PATCH 15/36] =?UTF-8?q?feat=20:=20RedisConfig=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 ++ .../linkode/api_server/config/RedisConfig.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/main/java/com/linkode/api_server/config/RedisConfig.java diff --git a/build.gradle b/build.gradle index 8ba0a43..abc50dd 100644 --- a/build.gradle +++ b/build.gradle @@ -40,6 +40,8 @@ dependencies { implementation 'io.jsonwebtoken:jjwt-impl:0.11.5' implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5' // JSON 처리용 추가 라이브러리 + // Spring Boot Redis Starter + implementation 'org.springframework.boot:spring-boot-starter-data-redis' } tasks.named('test') { diff --git a/src/main/java/com/linkode/api_server/config/RedisConfig.java b/src/main/java/com/linkode/api_server/config/RedisConfig.java new file mode 100644 index 0000000..ad142d4 --- /dev/null +++ b/src/main/java/com/linkode/api_server/config/RedisConfig.java @@ -0,0 +1,16 @@ +package com.linkode.api_server.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; + +@Configuration +public class RedisConfig { + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) { + RedisTemplate template = new RedisTemplate<>(); + template.setConnectionFactory(connectionFactory); + return template; + } +} From 5f19124effbcd5283a15ce654717e5e501e8fee6 Mon Sep 17 00:00:00 2001 From: jungeun Date: Wed, 3 Jul 2024 13:31:01 +0900 Subject: [PATCH 16/36] =?UTF-8?q?feat=20:=20=EB=A0=88=EB=94=94=EC=8A=A4=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=ED=95=98=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api_server/service/LoginService.java | 3 ++ .../api_server/service/TokenService.java | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/java/com/linkode/api_server/service/TokenService.java diff --git a/src/main/java/com/linkode/api_server/service/LoginService.java b/src/main/java/com/linkode/api_server/service/LoginService.java index 40f0a60..eac1b7d 100644 --- a/src/main/java/com/linkode/api_server/service/LoginService.java +++ b/src/main/java/com/linkode/api_server/service/LoginService.java @@ -26,6 +26,7 @@ public class LoginService { private final MemberRepository memberRepository; private final JwtProvider jwtProvider; + private final TokenService tokenService; /** * 소셜 로그인 @@ -40,6 +41,8 @@ public LoginResponse githubLogin(String code){ if(memberStatus){ jwtAccessToken = jwtProvider.createAccessToken(githubId); jwtRefreshToken = jwtProvider.createRefreshToken(githubId); + // 레디스 저장 + tokenService.storeToken(jwtRefreshToken, githubId); } return new LoginResponse(memberStatus,githubId,jwtAccessToken,jwtRefreshToken); diff --git a/src/main/java/com/linkode/api_server/service/TokenService.java b/src/main/java/com/linkode/api_server/service/TokenService.java new file mode 100644 index 0000000..243714d --- /dev/null +++ b/src/main/java/com/linkode/api_server/service/TokenService.java @@ -0,0 +1,35 @@ +package com.linkode.api_server.service; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import java.util.concurrent.TimeUnit; + +@Slf4j +@Service +@RequiredArgsConstructor +public class TokenService { + @Value("${jwt.refresh-token-expiration}") + private long refreshTokenExpiration; + + private final RedisTemplate redisTemplate; + + public void storeToken(String token, String githubId) { + // redis 에 토큰 저장 + redisTemplate.opsForValue().set(token, githubId, refreshTokenExpiration, TimeUnit.MILLISECONDS); + } + + public boolean checkTokenExists(String token) { + // 들어온 토큰이 redis 에 있는지 확인 + Boolean result = redisTemplate.hasKey(token); + return result != null && result; + } + + public void invalidateToken(String token) { + // redis 에서 토큰 삭제 + redisTemplate.delete(token); + } +} From ed9ae6e738c66f1c41eee3d21cbe415ccbb1847b Mon Sep 17 00:00:00 2001 From: jungeun Date: Wed, 3 Jul 2024 13:31:50 +0900 Subject: [PATCH 17/36] =?UTF-8?q?feat=20:=20=EB=A0=88=EB=94=94=EC=8A=A4=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=ED=95=98=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/linkode/api_server/dto/member/LoginResponse.java | 1 - src/main/java/com/linkode/api_server/service/LoginService.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/com/linkode/api_server/dto/member/LoginResponse.java b/src/main/java/com/linkode/api_server/dto/member/LoginResponse.java index 00c0b83..b4395cb 100644 --- a/src/main/java/com/linkode/api_server/dto/member/LoginResponse.java +++ b/src/main/java/com/linkode/api_server/dto/member/LoginResponse.java @@ -1,6 +1,5 @@ package com.linkode.api_server.dto.member; -import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/linkode/api_server/service/LoginService.java b/src/main/java/com/linkode/api_server/service/LoginService.java index eac1b7d..823d4e4 100644 --- a/src/main/java/com/linkode/api_server/service/LoginService.java +++ b/src/main/java/com/linkode/api_server/service/LoginService.java @@ -44,7 +44,6 @@ public LoginResponse githubLogin(String code){ // 레디스 저장 tokenService.storeToken(jwtRefreshToken, githubId); } - return new LoginResponse(memberStatus,githubId,jwtAccessToken,jwtRefreshToken); } private String getAccessToken(String code) { From 96e907eb29ab52d0a6330846be516b1bba22a7e2 Mon Sep 17 00:00:00 2001 From: jungeun Date: Wed, 3 Jul 2024 13:52:58 +0900 Subject: [PATCH 18/36] =?UTF-8?q?feat=20:=20=EB=A0=88=EB=94=94=EC=8A=A4=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=ED=95=98=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 48afc17..afbb5c5 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -16,6 +16,9 @@ spring: config: activate: on-profile: local + redis: + host: localhost + port: 6379 --- @@ -38,3 +41,5 @@ jwt: secret: ${JWT_SECRET} access-token-expiration: 3600000 # 1 hour in milliseconds refresh-token-expiration: 86400000 # 1 day in milliseconds + + From 3705bdf93bbc713dfb6dc88c36ccc3227275befd Mon Sep 17 00:00:00 2001 From: jungeun Date: Wed, 3 Jul 2024 13:53:10 +0900 Subject: [PATCH 19/36] =?UTF-8?q?feat=20:=20=EB=A0=88=EB=94=94=EC=8A=A4=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=ED=95=98=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index afbb5c5..05dcba4 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -19,7 +19,6 @@ spring: redis: host: localhost port: 6379 - --- spring: From dbc564670050be4a8a3cefb051793c0df83a9068 Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Wed, 3 Jul 2024 18:57:25 +0900 Subject: [PATCH 20/36] =?UTF-8?q?feat=20:=20=EB=A0=88=EB=94=94=EC=8A=A4=20?= =?UTF-8?q?ec2=20=EB=B0=B0=ED=8F=AC=20=ED=99=98=EA=B2=BD=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/gradle.yml | 3 +++ src/main/resources/application.yml | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 11c6c31..522b21b 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -22,6 +22,7 @@ jobs: SOCIAL_CLIENT_ID: ${{ secrets.SOCIAL_CLIENT_ID }} SOCIAL_CLIENT_PASSWD: ${{ secrets.SOCIAL_CLIENT_PASSWD }} SOCIAL_CLIENT_SECRET: ${{ secrets.SOCIAL_CLIENT_SECRET }} + JWT_SECRET: ${{ secrets.JWT_SECRET }} steps: - name: Checkout repository @@ -66,6 +67,7 @@ jobs: --build-arg SOCIAL_CLIENT_ID=${{ secrets.SOCIAL_CLIENT_ID }} \ --build-arg SOCIAL_CLIENT_PASSWD=${{ secrets.SOCIAL_CLIENT_PASSWD }} \ --build-arg SOCIAL_CLIENT_SECRET=${{ secrets.SOCIAL_CLIENT_SECRET }} \ + --build-arg JWT_SECRET=${{ secrets.JWT_SECRET }} \ -t linkode/linkode:latest . docker images docker push linkode/linkode:latest @@ -91,6 +93,7 @@ jobs: -e SOCIAL_CLIENT_ID=${{ secrets.SOCIAL_CLIENT_ID }} \ -e SOCIAL_CLIENT_PASSWD=${{ secrets.SOCIAL_CLIENT_PASSWD }} \ -e SOCIAL_CLIENT_SECRET=${{ secrets.SOCIAL_CLIENT_SECRET }} \ + -e JWT_SECRET=${{ secrets.JWT_SECRET }} -p 8080:8080 ${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }} sudo docker logs $(sudo docker ps -q --filter ancestor=${{ secrets.DOCKER_HUB_USERNAME }}/${{ secrets.DOCKER_HUB_REPO_NAME }}) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 05dcba4..ee40c6f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -9,7 +9,9 @@ spring: config: activate: on-profile: prod - + redis: + host: localhost + port: 6379 --- spring: From df06434585c6c33bf7f2ea3aba70ae6f5ebda296 Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Thu, 4 Jul 2024 10:05:20 +0900 Subject: [PATCH 21/36] =?UTF-8?q?feat=20:=20Authorization=20=ED=86=A0?= =?UTF-8?q?=ED=81=B0=EC=9D=84=20=ED=86=B5=ED=95=B4=20memberId=20=EB=B0=9B?= =?UTF-8?q?=EB=8A=94=20=EC=98=88=EB=B9=84=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=ED=95=B4=EB=91=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../linkode/api_server/controller/StudyroomController.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/linkode/api_server/controller/StudyroomController.java b/src/main/java/com/linkode/api_server/controller/StudyroomController.java index 27afe16..15ad8ca 100644 --- a/src/main/java/com/linkode/api_server/controller/StudyroomController.java +++ b/src/main/java/com/linkode/api_server/controller/StudyroomController.java @@ -1,5 +1,6 @@ package com.linkode.api_server.controller; +import com.linkode.api_server.JwtProvider; import com.linkode.api_server.common.response.status.BaseExceptionResponseStatus; import com.linkode.api_server.service.StudyroomService; import lombok.RequiredArgsConstructor; @@ -19,8 +20,12 @@ public class StudyroomController { @Autowired StudyroomService studyroomService; + JwtProvider jwtProvider; + @PatchMapping("/removal") - public ResponseEntity deleteStudyroom(@RequestParam long studyroomId, @RequestParam long memberId){ + public ResponseEntity deleteStudyroom(@RequestHeader("Authorization") String authorization,@RequestHeader @RequestParam long studyroomId, @RequestParam long memberId){ + +// long memberId = jwtProvider.getMemberId(authorization); BaseExceptionResponseStatus responseStatus = studyroomService.deleteStudyroom(studyroomId,memberId); log.info("Success Delete Studyroom API "); HttpStatus httpStatus = HttpStatus.OK; From a15aaf501d71b62e1b1b438555197ac2ee356c58 Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Thu, 4 Jul 2024 10:11:27 +0900 Subject: [PATCH 22/36] =?UTF-8?q?feat=20:=20Authorization=20=ED=86=A0?= =?UTF-8?q?=ED=81=B0=EC=9D=84=20=ED=86=B5=ED=95=B4=20memberId=20=EB=B0=9B?= =?UTF-8?q?=EB=8A=94=20=EC=98=88=EB=B9=84=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=ED=95=B4=EB=91=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/linkode/api_server/controller/StudyroomController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/linkode/api_server/controller/StudyroomController.java b/src/main/java/com/linkode/api_server/controller/StudyroomController.java index 15ad8ca..f16efbf 100644 --- a/src/main/java/com/linkode/api_server/controller/StudyroomController.java +++ b/src/main/java/com/linkode/api_server/controller/StudyroomController.java @@ -25,7 +25,7 @@ public class StudyroomController { @PatchMapping("/removal") public ResponseEntity deleteStudyroom(@RequestHeader("Authorization") String authorization,@RequestHeader @RequestParam long studyroomId, @RequestParam long memberId){ -// long memberId = jwtProvider.getMemberId(authorization); +// long memberId = jwtProvider.extractIdFromHeader(authorization); BaseExceptionResponseStatus responseStatus = studyroomService.deleteStudyroom(studyroomId,memberId); log.info("Success Delete Studyroom API "); HttpStatus httpStatus = HttpStatus.OK; From 197e46505cdbd555d25bf6372cc6417e5c304c7e Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Thu, 4 Jul 2024 12:58:22 +0900 Subject: [PATCH 23/36] =?UTF-8?q?feat=20:=20@EnableJpaAuditing=20=ED=86=B5?= =?UTF-8?q?=ED=95=B4=20=EC=83=9D=EC=84=B1=EC=9D=BC=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=EC=9D=BC=20=EC=9E=90=EB=8F=99=EC=83=9D=EA=B8=B0=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/linkode/api_server/ApiServerApplication.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/linkode/api_server/ApiServerApplication.java b/src/main/java/com/linkode/api_server/ApiServerApplication.java index 5d7b506..67ec4d8 100644 --- a/src/main/java/com/linkode/api_server/ApiServerApplication.java +++ b/src/main/java/com/linkode/api_server/ApiServerApplication.java @@ -2,8 +2,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @SpringBootApplication +@EnableJpaAuditing public class ApiServerApplication { public static void main(String[] args) { From b6709d619ef9ccecd9fdf55fbeedd034e87fb497 Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Thu, 4 Jul 2024 12:58:46 +0900 Subject: [PATCH 24/36] =?UTF-8?q?feat=20:=20=EB=AA=85=EC=84=B8=EC=84=9C=20?= =?UTF-8?q?=ED=98=95=EC=8B=9D=EC=9C=BC=EB=A1=9C=20api=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=EB=90=98=EB=8F=84=EB=A1=9D=20=EB=B0=98=ED=99=98=EC=9E=90?= =?UTF-8?q?=EB=A3=8C=ED=98=95=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../linkode/api_server/controller/StudyroomController.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/linkode/api_server/controller/StudyroomController.java b/src/main/java/com/linkode/api_server/controller/StudyroomController.java index f16efbf..837dc33 100644 --- a/src/main/java/com/linkode/api_server/controller/StudyroomController.java +++ b/src/main/java/com/linkode/api_server/controller/StudyroomController.java @@ -1,6 +1,7 @@ package com.linkode.api_server.controller; import com.linkode.api_server.JwtProvider; +import com.linkode.api_server.common.response.BaseResponse; import com.linkode.api_server.common.response.status.BaseExceptionResponseStatus; import com.linkode.api_server.service.StudyroomService; import lombok.RequiredArgsConstructor; @@ -23,13 +24,13 @@ public class StudyroomController { JwtProvider jwtProvider; @PatchMapping("/removal") - public ResponseEntity deleteStudyroom(@RequestHeader("Authorization") String authorization,@RequestHeader @RequestParam long studyroomId, @RequestParam long memberId){ + public BaseResponse deleteStudyroom(@RequestHeader("Authorization") String authorization, @RequestHeader @RequestParam long studyroomId, @RequestParam long memberId){ // long memberId = jwtProvider.extractIdFromHeader(authorization); BaseExceptionResponseStatus responseStatus = studyroomService.deleteStudyroom(studyroomId,memberId); log.info("Success Delete Studyroom API "); HttpStatus httpStatus = HttpStatus.OK; - return new ResponseEntity<>(responseStatus,httpStatus); + return new BaseResponse<>(responseStatus); } } From c1d5cd5ef6857ef1af6b54dd79ae99c8f45215f0 Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Thu, 4 Jul 2024 15:15:29 +0900 Subject: [PATCH 25/36] =?UTF-8?q?feat=20:=20MemberstudyroomRepository?= =?UTF-8?q?=EC=97=90=20=EC=97=AD=ED=95=A0=EC=B0=BE=EB=8A=94=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80,=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=EA=B3=84=EC=B8=B5=20=EC=88=98=EC=A0=95=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EA=B0=95?= =?UTF-8?q?=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 삭제요청한 스터디룸이 없는경우 500이 아닌 예외처리 메시지 반환하도록 --- .../api_server/common/response/BaseResponse.java | 7 +++++++ .../api_server/controller/StudyroomController.java | 10 ++++++---- .../repository/MemberstudyroomRepository.java | 6 +++--- .../api_server/service/StudyroomService.java | 13 ++++++++++--- src/main/resources/application-local.yml | 4 ++-- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/linkode/api_server/common/response/BaseResponse.java b/src/main/java/com/linkode/api_server/common/response/BaseResponse.java index ccebbca..3c2720f 100644 --- a/src/main/java/com/linkode/api_server/common/response/BaseResponse.java +++ b/src/main/java/com/linkode/api_server/common/response/BaseResponse.java @@ -26,6 +26,13 @@ public BaseResponse(T result) { this.result = result; } + public BaseResponse(ResponseStatus status, T result) { + this.code = status.getCode(); + this.status = status.getStatus(); + this.message = status.getMessage(); + this.result = result; + } + @Override public int getCode() { return code; diff --git a/src/main/java/com/linkode/api_server/controller/StudyroomController.java b/src/main/java/com/linkode/api_server/controller/StudyroomController.java index 837dc33..17662b2 100644 --- a/src/main/java/com/linkode/api_server/controller/StudyroomController.java +++ b/src/main/java/com/linkode/api_server/controller/StudyroomController.java @@ -28,9 +28,11 @@ public BaseResponse deleteStudyroom(@RequestHeader( // long memberId = jwtProvider.extractIdFromHeader(authorization); BaseExceptionResponseStatus responseStatus = studyroomService.deleteStudyroom(studyroomId,memberId); - log.info("Success Delete Studyroom API "); - HttpStatus httpStatus = HttpStatus.OK; - return new BaseResponse<>(responseStatus); - } + log.info("Rub Delete Studyroom API "); + if (responseStatus == BaseExceptionResponseStatus.SUCCESS) { + return new BaseResponse<>(responseStatus); + } else { + return new BaseResponse<>(responseStatus, responseStatus); + } } } diff --git a/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java b/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java index 8997384..6de023c 100644 --- a/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java +++ b/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java @@ -1,5 +1,6 @@ package com.linkode.api_server.repository; +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.Query; @@ -10,8 +11,7 @@ @Repository public interface MemberstudyroomRepository extends JpaRepository { - @Query("SELECT ms FROM MemberStudyroom ms WHERE ms.member.id = :memberId AND ms.studyroom.id = :studyroomId") - Optional findByMemberIdAndStudyroomId(long studyroomId, long memberId); - + @Query("SELECT ms.role FROM MemberStudyroom ms WHERE ms.member.id = :memberId AND ms.studyroom.id = :studyroomId") + Optional findRoleByMemberIdAndStudyroomId(long studyroomId, long memberId); } \ No newline at end of file diff --git a/src/main/java/com/linkode/api_server/service/StudyroomService.java b/src/main/java/com/linkode/api_server/service/StudyroomService.java index 6f5d7b2..113ecc5 100644 --- a/src/main/java/com/linkode/api_server/service/StudyroomService.java +++ b/src/main/java/com/linkode/api_server/service/StudyroomService.java @@ -23,11 +23,17 @@ public class StudyroomService { public BaseExceptionResponseStatus deleteStudyroom(long studyroomId, long memberId) { - MemberStudyroom memberStudyroom = memberstudyroomRepository.findByMemberIdAndStudyroomId(memberId, studyroomId) - .orElseThrow(() -> new IllegalArgumentException("Error because of Invalid Member Id or Invalid StudyRoom Id")); + + if(!studyroomRepository.findById(studyroomId).isPresent()){ + log.info("StudyRoom Id is Invalid"); + return BaseExceptionResponseStatus.FAILURE; + } - if (memberStudyroom.getRole().equals(MemberRole.CAPTAIN)) { + MemberRole memberRole = memberstudyroomRepository.findRoleByMemberIdAndStudyroomId(memberId, studyroomId) + .orElseThrow(() -> new IllegalArgumentException("Error because of Invalid Member Id or Invalid StudyRoom Id")); + + if (memberRole .equals(MemberRole.CAPTAIN)) { if(studyroomRepository.deleteStudyroom(studyroomId)==1){ log.info("Success delete studyRoom in Service layer"); return BaseExceptionResponseStatus.SUCCESS; @@ -39,5 +45,6 @@ public BaseExceptionResponseStatus deleteStudyroom(long studyroomId, long member log.info("Crew Member can't delete studyRoom"); return BaseExceptionResponseStatus.FAILURE; } + } } diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index aab2ccf..43a39a9 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -1,8 +1,8 @@ spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://127.0.0.1:3306/linkode?characterEncoding=UTF-8&serverTimezone=UTC - username: linkode + url: jdbc:mysql://localhost:3306/linkode?characterEncoding=UTF-8&serverTimezone=UTC + username: root password: ${DB_LOCAL_PASSWD} From ee1769f0512df37a36b2e1f603eb90701da78b0e Mon Sep 17 00:00:00 2001 From: jungeun Date: Thu, 4 Jul 2024 01:23:35 +0900 Subject: [PATCH 26/36] =?UTF-8?q?feat=20:=20memberId=20=EB=A1=9C=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존에 githubId 로 토큰을 만들었는데 memberId 로 만들도록 수정 --- .../com/linkode/api_server/JwtProvider.java | 58 ++++++++++++++++++- .../repository/MemberRepository.java | 1 + 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/linkode/api_server/JwtProvider.java b/src/main/java/com/linkode/api_server/JwtProvider.java index f4eb66d..2b05888 100644 --- a/src/main/java/com/linkode/api_server/JwtProvider.java +++ b/src/main/java/com/linkode/api_server/JwtProvider.java @@ -1,5 +1,7 @@ package com.linkode.api_server; +import com.linkode.api_server.domain.base.BaseStatus; +import com.linkode.api_server.repository.MemberRepository; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import io.jsonwebtoken.Claims; @@ -7,9 +9,11 @@ import org.springframework.stereotype.Component; import java.util.Date; +import java.util.NoSuchElementException; @Component public class JwtProvider { + private final MemberRepository memberRepository; @Value("${jwt.secret}") private String secretKey; @@ -20,8 +24,13 @@ public class JwtProvider { @Value("${jwt.refresh-token-expiration}") private long refreshTokenExpiration; + public JwtProvider(MemberRepository memberRepository) { + this.memberRepository = memberRepository; + } + // Access Token 생성 public String createAccessToken(String githubId) { + long memberId = memberRepository.findByGithubIdAndStatus(githubId, BaseStatus.ACTIVE); Claims claims = Jwts.claims().setSubject(githubId); Date now = new Date(); Date validity = new Date(now.getTime() + accessTokenExpiration); @@ -30,12 +39,14 @@ public String createAccessToken(String githubId) { .setClaims(claims) .setIssuedAt(now) .setExpiration(validity) + .claim("memberId", memberId) .signWith(SignatureAlgorithm.HS256, secretKey) .compact(); } // Refresh Token 생성 public String createRefreshToken(String githubId) { + long memberId = memberRepository.findByGithubIdAndStatus(githubId, BaseStatus.ACTIVE); Claims claims = Jwts.claims().setSubject(githubId); Date now = new Date(); Date validity = new Date(now.getTime() + refreshTokenExpiration); @@ -44,6 +55,7 @@ public String createRefreshToken(String githubId) { .setClaims(claims) .setIssuedAt(now) .setExpiration(validity) + .claim("memberId", memberId) .signWith(SignatureAlgorithm.HS256, secretKey) .compact(); } @@ -59,7 +71,49 @@ public boolean validateToken(String token) { } // 토큰에서 사용자 정보 추출 - public String getGithubId(String token) { - return Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token).getBody().getSubject(); + public Long extractIdFromHeader(String authorization) { + // Authorization 헤더에서 JWT 토큰 추출 + String jwtToken; + try { + jwtToken = extractJwtToken(authorization); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException("유효하지 않은 헤더 포멧입니다."); + } + + // JWT 토큰에서 사용자 정보 추출 + Long memberId; + try { + memberId = extractMemberIdFromJwtToken(jwtToken); + } catch (NoSuchElementException e) { + throw new NoSuchElementException("토큰에서 멤버 아이디를 찾을 수 없습니다."); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException("잘못된 토큰 형식입니다."); + } + + return memberId; + } + + public String extractJwtToken(String authorizationHeader) { + String[] parts = authorizationHeader.split(" "); + if (parts.length == 2) { + return parts[1]; // 토큰 부분 추출 + } + throw new IllegalArgumentException("유효하지 않은 헤더 포멧입니다."); + } + + public Long extractMemberIdFromJwtToken(String jwtToken) { + Claims claims = Jwts.parserBuilder() + .setSigningKey(secretKey) + .build() + .parseClaimsJws(jwtToken) + .getBody(); + + Long memberId = claims.get("memberId", Long.class); + + if (memberId == null) { + throw new NoSuchElementException("토큰에서 멤버 아이디를 찾을 수 없습니다."); + } + + return memberId; } } diff --git a/src/main/java/com/linkode/api_server/repository/MemberRepository.java b/src/main/java/com/linkode/api_server/repository/MemberRepository.java index c0770fb..a20037f 100644 --- a/src/main/java/com/linkode/api_server/repository/MemberRepository.java +++ b/src/main/java/com/linkode/api_server/repository/MemberRepository.java @@ -7,4 +7,5 @@ public interface MemberRepository extends JpaRepository { boolean existsByGithubIdAndStatus(String githubId, BaseStatus ACTIVE); + long findByGithubIdAndStatus(String githubId, BaseStatus ACTIVE); } From 254c68c4622051168ee1875239df58cf4591dfa9 Mon Sep 17 00:00:00 2001 From: jungeun Date: Thu, 4 Jul 2024 19:35:01 +0900 Subject: [PATCH 27/36] =?UTF-8?q?fix=20:=20=EA=B9=83=ED=97=88=EB=B8=8C=20?= =?UTF-8?q?=EC=86=8C=EC=85=9C=EB=A1=9C=EA=B7=B8=EC=9D=B8=20security=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=EC=9D=84=20=EC=9C=84=ED=95=9C=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 헤더로 들어온 토큰이 유효해야지만 해당 api 이용할 수 있도록 security 수정 --- build.gradle | 3 + .../api_server/config/SecurityConfig.java | 21 ++++-- .../repository/MemberRepository.java | 4 +- .../api_server/service/LoginService.java | 2 +- .../api_server/{ => util}/JwtProvider.java | 70 +++++++------------ 5 files changed, 48 insertions(+), 52 deletions(-) rename src/main/java/com/linkode/api_server/{ => util}/JwtProvider.java (54%) diff --git a/build.gradle b/build.gradle index abc50dd..1c0fd38 100644 --- a/build.gradle +++ b/build.gradle @@ -42,6 +42,9 @@ dependencies { // Spring Boot Redis Starter implementation 'org.springframework.boot:spring-boot-starter-data-redis' + + // Jakarta Servlet API + implementation 'jakarta.servlet:jakarta.servlet-api:5.0.0' } tasks.named('test') { diff --git a/src/main/java/com/linkode/api_server/config/SecurityConfig.java b/src/main/java/com/linkode/api_server/config/SecurityConfig.java index 9549388..10bde17 100644 --- a/src/main/java/com/linkode/api_server/config/SecurityConfig.java +++ b/src/main/java/com/linkode/api_server/config/SecurityConfig.java @@ -3,16 +3,23 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer; +import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.web.SecurityFilterChain; @Configuration -@EnableWebSecurity public class SecurityConfig { @Bean - protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception { - http - .oauth2Login().authorizationEndpoint().baseUri("/login"); - return http.build(); + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + return http + .csrf(CsrfConfigurer::disable) + .authorizeHttpRequests(requests -> + requests.requestMatchers("/login","/oauth2/redirect").permitAll() // requestMatchers의 인자로 전달된 url은 모두에게 허용 + .anyRequest().authenticated() // 그 외의 모든 요청은 인증 필요 + ) + .sessionManagement(sessionManagement -> + sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS) + ) // 세션을 사용하지 않으므로 STATELESS 설정 + .build(); } -} \ No newline at end of file +} diff --git a/src/main/java/com/linkode/api_server/repository/MemberRepository.java b/src/main/java/com/linkode/api_server/repository/MemberRepository.java index a20037f..f2b2f73 100644 --- a/src/main/java/com/linkode/api_server/repository/MemberRepository.java +++ b/src/main/java/com/linkode/api_server/repository/MemberRepository.java @@ -4,8 +4,10 @@ import com.linkode.api_server.domain.base.BaseStatus; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface MemberRepository extends JpaRepository { boolean existsByGithubIdAndStatus(String githubId, BaseStatus ACTIVE); - long findByGithubIdAndStatus(String githubId, BaseStatus ACTIVE); + Optional findByGithubIdAndStatus(String githubId, BaseStatus ACTIVE); } diff --git a/src/main/java/com/linkode/api_server/service/LoginService.java b/src/main/java/com/linkode/api_server/service/LoginService.java index 823d4e4..ccf6cbc 100644 --- a/src/main/java/com/linkode/api_server/service/LoginService.java +++ b/src/main/java/com/linkode/api_server/service/LoginService.java @@ -1,6 +1,6 @@ package com.linkode.api_server.service; -import com.linkode.api_server.JwtProvider; +import com.linkode.api_server.util.JwtProvider; import com.linkode.api_server.domain.base.BaseStatus; import com.linkode.api_server.dto.member.LoginResponse; import com.linkode.api_server.repository.MemberRepository; diff --git a/src/main/java/com/linkode/api_server/JwtProvider.java b/src/main/java/com/linkode/api_server/util/JwtProvider.java similarity index 54% rename from src/main/java/com/linkode/api_server/JwtProvider.java rename to src/main/java/com/linkode/api_server/util/JwtProvider.java index 2b05888..96173ad 100644 --- a/src/main/java/com/linkode/api_server/JwtProvider.java +++ b/src/main/java/com/linkode/api_server/util/JwtProvider.java @@ -1,11 +1,14 @@ -package com.linkode.api_server; +package com.linkode.api_server.util; +import com.linkode.api_server.domain.Member; import com.linkode.api_server.domain.base.BaseStatus; import com.linkode.api_server.repository.MemberRepository; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import io.jsonwebtoken.Claims; import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Component; import java.util.Date; @@ -30,7 +33,8 @@ public JwtProvider(MemberRepository memberRepository) { // Access Token 생성 public String createAccessToken(String githubId) { - long memberId = memberRepository.findByGithubIdAndStatus(githubId, BaseStatus.ACTIVE); + Member member = memberRepository.findByGithubIdAndStatus(githubId, BaseStatus.ACTIVE) + .orElseThrow(() -> new UsernameNotFoundException("해당 깃허브 아이디로 유저를 찾을 수 없습니다.: " + githubId)); Claims claims = Jwts.claims().setSubject(githubId); Date now = new Date(); Date validity = new Date(now.getTime() + accessTokenExpiration); @@ -39,14 +43,15 @@ public String createAccessToken(String githubId) { .setClaims(claims) .setIssuedAt(now) .setExpiration(validity) - .claim("memberId", memberId) + .claim("memberId", member.getMemberId()) .signWith(SignatureAlgorithm.HS256, secretKey) .compact(); } // Refresh Token 생성 public String createRefreshToken(String githubId) { - long memberId = memberRepository.findByGithubIdAndStatus(githubId, BaseStatus.ACTIVE); + Member member = memberRepository.findByGithubIdAndStatus(githubId, BaseStatus.ACTIVE) + .orElseThrow(() -> new UsernameNotFoundException("해당 깃허브 아이디로 유저를 찾을 수 없습니다.: " + githubId)); Claims claims = Jwts.claims().setSubject(githubId); Date now = new Date(); Date validity = new Date(now.getTime() + refreshTokenExpiration); @@ -55,7 +60,7 @@ public String createRefreshToken(String githubId) { .setClaims(claims) .setIssuedAt(now) .setExpiration(validity) - .claim("memberId", memberId) + .claim("memberId", member.getMemberId()) .signWith(SignatureAlgorithm.HS256, secretKey) .compact(); } @@ -71,49 +76,28 @@ public boolean validateToken(String token) { } // 토큰에서 사용자 정보 추출 - public Long extractIdFromHeader(String authorization) { - // Authorization 헤더에서 JWT 토큰 추출 - String jwtToken; - try { - jwtToken = extractJwtToken(authorization); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException("유효하지 않은 헤더 포멧입니다."); - } - - // JWT 토큰에서 사용자 정보 추출 - Long memberId; - try { - memberId = extractMemberIdFromJwtToken(jwtToken); - } catch (NoSuchElementException e) { - throw new NoSuchElementException("토큰에서 멤버 아이디를 찾을 수 없습니다."); - } catch (IllegalArgumentException e) { - throw new IllegalArgumentException("잘못된 토큰 형식입니다."); - } - - return memberId; + public String extractGithubId(String token) { + return Jwts.parserBuilder() + .setSigningKey(secretKey) + .build() + .parseClaimsJws(token) + .getBody() + .getSubject(); } - public String extractJwtToken(String authorizationHeader) { - String[] parts = authorizationHeader.split(" "); - if (parts.length == 2) { - return parts[1]; // 토큰 부분 추출 - } - throw new IllegalArgumentException("유효하지 않은 헤더 포멧입니다."); + // Validate JWT token + public boolean validateToken(String token, UserDetails userDetails) { + final String githubId = extractGithubId(token); + return (githubId.equals(userDetails.getUsername()) && !isTokenExpired(token)); } - public Long extractMemberIdFromJwtToken(String jwtToken) { - Claims claims = Jwts.parserBuilder() + private boolean isTokenExpired(String token) { + return Jwts.parserBuilder() .setSigningKey(secretKey) .build() - .parseClaimsJws(jwtToken) - .getBody(); - - Long memberId = claims.get("memberId", Long.class); - - if (memberId == null) { - throw new NoSuchElementException("토큰에서 멤버 아이디를 찾을 수 없습니다."); - } - - return memberId; + .parseClaimsJws(token) + .getBody() + .getExpiration() + .before(new Date()); } } From fb5b05b3f0d8ddfb5eb3faa6c6312a4d91826730 Mon Sep 17 00:00:00 2001 From: jungeun Date: Thu, 4 Jul 2024 19:48:07 +0900 Subject: [PATCH 28/36] =?UTF-8?q?fix=20:=20JwtProvider=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../linkode/api_server/util/JwtProvider.java | 55 +++++++++++++------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/linkode/api_server/util/JwtProvider.java b/src/main/java/com/linkode/api_server/util/JwtProvider.java index 96173ad..dfd02f9 100644 --- a/src/main/java/com/linkode/api_server/util/JwtProvider.java +++ b/src/main/java/com/linkode/api_server/util/JwtProvider.java @@ -76,28 +76,49 @@ public boolean validateToken(String token) { } // 토큰에서 사용자 정보 추출 - public String extractGithubId(String token) { - return Jwts.parserBuilder() - .setSigningKey(secretKey) - .build() - .parseClaimsJws(token) - .getBody() - .getSubject(); + public Long extractIdFromHeader(String authorization) { + // Authorization 헤더에서 JWT 토큰 추출 + String jwtToken; + try { + jwtToken = extractJwtToken(authorization); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException("유효하지 않은 헤더 포멧입니다."); + } + + // JWT 토큰에서 사용자 정보 추출 + Long memberId; + try { + memberId = extractMemberIdFromJwtToken(jwtToken); + } catch (NoSuchElementException e) { + throw new NoSuchElementException("토큰에서 멤버 아이디를 찾을 수 없습니다."); + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException("잘못된 토큰 형식입니다."); + } + + return memberId; } - // Validate JWT token - public boolean validateToken(String token, UserDetails userDetails) { - final String githubId = extractGithubId(token); - return (githubId.equals(userDetails.getUsername()) && !isTokenExpired(token)); + public String extractJwtToken(String authorizationHeader) { + String[] parts = authorizationHeader.split(" "); + if (parts.length == 2) { + return parts[1]; // 토큰 부분 추출 + } + throw new IllegalArgumentException("유효하지 않은 헤더 포멧입니다."); } - private boolean isTokenExpired(String token) { - return Jwts.parserBuilder() + public Long extractMemberIdFromJwtToken(String jwtToken) { + Claims claims = Jwts.parserBuilder() .setSigningKey(secretKey) .build() - .parseClaimsJws(token) - .getBody() - .getExpiration() - .before(new Date()); + .parseClaimsJws(jwtToken) + .getBody(); + + Long memberId = claims.get("memberId", Long.class); + + if (memberId == null) { + throw new NoSuchElementException("토큰에서 멤버 아이디를 찾을 수 없습니다."); + } + + return memberId; } } From fa6b671e6c79b590e8d3cbbd0fe292f75ae5e164 Mon Sep 17 00:00:00 2001 From: jungeun Date: Thu, 4 Jul 2024 20:14:42 +0900 Subject: [PATCH 29/36] =?UTF-8?q?fix=20:=20JwtProvider=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api_server/config/SecurityConfig.java | 19 +++++-- .../controller/MemberController.java | 5 ++ .../linkode/api_server/testController.java | 14 ----- .../util/JwtAuthenticationFilter.java | 54 +++++++++++++++++++ .../linkode/api_server/util/JwtProvider.java | 14 ++--- 5 files changed, 80 insertions(+), 26 deletions(-) delete mode 100644 src/main/java/com/linkode/api_server/testController.java create mode 100644 src/main/java/com/linkode/api_server/util/JwtAuthenticationFilter.java diff --git a/src/main/java/com/linkode/api_server/config/SecurityConfig.java b/src/main/java/com/linkode/api_server/config/SecurityConfig.java index 10bde17..c47eab0 100644 --- a/src/main/java/com/linkode/api_server/config/SecurityConfig.java +++ b/src/main/java/com/linkode/api_server/config/SecurityConfig.java @@ -1,25 +1,34 @@ package com.linkode.api_server.config; +import com.linkode.api_server.util.JwtAuthenticationFilter; +import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; @Configuration +@RequiredArgsConstructor public class SecurityConfig { + private final JwtAuthenticationFilter jwtAuthenticationFilter; + @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { - return http + http .csrf(CsrfConfigurer::disable) .authorizeHttpRequests(requests -> - requests.requestMatchers("/login","/oauth2/redirect").permitAll() // requestMatchers의 인자로 전달된 url은 모두에게 허용 - .anyRequest().authenticated() // 그 외의 모든 요청은 인증 필요 + requests + .requestMatchers("/login", "/oauth2/redirect").permitAll() // 이 URL은 모두에게 허용 + .anyRequest().authenticated() // 그 외의 모든 요청은 인증 필요 ) .sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS) - ) // 세션을 사용하지 않으므로 STATELESS 설정 - .build(); + ) // 세션을 사용하지 않으므로 STATELESS 설정 + .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); // JwtAuthenticationFilter를 UsernamePasswordAuthenticationFilter 전에 추가 + + return http.build(); } } diff --git a/src/main/java/com/linkode/api_server/controller/MemberController.java b/src/main/java/com/linkode/api_server/controller/MemberController.java index b25cace..e0e68da 100644 --- a/src/main/java/com/linkode/api_server/controller/MemberController.java +++ b/src/main/java/com/linkode/api_server/controller/MemberController.java @@ -6,6 +6,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -25,6 +26,10 @@ public BaseResponse githubLogin(@RequestParam String code) { return new BaseResponse<>(loginService.githubLogin(code)); } + @GetMapping("/test") + public String test(@RequestHeader("authorization") String authorization){ + return "success!"; + } } \ No newline at end of file diff --git a/src/main/java/com/linkode/api_server/testController.java b/src/main/java/com/linkode/api_server/testController.java deleted file mode 100644 index 1645039..0000000 --- a/src/main/java/com/linkode/api_server/testController.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.linkode.api_server; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class testController { - - @GetMapping("/test") - public String hello(){ - return "hello Linkode!!!!!! fixed"; - } - -} diff --git a/src/main/java/com/linkode/api_server/util/JwtAuthenticationFilter.java b/src/main/java/com/linkode/api_server/util/JwtAuthenticationFilter.java new file mode 100644 index 0000000..3623f51 --- /dev/null +++ b/src/main/java/com/linkode/api_server/util/JwtAuthenticationFilter.java @@ -0,0 +1,54 @@ +package com.linkode.api_server.util; + +import com.linkode.api_server.domain.Member; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.core.annotation.Order; +import org.springframework.http.HttpHeaders; +import org.springframework.security.authentication.AbstractAuthenticationToken; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.web.authentication.WebAuthenticationDetails; +import org.springframework.stereotype.Component; +import org.springframework.web.filter.OncePerRequestFilter; + +import java.io.IOException; +import java.util.Optional; + +@Order(0) +@RequiredArgsConstructor +@Component +public class JwtAuthenticationFilter extends OncePerRequestFilter { + private final JwtProvider jwtProvider; + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { + String token = parseBearerToken(request); + Member member = parseUserSpecification(token); + AbstractAuthenticationToken authenticated = new UsernamePasswordAuthenticationToken(member, null, null); + authenticated.setDetails(new WebAuthenticationDetails(request)); + SecurityContextHolder.getContext().setAuthentication(authenticated); + + filterChain.doFilter(request, response); + } + + private String parseBearerToken(HttpServletRequest request) { + return Optional.ofNullable(request.getHeader(HttpHeaders.AUTHORIZATION)) + .filter(token -> token.substring(0, 7).equalsIgnoreCase("Bearer ")) + .map(token -> token.substring(7)) + .orElse(null); + } + + private Member parseUserSpecification(String token) { + String[] split = Optional.ofNullable(token) + .filter(subject -> subject.length() >= 10) + .map(jwtProvider::validateTokenAndGetSubject) + .orElse("anonymous:ANONYMOUS") + .split(":"); + + return new Member(null, split[0], "", "", null, null); + } +} diff --git a/src/main/java/com/linkode/api_server/util/JwtProvider.java b/src/main/java/com/linkode/api_server/util/JwtProvider.java index dfd02f9..ae201e1 100644 --- a/src/main/java/com/linkode/api_server/util/JwtProvider.java +++ b/src/main/java/com/linkode/api_server/util/JwtProvider.java @@ -66,13 +66,13 @@ public String createRefreshToken(String githubId) { } // Access Token 검증 - public boolean validateToken(String token) { - try { - Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token); - return true; - } catch (Exception e) { - return false; - } + public String validateTokenAndGetSubject(String token) { + return Jwts.parserBuilder() + .setSigningKey(secretKey) + .build() + .parseClaimsJws(token) + .getBody() + .getSubject(); } // 토큰에서 사용자 정보 추출 From a2872644b4ad445f7443a3ee7182fe3fe10285ee Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Thu, 4 Jul 2024 20:47:35 +0900 Subject: [PATCH 30/36] =?UTF-8?q?feat=20:=20@Autowired=EB=A1=9C=20JwtProvi?= =?UTF-8?q?der=20=EC=A3=BC=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../linkode/api_server/controller/StudyroomController.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/linkode/api_server/controller/StudyroomController.java b/src/main/java/com/linkode/api_server/controller/StudyroomController.java index 17662b2..2ee5941 100644 --- a/src/main/java/com/linkode/api_server/controller/StudyroomController.java +++ b/src/main/java/com/linkode/api_server/controller/StudyroomController.java @@ -1,9 +1,9 @@ package com.linkode.api_server.controller; -import com.linkode.api_server.JwtProvider; import com.linkode.api_server.common.response.BaseResponse; import com.linkode.api_server.common.response.status.BaseExceptionResponseStatus; import com.linkode.api_server.service.StudyroomService; +import com.linkode.api_server.util.JwtProvider; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -21,12 +21,13 @@ public class StudyroomController { @Autowired StudyroomService studyroomService; + @Autowired JwtProvider jwtProvider; @PatchMapping("/removal") - public BaseResponse deleteStudyroom(@RequestHeader("Authorization") String authorization, @RequestHeader @RequestParam long studyroomId, @RequestParam long memberId){ + public BaseResponse deleteStudyroom(@RequestHeader("Authorization") String authorization, @RequestHeader @RequestParam long studyroomId){ -// long memberId = jwtProvider.extractIdFromHeader(authorization); + long memberId = jwtProvider.extractIdFromHeader(authorization); BaseExceptionResponseStatus responseStatus = studyroomService.deleteStudyroom(studyroomId,memberId); log.info("Rub Delete Studyroom API "); if (responseStatus == BaseExceptionResponseStatus.SUCCESS) { From ed79baee0d5899dca7a7f2afa6295ebb0641acc2 Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Fri, 5 Jul 2024 01:08:07 +0900 Subject: [PATCH 31/36] =?UTF-8?q?feat=20:=20findRoleByMemberIdAndStudyroom?= =?UTF-8?q?Id=EB=A5=BC=20=EC=84=9C=EB=B9=84=EC=8A=A4=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=ED=8C=8C=EB=9D=BC=EB=A7=A4=ED=84=B0=20=EC=9E=98=EB=AA=BB=20?= =?UTF-8?q?=EB=84=98=EA=B2=A8=EC=A3=BC=EB=8A=94=20=EB=AC=B8=EC=A0=9C?= =?UTF-8?q?=ED=95=B4=EA=B2=B0=20+=20=EC=8A=A4=ED=84=B0=EB=94=94=EB=A3=B8?= =?UTF-8?q?=20=EA=B2=80=EC=83=89=EC=97=90=20=EC=83=81=ED=83=9C=20=ED=95=84?= =?UTF-8?q?=ED=84=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/MemberstudyroomRepository.java | 2 +- .../api_server/repository/StudyroomRepository.java | 4 ++++ .../linkode/api_server/service/StudyroomService.java | 11 ++++++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java b/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java index 6de023c..4b49003 100644 --- a/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java +++ b/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java @@ -11,7 +11,7 @@ @Repository public interface MemberstudyroomRepository extends JpaRepository { - @Query("SELECT ms.role FROM MemberStudyroom ms WHERE ms.member.id = :memberId AND ms.studyroom.id = :studyroomId") + @Query("SELECT ms.role FROM MemberStudyroom ms WHERE ms.studyroom.studyroomId = :studyroomId AND ms.member.memberId = :memberId") Optional findRoleByMemberIdAndStudyroomId(long studyroomId, long memberId); } \ No newline at end of file diff --git a/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java b/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java index 3116fac..91207e9 100644 --- a/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java +++ b/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java @@ -8,6 +8,8 @@ import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; +import java.util.Optional; + @Repository public interface StudyroomRepository extends JpaRepository { @Transactional @@ -15,4 +17,6 @@ public interface StudyroomRepository extends JpaRepository { @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 findById(long studyroomId); } \ No newline at end of file diff --git a/src/main/java/com/linkode/api_server/service/StudyroomService.java b/src/main/java/com/linkode/api_server/service/StudyroomService.java index 113ecc5..8602c0e 100644 --- a/src/main/java/com/linkode/api_server/service/StudyroomService.java +++ b/src/main/java/com/linkode/api_server/service/StudyroomService.java @@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Optional; + @Service @AllArgsConstructor @Slf4j @@ -29,9 +31,12 @@ public BaseExceptionResponseStatus deleteStudyroom(long studyroomId, long member return BaseExceptionResponseStatus.FAILURE; } - - MemberRole memberRole = memberstudyroomRepository.findRoleByMemberIdAndStudyroomId(memberId, studyroomId) - .orElseThrow(() -> new IllegalArgumentException("Error because of Invalid Member Id or Invalid StudyRoom Id")); + Optional 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){ From f3d086cb80be07ab3602d75c39560bdbf41f43c4 Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Fri, 5 Jul 2024 01:10:34 +0900 Subject: [PATCH 32/36] =?UTF-8?q?feat=20:=20@Transactional(readOnly=20=3D?= =?UTF-8?q?=20true)=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api_server/repository/MemberstudyroomRepository.java | 2 ++ .../com/linkode/api_server/repository/StudyroomRepository.java | 1 + 2 files changed, 3 insertions(+) diff --git a/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java b/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java index 4b49003..93d1514 100644 --- a/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java +++ b/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java @@ -5,10 +5,12 @@ import org.springframework.data.jpa.repository.JpaRepository; 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 { @Query("SELECT ms.role FROM MemberStudyroom ms WHERE ms.studyroom.studyroomId = :studyroomId AND ms.member.memberId = :memberId") diff --git a/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java b/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java index 91207e9..bf8c60f 100644 --- a/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java +++ b/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java @@ -11,6 +11,7 @@ import java.util.Optional; @Repository +@Transactional(readOnly = true) public interface StudyroomRepository extends JpaRepository { @Transactional @Modifying From 844eea920633950ba9b90546747946a5c90d3af4 Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Fri, 5 Jul 2024 02:19:13 +0900 Subject: [PATCH 33/36] =?UTF-8?q?feat=20:=20@RequestHeader=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/linkode/api_server/controller/StudyroomController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/linkode/api_server/controller/StudyroomController.java b/src/main/java/com/linkode/api_server/controller/StudyroomController.java index 2ee5941..16fb7d9 100644 --- a/src/main/java/com/linkode/api_server/controller/StudyroomController.java +++ b/src/main/java/com/linkode/api_server/controller/StudyroomController.java @@ -25,7 +25,7 @@ public class StudyroomController { JwtProvider jwtProvider; @PatchMapping("/removal") - public BaseResponse deleteStudyroom(@RequestHeader("Authorization") String authorization, @RequestHeader @RequestParam long studyroomId){ + public BaseResponse deleteStudyroom(@RequestHeader("Authorization") String authorization, @RequestParam long studyroomId){ long memberId = jwtProvider.extractIdFromHeader(authorization); BaseExceptionResponseStatus responseStatus = studyroomService.deleteStudyroom(studyroomId,memberId); From 11bdf816cd740e93152f3333148f2f3b724203bf Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Fri, 5 Jul 2024 02:42:25 +0900 Subject: [PATCH 34/36] =?UTF-8?q?feat=20:=20=EC=8A=A4=ED=84=B0=EB=94=94?= =?UTF-8?q?=EB=A3=B8=20=EC=82=AD=EC=A0=9C=EC=8B=9C=20=EB=A7=B4=EB=B2=84=20?= =?UTF-8?q?=EC=8A=A4=ED=84=B0=EB=94=94=EB=A3=B8=EB=8F=84=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=EB=90=98=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../linkode/api_server/controller/StudyroomController.java | 2 +- .../dto/{ => studyroom}/DeleteStudyroomRequest.java | 2 +- .../api_server/repository/MemberstudyroomRepository.java | 6 +++++- .../linkode/api_server/repository/StudyroomRepository.java | 1 - .../com/linkode/api_server/service/StudyroomService.java | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) rename src/main/java/com/linkode/api_server/dto/{ => studyroom}/DeleteStudyroomRequest.java (83%) diff --git a/src/main/java/com/linkode/api_server/controller/StudyroomController.java b/src/main/java/com/linkode/api_server/controller/StudyroomController.java index 16fb7d9..e46fc76 100644 --- a/src/main/java/com/linkode/api_server/controller/StudyroomController.java +++ b/src/main/java/com/linkode/api_server/controller/StudyroomController.java @@ -29,7 +29,7 @@ public BaseResponse deleteStudyroom(@RequestHeader( long memberId = jwtProvider.extractIdFromHeader(authorization); BaseExceptionResponseStatus responseStatus = studyroomService.deleteStudyroom(studyroomId,memberId); - log.info("Rub Delete Studyroom API "); + log.info("Run Delete Studyroom API "); if (responseStatus == BaseExceptionResponseStatus.SUCCESS) { return new BaseResponse<>(responseStatus); } else { diff --git a/src/main/java/com/linkode/api_server/dto/DeleteStudyroomRequest.java b/src/main/java/com/linkode/api_server/dto/studyroom/DeleteStudyroomRequest.java similarity index 83% rename from src/main/java/com/linkode/api_server/dto/DeleteStudyroomRequest.java rename to src/main/java/com/linkode/api_server/dto/studyroom/DeleteStudyroomRequest.java index 92c3f74..b6f377e 100644 --- a/src/main/java/com/linkode/api_server/dto/DeleteStudyroomRequest.java +++ b/src/main/java/com/linkode/api_server/dto/studyroom/DeleteStudyroomRequest.java @@ -1,4 +1,4 @@ -package com.linkode.api_server.dto; +package com.linkode.api_server.dto.studyroom; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java b/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java index 93d1514..36e3d80 100644 --- a/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java +++ b/src/main/java/com/linkode/api_server/repository/MemberstudyroomRepository.java @@ -3,6 +3,7 @@ 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; @@ -15,5 +16,8 @@ public interface MemberstudyroomRepository extends JpaRepository findRoleByMemberIdAndStudyroomId(long studyroomId, long memberId); - + @Transactional + @Modifying + @Query("UPDATE MemberStudyroom ms SET ms.status = 'DELETE' WHERE ms.studyroom.studyroomId = :studyroomId") + int deleteMemberStudyroom(long studyroomId); } \ No newline at end of file diff --git a/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java b/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java index bf8c60f..4aa27f2 100644 --- a/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java +++ b/src/main/java/com/linkode/api_server/repository/StudyroomRepository.java @@ -1,7 +1,6 @@ package com.linkode.api_server.repository; import com.linkode.api_server.domain.Studyroom; -import com.linkode.api_server.dto.DeleteStudyroomRequest; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; diff --git a/src/main/java/com/linkode/api_server/service/StudyroomService.java b/src/main/java/com/linkode/api_server/service/StudyroomService.java index 8602c0e..e8ccdb6 100644 --- a/src/main/java/com/linkode/api_server/service/StudyroomService.java +++ b/src/main/java/com/linkode/api_server/service/StudyroomService.java @@ -39,7 +39,7 @@ public BaseExceptionResponseStatus deleteStudyroom(long studyroomId, long member 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){ + if(studyroomRepository.deleteStudyroom(studyroomId)==1 && memberstudyroomRepository.deleteMemberStudyroom(memberId)==1){ log.info("Success delete studyRoom in Service layer"); return BaseExceptionResponseStatus.SUCCESS; }else { From ce20573efdb9f3f36f2715b52eb1caff9aae424d Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Fri, 5 Jul 2024 10:35:13 +0900 Subject: [PATCH 35/36] =?UTF-8?q?feat=20:=20=EC=A1=B0=EA=B1=B4=EB=AC=B8=20?= =?UTF-8?q?=EC=A1=B0=EA=B1=B4=EC=97=90=20=EB=85=BC=EB=A6=AC=EC=A0=81?= =?UTF-8?q?=EC=9D=B8=20=EC=98=A4=EB=A5=98=EA=B0=80=EC=9E=88=EC=96=B4?= =?UTF-8?q?=EC=84=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/linkode/api_server/service/StudyroomService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/linkode/api_server/service/StudyroomService.java b/src/main/java/com/linkode/api_server/service/StudyroomService.java index e8ccdb6..0f6cf87 100644 --- a/src/main/java/com/linkode/api_server/service/StudyroomService.java +++ b/src/main/java/com/linkode/api_server/service/StudyroomService.java @@ -39,7 +39,8 @@ public BaseExceptionResponseStatus deleteStudyroom(long studyroomId, long member 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(memberId)==1){ + if(studyroomRepository.deleteStudyroom(studyroomId)==1){ + memberstudyroomRepository.deleteMemberStudyroom(studyroomId); log.info("Success delete studyRoom in Service layer"); return BaseExceptionResponseStatus.SUCCESS; }else { From a88d6cdc41bb371cfe65f06c0efbb19483018927 Mon Sep 17 00:00:00 2001 From: HyunJun Mun <137624597+Mouon@users.noreply.github.com> Date: Fri, 5 Jul 2024 11:38:57 +0900 Subject: [PATCH 36/36] =?UTF-8?q?chore=20:=20dto=20=ED=8F=B4=EB=8D=94=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api_server/controller/StudyroomController.java | 4 ++-- .../{ => studyroom}/CreateStudyroomRequest.java | 2 +- .../{ => studyroom}/CreateStudyroomResponse.java | 2 +- .../dto/{ => studyroom}/JoinStudyroomRequest.java | 2 +- .../api_server/service/StudyroomService.java | 14 +++----------- 5 files changed, 8 insertions(+), 16 deletions(-) rename src/main/java/com/linkode/api_server/dto/{ => studyroom}/CreateStudyroomRequest.java (87%) rename src/main/java/com/linkode/api_server/dto/{ => studyroom}/CreateStudyroomResponse.java (87%) rename src/main/java/com/linkode/api_server/dto/{ => studyroom}/JoinStudyroomRequest.java (88%) diff --git a/src/main/java/com/linkode/api_server/controller/StudyroomController.java b/src/main/java/com/linkode/api_server/controller/StudyroomController.java index 3f16402..d7a6052 100644 --- a/src/main/java/com/linkode/api_server/controller/StudyroomController.java +++ b/src/main/java/com/linkode/api_server/controller/StudyroomController.java @@ -2,8 +2,8 @@ import com.linkode.api_server.common.response.BaseResponse; import com.linkode.api_server.common.response.status.BaseExceptionResponseStatus; -import com.linkode.api_server.dto.CreateStudyroomRequest; -import com.linkode.api_server.dto.CreateStudyroomResponse; +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; diff --git a/src/main/java/com/linkode/api_server/dto/CreateStudyroomRequest.java b/src/main/java/com/linkode/api_server/dto/studyroom/CreateStudyroomRequest.java similarity index 87% rename from src/main/java/com/linkode/api_server/dto/CreateStudyroomRequest.java rename to src/main/java/com/linkode/api_server/dto/studyroom/CreateStudyroomRequest.java index bbcc377..2eae378 100644 --- a/src/main/java/com/linkode/api_server/dto/CreateStudyroomRequest.java +++ b/src/main/java/com/linkode/api_server/dto/studyroom/CreateStudyroomRequest.java @@ -1,4 +1,4 @@ -package com.linkode.api_server.dto; +package com.linkode.api_server.dto.studyroom; import jakarta.persistence.Column; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/linkode/api_server/dto/CreateStudyroomResponse.java b/src/main/java/com/linkode/api_server/dto/studyroom/CreateStudyroomResponse.java similarity index 87% rename from src/main/java/com/linkode/api_server/dto/CreateStudyroomResponse.java rename to src/main/java/com/linkode/api_server/dto/studyroom/CreateStudyroomResponse.java index 1fd2824..3ddb224 100644 --- a/src/main/java/com/linkode/api_server/dto/CreateStudyroomResponse.java +++ b/src/main/java/com/linkode/api_server/dto/studyroom/CreateStudyroomResponse.java @@ -1,4 +1,4 @@ -package com.linkode.api_server.dto; +package com.linkode.api_server.dto.studyroom; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/com/linkode/api_server/dto/JoinStudyroomRequest.java b/src/main/java/com/linkode/api_server/dto/studyroom/JoinStudyroomRequest.java similarity index 88% rename from src/main/java/com/linkode/api_server/dto/JoinStudyroomRequest.java rename to src/main/java/com/linkode/api_server/dto/studyroom/JoinStudyroomRequest.java index fa1ea13..b2fbc3a 100644 --- a/src/main/java/com/linkode/api_server/dto/JoinStudyroomRequest.java +++ b/src/main/java/com/linkode/api_server/dto/studyroom/JoinStudyroomRequest.java @@ -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; diff --git a/src/main/java/com/linkode/api_server/service/StudyroomService.java b/src/main/java/com/linkode/api_server/service/StudyroomService.java index ae24fdb..20a6aac 100644 --- a/src/main/java/com/linkode/api_server/service/StudyroomService.java +++ b/src/main/java/com/linkode/api_server/service/StudyroomService.java @@ -5,7 +5,6 @@ import com.linkode.api_server.domain.memberstudyroom.MemberStudyroom; import com.linkode.api_server.repository.MemberstudyroomRepository; import com.linkode.api_server.repository.StudyroomRepository; -import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -13,17 +12,10 @@ 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.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.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 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 org.springframework.transaction.annotation.Transactional; @Service