Skip to content

Commit

Permalink
Merge pull request #136 from TEAM-MODDY/fix/#135
Browse files Browse the repository at this point in the history
#135 [fix] 함수명 리팩토링 && [GET메소드] ENUM return을 value 값으로 변경
  • Loading branch information
hellozo0 authored Jan 15, 2024
2 parents 7148f30 + 4ea6e7a commit ec685f4
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 175 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.moddy.server.controller.auth;



import com.moddy.server.common.dto.ErrorResponse;
import com.moddy.server.common.dto.SuccessNonDataResponse;
import com.moddy.server.common.dto.SuccessResponse;
Expand Down Expand Up @@ -84,8 +86,8 @@ public SuccessResponse<List<RegionResponse>> getRegionList() {
@PostMapping(value = "/signup/designer", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
SuccessResponse<UserCreateResponse> createDesigner(
@Parameter(hidden = true) @UserId Long userId,
@RequestPart MultipartFile profileImg,
@RequestPart DesignerCreateRequest designerInfo
@RequestPart("profileImg") MultipartFile profileImg,
@RequestPart("designerInfo") DesignerCreateRequest designerInfo
) {
return SuccessResponse.success(SuccessCode.DESIGNER_CREATE_SUCCESS, designerService.createDesigner(userId, designerInfo, profileImg));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public SuccessResponse<DesignerMainResponse> getDesignerMainInfo(
@Parameter(name = "page", description = "페이지 ") @RequestParam(value = "page") int page,
@Parameter(name = "size", description = "페이지 ") @RequestParam(value = "size") int size
){
return SuccessResponse.success(SuccessCode.FIND_DESIGNER_MAIN_INFO_SUCCESS, designerService.getDesignerMainView(userId, page, size));
return SuccessResponse.success(SuccessCode.FIND_DESIGNER_MAIN_INFO_SUCCESS, designerService.getDesignerMainInfo(userId, page, size));
}

@Operation(summary = "[JWT] 제안서 작성하기", description = "제안서 작성하기 API입니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public record HairModelApplicationResponse(
int age,
String imgUrl,
String gender,
List<HairStyle> preferHairStyles
List<String> preferHairStyles
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public SuccessResponse<ModelMainResponse> getModelMainInfo(
public SuccessResponse<DetailOfferResponse> getModelDetailOfferInfo(
@Parameter(hidden = true) @UserId Long userId,
@Parameter(name = "offerId", description = "제안서아이디") @PathVariable(value = "offerId") Long offerId){
return SuccessResponse.success(SuccessCode.FIND_MODEL_DETAIL_OFFER_SUCCESS, modelService.getModelDetailOfferInfo(userId, offerId));
return SuccessResponse.success(SuccessCode.FIND_MODEL_DETAIL_OFFER_SUCCESS, modelService.getOfferDetail(userId, offerId));
}

@Operation(summary = "[JWT] 카카오톡 오픈채팅", description = "지원서 캡처 이미지 및 디자이너 정보 조회입니다")
Expand Down Expand Up @@ -102,12 +102,12 @@ public SuccessNonDataResponse acceptOffer(
@ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
@SecurityRequirement(name = "JWT Auth")
@PostMapping(value = "/model/application", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
@PostMapping(value = "/application", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public SuccessNonDataResponse submitModelApplication(
@Parameter(hidden = true) @UserId Long userId,
@ModelAttribute ModelApplicationRequest request
) {
modelService.createModelApplication(userId, request);
modelService.postApplication(userId, request);
return SuccessNonDataResponse.success(SuccessCode.CREATE_MODEL_APPLICATION_SUCCESS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record DesignerInfoResponse(
String instagramUrl,
String naverPlaceUrl,
String introduction,
Gender gender,
String gender,
List<String> dayoffs,
String shopAddress,
String shopDetailAddress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public record OfferResponse(
String imgUrl,
String name,
String shopName,
List<OfferCondition> conditions,
List<String> conditions,
boolean isClicked
) {
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.moddy.server.domain.designer.repository;

import com.moddy.server.domain.designer.Designer;
import feign.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

public interface DesignerJpaRepository extends JpaRepository<Designer, Long> {
@Modifying(clearAutomatically = true)
@Query(value = "insert into Designer (id, hair_shop_address, hair_shop_detail_address, hair_shop_name, instagram_url, naver_place_url, introduction, kakao_open_chat_url) VALUES (:id, :hairShopAddress, :hairShopDetailAddress, :hairShopName, :instagramUrl, :naverPlaceUrl, :introduction, :kakaoOpenChatUrl)", nativeQuery = true)
void designerRegister(@Param("id") Long id, @Param("hairShopAddress") String hairShopAddress, @Param("hairShopDetailAddress") String hairShopDetailAddress, @Param("hairShopName") String hairShopName,@Param("instagramUrl") String instagramUrl,@Param("naverPlaceUrl") String naverPlaceUrl,@Param("introduction") String introduction,@Param("kakaoOpenChatUrl") String kakaoOpenChatUrl);
void designerRegister(@Param("id") Long id, @Param("hairShopAddress") String hairShopAddress, @Param("hairShopDetailAddress") String hairShopDetailAddress, @Param("hairShopName") String hairShopName, @Param("instagramUrl") String instagramUrl, @Param("naverPlaceUrl") String naverPlaceUrl, @Param("introduction") String introduction, @Param("kakaoOpenChatUrl") String kakaoOpenChatUrl);
Optional<Designer> findById(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,42 @@ public class DesignerService {
private final HairServiceOfferJpaRepository hairServiceOfferJpaRepository;


private Page<HairModelApplication> findApplications(int page, int size){
PageRequest pageRequest = PageRequest.of(page-1, size, Sort.by(Sort.Direction.DESC,"id"));
Page<HairModelApplication> applicationPage = hairModelApplicationJpaRepository.findAll(pageRequest);
@Transactional
public DesignerMainResponse getDesignerMainInfo(Long userId, int page, int size){
User user = new User();
Designer designer = designerJpaRepository.findById(userId).orElseThrow(() -> new NotFoundException(ErrorCode.USER_NOT_FOUND_EXCEPTION));

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

private Boolean getIsSendStatus(Long applicationId, Long userId){
Optional<HairServiceOffer> offer = hairServiceOfferJpaRepository.findByHairModelApplicationIdAndUserId(applicationId, userId);
return offer.isPresent();
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();
}).collect(Collectors.toList());

HairModelApplicationResponse applicationResponse = new HairModelApplicationResponse(
application.getId(),
model.getName(),
user.getAge(model.getYear()),
model.getProfileImgUrl(),
model.getGender().getValue(),
top2hairStyles
);
return applicationResponse;
}).collect(Collectors.toList());

return new DesignerMainResponse(
page,
size,
totalElements,
designer.getName(),
applicationResponsesList
);
}

@Transactional
Expand Down Expand Up @@ -117,40 +143,6 @@ public UserCreateResponse createDesigner(Long userId, DesignerCreateRequest requ
return authService.createUserToken(designer.getId().toString());
}

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

Page<HairModelApplication> applicationPage = findApplications(page, size);
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<HairStyle> top2hairStyles= preferHairStyle.stream().map(PreferHairStyle::getHairStyle).collect(Collectors.toList());
HairModelApplicationResponse applicationResponse = new HairModelApplicationResponse(
application.getId(),
model.getName(),
user.getAge(model.getYear()),
model.getProfileImgUrl(),
model.getGender().getValue(),
top2hairStyles
);
return applicationResponse;
}).collect(Collectors.toList());

return new DesignerMainResponse(
page,
size,
totalElements,
designer.getName(),
applicationResponsesList
);
}

@Transactional
public void postOffer(Long userId, Long applicationId, OfferCreateRequest request) {
Expand Down Expand Up @@ -231,6 +223,17 @@ public ApplicationDetailInfoResponse getApplicationDetail(Long userId, Long appl
applicationInfoResponse,
modelInfoResponse
);
}

private Page<HairModelApplication> findApplicationsByPaging(int page, 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){
Optional<HairServiceOffer> offer = hairServiceOfferJpaRepository.findByHairModelApplicationIdAndUserId(applicationId, userId);
return offer.isPresent();
}
}
Loading

0 comments on commit ec685f4

Please sign in to comment.