From f5b01d6cea2845917aea99d270709c4f1d4b9262 Mon Sep 17 00:00:00 2001 From: kimdohyung Date: Thu, 23 Nov 2023 01:53:26 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EC=99=80=20=EB=8C=80=ED=95=99=20=EB=A7=A4=ED=95=91=20=EA=B4=80?= =?UTF-8?q?=EA=B3=84=20=EC=88=98=EC=A0=95=20(#36)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/contract/repository/ContractRepository.java | 2 +- .../com/backend/domain/popup/repository/PopupRepository.java | 4 ++-- .../com/backend/domain/university/entity/University.java | 4 ++-- src/main/java/com/backend/domain/user/entity/User.java | 5 +++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/backend/domain/contract/repository/ContractRepository.java b/src/main/java/com/backend/domain/contract/repository/ContractRepository.java index c16a096..75b6e35 100644 --- a/src/main/java/com/backend/domain/contract/repository/ContractRepository.java +++ b/src/main/java/com/backend/domain/contract/repository/ContractRepository.java @@ -15,7 +15,7 @@ public interface ContractRepository extends JpaRepository { - @Query("SELECT c FROM Contract c JOIN c.university u JOIN u.user user " + + @Query("SELECT c FROM Contract c JOIN c.university u JOIN u.users user " + "WHERE user.id = :userId AND c.store.storeId = :storeId") Optional findContractByUserIdAndStoreId(@Param("userId") Long userId, @Param("storeId") Long storeId); diff --git a/src/main/java/com/backend/domain/popup/repository/PopupRepository.java b/src/main/java/com/backend/domain/popup/repository/PopupRepository.java index 94469bb..d23a02f 100644 --- a/src/main/java/com/backend/domain/popup/repository/PopupRepository.java +++ b/src/main/java/com/backend/domain/popup/repository/PopupRepository.java @@ -10,9 +10,9 @@ import java.util.List; public interface PopupRepository extends JpaRepository { - @Query("SELECT p FROM Popup p JOIN p.contract c JOIN c.university u JOIN u.user user WHERE user.id = :userId") + @Query("SELECT p FROM Popup p JOIN p.contract c JOIN c.university u JOIN u.users user WHERE user.id = :userId") Page findPopupsPageByUserId(@Param("userId") Long userId, Pageable pageable); - @Query("SELECT p FROM Popup p JOIN p.contract c JOIN c.university u JOIN u.user user WHERE user.id = :userId") + @Query("SELECT p FROM Popup p JOIN p.contract c JOIN c.university u JOIN u.users user WHERE user.id = :userId") List findPopupsByUserId(@Param("userId") Long userId); } \ No newline at end of file diff --git a/src/main/java/com/backend/domain/university/entity/University.java b/src/main/java/com/backend/domain/university/entity/University.java index 38a0f1b..6ccb88d 100644 --- a/src/main/java/com/backend/domain/university/entity/University.java +++ b/src/main/java/com/backend/domain/university/entity/University.java @@ -31,6 +31,6 @@ public class University { @OneToMany(mappedBy = "university") private List contracts = new ArrayList<>(); - @OneToOne(mappedBy = "university") - private User user; + @OneToMany(mappedBy = "university") + private List users = new ArrayList<>(); } diff --git a/src/main/java/com/backend/domain/user/entity/User.java b/src/main/java/com/backend/domain/user/entity/User.java index 3fb1f3e..9422b80 100644 --- a/src/main/java/com/backend/domain/user/entity/User.java +++ b/src/main/java/com/backend/domain/user/entity/User.java @@ -36,7 +36,7 @@ public class User extends BaseEntity { private String proofImageUrl; - @OneToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "university_id") private University university; @@ -44,13 +44,14 @@ public class User extends BaseEntity { private List picks = new ArrayList<>(); @Builder - public User(String email, String password, GroupType type, String typeName, String refreshToken, String proofImageUrl) { + public User(String email, String password, GroupType type, String typeName, String refreshToken, String proofImageUrl, University university) { this.email = email; this.password = password; this.type = type; this.typeName = typeName; this.refreshToken = refreshToken; this.proofImageUrl = proofImageUrl; + this.university = university; } public void updateRefreshToken(String refreshToken) { From f0c73cbf0e8c628fa445ef09d224ebe2b2d49876 Mon Sep 17 00:00:00 2001 From: kimdohyung Date: Thu, 23 Nov 2023 01:54:35 +0900 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EA=B0=80=20=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=20=ED=95=A0=20?= =?UTF-8?q?=EB=95=8C=20=EB=8C=80=ED=95=99=EC=9D=84=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=20(#36)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/auth/dto/request/JoinRequestDto.java | 10 ++++++---- .../com/backend/domain/auth/service/AuthService.java | 7 ++++++- src/main/java/com/backend/error/ErrorCode.java | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/backend/domain/auth/dto/request/JoinRequestDto.java b/src/main/java/com/backend/domain/auth/dto/request/JoinRequestDto.java index 78bdaed..aefbcd5 100644 --- a/src/main/java/com/backend/domain/auth/dto/request/JoinRequestDto.java +++ b/src/main/java/com/backend/domain/auth/dto/request/JoinRequestDto.java @@ -1,19 +1,21 @@ package com.backend.domain.auth.dto.request; +import com.backend.domain.university.entity.University; import com.backend.domain.user.entity.GroupType; import com.backend.domain.user.entity.User; -import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotBlank; import org.springframework.security.crypto.password.PasswordEncoder; -public record JoinRequestDto(@NotEmpty String password, @NotEmpty String email, @NotEmpty String type, - @NotEmpty String typeName, @NotEmpty String proofImageUrl) { - public User toEntity(PasswordEncoder passwordEncoder) { +public record JoinRequestDto(@NotBlank String password, @NotBlank String email, @NotBlank String type, + @NotBlank String typeName, @NotBlank String proofImageUrl, @NotBlank Long univId) { + public User toEntity(PasswordEncoder passwordEncoder, University university) { return User.builder() .email(email) .password(passwordEncoder.encode(this.password)) .type(GroupType.create(type)) .typeName(typeName) .proofImageUrl(proofImageUrl) + .university(university) .build(); } } \ No newline at end of file diff --git a/src/main/java/com/backend/domain/auth/service/AuthService.java b/src/main/java/com/backend/domain/auth/service/AuthService.java index cc9b647..aaef26c 100644 --- a/src/main/java/com/backend/domain/auth/service/AuthService.java +++ b/src/main/java/com/backend/domain/auth/service/AuthService.java @@ -3,6 +3,8 @@ import com.backend.domain.auth.dto.LoginUser; import com.backend.domain.auth.dto.request.JoinRequestDto; import com.backend.domain.auth.dto.request.LoginRequestDto; +import com.backend.domain.university.entity.University; +import com.backend.domain.university.repository.UniversityRepository; import com.backend.jwt.service.JwtProvider; import com.backend.jwt.token.RefreshToken; import com.backend.jwt.token.Token; @@ -23,6 +25,7 @@ public class AuthService { private final UserRepository userRepository; + private final UniversityRepository universityRepository; private final JwtProvider jwtProvider; private final PasswordEncoder passwordEncoder; @@ -51,7 +54,9 @@ public void join(JoinRequestDto joinRequestDto) { throw new BusinessException(ErrorCode.ALREADY_EXIST_EMAIL); } // if (userRepository.existsByNickname(joinRequestDto.getNickname())) {} - userRepository.save(joinRequestDto.toEntity(passwordEncoder)); + University university = universityRepository.findById(joinRequestDto.univId()) + .orElseThrow(() -> new BusinessException(ErrorCode.UNIV_NOT_FOUND)); + userRepository.save(joinRequestDto.toEntity(passwordEncoder, university)); } @Transactional diff --git a/src/main/java/com/backend/error/ErrorCode.java b/src/main/java/com/backend/error/ErrorCode.java index f966734..ff01ac0 100644 --- a/src/main/java/com/backend/error/ErrorCode.java +++ b/src/main/java/com/backend/error/ErrorCode.java @@ -23,7 +23,8 @@ public enum ErrorCode { STORE_NOT_FOUND(NOT_FOUND, "해당 가게를 찾을 수 없습니다."), INVALID_DATE(BAD_REQUEST, "잘못된 날짜 형식입니다."), POPUP_NOT_FOUND(NOT_FOUND, "팝업이 존재하지 않습니다."), - INVALID_POPUP(BAD_REQUEST, "잘못된 팝업 요청입니다."); + INVALID_POPUP(BAD_REQUEST, "잘못된 팝업 요청입니다."), + UNIV_NOT_FOUND(BAD_REQUEST, "해당 대학을 찾을 수 없습니다."); private final int code; private final String message; From e11a2c64a27b673d49943faeeed5ded2c65a7357 Mon Sep 17 00:00:00 2001 From: kimdohyung Date: Thu, 23 Nov 2023 02:05:55 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20=EB=8C=80=ED=95=99=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20id=EB=8F=84=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20(#36)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/university/dto/response/getUnivResponseDto.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/backend/domain/university/dto/response/getUnivResponseDto.java b/src/main/java/com/backend/domain/university/dto/response/getUnivResponseDto.java index 5b0fee1..ad22a7d 100644 --- a/src/main/java/com/backend/domain/university/dto/response/getUnivResponseDto.java +++ b/src/main/java/com/backend/domain/university/dto/response/getUnivResponseDto.java @@ -2,8 +2,8 @@ import com.backend.domain.university.entity.University; -public record getUnivResponseDto(String univName, String email) { +public record getUnivResponseDto(Long universityId, String univName, String email) { public static getUnivResponseDto from(University university) { - return new getUnivResponseDto(university.getName(), university.getEmail()); + return new getUnivResponseDto(university.getUniversityId(), university.getName(), university.getEmail()); } } \ No newline at end of file From db77f926f1d9aaf9909bfc5168b2bb15d052055d Mon Sep 17 00:00:00 2001 From: kimdohyung Date: Thu, 23 Nov 2023 02:44:44 +0900 Subject: [PATCH 4/4] =?UTF-8?q?docs:=20swagger=20=EB=AC=B8=EC=84=9C?= =?UTF-8?q?=EC=97=90=EC=84=9C=20token=EC=9D=B4=20=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20api=EC=97=90=20=EB=82=B4=EC=9A=A9=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(#36)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/backend/domain/auth/controller/AuthController.java | 2 ++ .../com/backend/domain/popup/controller/PopupController.java | 2 ++ .../java/com/backend/domain/s3/controller/S3Controller.java | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/main/java/com/backend/domain/auth/controller/AuthController.java b/src/main/java/com/backend/domain/auth/controller/AuthController.java index cb12839..657b7c7 100644 --- a/src/main/java/com/backend/domain/auth/controller/AuthController.java +++ b/src/main/java/com/backend/domain/auth/controller/AuthController.java @@ -14,6 +14,7 @@ import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; @@ -90,6 +91,7 @@ public ResponseEntity reissueToken(@Parameter @CookieValue(name = "Autho @ApiResponse(responseCode = "204", description = "로그아웃 성공, AccessToken이 필요합니다.", content = @Content(schema = @Schema(implementation = String.class))) }) + @SecurityRequirement(name = "bearer-key") @PostMapping("/logout") public ResponseEntity logout(@Login @Schema(hidden = true) LoginUser loginUser, HttpServletResponse response) { authService.logout(loginUser); diff --git a/src/main/java/com/backend/domain/popup/controller/PopupController.java b/src/main/java/com/backend/domain/popup/controller/PopupController.java index a510442..eb79cd9 100644 --- a/src/main/java/com/backend/domain/popup/controller/PopupController.java +++ b/src/main/java/com/backend/domain/popup/controller/PopupController.java @@ -11,6 +11,7 @@ import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; @@ -20,6 +21,7 @@ @RestController @RequiredArgsConstructor @RequestMapping("/popups") +@SecurityRequirement(name = "bearer-key") public class PopupController { private final PopupService popupService; diff --git a/src/main/java/com/backend/domain/s3/controller/S3Controller.java b/src/main/java/com/backend/domain/s3/controller/S3Controller.java index 7edef26..4763e5d 100644 --- a/src/main/java/com/backend/domain/s3/controller/S3Controller.java +++ b/src/main/java/com/backend/domain/s3/controller/S3Controller.java @@ -9,6 +9,7 @@ import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -38,6 +39,7 @@ public ResponseEntity uploadImage(@RequestPart MultipartFile file) { @ApiResponse(responseCode = "401", description = "토큰이 올바르지 않을 때 예외가 발생합니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))) }) + @SecurityRequirement(name = "bearer-key") @DeleteMapping("/delete") public ResponseEntity deleteImage(@Login LoginUser loginUser, @RequestPart String fileName) { s3Service.deleteImage(loginUser, fileName);