Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Tht server 263 디바이스 토큰 갱신 API 생성 #265

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class UserFacade {
private final UserAgreementService userAgreementService;
private final UserFriendService userFriendService;
private final ChatRoomUserService chatRoomUserService;
private final UserDeviceKeyService userDeviceKeyService;

public MainScreenResponse findAllToDayFallingUserList(final User user,
final MainScreenUserInfoRequest request) {
Expand Down Expand Up @@ -220,4 +221,9 @@ public void updateSingleUserAgreement(final User user, final UserAgreementUpdate
userAgreementService.updateSingleAgreement(user.getUserUuid(), request.agreementName(), request.value());
}

@Transactional
public void updateDeviceKey(final String userUuid, final String deviceKey) {

userDeviceKeyService.update(userUuid, deviceKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class UserJoinFacade {
private final UserProfilePhotoService userProfilePhotoService;
private final UserInterestsService userInterestsService;
private final UserIdealTypeService userIdealTypeService;
private final UserDeviceKeyService userDeviceKeyService;
private final UserSnsService userSnsService;
private final UserAlarmAgreementService userAlarmAgreementService;
private final UserTokenService userTokenService;
Expand All @@ -57,7 +56,6 @@ public TokenDto signUp(final UserSignUpRequest request) {
userProfilePhotoService.createOf(request.makeUserProfilePhotoList(user.getUserUuid()));
userInterestsService.createOf(request.makeUserInterestsList(user.getUserUuid()));
userIdealTypeService.createOf(request.makeUserIdealTypeList(user.getUserUuid()));
userDeviceKeyService.create(user.getUserUuid(), request.deviceKey());

if (request.snsType().isSns()) {
userSnsService.create(user.getUserUuid(), request.snsType(), request.snsUniqueId(),
Expand Down Expand Up @@ -91,7 +89,6 @@ public TokenDto integratedSnsId(final UserSnsSignUpRequest request) {

userSnsService.create(user.getUserUuid(), request.snsType(), request.snsUniqueId(),
request.email());
userDeviceKeyService.create(user.getUserUuid(), request.deviceKey());

return getUserSignUpResponse(user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class UserLoginFacade {
public TokenDto login(final UserLoginRequest request) {

final User user = userService.findByPhoneNumber(request.phoneNumber());
deviceKeyService.create(user.getUserUuid(), request.deviceKey());
deviceKeyService.update(user.getUserUuid(), request.deviceKey());
user.login();

return getGenerateJWT(user);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.tht.thtapis.facade.user.request;

import jakarta.validation.constraints.NotEmpty;

public record UserDeviceKeyRequest(
@NotEmpty String deviceKey
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public record UserSignUpRequest(
Gender gender,
Gender preferGender,
@NotNull(message = "introduction 는 null 이어서는 안됩니다.") String introduction,
@NotBlank(message = "deviceKey 는 비어있을 수 없습니다.") String deviceKey,
@NotNull(message = "agreement 는 null 이어서는 안됩니다.") @Valid UserAgreementRequest agreement,
@NotNull(message = "locationRequest 는 null 이어서는 안됩니다.") @Valid UserLocationRequest locationRequest,
@Size(min = 2, max = 3, message = "사진은 최소 2장, 최대 3장을 등록해야합니다.")
Expand Down Expand Up @@ -67,7 +66,7 @@ public record UserSignUpRequest(

public UserSignUpRequest(final String phoneNumber, final String username, final String email,
final String birthDay, final String gender, final String preferGender,
final String introduction, final String deviceKey,
final String introduction,
final UserAgreementRequest agreement, final UserLocationRequest locationRequest,
final List<String> photoList, final List<Integer> interestList,
final List<Integer> idealTypeList, final String snsType, final String snsUniqueId,
Expand All @@ -81,7 +80,6 @@ public UserSignUpRequest(final String phoneNumber, final String username, final
Gender.toConverter(gender),
Gender.toConverter(preferGender),
introduction,
deviceKey,
agreement,
locationRequest,
photoList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
public record UserSnsSignUpRequest(

@NotBlank(message = "phoneNumber 는 비어있을 수 없습니다.") String phoneNumber,
@NotBlank(message = "deviceKey 는 비어있을 수 없습니다.") String deviceKey,
@NotNull(message = "smsType 을 적어주세요") SNSType snsType,
@NotNull(message = "sns unique id 가 필수값입니다.") String snsUniqueId,
@NotBlank(message = "sns email 은 필수값입니다.") String email
Expand All @@ -21,13 +20,11 @@ public record UserSnsSignUpRequest(
@JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
public UserSnsSignUpRequest(
@JsonProperty("phoneNumber") final String phoneNumber,
@JsonProperty("deviceKey") final String deviceKey,
@JsonProperty("snsType") final String snsType,
@JsonProperty("snsUniqueId") final String snsUniqueId,
@JsonProperty("email") final String email) {

this(phoneNumber.replaceAll(removeHyphenRegex, ""),
deviceKey,
SNSType.toSNSConverter(snsType),
snsUniqueId,
email
Expand Down
75 changes: 41 additions & 34 deletions tht-apis/src/main/java/com/tht/thtapis/ui/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class UserController {

@PostMapping("/user/report")
public ResponseEntity<Object> reportUser(
@AuthenticationPrincipal final User user,
@RequestBody @Valid final UserReportRequest request
@AuthenticationPrincipal final User user,
@RequestBody @Valid final UserReportRequest request
) {

userFacade.report(user.getUserUuid(), request);
Expand All @@ -32,8 +32,8 @@ public ResponseEntity<Object> reportUser(

@PostMapping("/user/block/{block-user-uuid}")
public ResponseEntity<Object> blockUser(
@AuthenticationPrincipal final User user,
@PathVariable(name = "block-user-uuid") final String blockUserUuid
@AuthenticationPrincipal final User user,
@PathVariable(name = "block-user-uuid") final String blockUserUuid
) {

userFacade.block(user.getUserUuid(), blockUserUuid);
Expand All @@ -42,112 +42,112 @@ public ResponseEntity<Object> blockUser(

@GetMapping("/user")
public ResponseEntity<UserDetailResponse> getUserDetail(
@AuthenticationPrincipal final User user) {
@AuthenticationPrincipal final User user) {

return ResponseEntity.ok(userFacade.getUserDetail(user.getUserUuid()));
}

@GetMapping("/user/another/{user-uuid}")
public ResponseEntity<UserDetailResponse> getAnotherUserDetail(
@AuthenticationPrincipal final User user,
@PathVariable(value = "user-uuid") final String userUuid) {
@AuthenticationPrincipal final User user,
@PathVariable(value = "user-uuid") final String userUuid) {

return ResponseEntity.ok(userFacade.getUserDetail(userUuid));
}

@PatchMapping("/user/phone-number/{phone-number}")
public ResponseEntity<Object> updatePhoneNumber(
@PathVariable(name = "phone-number") final String phoneNumber,
@AuthenticationPrincipal final User user) {
@PathVariable(name = "phone-number") final String phoneNumber,
@AuthenticationPrincipal final User user) {

userFacade.updatePhoneNumber(user, phoneNumber);
return ResponseEntity.ok().build();
}

@PatchMapping("/user/email/{email}")
public ResponseEntity<Object> updateEmail(
@PathVariable final String email,
@AuthenticationPrincipal final User user) {
@PathVariable final String email,
@AuthenticationPrincipal final User user) {

userFacade.updateEmail(user, email);
return ResponseEntity.ok().build();
}

@PutMapping("/user/interests")
public ResponseEntity<Object> modifiedInterests(
@AuthenticationPrincipal final User user,
@RequestBody @Valid final ModifiedInterestsRequest request) {
@AuthenticationPrincipal final User user,
@RequestBody @Valid final ModifiedInterestsRequest request) {

userFacade.modifiedInterests(user.getUserUuid(), request);
return ResponseEntity.ok().build();
}

@PutMapping("/user/ideal-type")
public ResponseEntity<Object> modifiedIdealType(
@AuthenticationPrincipal final User user,
@RequestBody @Valid final ModifiedIdealTypeRequest request) {
@AuthenticationPrincipal final User user,
@RequestBody @Valid final ModifiedIdealTypeRequest request) {

userFacade.modifiedIdealType(user.getUserUuid(), request);
return ResponseEntity.ok().build();
}

@PatchMapping("/user/location")
public ResponseEntity<Object> updateMyLocation(
@AuthenticationPrincipal final User user,
@RequestBody @Valid final UserLocationRequest request) {
@AuthenticationPrincipal final User user,
@RequestBody @Valid final UserLocationRequest request) {

userFacade.updateLocation(user.getUserUuid(), request);
return ResponseEntity.ok().build();
}

@PatchMapping("/user/name/{nick-name}")
public ResponseEntity<TokenDto> updateNickName(
@AuthenticationPrincipal final User user,
@PathVariable(name = "nick-name") final String updateNickName) {
@AuthenticationPrincipal final User user,
@PathVariable(name = "nick-name") final String updateNickName) {

return ResponseEntity.ok(userFacade.updateNickName(user, updateNickName));
}

@PatchMapping("/user/introduction")
public ResponseEntity<Object> updateSelfIntroduce(
@AuthenticationPrincipal final User user,
@RequestBody final ModifiedIntroductionRequest request) {
@AuthenticationPrincipal final User user,
@RequestBody final ModifiedIntroductionRequest request) {

userFacade.updateIntroduction(user, request.introduction());
return ResponseEntity.ok().build();
}

@PatchMapping("/user/profile-photo")
public ResponseEntity<Object> updateProfileList(
@AuthenticationPrincipal final User user,
@RequestBody @Valid final UserModifyProfilePhotoRequest request) {
@AuthenticationPrincipal final User user,
@RequestBody @Valid final UserModifyProfilePhotoRequest request) {

userFacade.updateUserProfilePhoto(user.getUserUuid(), request.userProfilePhotoList());
return ResponseEntity.ok().build();
}

@PatchMapping("/user/preferred-gender/{gender}")
public ResponseEntity<Object> updatePreferGender(
@AuthenticationPrincipal final User user,
@PathVariable final Gender gender) {
@AuthenticationPrincipal final User user,
@PathVariable final Gender gender) {

userFacade.updatePreferGender(user, gender);
return ResponseEntity.ok().build();
}

@PatchMapping("/user/alarm-agreement")
public ResponseEntity<Object> updateUserAlarm(
@AuthenticationPrincipal final User user,
@RequestBody @Valid final UserAlarmAgreementModifyRequest request) {
@AuthenticationPrincipal final User user,
@RequestBody @Valid final UserAlarmAgreementModifyRequest request) {

userFacade.updatePersonalAlarmAgree(user.getUserUuid(), request);
return ResponseEntity.ok().build();
}

@DeleteMapping("/user/account-withdrawal")
public ResponseEntity<Object> withDraw(
@AuthenticationPrincipal final User user,
@RequestBody @Valid final UserWithDrawRequest request
@AuthenticationPrincipal final User user,
@RequestBody @Valid final UserWithDrawRequest request
) {

userFacade.withDraw(user, request);
Expand All @@ -158,19 +158,19 @@ public ResponseEntity<Object> withDraw(
public ResponseEntity<UserFriendContactResponse> getMyFriendListCount(@AuthenticationPrincipal final User user) {

return ResponseEntity.ok(
new UserFriendContactResponse(userFacade.getFriendCount(user.getUserUuid()))
new UserFriendContactResponse(userFacade.getFriendCount(user.getUserUuid()))
);
}

@PostMapping("/user/friend-contact-list")
public ResponseEntity<UserFriendContactResponse> updateMyFriendContactList(
@AuthenticationPrincipal final User user,
@RequestBody @Valid final UserFriendContactRequest request
@AuthenticationPrincipal final User user,
@RequestBody @Valid final UserFriendContactRequest request
) {

return ResponseEntity.ok(
new UserFriendContactResponse(
userFacade.updateFriendContactList(user.getUserUuid(), request.contacts()))
new UserFriendContactResponse(
userFacade.updateFriendContactList(user.getUserUuid(), request.contacts()))
);
}

Expand All @@ -180,4 +180,11 @@ public ResponseEntity<Object> patchUserAgreement(@AuthenticationPrincipal final
userFacade.updateSingleUserAgreement(user, request);
return ResponseEntity.ok().build();
}

@PatchMapping("/user/device-key")
public ResponseEntity<Object> saveDeviceKey(@AuthenticationPrincipal final User user, @RequestBody @Valid final UserDeviceKeyRequest request) {
userFacade.updateDeviceKey(user.getUserUuid(), request.deviceKey());
return ResponseEntity.ok().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -760,4 +760,37 @@ void updateFriendList() throws Exception {
)
.andExpect(MockMvcResultMatchers.status().isOk());
}

@Test
@WithCustomMockUser
@DisplayName("유저 디바이스 키 갱싱 api docs")
void docsDeviceKey() throws Exception {

UserDeviceKeyRequest request = new UserDeviceKeyRequest("device-key");
String requestBody = ControllerTestConfig.objectMapper.writeValueAsString(request);

//given
mockMvc.perform(
patch("/user/device-key")
.header("Authorization", "Bearer {ACCESS_TOKEN}")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content(requestBody)
).andDo(
document("유저 디바이스키 갱신 api docs",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
resource(
ResourceSnippetParameters.builder()
.tag("회원가입")
.description("유저 디바이스 키 갱신")
.requestFields(
fieldWithPath("deviceKey").description("유저 디바이스 키")
)
.build()
)
)
)
.andExpect(MockMvcResultMatchers.status().isOk());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ void normalUserJoin() throws Exception {
fieldWithPath("introduction").description("자기소개"),
fieldWithPath("gender").description("성별"),
fieldWithPath("preferGender").description("선호 성별"),
fieldWithPath("deviceKey").description("유저 디바이스 키"),

fieldWithPath("agreement").description("약관 동의 내역"),
fieldWithPath("agreement.serviceUseAgree").description("서비스 약관 동의"),
Expand Down Expand Up @@ -269,7 +268,6 @@ void integratedUserJoin() throws Exception {
.description("유저 SNS 아이디 통합 회원 가입")
.requestFields(
fieldWithPath("phoneNumber").description("전화번호"),
fieldWithPath("deviceKey").description("유저 디바이스 키"),

fieldWithPath("snsType").type(JsonFieldType.STRING)
.description("회원가입 타입 - KAKAO, NAVER, GOOGLE"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class UserJoinFacadeTest {
@Mock
UserIdealTypeService userIdealTypeService;
@Mock
UserDeviceKeyService userDeviceKeyService;
@Mock
UserSnsService userSnsService;
@Mock
TokenProvider tokenProvider;
Expand Down Expand Up @@ -80,8 +78,6 @@ void userJoinFacadeTest() {
verify(userInterestsService).createOf(request.makeUserInterestsList(any()));
//이상형
verify(userIdealTypeService).createOf(request.makeUserIdealTypeList(any()));
//디바이스 키
verify(userDeviceKeyService).create(anyString(), anyString());

verify(userSnsService, times(0)).create(anyString(), any(), anyString(), anyString());

Expand Down
Loading
Loading