Skip to content

Commit

Permalink
#117 [refactor] 파라미터 final 붙이기, primitive type으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
hellozo0 committed Jan 15, 2024
1 parent 16b71a8 commit 3d07e29
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 46 deletions.
3 changes: 1 addition & 2 deletions src/main/java/com/moddy/server/service/auth/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
@Service
@RequiredArgsConstructor
public class AuthService {

private final SmsUtil smsUtil;
private final JwtService jwtService;
private final KakaoSocialService kakaoSocialService;
Expand Down Expand Up @@ -60,7 +61,6 @@ public LoginResponseDto login(final String baseUrl, final String kakaoCode) {
}

public List<RegionResponse> getRegionList() {

List<RegionResponse> regionResponseList = regionJpaRepository.findAll().stream().map(region -> {
RegionResponse regionResponse = new RegionResponse(
region.getId(),
Expand All @@ -73,7 +73,6 @@ public List<RegionResponse> getRegionList() {
}

public UserCreateResponse createUserToken(String useId) {

TokenPair tokenPair = jwtService.generateTokenPair(useId);
UserCreateResponse userCreateResponse = new UserCreateResponse(tokenPair.accessToken(), tokenPair.refreshToken());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
import com.moddy.server.config.jwt.JwtService;
import com.moddy.server.controller.designer.dto.request.DesignerCreateRequest;
import com.moddy.server.controller.designer.dto.request.OfferCreateRequest;
import com.moddy.server.controller.designer.dto.response.*;
import com.moddy.server.controller.designer.dto.response.ApplicationDetailInfoResponse;
import com.moddy.server.controller.designer.dto.response.ApplicationInfoResponse;
import com.moddy.server.controller.designer.dto.response.DesignerMainResponse;
import com.moddy.server.controller.designer.dto.response.HairModelApplicationResponse;
import com.moddy.server.controller.designer.dto.response.HairRecordResponse;
import com.moddy.server.controller.designer.dto.response.ModelInfoResponse;
import com.moddy.server.controller.designer.dto.response.UserCreateResponse;
import com.moddy.server.domain.day_off.DayOff;
import com.moddy.server.domain.day_off.repository.DayOffJpaRepository;
import com.moddy.server.domain.designer.Designer;
Expand All @@ -20,7 +26,6 @@
import com.moddy.server.domain.hair_service_record.repository.HairServcieRecordJpaRepository;
import com.moddy.server.domain.model.Model;
import com.moddy.server.domain.model.repository.ModelJpaRepository;
import com.moddy.server.domain.prefer_hair_style.HairStyle;
import com.moddy.server.domain.prefer_hair_style.PreferHairStyle;
import com.moddy.server.domain.prefer_hair_style.repository.PreferHairStyleJpaRepository;
import com.moddy.server.domain.prefer_offer_condition.PreferOfferCondition;
Expand Down Expand Up @@ -74,21 +79,19 @@ public class DesignerService {


@Transactional
public DesignerMainResponse getDesignerMainInfo(Long userId, int page, int size){
public DesignerMainResponse getDesignerMainInfo(final long userId, final int page, final int size){
User user = new User();
Designer designer = designerJpaRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.USER_NOT_FOUND_EXCEPTION));

Page<HairModelApplication> applicationPage = findApplicationsByPaging(page, size);
long totalElements = applicationPage.getTotalElements();
final long totalElements = applicationPage.getTotalElements();

List<HairModelApplicationResponse> applicationResponsesList = applicationPage.stream().map(application -> {

Model model = modelJpaRepository.findById(application.getUser().getId()).orElseThrow(() -> new NotFoundException(ErrorCode.MODEL_NOT_FOUND_EXCEPTION));

List<PreferHairStyle> preferHairStyle = preferHairStyleJpaRepository.findTop2ByHairModelApplicationId(application.getId());

List<String> top2hairStyles= preferHairStyle.stream().map( haireStyle -> {
return haireStyle.getHairStyle().getValue();
List<String> top2hairStyles= preferHairStyle.stream().map( hairStyle -> {
return hairStyle.getHairStyle().getValue();
}).collect(Collectors.toList());

HairModelApplicationResponse applicationResponse = new HairModelApplicationResponse(
Expand All @@ -112,12 +115,10 @@ public DesignerMainResponse getDesignerMainInfo(Long userId, int page, int size)
}

@Transactional
public UserCreateResponse createDesigner(Long userId, DesignerCreateRequest request, MultipartFile profileImg) {

public UserCreateResponse createDesigner(final long userId, DesignerCreateRequest request, MultipartFile profileImg) {
String profileImgUrl = s3Service.uploadProfileImage(profileImg, Role.HAIR_DESIGNER);

User user = userRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.USER_NOT_FOUND_EXCEPTION));

user.update(request.name(),request.gender(), request.phoneNumber(), request.isMarketingAgree(), profileImgUrl, Role.HAIR_DESIGNER);

HairShop hairShop = HairShop.builder()
Expand All @@ -129,6 +130,7 @@ public UserCreateResponse createDesigner(Long userId, DesignerCreateRequest requ
.instagramUrl(request.portfolio().instagramUrl())
.naverPlaceUrl(request.portfolio().naverPlaceUrl())
.build();

designerJpaRepository.designerRegister(user.getId(), hairShop.getAddress(), hairShop.getDetailAddress(), hairShop.getName(), portfolio.getInstagramUrl(), portfolio.getNaverPlaceUrl(), request.introduction(), request.kakaoOpenChatUrl());
Designer designer = designerJpaRepository.findById(user.getId()).orElseThrow(() -> new NotFoundException(ErrorCode.DESIGNER_NOT_FOUND_EXCEPTION));
request.dayOffs().stream()
Expand All @@ -145,7 +147,7 @@ public UserCreateResponse createDesigner(Long userId, DesignerCreateRequest requ


@Transactional
public void postOffer(Long userId, Long applicationId, OfferCreateRequest request) {
public void postOffer(final long userId, final long applicationId, OfferCreateRequest request) {
Designer designer = designerJpaRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.DESIGNER_NOT_FOUND_EXCEPTION));
HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));
HairServiceOffer offer = HairServiceOffer.builder()
Expand All @@ -165,20 +167,17 @@ public void postOffer(Long userId, Long applicationId, OfferCreateRequest reques
.hairServiceOffer(offer)
.build();
preferOfferConditionJpaRepository.save(preferOfferCondition);

});
}

@Transactional
public ApplicationDetailInfoResponse getApplicationDetail(Long userId, Long applicationId){
public ApplicationDetailInfoResponse getApplicationDetail(final long userId, final long applicationId){
User user = new User();

HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(applicationId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));

Model model = modelJpaRepository.findById(hairModelApplication.getUser().getId()).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));

List<PreferHairStyle> preferHairStyles = preferHairStyleJpaRepository.findAllByHairModelApplicationId(applicationId);

List<String> preferhairStyleList = preferHairStyles.stream().map(hairStyle -> {
return hairStyle.getHairStyle().getValue();
}).collect(Collectors.toList());
Expand All @@ -187,7 +186,6 @@ public ApplicationDetailInfoResponse getApplicationDetail(Long userId, Long appl
hairServiceRecords.sort(Comparator.comparingInt(e -> e.getServiceRecordTerm().ordinal()));

List <PreferRegion> preferRegions = preferRegionJpaRepository.findAllByUserId(model.getId());

List<String> regionList = preferRegions.stream().map(preferregion ->{
return preferregion.getRegion().getName();
}).collect(Collectors.toList());
Expand Down Expand Up @@ -225,14 +223,14 @@ public ApplicationDetailInfoResponse getApplicationDetail(Long userId, Long appl
);
}

private Page<HairModelApplication> findApplicationsByPaging(int page, int size){
private Page<HairModelApplication> findApplicationsByPaging(final int page, final int size){
PageRequest pageRequest = PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC,"id"));
Page<HairModelApplication> applicationPage = hairModelApplicationJpaRepository.findAll(pageRequest);

return applicationPage;
}

private Boolean getIsSendStatus(Long applicationId, Long userId){
private Boolean getIsSendStatus(final long applicationId, final long userId){
Optional<HairServiceOffer> offer = hairServiceOfferJpaRepository.findByHairModelApplicationIdAndUserId(applicationId, userId);
return offer.isPresent();
}
Expand Down
46 changes: 21 additions & 25 deletions src/main/java/com/moddy/server/service/model/ModelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
import com.moddy.server.controller.model.dto.request.ModelApplicationRequest;
import com.moddy.server.controller.model.dto.request.ModelCreateRequest;
import com.moddy.server.controller.designer.dto.response.UserCreateResponse;
import com.moddy.server.controller.model.dto.response.*;
import com.moddy.server.controller.model.dto.response.DesignerInfoOpenChatResponse;
import com.moddy.server.controller.model.dto.response.DesignerInfoResponse;
import com.moddy.server.controller.model.dto.response.DetailOfferResponse;
import com.moddy.server.controller.model.dto.response.ModelMainResponse;
import com.moddy.server.controller.model.dto.response.OfferResponse;
import com.moddy.server.controller.model.dto.response.OpenChatResponse;
import com.moddy.server.controller.model.dto.response.StyleDetailResponse;
import com.moddy.server.domain.day_off.DayOff;
import com.moddy.server.domain.day_off.repository.DayOffJpaRepository;
import com.moddy.server.domain.designer.Designer;
Expand Down Expand Up @@ -36,7 +42,6 @@
import com.moddy.server.domain.user.Role;
import com.moddy.server.domain.user.User;
import com.moddy.server.domain.user.repository.UserRepository;
import com.moddy.server.external.kakao.service.KakaoSocialService;
import com.moddy.server.external.s3.S3Service;
import com.moddy.server.service.auth.AuthService;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -70,16 +75,14 @@ public class ModelService {
private final AuthService authService;
private final S3Service s3Service;


public ModelMainResponse getModelMainInfo(Long userId, int page, int size){

public ModelMainResponse getModelMainInfo(final long userId, final int page, final int size){
User user = modelJpaRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_MODEL_INFO));

Page<HairServiceOffer> offerPage = findOffersByPaging(userId, page, size);
long totalElements = offerPage.getTotalElements();
final long totalElements = offerPage.getTotalElements();

boolean applyStatus = hairModelApplicationJpaRepository.existsByUserId(userId);
boolean offerStatus = hairServiceOfferJpaRepository.existsByUserId(userId);
final boolean applyStatus = hairModelApplicationJpaRepository.existsByUserId(userId);
final boolean offerStatus = hairServiceOfferJpaRepository.existsByUserId(userId);
ModelApplyStatus modelApplyStatus = calModelStatus(applyStatus, offerStatus);

if(modelApplyStatus != ModelApplyStatus.APPLY_AND_OFFER){
Expand Down Expand Up @@ -122,7 +125,7 @@ public ModelMainResponse getModelMainInfo(Long userId, int page, int size){
}

@Transactional
public UserCreateResponse createModel(long userId, ModelCreateRequest request) {
public UserCreateResponse createModel(final long userId, ModelCreateRequest request) {

User user = userRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.USER_NOT_FOUND_EXCEPTION));
user.update(request.name(),request.gender(), request.phoneNumber(), request.isMarketingAgree(), s3Service.getDefaultProfileImageUrl(), Role.MODEL);
Expand All @@ -140,7 +143,7 @@ public UserCreateResponse createModel(long userId, ModelCreateRequest request) {
}

@Transactional
public void postApplication(Long userId, ModelApplicationRequest request){
public void postApplication(final long userId, ModelApplicationRequest request) {

Model model = modelJpaRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_MODEL_INFO));
String modelImgUrl = s3Service.uploadProfileImage(request.modelImgUrl(), model.getRole());
Expand Down Expand Up @@ -177,8 +180,7 @@ public void postApplication(Long userId, ModelApplicationRequest request){
}

@Transactional
public DetailOfferResponse getOfferDetail(Long userId, Long offerId){

public DetailOfferResponse getOfferDetail(final long userId, final long offerId) {
HairServiceOffer hairServiceOffer = hairServiceOfferJpaRepository.findById(offerId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_OFFER_EXCEPTION));

DesignerInfoResponse designerInfoResponseList = getDesignerInfoResponse(hairServiceOffer, userId, offerId);
Expand All @@ -189,14 +191,13 @@ public DetailOfferResponse getOfferDetail(Long userId, Long offerId){
}

@Transactional
public void updateOfferAgreeStatus(Long offerId){
public void updateOfferAgreeStatus(final long offerId) {
HairServiceOffer hairServiceOffer = hairServiceOfferJpaRepository.findById(offerId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_OFFER_EXCEPTION));

hairServiceOffer.setIsModelAgree(true);
}

public OpenChatResponse getOpenChatInfo(Long userId, Long offerId) {

public OpenChatResponse getOpenChatInfo(final long userId, final long offerId) {
HairServiceOffer hairServiceOffer = hairServiceOfferJpaRepository.findById(offerId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUNT_OFFER_EXCEPTION));
HairModelApplication application = hairModelApplicationJpaRepository.findById(hairServiceOffer.getId()).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));
Designer designer = designerJpaRepository.findById(hairServiceOffer.getDesigner().getId()).orElseThrow(() -> new NotFoundException(ErrorCode.DESIGNER_NOT_FOUND_EXCEPTION));
Expand All @@ -217,8 +218,7 @@ public OpenChatResponse getOpenChatInfo(Long userId, Long offerId) {
return openChatResponse;
}

private DesignerInfoResponse getDesignerInfoResponse(HairServiceOffer hairServiceOffer, Long userId, Long offerId){

private DesignerInfoResponse getDesignerInfoResponse(HairServiceOffer hairServiceOffer, final long userId, final long offerId) {
Designer designer = designerJpaRepository.findById(hairServiceOffer.getDesigner().getId()).orElseThrow(() -> new NotFoundException(ErrorCode.DESIGNER_NOT_FOUND_EXCEPTION));

List<DayOff> dayOffList = dayOffJpaRepository.findAllByDesignerId(designer.getId());
Expand All @@ -243,8 +243,7 @@ private DesignerInfoResponse getDesignerInfoResponse(HairServiceOffer hairServic

}

private StyleDetailResponse getStyleDetailResponse(HairServiceOffer hairServiceOffer, Long userId, Long offerId) {

private StyleDetailResponse getStyleDetailResponse(HairServiceOffer hairServiceOffer, final long userId, final long offerId) {
HairModelApplication hairModelApplication = hairModelApplicationJpaRepository.findById(hairServiceOffer.getHairModelApplication().getId()).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_APPLICATION_EXCEPTION));

List<PreferHairStyle> preferHairStyles = preferHairStyleJpaRepository.findAllByHairModelApplicationId(hairServiceOffer.getHairModelApplication().getId());
Expand All @@ -270,27 +269,24 @@ private StyleDetailResponse getStyleDetailResponse(HairServiceOffer hairServiceO
return styleDetailResponse;
}

private void handleOfferClickStatus(HairServiceOffer hairServiceOffer){

private void handleOfferClickStatus(HairServiceOffer hairServiceOffer) {
if(!hairServiceOffer.getIsClicked()){
hairServiceOffer.updateClickStatus();
}
}

private Page<HairServiceOffer> findOffersByPaging(Long userId, int page, int size){
private Page<HairServiceOffer> findOffersByPaging(final long userId, final int page, final int size) {
PageRequest pageRequest = PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC,"id"));
Page<HairServiceOffer> offerPage = hairServiceOfferJpaRepository.findByUserId(userId, pageRequest);

return offerPage;
}

private ModelApplyStatus calModelStatus(boolean apply, boolean offer){

private ModelApplyStatus calModelStatus(final boolean apply, final boolean offer) {
if(!apply && !offer) return ModelApplyStatus.NOTHING;
else if (apply && !offer) return ModelApplyStatus.APPLY;
else if (apply && offer) return ModelApplyStatus.APPLY_AND_OFFER;
else throw new NotFoundException(ErrorCode.NOT_FOUND_MODEL_STATUS);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
@Service
@RequiredArgsConstructor
public class UserService {

private final UserRepository userRepository;
private final HairModelApplicationJpaRepository hairModelApplicationJpaRepository;
private final HairServiceOfferJpaRepository hairServiceOfferJpaRepository;
Expand Down

0 comments on commit 3d07e29

Please sign in to comment.