From 9efeb9ad3e02c9b3be996a2b3ef03ea533bd2280 Mon Sep 17 00:00:00 2001 From: Minsu Kim Date: Sat, 12 Aug 2023 21:24:59 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EC=9C=84=EC=B9=98=EC=A0=95=EB=B3=B4=20CRUD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../application/dto/req/UserRequestDto.java | 121 ------------------ .../dto/request/AdditionInfoRequest.java | 42 ++++++ .../request/GetCommunityUserInfoRequest.java | 16 +++ .../application/dto/request/LoginRequest.java | 22 ++++ .../dto/request/TestLoginRequest.java | 16 +++ .../dto/request/TestSignUpRequest.java | 24 ++++ .../dto/request/UserLocationRequest.java | 24 ++++ .../application/dto/res/UserResponseDto.java | 95 -------------- .../dto/response/CommunityUserInfoBlocks.java | 20 +++ .../response/CommunityUserInfoResponse.java | 19 +++ .../dto/response/LocationResponse.java | 19 +++ .../dto/response/LoginResponse.java | 27 ++++ .../ReissueTokenResponse.java | 2 +- .../dto/response/UserInfoResponse.java | 39 ++++++ .../dto/response/UserLocationResponse.java | 18 +++ .../user/application/mapper/UserMapper.java | 63 ++++----- .../service/ReissueTokenService.java | 2 +- .../service/UserDeleteService.java | 12 +- .../application/service/UserInfoService.java | 16 +-- .../service/UserLocationService.java | 50 ++++++++ .../application/service/UserLoginService.java | 20 +-- .../service/UserSignUpService.java | 16 +-- .../domain/user/domain/entity/Location.java | 41 ++++++ .../user/domain/user/domain/entity/User.java | 61 +++++++-- .../domain/repository/LocationRepository.java | 7 + .../domain/repository/UserRepository.java | 3 + .../repository/UserRepositoryCustom.java | 5 +- .../repository/UserRepositoryCustomImpl.java | 13 +- .../domain/service/LocationDeleteService.java | 19 +++ .../domain/service/LocationSaveService.java | 19 +++ .../user/domain/service/UserQueryService.java | 8 +- .../user/presentation/UserController.java | 67 +++++++--- .../constant/EUserResponseMessage.java | 6 +- .../user/presentation/constant/Process.java | 14 -- .../config/security/SecurityConfig.java | 1 + .../config/security/utils/SecurityUtils.java | 26 ---- .../exception/LocationLimitException.java | 12 ++ .../exception/NotFoundLocationException.java | 13 ++ .../exception/constant/UserExceptionList.java | 4 +- 40 files changed, 626 insertions(+), 377 deletions(-) delete mode 100644 src/main/java/porori/backend/user/domain/user/application/dto/req/UserRequestDto.java create mode 100644 src/main/java/porori/backend/user/domain/user/application/dto/request/AdditionInfoRequest.java create mode 100644 src/main/java/porori/backend/user/domain/user/application/dto/request/GetCommunityUserInfoRequest.java create mode 100644 src/main/java/porori/backend/user/domain/user/application/dto/request/LoginRequest.java create mode 100644 src/main/java/porori/backend/user/domain/user/application/dto/request/TestLoginRequest.java create mode 100644 src/main/java/porori/backend/user/domain/user/application/dto/request/TestSignUpRequest.java create mode 100644 src/main/java/porori/backend/user/domain/user/application/dto/request/UserLocationRequest.java delete mode 100644 src/main/java/porori/backend/user/domain/user/application/dto/res/UserResponseDto.java create mode 100644 src/main/java/porori/backend/user/domain/user/application/dto/response/CommunityUserInfoBlocks.java create mode 100644 src/main/java/porori/backend/user/domain/user/application/dto/response/CommunityUserInfoResponse.java create mode 100644 src/main/java/porori/backend/user/domain/user/application/dto/response/LocationResponse.java create mode 100644 src/main/java/porori/backend/user/domain/user/application/dto/response/LoginResponse.java rename src/main/java/porori/backend/user/domain/user/application/dto/{res => response}/ReissueTokenResponse.java (90%) create mode 100644 src/main/java/porori/backend/user/domain/user/application/dto/response/UserInfoResponse.java create mode 100644 src/main/java/porori/backend/user/domain/user/application/dto/response/UserLocationResponse.java create mode 100644 src/main/java/porori/backend/user/domain/user/application/service/UserLocationService.java create mode 100644 src/main/java/porori/backend/user/domain/user/domain/entity/Location.java create mode 100644 src/main/java/porori/backend/user/domain/user/domain/repository/LocationRepository.java create mode 100644 src/main/java/porori/backend/user/domain/user/domain/service/LocationDeleteService.java create mode 100644 src/main/java/porori/backend/user/domain/user/domain/service/LocationSaveService.java delete mode 100644 src/main/java/porori/backend/user/domain/user/presentation/constant/Process.java delete mode 100644 src/main/java/porori/backend/user/global/config/security/utils/SecurityUtils.java create mode 100644 src/main/java/porori/backend/user/global/exception/LocationLimitException.java create mode 100644 src/main/java/porori/backend/user/global/exception/NotFoundLocationException.java diff --git a/.gitignore b/.gitignore index 23781dc..f6b9b85 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ out/ ### VS Code ### .vscode/ application.yml +.DS_store diff --git a/src/main/java/porori/backend/user/domain/user/application/dto/req/UserRequestDto.java b/src/main/java/porori/backend/user/domain/user/application/dto/req/UserRequestDto.java deleted file mode 100644 index 4f47598..0000000 --- a/src/main/java/porori/backend/user/domain/user/application/dto/req/UserRequestDto.java +++ /dev/null @@ -1,121 +0,0 @@ -package porori.backend.user.domain.user.application.dto.req; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import porori.backend.user.domain.user.domain.entity.UserConstant; - -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import java.util.LinkedList; -import java.util.List; - -public class UserRequestDto { - @Getter - @AllArgsConstructor - @Builder - @ApiModel(description = "애플 로그인을 위한 요청 객체") - @NoArgsConstructor - public static class LoginRequest { - @NotBlank(message = "애플 identity token을 입력해주세요.") - @ApiModelProperty(notes = "카카오 identity token을 주세요.") - private String token; - - } - - @Getter - @Builder - @AllArgsConstructor - @NoArgsConstructor - @ApiModel(description = "추가 정보 입력을 위한 요청 객체") - public static class AdditionInfoRequest { - @NotBlank(message = "자체 액세스 토큰을 입력해주세요.") - private String accessToken; - - @NotBlank(message = "본명을 입력해주세요.") - private String name; - - @NotBlank(message = "닉네임을 입력해주세요.") - private String nickName; - - @NotBlank(message = "전화번호를 입력해주세요.") - private String phoneNumber; - - @NotNull(message = "성별을 입력해주세요.") - private Boolean gender; - - @NotBlank(message="프로필 사진 URl입력해주세요.") - private String imageUrl; - - @NotBlank(message="이메일을 입력해주세요.") - private String email; - - @NotBlank(message = "주소를 입력해주세요.") - private String address; - - } - - @Getter - @AllArgsConstructor - @Builder - @ApiModel(description = "회원 탈퇴를 위한 요청 객체") - @NoArgsConstructor - public static class DeleteAccountRequest { - @NotBlank(message = "카카오 액세스 토큰을 입력해주세요.") - @ApiModelProperty(notes = "카카오 accessToken을 주세요.") - private String token; - - @NotBlank(message = "탈퇴 이유를 입력해주세요.") - @ApiModelProperty(notes = "탈퇴 이유를 입력해주세요.") - private String reasonToLeave; - } - - @Getter - @AllArgsConstructor - @Builder - @NoArgsConstructor - public static class TestSignUpRequest { - - private String name; - private String phoneNumber; - private String appleID; - private String nickName; - private Boolean gender; - private String imageUrl; - private String email; - private String address; - - - } - - @Getter - @AllArgsConstructor - @Builder - @NoArgsConstructor - public static class TestLoginRequest { - - private String appleId; - - } - - @Getter - @AllArgsConstructor - @Builder - @NoArgsConstructor - public static class GetUserInfoRequest { - - private String accessToken; - - } - - @Getter - @AllArgsConstructor - @Builder - @NoArgsConstructor - public static class GetCommunityUserInfoRequest{ - private List userIdList; - } -} diff --git a/src/main/java/porori/backend/user/domain/user/application/dto/request/AdditionInfoRequest.java b/src/main/java/porori/backend/user/domain/user/application/dto/request/AdditionInfoRequest.java new file mode 100644 index 0000000..bcd4dc2 --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/application/dto/request/AdditionInfoRequest.java @@ -0,0 +1,42 @@ +package porori.backend.user.domain.user.application.dto.request; + +import io.swagger.annotations.ApiModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ApiModel(description = "추가 정보 입력을 위한 요청 객체") +public class AdditionInfoRequest { + @NotBlank(message = "자체 액세스 토큰을 입력해주세요.") + private String accessToken; + + @NotBlank(message = "본명을 입력해주세요.") + private String name; + + @NotBlank(message = "닉네임을 입력해주세요.") + private String nickName; + + @NotBlank(message = "전화번호를 입력해주세요.") + private String phoneNumber; + + @NotNull(message = "성별을 입력해주세요.") + private Boolean gender; + + @NotBlank(message="프로필 사진 URl입력해주세요.") + private String imageUrl; + + @NotBlank(message="이메일을 입력해주세요.") + private String email; + + @NotBlank(message = "주소를 입력해주세요.") + private String address; + +} \ No newline at end of file diff --git a/src/main/java/porori/backend/user/domain/user/application/dto/request/GetCommunityUserInfoRequest.java b/src/main/java/porori/backend/user/domain/user/application/dto/request/GetCommunityUserInfoRequest.java new file mode 100644 index 0000000..3b5fbc0 --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/application/dto/request/GetCommunityUserInfoRequest.java @@ -0,0 +1,16 @@ +package porori.backend.user.domain.user.application.dto.request; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Getter +@AllArgsConstructor +@Builder +@NoArgsConstructor +public class GetCommunityUserInfoRequest{ + private List userIdList; +} diff --git a/src/main/java/porori/backend/user/domain/user/application/dto/request/LoginRequest.java b/src/main/java/porori/backend/user/domain/user/application/dto/request/LoginRequest.java new file mode 100644 index 0000000..8041af8 --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/application/dto/request/LoginRequest.java @@ -0,0 +1,22 @@ +package porori.backend.user.domain.user.application.dto.request; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; + +@Getter +@AllArgsConstructor +@Builder +@ApiModel(description = "애플 로그인을 위한 요청 객체") +@NoArgsConstructor +public class LoginRequest { + @NotBlank(message = "애플 identity token을 입력해주세요.") + @ApiModelProperty(notes = "카카오 identity token을 주세요.") + private String token; + +} diff --git a/src/main/java/porori/backend/user/domain/user/application/dto/request/TestLoginRequest.java b/src/main/java/porori/backend/user/domain/user/application/dto/request/TestLoginRequest.java new file mode 100644 index 0000000..8306b5d --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/application/dto/request/TestLoginRequest.java @@ -0,0 +1,16 @@ +package porori.backend.user.domain.user.application.dto.request; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@Builder +@NoArgsConstructor +public class TestLoginRequest { + + private String appleId; + +} \ No newline at end of file diff --git a/src/main/java/porori/backend/user/domain/user/application/dto/request/TestSignUpRequest.java b/src/main/java/porori/backend/user/domain/user/application/dto/request/TestSignUpRequest.java new file mode 100644 index 0000000..5a0970d --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/application/dto/request/TestSignUpRequest.java @@ -0,0 +1,24 @@ +package porori.backend.user.domain.user.application.dto.request; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@Builder +@NoArgsConstructor +public class TestSignUpRequest { + + private String name; + private String phoneNumber; + private String appleID; + private String nickName; + private Boolean gender; + private String imageUrl; + private String email; + private String address; + + +} \ No newline at end of file diff --git a/src/main/java/porori/backend/user/domain/user/application/dto/request/UserLocationRequest.java b/src/main/java/porori/backend/user/domain/user/application/dto/request/UserLocationRequest.java new file mode 100644 index 0000000..0c18781 --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/application/dto/request/UserLocationRequest.java @@ -0,0 +1,24 @@ +package porori.backend.user.domain.user.application.dto.request; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Getter +@AllArgsConstructor +@Builder +@NoArgsConstructor +public class UserLocationRequest { + @NotBlank(message = "이름을 입력해주세요.") + private String name; + + @NotNull(message = "경도를 입력해주세요.") + private Double longitude; + + @NotNull(message = "위도를 입력해주세요.") + private Double latitude; +} diff --git a/src/main/java/porori/backend/user/domain/user/application/dto/res/UserResponseDto.java b/src/main/java/porori/backend/user/domain/user/application/dto/res/UserResponseDto.java deleted file mode 100644 index 20d3eda..0000000 --- a/src/main/java/porori/backend/user/domain/user/application/dto/res/UserResponseDto.java +++ /dev/null @@ -1,95 +0,0 @@ -package porori.backend.user.domain.user.application.dto.res; - -import com.querydsl.core.annotations.QueryProjection; -import io.swagger.annotations.ApiModel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import porori.backend.user.domain.user.domain.entity.User; -import porori.backend.user.global.dto.TokenInfoResponse; - -import java.util.ArrayList; -import java.util.List; - -public class UserResponseDto { - - - - @Getter - @Builder - @AllArgsConstructor - @NoArgsConstructor - @ApiModel(description = "로그인을 위한 응답 객체") - public static class LoginResponse { - private String accessToken; - private String refreshToken; - private boolean registrationStatus; - - public static LoginResponse from(TokenInfoResponse tokenInfoResponse, boolean registrationStatus) { - return LoginResponse.builder() - .accessToken(tokenInfoResponse.getAccessToken()) - .refreshToken(tokenInfoResponse.getRefreshToken()) - .registrationStatus(registrationStatus) - .build(); - } - } - - @Getter - @Builder - @AllArgsConstructor - @NoArgsConstructor - @ApiModel(description = "사용자 정보 객체") - public static class GetUserInfoResponse{ - private Long userId; - private String name; - private String nickName; - private String phoneNumber; - private boolean gender; - private String address; - private String imageUrl; - private String email; - private String backgroundColor; - - public static GetUserInfoResponse from(User user){ - return GetUserInfoResponse.builder() - .userId(user.getUserId()) - .name(user.getName()) - .nickName(user.getNickName()) - .phoneNumber(user.getPhoneNumber()) - .gender(user.isGender()) - .imageUrl(user.getImageUrl()) - .email(user.getEmail()) - .backgroundColor(user.getBackgroundColor()) - .address(user.getAddress()) - .build(); - } - } - - @Getter - @Builder - @AllArgsConstructor - @NoArgsConstructor - @ApiModel(description = "사용자 정보 객체") - public static class GetCommunityUserInfoResponse { - private List communityUserInfoBlocks = new ArrayList<>(); - } - - @Getter - public static class CommunityUserInfoBlocks { - private Long userId; - private String image; - private String backgroundColor; - private String nickname; - - @QueryProjection - public CommunityUserInfoBlocks(Long userId, String image, String backgroundColor, String nickname) { - this.userId = userId; - this.image = image; - this.backgroundColor = backgroundColor; - this.nickname = nickname; - } - } - - -} diff --git a/src/main/java/porori/backend/user/domain/user/application/dto/response/CommunityUserInfoBlocks.java b/src/main/java/porori/backend/user/domain/user/application/dto/response/CommunityUserInfoBlocks.java new file mode 100644 index 0000000..0b1bb2f --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/application/dto/response/CommunityUserInfoBlocks.java @@ -0,0 +1,20 @@ +package porori.backend.user.domain.user.application.dto.response; + +import com.querydsl.core.annotations.QueryProjection; +import lombok.Getter; + +@Getter +public class CommunityUserInfoBlocks { + private Long userId; + private String image; + private String backgroundColor; + private String nickname; + + @QueryProjection + public CommunityUserInfoBlocks(Long userId, String image, String backgroundColor, String nickname) { + this.userId = userId; + this.image = image; + this.backgroundColor = backgroundColor; + this.nickname = nickname; + } +} diff --git a/src/main/java/porori/backend/user/domain/user/application/dto/response/CommunityUserInfoResponse.java b/src/main/java/porori/backend/user/domain/user/application/dto/response/CommunityUserInfoResponse.java new file mode 100644 index 0000000..4c147b8 --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/application/dto/response/CommunityUserInfoResponse.java @@ -0,0 +1,19 @@ +package porori.backend.user.domain.user.application.dto.response; + +import io.swagger.annotations.ApiModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ApiModel(description = "사용자 정보 객체") +public class CommunityUserInfoResponse { + private List communityUserInfoBlocks = new ArrayList<>(); +} diff --git a/src/main/java/porori/backend/user/domain/user/application/dto/response/LocationResponse.java b/src/main/java/porori/backend/user/domain/user/application/dto/response/LocationResponse.java new file mode 100644 index 0000000..6548460 --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/application/dto/response/LocationResponse.java @@ -0,0 +1,19 @@ +package porori.backend.user.domain.user.application.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class LocationResponse { + + private Long locationId; + private String name; + private Double longitude; + private Double latitude; + +} diff --git a/src/main/java/porori/backend/user/domain/user/application/dto/response/LoginResponse.java b/src/main/java/porori/backend/user/domain/user/application/dto/response/LoginResponse.java new file mode 100644 index 0000000..7331c2c --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/application/dto/response/LoginResponse.java @@ -0,0 +1,27 @@ +package porori.backend.user.domain.user.application.dto.response; + +import io.swagger.annotations.ApiModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import porori.backend.user.global.dto.TokenInfoResponse; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ApiModel(description = "로그인을 위한 응답 객체") +public class LoginResponse { + private String accessToken; + private String refreshToken; + private boolean registrationStatus; + + public static LoginResponse from(TokenInfoResponse tokenInfoResponse, boolean registrationStatus) { + return LoginResponse.builder() + .accessToken(tokenInfoResponse.getAccessToken()) + .refreshToken(tokenInfoResponse.getRefreshToken()) + .registrationStatus(registrationStatus) + .build(); + } +} diff --git a/src/main/java/porori/backend/user/domain/user/application/dto/res/ReissueTokenResponse.java b/src/main/java/porori/backend/user/domain/user/application/dto/response/ReissueTokenResponse.java similarity index 90% rename from src/main/java/porori/backend/user/domain/user/application/dto/res/ReissueTokenResponse.java rename to src/main/java/porori/backend/user/domain/user/application/dto/response/ReissueTokenResponse.java index 4b21542..c32edea 100644 --- a/src/main/java/porori/backend/user/domain/user/application/dto/res/ReissueTokenResponse.java +++ b/src/main/java/porori/backend/user/domain/user/application/dto/response/ReissueTokenResponse.java @@ -1,4 +1,4 @@ -package porori.backend.user.domain.user.application.dto.res; +package porori.backend.user.domain.user.application.dto.response; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/porori/backend/user/domain/user/application/dto/response/UserInfoResponse.java b/src/main/java/porori/backend/user/domain/user/application/dto/response/UserInfoResponse.java new file mode 100644 index 0000000..c679f16 --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/application/dto/response/UserInfoResponse.java @@ -0,0 +1,39 @@ +package porori.backend.user.domain.user.application.dto.response; + +import io.swagger.annotations.ApiModel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import porori.backend.user.domain.user.domain.entity.User; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ApiModel(description = "사용자 정보 객체") +public class UserInfoResponse { + private Long userId; + private String name; + private String nickName; + private String phoneNumber; + private boolean gender; + private String address; + private String imageUrl; + private String email; + private String backgroundColor; + + public static UserInfoResponse from(User user){ + return UserInfoResponse.builder() + .userId(user.getUserId()) + .name(user.getName()) + .nickName(user.getNickName()) + .phoneNumber(user.getPhoneNumber()) + .gender(user.isGender()) + .imageUrl(user.getImageUrl()) + .email(user.getEmail()) + .backgroundColor(user.getBackgroundColor()) + .address(user.getAddress()) + .build(); + } +} \ No newline at end of file diff --git a/src/main/java/porori/backend/user/domain/user/application/dto/response/UserLocationResponse.java b/src/main/java/porori/backend/user/domain/user/application/dto/response/UserLocationResponse.java new file mode 100644 index 0000000..412da58 --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/application/dto/response/UserLocationResponse.java @@ -0,0 +1,18 @@ +package porori.backend.user.domain.user.application.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class UserLocationResponse { + private Long userId; + private List myLocations = new ArrayList<>(); +} diff --git a/src/main/java/porori/backend/user/domain/user/application/mapper/UserMapper.java b/src/main/java/porori/backend/user/domain/user/application/mapper/UserMapper.java index 9cffcaa..f59e0a8 100644 --- a/src/main/java/porori/backend/user/domain/user/application/mapper/UserMapper.java +++ b/src/main/java/porori/backend/user/domain/user/application/mapper/UserMapper.java @@ -1,51 +1,38 @@ package porori.backend.user.domain.user.application.mapper; -import org.springframework.context.annotation.Bean; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; -import org.springframework.security.oauth2.core.user.DefaultOAuth2User; -import org.springframework.security.oauth2.core.user.OAuth2User; import org.springframework.stereotype.Service; +import porori.backend.user.domain.user.application.dto.request.UserLocationRequest; +import porori.backend.user.domain.user.application.dto.response.LocationResponse; +import porori.backend.user.domain.user.application.dto.response.UserLocationResponse; +import porori.backend.user.domain.user.domain.entity.Location; import porori.backend.user.domain.user.domain.entity.User; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; - -import static porori.backend.user.domain.user.domain.entity.UserConstant.Role.ROLE_USER; +import java.util.stream.Collectors; @Service public class UserMapper { - public OAuth2User createOAuth2UserByUser(List authorities, User user) { - Map userMap = new HashMap(); - userMap.put("appleId", user.getAppleId()); - OAuth2User userDetails = new DefaultOAuth2User(authorities, userMap, "appleId"); - return userDetails; + public UserLocationResponse toUserLocationResponse(User user) { + return new UserLocationResponse( + user.getUserId(), + user.getMyLocations().stream() + .map(l -> toLocationResponse(l)) + .collect(Collectors.toList()) + ); } - - - public OAuth2User createOAuth2UserByApple(List authorities, String appleId) { - Map userMap = new HashMap(); - userMap.put("appleId", appleId); - authorities.add(new SimpleGrantedAuthority(String.valueOf(ROLE_USER))); - OAuth2User userDetails = new DefaultOAuth2User(authorities, userMap, "appleId"); - return userDetails; + private LocationResponse toLocationResponse(Location location) { + return LocationResponse.builder() + .locationId(location.getLocationId()) + .name(location.getName()) + .longitude(location.getLongitude()) + .latitude(location.getLatitude()) + .build(); } - - - public List initAuthorities() { - List authorities = new ArrayList<>(); - authorities.add(new SimpleGrantedAuthority(String.valueOf(ROLE_USER))); - return authorities; - } - - public OAuth2AuthenticationToken configureAuthentication(OAuth2User userDetails, List authorities) { - OAuth2AuthenticationToken auth = new OAuth2AuthenticationToken(userDetails, authorities, "email"); - auth.setDetails(userDetails); - SecurityContextHolder.getContext().setAuthentication(auth); - return auth; + public Location toLocation(UserLocationRequest userLocationRequest) { + return Location.builder() + .name(userLocationRequest.getName()) + .longitude(userLocationRequest.getLongitude()) + .latitude(userLocationRequest.getLatitude()) + .build(); } } diff --git a/src/main/java/porori/backend/user/domain/user/application/service/ReissueTokenService.java b/src/main/java/porori/backend/user/domain/user/application/service/ReissueTokenService.java index 0e73c9a..a07ac14 100644 --- a/src/main/java/porori/backend/user/domain/user/application/service/ReissueTokenService.java +++ b/src/main/java/porori/backend/user/domain/user/application/service/ReissueTokenService.java @@ -3,7 +3,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import porori.backend.user.domain.user.application.dto.res.ReissueTokenResponse; +import porori.backend.user.domain.user.application.dto.response.ReissueTokenResponse; import porori.backend.user.global.config.security.exception.NotFoundRefreshTokenException; import porori.backend.user.global.config.security.jwt.TokenUtil; import porori.backend.user.global.dto.TokenInfoResponse; diff --git a/src/main/java/porori/backend/user/domain/user/application/service/UserDeleteService.java b/src/main/java/porori/backend/user/domain/user/application/service/UserDeleteService.java index 452b1a1..f1ce815 100644 --- a/src/main/java/porori/backend/user/domain/user/application/service/UserDeleteService.java +++ b/src/main/java/porori/backend/user/domain/user/application/service/UserDeleteService.java @@ -2,10 +2,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import porori.backend.user.domain.user.application.dto.req.UserRequestDto; import porori.backend.user.domain.user.domain.entity.User; -import porori.backend.user.domain.user.domain.service.UserSaveService; -import porori.backend.user.global.config.security.utils.SecurityUtils; +import porori.backend.user.domain.user.domain.service.UserValidationService; import javax.transaction.Transactional; @@ -14,12 +12,10 @@ @Transactional public class UserDeleteService { - private final UserSaveService userSaveService; - - public void deleteAccount(UserRequestDto.DeleteAccountRequest deleteAccountRequest) { - User user = SecurityUtils.getLoggedInUser(); + private final UserValidationService userValidationService; + public void deleteAccount(String appleId) { + User user = userValidationService.validateAppleId(appleId); user.withdraw(); - userSaveService.saveUser(user); } } diff --git a/src/main/java/porori/backend/user/domain/user/application/service/UserInfoService.java b/src/main/java/porori/backend/user/domain/user/application/service/UserInfoService.java index 549a4b1..7d49da1 100644 --- a/src/main/java/porori/backend/user/domain/user/application/service/UserInfoService.java +++ b/src/main/java/porori/backend/user/domain/user/application/service/UserInfoService.java @@ -1,17 +1,17 @@ package porori.backend.user.domain.user.application.service; import lombok.RequiredArgsConstructor; -import org.springframework.security.core.Authentication; import org.springframework.stereotype.Service; -import porori.backend.user.domain.user.application.dto.req.UserRequestDto; -import porori.backend.user.domain.user.application.dto.res.UserResponseDto; -import porori.backend.user.domain.user.application.dto.res.UserResponseDto.GetCommunityUserInfoResponse; +import porori.backend.user.domain.user.application.dto.request.GetCommunityUserInfoRequest; +import porori.backend.user.domain.user.application.dto.response.CommunityUserInfoResponse; +import porori.backend.user.domain.user.application.dto.response.UserInfoResponse; import porori.backend.user.domain.user.domain.entity.User; import porori.backend.user.domain.user.domain.service.UserQueryService; import porori.backend.user.domain.user.domain.service.UserValidationService; import porori.backend.user.global.config.security.jwt.TokenUtil; import javax.transaction.Transactional; +import java.util.List; @Service @RequiredArgsConstructor @@ -21,13 +21,13 @@ public class UserInfoService { private final UserValidationService userValidationService; private final UserQueryService userQueryService; - public UserResponseDto.GetUserInfoResponse getUserInfo(String appleId) { + public UserInfoResponse getUserInfo(String appleId) { User user = userValidationService.validateAppleId(appleId); - return UserResponseDto.GetUserInfoResponse.from(user); + return UserInfoResponse.from(user); } - public GetCommunityUserInfoResponse getCommunityUserInfo(UserRequestDto.GetCommunityUserInfoRequest getCommunityUserInfoRequest) { - return userQueryService.getCommunityUserInfoByUserIdList(getCommunityUserInfoRequest); + public CommunityUserInfoResponse getCommunityUserInfo(List userIdList) { + return userQueryService.getCommunityUserInfoByUserIdList(userIdList); } } diff --git a/src/main/java/porori/backend/user/domain/user/application/service/UserLocationService.java b/src/main/java/porori/backend/user/domain/user/application/service/UserLocationService.java new file mode 100644 index 0000000..b341a5b --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/application/service/UserLocationService.java @@ -0,0 +1,50 @@ +package porori.backend.user.domain.user.application.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import porori.backend.user.domain.user.application.dto.request.UserLocationRequest; +import porori.backend.user.domain.user.application.dto.response.UserLocationResponse; +import porori.backend.user.domain.user.application.mapper.UserMapper; +import porori.backend.user.domain.user.domain.entity.Location; +import porori.backend.user.domain.user.domain.entity.User; +import porori.backend.user.domain.user.domain.service.LocationDeleteService; +import porori.backend.user.domain.user.domain.service.LocationSaveService; +import porori.backend.user.domain.user.domain.service.UserValidationService; + +import javax.transaction.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +public class UserLocationService { + + private final UserValidationService userValidationService; + private final UserMapper userMapper; + private final LocationSaveService locationSaveService; + private final LocationDeleteService locationDeleteService; + + public UserLocationResponse getUserLocation(String appleId){ + User user = userValidationService.validateAppleId(appleId); + return userMapper.toUserLocationResponse(user); + } + + public void addUserLocation(String appleId, UserLocationRequest userLocationRequest){ + Location newLocation=userMapper.toLocation(userLocationRequest); + locationSaveService.saveLocation(newLocation); + + User user = userValidationService.validateAppleId(appleId); + user.addMyLocation(newLocation); + } + + public void updateUserLocation(String appleId, Long locationId, UserLocationRequest userLocationRequest){ + User user = userValidationService.validateAppleId(appleId); + Location newLocation=userMapper.toLocation(userLocationRequest); + user.updateMyLocation(locationId, newLocation); + } + + public void deleteUserLocation(String appleId, Long locationId){ + User user=userValidationService.validateAppleId(appleId); + Location location=user.deleteMyLocation(locationId); + locationDeleteService.deleteLocation(location); + } +} diff --git a/src/main/java/porori/backend/user/domain/user/application/service/UserLoginService.java b/src/main/java/porori/backend/user/domain/user/application/service/UserLoginService.java index de91f2c..8894787 100644 --- a/src/main/java/porori/backend/user/domain/user/application/service/UserLoginService.java +++ b/src/main/java/porori/backend/user/domain/user/application/service/UserLoginService.java @@ -1,12 +1,10 @@ package porori.backend.user.domain.user.application.service; import lombok.RequiredArgsConstructor; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; -import org.springframework.security.oauth2.core.user.OAuth2User; import org.springframework.stereotype.Service; -import porori.backend.user.domain.user.application.dto.req.UserRequestDto; -import porori.backend.user.domain.user.application.dto.res.UserResponseDto; +import porori.backend.user.domain.user.application.dto.request.LoginRequest; +import porori.backend.user.domain.user.application.dto.request.TestLoginRequest; +import porori.backend.user.domain.user.application.dto.response.LoginResponse; import porori.backend.user.domain.user.application.mapper.UserMapper; import porori.backend.user.domain.user.domain.entity.User; import porori.backend.user.domain.user.domain.entity.UserConstant; @@ -18,10 +16,6 @@ import porori.backend.user.global.exception.ConnException; import javax.transaction.Transactional; -import java.util.List; - -import static porori.backend.user.domain.user.presentation.constant.Process.LOGIN_SUCCESS; -import static porori.backend.user.domain.user.presentation.constant.Process.SIGN_UP_ING; @Service @RequiredArgsConstructor @@ -35,7 +29,7 @@ public class UserLoginService { private final TokenUtil tokenUtil; public final UserMapper userMapper; - public UserResponseDto.LoginResponse login(UserRequestDto.LoginRequest loginRequest) { + public LoginResponse login(LoginRequest loginRequest) { //1. 프론트에게 받은 액세스 토큰 이용해서 사용자 정보 가져오기 String token = loginRequest.getToken(); String appleId = appleService.verifyIdentityToken(token).orElseThrow(() -> new ConnException()); @@ -48,11 +42,11 @@ public UserResponseDto.LoginResponse login(UserRequestDto.LoginRequest loginRequ //5. refresh token 저장 tokenUtil.storeRefreshToken(user.getAppleId(), tokenResponse); - return UserResponseDto.LoginResponse.from(tokenResponse, registrationStatus); + return LoginResponse.from(tokenResponse, registrationStatus); } - public UserResponseDto.LoginResponse testLogin(UserRequestDto.TestLoginRequest testLoginRequest) { + public LoginResponse testLogin(TestLoginRequest testLoginRequest) { User user = userValidationService.validateAppleId(testLoginRequest.getAppleId()); boolean registrationStatus = user.getRegistrationStatus().equals(UserConstant.RegistrationStatus.COMPLETED); @@ -63,6 +57,6 @@ public UserResponseDto.LoginResponse testLogin(UserRequestDto.TestLoginRequest t //5. refresh token 저장 tokenUtil.storeRefreshToken(user.getAppleId(), tokenResponse); - return UserResponseDto.LoginResponse.from(tokenResponse, registrationStatus); + return LoginResponse.from(tokenResponse, registrationStatus); } } diff --git a/src/main/java/porori/backend/user/domain/user/application/service/UserSignUpService.java b/src/main/java/porori/backend/user/domain/user/application/service/UserSignUpService.java index 43a1691..6787f1c 100644 --- a/src/main/java/porori/backend/user/domain/user/application/service/UserSignUpService.java +++ b/src/main/java/porori/backend/user/domain/user/application/service/UserSignUpService.java @@ -2,11 +2,11 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import porori.backend.user.domain.user.application.dto.req.UserRequestDto; -import porori.backend.user.domain.user.application.dto.res.UserResponseDto; +import porori.backend.user.domain.user.application.dto.request.AdditionInfoRequest; +import porori.backend.user.domain.user.application.dto.request.TestSignUpRequest; +import porori.backend.user.domain.user.application.dto.response.LoginResponse; import porori.backend.user.domain.user.application.mapper.UserMapper; import porori.backend.user.domain.user.domain.entity.User; -import porori.backend.user.domain.user.domain.entity.UserConstant.RegistrationStatus; import porori.backend.user.domain.user.domain.service.UserSaveService; import porori.backend.user.domain.user.domain.service.UserValidationService; import porori.backend.user.global.config.security.jwt.TokenUtil; @@ -27,7 +27,7 @@ public class UserSignUpService { private final AuthenticationUtil authenticationUtil; private final UserMapper userMapper; - public UserResponseDto.LoginResponse signup(UserRequestDto.AdditionInfoRequest additionInfoRequest) { + public LoginResponse signup(AdditionInfoRequest additionInfoRequest) { //1. 유저 찾기 String socialId = tokenUtil.getAppleId(additionInfoRequest.getAccessToken()); User user = userValidationService.validateAppleId(socialId); @@ -40,14 +40,14 @@ public UserResponseDto.LoginResponse signup(UserRequestDto.AdditionInfoRequest a //5. refresh token 저장 tokenUtil.storeRefreshToken(user.getAppleId(), tokenResponse); - return UserResponseDto.LoginResponse.from(tokenResponse, true); + return LoginResponse.from(tokenResponse, true); } - public UserResponseDto.LoginResponse testSignUp(UserRequestDto.TestSignUpRequest signUpRequest) { + public LoginResponse testSignUp(TestSignUpRequest signUpRequest) { User user = new User(signUpRequest); + //2. signUp 처리; user.updateRegistrationStatus(); userSaveService.saveUser(user); - //2. signUp 처리; //3. security 처리 AuthenticationUtil.makeAuthentication(user); //4. token 만들기 @@ -55,7 +55,7 @@ public UserResponseDto.LoginResponse testSignUp(UserRequestDto.TestSignUpRequest //5. refresh token 저장 tokenUtil.storeRefreshToken(user.getAppleId(), tokenResponse); - return UserResponseDto.LoginResponse.from(tokenResponse, true); + return LoginResponse.from(tokenResponse, true); } } diff --git a/src/main/java/porori/backend/user/domain/user/domain/entity/Location.java b/src/main/java/porori/backend/user/domain/user/domain/entity/Location.java new file mode 100644 index 0000000..3ed42a0 --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/domain/entity/Location.java @@ -0,0 +1,41 @@ +package porori.backend.user.domain.user.domain.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import porori.backend.user.domain.user.application.dto.request.UserLocationRequest; + +import javax.persistence.*; + +@Entity +@Getter +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class Location { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "location_id") + private Long locationId; + + private String name; + private Double longitude; + private Double latitude; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + //==연관관계 메서드==// + public void updateUser(User user) { + this.user=user; + user.getMyLocations().add(this); + } + + public void updateLocation(Location location){ + this.name=location.getName(); + this.longitude=location.getLongitude(); + this.latitude=location.getLatitude(); + } +} diff --git a/src/main/java/porori/backend/user/domain/user/domain/entity/User.java b/src/main/java/porori/backend/user/domain/user/domain/entity/User.java index f8558d3..8a70a6c 100644 --- a/src/main/java/porori/backend/user/domain/user/domain/entity/User.java +++ b/src/main/java/porori/backend/user/domain/user/domain/entity/User.java @@ -4,11 +4,16 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import porori.backend.user.domain.user.application.dto.req.UserRequestDto; +import porori.backend.user.domain.user.application.dto.request.AdditionInfoRequest; +import porori.backend.user.domain.user.application.dto.request.TestSignUpRequest; import porori.backend.user.domain.user.domain.entity.UserConstant.RegistrationStatus; import porori.backend.user.domain.user.domain.entity.UserConstant.Role; +import porori.backend.user.global.exception.LocationLimitException; +import porori.backend.user.global.exception.NotFoundLocationException; import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; @Entity @Builder @@ -33,6 +38,11 @@ public class User { private Role role; private boolean withdrawalStatus; + + //내 위치 설정 (최대 2개) + @OneToMany(mappedBy = "user", cascade = CascadeType.ALL) + private List myLocations = new ArrayList<>(); + @Enumerated(EnumType.STRING) private RegistrationStatus registrationStatus; @@ -43,19 +53,19 @@ public User(String appleId, Role role) { } @Builder - public User(UserRequestDto.TestSignUpRequest signUpRequest) { - this.name=signUpRequest.getName(); + public User(TestSignUpRequest signUpRequest) { + this.name = signUpRequest.getName(); this.nickName = signUpRequest.getNickName(); this.phoneNumber = signUpRequest.getPhoneNumber(); this.gender = signUpRequest.getGender(); this.address = signUpRequest.getAddress(); this.imageUrl = signUpRequest.getImageUrl(); this.email = signUpRequest.getEmail(); - this.appleId=signUpRequest.getAppleID(); - this.role=Role.ROLE_USER; + this.appleId = signUpRequest.getAppleID(); + this.role = Role.ROLE_USER; } - public void signup(UserRequestDto.AdditionInfoRequest additionInfoRequest) { + public void signup(AdditionInfoRequest additionInfoRequest) { this.name = additionInfoRequest.getName(); this.nickName = additionInfoRequest.getNickName(); this.phoneNumber = additionInfoRequest.getPhoneNumber(); @@ -63,14 +73,43 @@ public void signup(UserRequestDto.AdditionInfoRequest additionInfoRequest) { this.address = additionInfoRequest.getAddress(); this.imageUrl = additionInfoRequest.getImageUrl(); this.email = additionInfoRequest.getEmail(); - this.registrationStatus=RegistrationStatus.COMPLETED; + this.registrationStatus = RegistrationStatus.COMPLETED; + } + + public void updateRegistrationStatus() { + this.registrationStatus = RegistrationStatus.COMPLETED; + } + + public void withdraw() { + this.withdrawalStatus = true; + } + + //==위치 관계 업데이트==// + public void addMyLocation(Location location) { + if (myLocations.size() < 2) { // 내 위치는 최대 2개 + myLocations.add(location); + location.updateUser(this); // 양방향 관계 설정 + } else { + throw new LocationLimitException(); + } + } + + private Location findLocationById(Long locationId) { + return myLocations.stream() + .filter(location -> location.getLocationId().equals(locationId)) + .findFirst() + .orElseThrow(() -> new NotFoundLocationException()); } - public void updateRegistrationStatus(){ - this.registrationStatus=RegistrationStatus.COMPLETED; + public void updateMyLocation(Long locationId, Location newLocationData) { + Location location = findLocationById(locationId); + // Location 엔티티 내에 정보를 업데이트하는 메서드를 호출 + location.updateLocation(newLocationData); } - public void withdraw(){ - this.withdrawalStatus=true; + public Location deleteMyLocation(Long locationId) { + Location location = findLocationById(locationId); + myLocations.remove(location); + return location; } } diff --git a/src/main/java/porori/backend/user/domain/user/domain/repository/LocationRepository.java b/src/main/java/porori/backend/user/domain/user/domain/repository/LocationRepository.java new file mode 100644 index 0000000..8b3e6b9 --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/domain/repository/LocationRepository.java @@ -0,0 +1,7 @@ +package porori.backend.user.domain.user.domain.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import porori.backend.user.domain.user.domain.entity.Location; + +public interface LocationRepository extends JpaRepository { +} diff --git a/src/main/java/porori/backend/user/domain/user/domain/repository/UserRepository.java b/src/main/java/porori/backend/user/domain/user/domain/repository/UserRepository.java index 3c01083..fc16489 100644 --- a/src/main/java/porori/backend/user/domain/user/domain/repository/UserRepository.java +++ b/src/main/java/porori/backend/user/domain/user/domain/repository/UserRepository.java @@ -1,7 +1,10 @@ package porori.backend.user.domain.user.domain.repository; import org.springframework.data.jpa.repository.JpaRepository; +import porori.backend.user.domain.user.domain.entity.Location; import porori.backend.user.domain.user.domain.entity.User; +import java.util.List; + public interface UserRepository extends JpaRepository , UserRepositoryCustom { } diff --git a/src/main/java/porori/backend/user/domain/user/domain/repository/UserRepositoryCustom.java b/src/main/java/porori/backend/user/domain/user/domain/repository/UserRepositoryCustom.java index cf2afee..1711684 100644 --- a/src/main/java/porori/backend/user/domain/user/domain/repository/UserRepositoryCustom.java +++ b/src/main/java/porori/backend/user/domain/user/domain/repository/UserRepositoryCustom.java @@ -1,6 +1,7 @@ package porori.backend.user.domain.user.domain.repository; -import porori.backend.user.domain.user.application.dto.res.UserResponseDto.GetCommunityUserInfoResponse; +import porori.backend.user.domain.user.application.dto.response.CommunityUserInfoResponse; +import porori.backend.user.domain.user.application.dto.response.UserLocationResponse; import porori.backend.user.domain.user.domain.entity.User; import java.util.List; @@ -9,5 +10,5 @@ public interface UserRepositoryCustom { Optional findNotWithdrawByAppleId(String appleId); - GetCommunityUserInfoResponse findCommunityUserInfoByUserIdList(List userIdList); + CommunityUserInfoResponse findCommunityUserInfoByUserIdList(List userIdList); } diff --git a/src/main/java/porori/backend/user/domain/user/domain/repository/UserRepositoryCustomImpl.java b/src/main/java/porori/backend/user/domain/user/domain/repository/UserRepositoryCustomImpl.java index d5bfe8a..cf23758 100644 --- a/src/main/java/porori/backend/user/domain/user/domain/repository/UserRepositoryCustomImpl.java +++ b/src/main/java/porori/backend/user/domain/user/domain/repository/UserRepositoryCustomImpl.java @@ -1,8 +1,9 @@ package porori.backend.user.domain.user.domain.repository; import com.querydsl.jpa.impl.JPAQueryFactory; -import porori.backend.user.domain.user.application.dto.res.QUserResponseDto_CommunityUserInfoBlocks; -import porori.backend.user.domain.user.application.dto.res.UserResponseDto; +import porori.backend.user.domain.user.application.dto.response.CommunityUserInfoBlocks; +import porori.backend.user.domain.user.application.dto.response.CommunityUserInfoResponse; +import porori.backend.user.domain.user.application.dto.response.QUserResponseDto_CommunityUserInfoBlocks; import porori.backend.user.domain.user.domain.entity.User; import javax.persistence.EntityManager; @@ -30,8 +31,8 @@ public Optional findNotWithdrawByAppleId(String appleId) { } @Override - public UserResponseDto.GetCommunityUserInfoResponse findCommunityUserInfoByUserIdList(List userIdList) { - List blocks = queryFactory.select(new QUserResponseDto_CommunityUserInfoBlocks( + public CommunityUserInfoResponse findCommunityUserInfoByUserIdList(List userIdList) { + List blocks = queryFactory.select(new QUserResponseDto_CommunityUserInfoBlocks( user.userId, user.imageUrl, user.backgroundColor, @@ -39,6 +40,8 @@ public UserResponseDto.GetCommunityUserInfoResponse findCommunityUserInfoByUserI .from(user) .where(user.userId.in(userIdList)) // userIdList 내의 userId들을 기준으로 조회 .fetch(); - return new UserResponseDto.GetCommunityUserInfoResponse(blocks); + return new CommunityUserInfoResponse(blocks); } + + } diff --git a/src/main/java/porori/backend/user/domain/user/domain/service/LocationDeleteService.java b/src/main/java/porori/backend/user/domain/user/domain/service/LocationDeleteService.java new file mode 100644 index 0000000..4f27985 --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/domain/service/LocationDeleteService.java @@ -0,0 +1,19 @@ +package porori.backend.user.domain.user.domain.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import porori.backend.user.domain.user.domain.entity.Location; +import porori.backend.user.domain.user.domain.repository.LocationRepository; + +import javax.transaction.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +public class LocationDeleteService { + private final LocationRepository locationRepository; + + public void deleteLocation(Location location){ + locationRepository.delete(location); + } +} diff --git a/src/main/java/porori/backend/user/domain/user/domain/service/LocationSaveService.java b/src/main/java/porori/backend/user/domain/user/domain/service/LocationSaveService.java new file mode 100644 index 0000000..b4ef45d --- /dev/null +++ b/src/main/java/porori/backend/user/domain/user/domain/service/LocationSaveService.java @@ -0,0 +1,19 @@ +package porori.backend.user.domain.user.domain.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import porori.backend.user.domain.user.domain.entity.Location; +import porori.backend.user.domain.user.domain.repository.LocationRepository; + +import javax.transaction.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional +public class LocationSaveService { + private final LocationRepository locationRepository; + + public void saveLocation(Location location){ + locationRepository.save(location); + } +} diff --git a/src/main/java/porori/backend/user/domain/user/domain/service/UserQueryService.java b/src/main/java/porori/backend/user/domain/user/domain/service/UserQueryService.java index 08a1735..b95a88f 100644 --- a/src/main/java/porori/backend/user/domain/user/domain/service/UserQueryService.java +++ b/src/main/java/porori/backend/user/domain/user/domain/service/UserQueryService.java @@ -2,8 +2,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import porori.backend.user.domain.user.application.dto.req.UserRequestDto; -import porori.backend.user.domain.user.application.dto.res.UserResponseDto; +import porori.backend.user.domain.user.application.dto.request.GetCommunityUserInfoRequest; +import porori.backend.user.domain.user.application.dto.response.CommunityUserInfoResponse; import porori.backend.user.domain.user.domain.repository.UserRepository; import javax.transaction.Transactional; @@ -15,7 +15,7 @@ public class UserQueryService { private final UserRepository userRepository; - public UserResponseDto.GetCommunityUserInfoResponse getCommunityUserInfoByUserIdList(UserRequestDto.GetCommunityUserInfoRequest getCommunityUserInfoRequest){ - return userRepository.findCommunityUserInfoByUserIdList(getCommunityUserInfoRequest.getUserIdList()); + public CommunityUserInfoResponse getCommunityUserInfoByUserIdList(List userIdList) { + return userRepository.findCommunityUserInfoByUserIdList(userIdList); } } diff --git a/src/main/java/porori/backend/user/domain/user/presentation/UserController.java b/src/main/java/porori/backend/user/domain/user/presentation/UserController.java index 9885fef..834a0c7 100644 --- a/src/main/java/porori/backend/user/domain/user/presentation/UserController.java +++ b/src/main/java/porori/backend/user/domain/user/presentation/UserController.java @@ -7,17 +7,16 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; -import porori.backend.user.domain.user.application.dto.req.UserRequestDto.*; -import porori.backend.user.domain.user.application.dto.res.ReissueTokenResponse; -import porori.backend.user.domain.user.application.dto.res.UserResponseDto; -import porori.backend.user.domain.user.application.dto.res.UserResponseDto.LoginResponse; +import porori.backend.user.domain.user.application.dto.request.*; +import porori.backend.user.domain.user.application.dto.response.*; import porori.backend.user.domain.user.application.service.*; import porori.backend.user.global.config.security.dto.CustomUser; import porori.backend.user.global.dto.ResponseDto; -import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; +import java.util.List; + import static porori.backend.user.domain.user.presentation.constant.EUserResponseMessage.*; @@ -32,6 +31,7 @@ public class UserController { private final UserDeleteService userDeleteService; private final UserInfoService userInfoService; private final ReissueTokenService reissueTokenService; + private final UserLocationService userLocationService; @ApiOperation(value = "애플 로그인", notes = "애플 로그인을 합니다.") @@ -49,17 +49,17 @@ public ResponseEntity> additionalInfo(@Valid @Request @ApiOperation(value = "회원 탈퇴", notes = "회원 탈퇴를 합니다.") @DeleteMapping - public ResponseEntity delete(@Valid @RequestBody DeleteAccountRequest deleteAccountRequest) { - this.userDeleteService.deleteAccount(deleteAccountRequest); + public ResponseEntity delete(@AuthenticationPrincipal CustomUser customUser) { + this.userDeleteService.deleteAccount(customUser.getAppleId()); return ResponseEntity.ok(ResponseDto.create(HttpStatus.OK.value(), DELETE_SUCCESS.getMessage())); } @ApiOperation(value = "사용자 정보 보기", notes = "사용자 정보를 확인합니다.") @GetMapping("/token/me") - public ResponseEntity> getUserInfo( + public ResponseEntity> getUserInfo( @AuthenticationPrincipal CustomUser customUser) { - return ResponseEntity.ok(ResponseDto.create(HttpStatus.OK.value(), GET_USERINFO_SUCCESS.getMessage(),userInfoService.getUserInfo(customUser.getAppleId()))); + return ResponseEntity.ok(ResponseDto.create(HttpStatus.OK.value(), GET_USERINFO_SUCCESS.getMessage(), userInfoService.getUserInfo(customUser.getAppleId()))); } @ApiOperation(value = "(테스트)회원가입", notes = "회원가입을 합니다") @@ -80,22 +80,49 @@ public ResponseEntity> jwtTokenTest() { return ResponseEntity.ok(ResponseDto.create(HttpStatus.OK.value(), VALID_TOKEN.getMessage())); } - @ApiOperation(value="커뮤니티 회원 정보 보기" , notes="커뮤니티 회원 정보 보기") - @PostMapping("/communities/info") - public ResponseEntity> getCommunityUserInfo( - @Valid @RequestBody GetCommunityUserInfoRequest getCommunityUserInfoRequest){ - return ResponseEntity.ok(ResponseDto.create(HttpStatus.OK.value(), GET_COMMUNITY_USERINFO_SUCCESS.getMessage(), this.userInfoService.getCommunityUserInfo(getCommunityUserInfoRequest))); + @ApiOperation(value = "커뮤니티 회원 정보 보기", notes = "커뮤니티 회원 정보 보기") + @GetMapping("/communities/info") + public ResponseEntity> getCommunityUserInfo(@RequestParam List userIdList) { + return ResponseEntity.ok(ResponseDto.create(HttpStatus.OK.value(), GET_COMMUNITY_USERINFO_SUCCESS.getMessage(), this.userInfoService.getCommunityUserInfo(userIdList))); } + @ApiOperation(value = "토큰 재발급", notes = "토큰을 재발급합니다.") @GetMapping("/reissue") - public ResponseEntity> reissue(HttpServletRequest request) { - - // 헤더로부터 RefreshToken 추출. - String token = request.getHeader("RefreshToken"); - // 토큰 재발행 + public ResponseEntity> reissue(@RequestHeader(value = "RefreshToken") String token) { ReissueTokenResponse reissueToken = reissueTokenService.reissueToken(token); - return ResponseEntity.ok(ResponseDto.create(HttpStatus.OK.value(), REISSUE_TOKEN_SUCCESS.getMessage(), reissueToken)); } + + @ApiOperation(value = "사용자 위치 보기", notes = "사용자 위치를 확인합니다.") + @GetMapping("/locations") + public ResponseEntity> getUserLocation( + @AuthenticationPrincipal CustomUser customUser) { + return ResponseEntity.ok(ResponseDto.create(HttpStatus.OK.value(), GET_USERLOCATION_SUCCESS.getMessage(), userLocationService.getUserLocation(customUser.getAppleId()))); + } + + @ApiOperation(value = "사용자 위치 조회", notes = "사용자 위치를 조회합니다.") + @PostMapping("/locations") + public ResponseEntity addUserLocation(@AuthenticationPrincipal CustomUser customUser, + @Valid @RequestBody UserLocationRequest userLocationRequest) { + userLocationService.addUserLocation(customUser.getAppleId(), userLocationRequest); + return ResponseEntity.ok(ResponseDto.create(HttpStatus.OK.value(), ADD_USERLOCATION_SUCCESS.getMessage())); + } + @ApiOperation(value = "사용자 위치 수정", notes = "사용자 위치를 수정합니다.") + @PutMapping("/locations/{locationId}") + public ResponseEntity updateUserLocation(@AuthenticationPrincipal CustomUser customUser, + @PathVariable Long locationId, + @Valid @RequestBody UserLocationRequest userLocationRequest) { + userLocationService.updateUserLocation(customUser.getAppleId(), locationId, userLocationRequest); + return ResponseEntity.ok(ResponseDto.create(HttpStatus.OK.value(), UPDATE_USERLOCATION_SUCCESS.getMessage())); + } + + @ApiOperation(value = "사용자 위치 삭제", notes = "사용자 위치를 삭제합니다.") + @DeleteMapping("/locations/{locationId}") + public ResponseEntity deleteUserLocation(@AuthenticationPrincipal CustomUser customUser, + @PathVariable Long locationId) { + userLocationService.deleteUserLocation(customUser.getAppleId(), locationId); + return ResponseEntity.ok(ResponseDto.create(HttpStatus.OK.value(), DELETE_USERLOCATION_SUCCESS.getMessage())); + } + } diff --git a/src/main/java/porori/backend/user/domain/user/presentation/constant/EUserResponseMessage.java b/src/main/java/porori/backend/user/domain/user/presentation/constant/EUserResponseMessage.java index 97b8ac7..8d47ea0 100644 --- a/src/main/java/porori/backend/user/domain/user/presentation/constant/EUserResponseMessage.java +++ b/src/main/java/porori/backend/user/domain/user/presentation/constant/EUserResponseMessage.java @@ -13,7 +13,11 @@ public enum EUserResponseMessage { VALID_TOKEN("유효한 토큰입니다"), GET_USERINFO_SUCCESS("사용자 정보 조회를 완료했습니다"), GET_COMMUNITY_USERINFO_SUCCESS("커뮤니티에서 사용자 정보 조회를 완료했습니다"), - REISSUE_TOKEN_SUCCESS("토큰을 재발급하였습니다."); + REISSUE_TOKEN_SUCCESS("토큰을 재발급하였습니다."), + GET_USERLOCATION_SUCCESS("사용자 위치를 조회했습니다"), + ADD_USERLOCATION_SUCCESS("사용자 위치를 추가했습니다"), + UPDATE_USERLOCATION_SUCCESS("사용자 위치를 수정했습니다"), + DELETE_USERLOCATION_SUCCESS("사용자 위치를 삭제했습니다"); private final String message; } diff --git a/src/main/java/porori/backend/user/domain/user/presentation/constant/Process.java b/src/main/java/porori/backend/user/domain/user/presentation/constant/Process.java deleted file mode 100644 index 5c62cbe..0000000 --- a/src/main/java/porori/backend/user/domain/user/presentation/constant/Process.java +++ /dev/null @@ -1,14 +0,0 @@ -package porori.backend.user.domain.user.presentation.constant; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor -public enum Process { - SIGN_UP_ING("회원가입 중-추가 정보를 입력해주세요."), - SIGN_UP_SUCCESS("회원가입이 완료되었습니다"), - LOGIN_SUCCESS("로그인이 완료되었습니다"); - - private final String message; -} diff --git a/src/main/java/porori/backend/user/global/config/security/SecurityConfig.java b/src/main/java/porori/backend/user/global/config/security/SecurityConfig.java index fcfd77f..1d41786 100644 --- a/src/main/java/porori/backend/user/global/config/security/SecurityConfig.java +++ b/src/main/java/porori/backend/user/global/config/security/SecurityConfig.java @@ -57,6 +57,7 @@ protected void configure(HttpSecurity http) throws Exception { .antMatchers("/v3/api-docs").permitAll() .antMatchers("/api/users/test/jwt").authenticated() .antMatchers("/api/users/token/me").authenticated() + .antMatchers("/api/users/locations/**").authenticated() .anyRequest().permitAll() .and() .apply(new JwtSecurityConfig(tokenUtil,userValidationService)); diff --git a/src/main/java/porori/backend/user/global/config/security/utils/SecurityUtils.java b/src/main/java/porori/backend/user/global/config/security/utils/SecurityUtils.java deleted file mode 100644 index b43e2c5..0000000 --- a/src/main/java/porori/backend/user/global/config/security/utils/SecurityUtils.java +++ /dev/null @@ -1,26 +0,0 @@ -package porori.backend.user.global.config.security.utils; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.transaction.annotation.Transactional; -import porori.backend.user.domain.user.domain.entity.User; -import porori.backend.user.global.config.security.exception.RequiredLoggedInException; -import porori.backend.user.global.config.security.service.CustomUserDetails; - -import java.util.Objects; - -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@Transactional -public class SecurityUtils { - - public static User getLoggedInUser() { - try { - return - ((CustomUserDetails) Objects.requireNonNull(SecurityContextHolder.getContext().getAuthentication()).getPrincipal()).getUser(); - } catch (NullPointerException e) { - throw new RequiredLoggedInException(); - } - } - -} \ No newline at end of file diff --git a/src/main/java/porori/backend/user/global/exception/LocationLimitException.java b/src/main/java/porori/backend/user/global/exception/LocationLimitException.java new file mode 100644 index 0000000..2961261 --- /dev/null +++ b/src/main/java/porori/backend/user/global/exception/LocationLimitException.java @@ -0,0 +1,12 @@ +package porori.backend.user.global.exception; + +import static porori.backend.user.global.exception.constant.UserExceptionList.LOCATION_LIMIT_ERROR; + +public class LocationLimitException extends UserException { + public LocationLimitException() { + super(LOCATION_LIMIT_ERROR.getErrorCode(), + LOCATION_LIMIT_ERROR.getHttpStatus(), + LOCATION_LIMIT_ERROR.getMessage() + ); + } +} diff --git a/src/main/java/porori/backend/user/global/exception/NotFoundLocationException.java b/src/main/java/porori/backend/user/global/exception/NotFoundLocationException.java new file mode 100644 index 0000000..b38bf80 --- /dev/null +++ b/src/main/java/porori/backend/user/global/exception/NotFoundLocationException.java @@ -0,0 +1,13 @@ +package porori.backend.user.global.exception; + +import porori.backend.user.global.exception.constant.UserExceptionList; + +import static porori.backend.user.global.exception.constant.UserExceptionList.NOT_FOUND_LOCATION_ERROR; + +public class NotFoundLocationException extends UserException{ + public NotFoundLocationException(){ + super(NOT_FOUND_LOCATION_ERROR.getErrorCode(), + NOT_FOUND_LOCATION_ERROR.getHttpStatus(), + NOT_FOUND_LOCATION_ERROR.getMessage()); + } +} diff --git a/src/main/java/porori/backend/user/global/exception/constant/UserExceptionList.java b/src/main/java/porori/backend/user/global/exception/constant/UserExceptionList.java index e1e9994..5701160 100644 --- a/src/main/java/porori/backend/user/global/exception/constant/UserExceptionList.java +++ b/src/main/java/porori/backend/user/global/exception/constant/UserExceptionList.java @@ -9,7 +9,9 @@ public enum UserExceptionList { CONNECTION_ERROR("U0001", HttpStatus.UNAUTHORIZED, "AccessToken 값이 잘못되었습니다"), NOT_FOUND_APPLEID_ERROR("U0002", HttpStatus.NOT_FOUND, "해당 appleId로 User를 찾을 수 없습니다."), - NOT_FOUND_USERID_ERROR("U0003", HttpStatus.NOT_FOUND, "해당 id로 User를 찾을 수 없습니다."); + NOT_FOUND_USER_ERROR("U0003", HttpStatus.NOT_FOUND, "해당 id로 User를 찾을 수 없습니다."), + LOCATION_LIMIT_ERROR("U0004",HttpStatus.BAD_REQUEST, "더 이상 위치를 추가할 수 없습니다."), + NOT_FOUND_LOCATION_ERROR("U0005",HttpStatus.NOT_FOUND,"유효하지 않는 장소입니다."); private final String errorCode; private final HttpStatus httpStatus; private final String message; From 7784f60af73a406b25e6ff0d386e40dd58d8b039 Mon Sep 17 00:00:00 2001 From: Minsu Kim Date: Sat, 12 Aug 2023 21:29:17 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20ApiOperation=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/user/domain/user/presentation/UserController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/porori/backend/user/domain/user/presentation/UserController.java b/src/main/java/porori/backend/user/domain/user/presentation/UserController.java index 834a0c7..452776e 100644 --- a/src/main/java/porori/backend/user/domain/user/presentation/UserController.java +++ b/src/main/java/porori/backend/user/domain/user/presentation/UserController.java @@ -93,14 +93,14 @@ public ResponseEntity> reissue(@RequestHeader( return ResponseEntity.ok(ResponseDto.create(HttpStatus.OK.value(), REISSUE_TOKEN_SUCCESS.getMessage(), reissueToken)); } - @ApiOperation(value = "사용자 위치 보기", notes = "사용자 위치를 확인합니다.") + @ApiOperation(value = "사용자 위치 조회", notes = "사용자 위치를 조회합니다.") @GetMapping("/locations") public ResponseEntity> getUserLocation( @AuthenticationPrincipal CustomUser customUser) { return ResponseEntity.ok(ResponseDto.create(HttpStatus.OK.value(), GET_USERLOCATION_SUCCESS.getMessage(), userLocationService.getUserLocation(customUser.getAppleId()))); } - @ApiOperation(value = "사용자 위치 조회", notes = "사용자 위치를 조회합니다.") + @ApiOperation(value = "사용자 위치 추가", notes = "사용자 위치를 추가합니다.") @PostMapping("/locations") public ResponseEntity addUserLocation(@AuthenticationPrincipal CustomUser customUser, @Valid @RequestBody UserLocationRequest userLocationRequest) { From a97cb28152332f2c84e2ad96eff8b34bafe083da Mon Sep 17 00:00:00 2001 From: Minsu Kim Date: Sun, 13 Aug 2023 01:32:26 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=EC=95=A0=ED=94=8C=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=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 --- .../porori/backend/user/domain/user/domain/entity/User.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/porori/backend/user/domain/user/domain/entity/User.java b/src/main/java/porori/backend/user/domain/user/domain/entity/User.java index 8a70a6c..3576672 100644 --- a/src/main/java/porori/backend/user/domain/user/domain/entity/User.java +++ b/src/main/java/porori/backend/user/domain/user/domain/entity/User.java @@ -50,6 +50,7 @@ public class User { public User(String appleId, Role role) { this.appleId = appleId; this.role = role; + this.registrationStatus=RegistrationStatus.UNCOMPLETED; } @Builder @@ -76,6 +77,7 @@ public void signup(AdditionInfoRequest additionInfoRequest) { this.registrationStatus = RegistrationStatus.COMPLETED; } + public void updateRegistrationStatus() { this.registrationStatus = RegistrationStatus.COMPLETED; }