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

Dev user refactor #13

Merged
merged 2 commits into from
Dec 21, 2023
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
@@ -1,5 +1,6 @@
package com.bit.lotte.flower.user.admin.http.feign;

import bloomingblooms.response.CommonResponse;
import com.bit.lotte.flower.user.common.valueobject.StoreManagerStatus;
import java.util.List;
import org.springframework.cloud.openfeign.FeignClient;
Expand All @@ -8,8 +9,7 @@

@FeignClient(name = "get-store-manager-applications", url = "${service.auth.domain}")
public interface GetUserApplicationsByStatusFeignRequest {

@GetMapping("/store-manager/{status}")
public List<Long> getStoreManagerApplications(@PathVariable StoreManagerStatus status);
public CommonResponse<List<Long>> getStoreManagerApplications(@PathVariable StoreManagerStatus status);
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public class GetUserApplicationByIdRequestImpl implements

@Override
public List<Long> request(StoreManagerStatus storeManagerStatus) {
return feignRequest.getStoreManagerApplications(storeManagerStatus);
return feignRequest.getStoreManagerApplications(storeManagerStatus).getData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
Expand All @@ -14,15 +15,22 @@
@EntityListeners(AuditingEntityListener.class)
public class BaseEntity {

@CreatedDate
@Column(name = "created_at")
private LocalDateTime createdAt;
@CreatedDate
@Column(name = "created_at")
private LocalDateTime createdAt;

@LastModifiedDate
@Column(name = "updated_at")
private LocalDateTime updatedAt;
@LastModifiedDate
@Column(name = "updated_at")
private LocalDateTime updatedAt;

@Column(name = "is_deleted")
private Boolean isDeleted;
}
@Column(name = "is_deleted")
private Boolean isDeleted;

@PrePersist
public void prePersist() {
this.createdAt = LocalDateTime.now();
this.updatedAt = LocalDateTime.now();
this.isDeleted = false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
public class SocialUser extends BaseEntity{

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Long oauthId;
private String email;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,8 @@ public class SocialUserRestController {
private final GetUserLikesCntRequest getUserLikesCntRequest;
private final GetUserCouponCntRequest getUserCouponCntRequest;
private final GetUserInfoServiceImpl getUserInfoServiceImpl;
private final SocialUserLoginManager socialUserLoginManager;
private final SocialUpdateUserService socialUserService;

@PostMapping("/social")
public ResponseEntity<UserLoginDataResponse> userLogin(
@RequestBody UserLoginCommand userLoginCommand) {
UserLoginDataResponse response = socialUserLoginManager.process(userLoginCommand);
return ResponseEntity.ok(response);
}

@PutMapping("/social/phone-number")
public CommonResponse<String> userPhoneNumberUpdate(
Expand All @@ -61,7 +54,6 @@ public CommonResponse<String> updateUserData(@RequestHeader Long userId,
socialUserService.updateUserInfo(userId, command.getNickname(), command.getEmail(),
command.getPhoneNumber());
return CommonResponse.success("업데이트 성공");

}

private UserMypageResponse<UserDataDto> getUserMypageResponse(UserDataDto userDataDto, Long likesCnt,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.bit.lotte.flower.user.social.http.feign;

import bloomingblooms.response.CommonResponse;
import com.bit.lotte.flower.user.common.valueobject.UserId;
import com.bit.lotte.flower.user.social.dto.command.UserLoginCommand;
import com.bit.lotte.flower.user.social.dto.response.UserLoginDataResponse;
import com.bit.lotte.flower.user.social.service.SocialUserLoginManager;
import com.bit.lotte.flower.user.social.service.SoftDeleteStrategyService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
public class UserFeignController {

private final SoftDeleteStrategyService softDeleteStrategyService;
private final SocialUserLoginManager socialUserLoginManager;


@PostMapping("/client/social")
public CommonResponse<UserLoginDataResponse> userLogin(
@RequestBody UserLoginCommand userLoginCommand) {
UserLoginDataResponse response = socialUserLoginManager.process(userLoginCommand);
return CommonResponse.success(response);
}


@PutMapping("/client/users/{userId}")
CommonResponse<Boolean> delete(@PathVariable Long userId) {
softDeleteStrategyService.userWithdrawal(new UserId(userId));
return CommonResponse.success(Boolean.TRUE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ public static SocialUser updateUserInfo(SocialUser socialUser, String nickname,
String phoneNumber) {
return SocialUser.builder().id(socialUser.getId()).oauthId(socialUser.getOauthId())
.profileImage(socialUser.getProfileImage()).phoneNumber(phoneNumber).email(email)
.nickname(email).isDeleted(socialUser.getIsDeleted()).build();
.nickname(nickname).isDeleted(socialUser.getIsDeleted()).build();
}

public static SocialUser changeUserStatus(SocialUser socialUser, Boolean status) {
return SocialUser.builder().id(socialUser.getId()).oauthId(socialUser.getOauthId())
.profileImage(socialUser.getProfileImage()).phoneNumber(socialUser.getPhoneNumber())
.email(socialUser.getEmail())
.nickname(socialUser.getNickname()).isDeleted(status).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public SocialUser findUserElseThrowError(Long id) {
throw new SocialUserDomainException("존재하지 않는 회원입니다.");
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.bit.lotte.flower.user.social.service;

import com.bit.lotte.flower.user.common.valueobject.UserId;
import com.bit.lotte.flower.user.social.entity.SocialUser;
import com.bit.lotte.flower.user.social.mapper.SocialUserMapper;
import com.bit.lotte.flower.user.social.repository.FindSocialUserByLongIdService;
import com.bit.lotte.flower.user.social.repository.SocialUserJpaRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class SoftDeleteStrategyService implements UserWithdrawalService<UserId> {

private final FindSocialUserByLongIdService findSocialUserByLongIdService;
private final SocialUserJpaRepository repository;

@Override
public void userWithdrawal(UserId userId) {
SocialUser socialUser = findSocialUserByLongIdService.findUserElseThrowError(userId.getValue());

SocialUser notSoftDeletedUser = getNotSoftDeletedUser(repository
.findAllByOauthId(socialUser.getOauthId()));

SocialUser updatedToDeleted = SocialUserMapper.changeUserStatus(notSoftDeletedUser,
Boolean.TRUE);
repository.save(updatedToDeleted);
}


private SocialUser getNotSoftDeletedUser(List<SocialUser> allSocialUserByOauthId) {

return allSocialUserByOauthId.stream()
.filter(user -> !user.getIsDeleted())
.findFirst()
.orElse(null);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.bit.lotte.flower.user.social.service;

import com.bit.lotte.flower.user.common.valueobject.UserId;
import org.springframework.stereotype.Service;

@Service
public interface UserWithdrawalService<ID extends UserId> {
public void userWithdrawal(ID userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;

@FeignClient(name = "init-storemanager-status",url = "${service.auth.domain}")
@FeignClient(name = "init-store-manager-status",url = "${service.auth.domain}")
public interface InitStoreManagerStatusPendingFeignRequest {
@PatchMapping("/admin/store-manager")
@PatchMapping("/client/admin/store-manager")
public void publish(@RequestBody UpdateStoreManagerPendingStausDto dto);
}
Loading