Skip to content

Commit

Permalink
[FEAT] 사업체 관련 API 기능 구현 (#29)
Browse files Browse the repository at this point in the history
* [FEAT] 광고 주문자 상세정보 조회

* [FEAT] 사업체 팝업스토어 현황 API 구현

* [FEAT] 사업체 팝업스토어 현황 API 구현
  • Loading branch information
kyukong authored Feb 29, 2024
1 parent 3e5dfd0 commit 10354d8
Show file tree
Hide file tree
Showing 26 changed files with 350 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.oya.kr.community.mapper.dto.response.CommunityBasicMapperResponse;
import com.oya.kr.community.mapper.dto.request.ReadCommunityMapperRequest;
import com.oya.kr.community.mapper.dto.response.StatisticsResponseMapper;
import com.oya.kr.popup.mapper.dto.response.StatisticsCommunityMapperResponse;

/**
* @author 이상민
Expand All @@ -27,6 +28,7 @@ public interface CommunityMapper {
void saveImage(@Param("imageUrl") String imageUrl, @Param("communityId") long communityId);
List<String> findByImage(long communityId);
List<StatisticsResponseMapper> statistics();
StatisticsCommunityMapperResponse statisticsForBusiness(Long userId);
int findSizeByAll();
int findSizeByType(String type);
int findSizeByCollection(Long userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.oya.kr.community.mapper.dto.response.CommunityBasicMapperResponse;
import com.oya.kr.community.mapper.dto.response.StatisticsResponseMapper;
import com.oya.kr.global.exception.ApplicationException;
import com.oya.kr.popup.mapper.dto.response.StatisticsCommunityMapperResponse;
import com.oya.kr.user.domain.User;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -224,4 +225,16 @@ public int findSizeByType(User loginUser, String type) {
public boolean existCollection(long communityId, Long userId) {
return communityMapper.existCollection(communityId, userId);
}

/**
* 커뮤니티 게시글 통계 정보 조회
*
* @parameter Long
* @return StatisticsCommunityMapperResponse
* @author 김유빈
* @since 2024.02.28
*/
public StatisticsCommunityMapperResponse statisticsForBusiness(Long userId) {
return communityMapper.statisticsForBusiness(userId);
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/oya/kr/popup/controller/PopupController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.oya.kr.popup.controller.dto.response.PopupImageResponse;
import com.oya.kr.popup.controller.dto.response.PopupsListResponse;
import com.oya.kr.popup.controller.dto.response.PopupResponse;
import com.oya.kr.popup.controller.dto.response.StatisticsResponse;
import com.oya.kr.popup.service.PopupService;

import lombok.AccessLevel;
Expand Down Expand Up @@ -126,4 +127,18 @@ public ResponseEntity<ApplicationResponse<Void>> collect(Principal principal, @P
popupService.collect(principal.getName(), popupId);
return ResponseEntity.ok(ApplicationResponse.success(null));
}

/**
* 사업체 팝업스토어 현황 조회 기능 구현
*
* @parameter Principal
* @return ResponseEntity<ApplicationResponse<StatisticsResponse>>
* @author 김유빈
* @since 2024.02.28
*/
@GetMapping("/statistics")
public ResponseEntity<ApplicationResponse<StatisticsResponse>> statistics(Principal principal) {
StatisticsResponse response = popupService.statistics(principal.getName());
return ResponseEntity.ok(ApplicationResponse.success(response));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.oya.kr.popup.controller.dto.response;

import com.oya.kr.popup.mapper.dto.response.StatisticsCommunityMapperResponse;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class StatisticsCommunityResponse {

private final int total;
private final int ad;

public static StatisticsCommunityResponse from(StatisticsCommunityMapperResponse communities) {
return new StatisticsCommunityResponse(
communities.getTotal(),
communities.getAd()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.oya.kr.popup.controller.dto.response;

import com.oya.kr.popup.mapper.dto.response.StatisticsPlanMapperResponse;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class StatisticsPlanResponse {

private final int total;
private final int request;
private final int waiting;
private final int approval;
private final int rejection;
private final int withdrawal;

public static StatisticsPlanResponse from(StatisticsPlanMapperResponse plans) {
return new StatisticsPlanResponse(
plans.getTotal(),
plans.getRequest(),
plans.getWaiting(),
plans.getApproval(),
plans.getRejection(),
plans.getWithdrawal()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.oya.kr.popup.controller.dto.response;

import com.oya.kr.popup.mapper.dto.response.StatisticsPopupMapperResponse;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class StatisticsPopupResponse {

private final int total;
private final int ad;

public static StatisticsPopupResponse from(StatisticsPopupMapperResponse popups) {
return new StatisticsPopupResponse(
popups.getTotal(),
popups.getAd()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.oya.kr.popup.controller.dto.response;

import com.oya.kr.popup.mapper.dto.response.StatisticsCommunityMapperResponse;
import com.oya.kr.popup.mapper.dto.response.StatisticsPlanMapperResponse;
import com.oya.kr.popup.mapper.dto.response.StatisticsPopupMapperResponse;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class StatisticsResponse {

private final StatisticsPlanResponse plan;
private final StatisticsPopupResponse popup;
private final StatisticsCommunityResponse community;

public static StatisticsResponse from(StatisticsPlanMapperResponse plans, StatisticsPopupMapperResponse popups, StatisticsCommunityMapperResponse communities) {
return new StatisticsResponse(
StatisticsPlanResponse.from(plans),
StatisticsPopupResponse.from(popups),
StatisticsCommunityResponse.from(communities)
);
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/oya/kr/popup/mapper/PlanMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.oya.kr.popup.mapper.dto.response.AllPlanMapperResponse;
import com.oya.kr.popup.mapper.dto.response.PlanAboutMeMapperResponse;
import com.oya.kr.popup.mapper.dto.response.PlanMapperResponse;
import com.oya.kr.popup.mapper.dto.response.StatisticsPlanMapperResponse;

/**
* @author 김유빈
Expand All @@ -25,6 +26,8 @@ public interface PlanMapper {

List<AllPlanMapperResponse> findAll(AllPlanMapperRequest request);

StatisticsPlanMapperResponse statistics(Long userId);

int countAboutMe(PlanAboutMeMapperRequest request);

int countAboutAll(AllPlanMapperRequest request);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/oya/kr/popup/mapper/PopupMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.oya.kr.popup.mapper.dto.request.PopupSearchMapperRequest;
import com.oya.kr.popup.mapper.dto.response.PopupDetailMapperResponse;
import com.oya.kr.popup.mapper.dto.response.PopupMapperResponse;
import com.oya.kr.popup.mapper.dto.response.StatisticsPopupMapperResponse;

/**
* @author 김유빈
Expand All @@ -31,6 +32,8 @@ public interface PopupMapper {

List<PopupDetailMapperResponse> findAllRecommended(PopupSearchMapperRequest request);

StatisticsPopupMapperResponse statistics(Long userId);

void save(PopupSaveMapperRequest request);

void deleteAll();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.oya.kr.popup.mapper.dto.response;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class StatisticsCommunityMapperResponse {

private final int total;
private final int ad;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.oya.kr.popup.mapper.dto.response;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class StatisticsPlanMapperResponse {

private final int total;
private final int request;
private final int waiting;
private final int approval;
private final int rejection;
private final int withdrawal;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.oya.kr.popup.mapper.dto.response;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class StatisticsPopupMapperResponse {

private final int total;
private final int ad;
}
13 changes: 13 additions & 0 deletions src/main/java/com/oya/kr/popup/repository/PlanRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.oya.kr.popup.mapper.dto.request.PlanUpdateEntranceStatusMapperRequest;
import com.oya.kr.popup.mapper.dto.response.AllPlanMapperResponse;
import com.oya.kr.popup.mapper.dto.response.PlanAboutMeMapperResponse;
import com.oya.kr.popup.mapper.dto.response.StatisticsPlanMapperResponse;
import com.oya.kr.user.domain.User;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -135,4 +136,16 @@ public void updateEntranceStatus(Plan plan) {
PlanUpdateEntranceStatusMapperRequest mapperRequest = PlanUpdateEntranceStatusMapperRequest.from(plan);
planMapper.updateEntranceStatus(mapperRequest);
}

/**
* 사업계획서 통계 정보 조회
*
* @parameter Long
* @return StatisticsPlanMapperResponse
* @author 김유빈
* @since 2024.02.28
*/
public StatisticsPlanMapperResponse statistics(Long userId) {
return planMapper.statistics(userId);
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/oya/kr/popup/repository/PopupRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.oya.kr.popup.mapper.dto.response.PopupCollectionMapperResponse;
import com.oya.kr.popup.mapper.dto.response.PopupDetailMapperResponse;
import com.oya.kr.popup.mapper.dto.response.PopupMapperResponse;
import com.oya.kr.popup.mapper.dto.response.StatisticsPopupMapperResponse;
import com.oya.kr.user.domain.User;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -158,6 +159,18 @@ public void collect(Popup popup, User user) {
}
}

/**
* 팝업스토어 게시글 통계 정보 조회
*
* @parameter Long
* @return StatisticsPopupMapperResponse
* @author 김유빈
* @since 2024.02.28
*/
public StatisticsPopupMapperResponse statistics(Long userId) {
return popupMapper.statistics(userId);
}

private void countView(Long id, Long userId) {
PopupViewCreateOrUpdateMapperRequest request = new PopupViewCreateOrUpdateMapperRequest(userId, id);
popupViewMapper.createOrUpdatePopupView(request);
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/oya/kr/popup/service/PopupService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import com.oya.kr.community.repository.CommunityRepository;
import com.oya.kr.global.dto.request.PaginationRequest;
import com.oya.kr.global.exception.ApplicationException;
import com.oya.kr.global.support.S3Connector;
import com.oya.kr.popup.controller.dto.request.PopupSaveRequest;
import com.oya.kr.popup.controller.dto.response.PopupImageResponse;
import com.oya.kr.popup.controller.dto.response.PopupResponse;
import com.oya.kr.popup.controller.dto.response.PopupsListResponse;
import com.oya.kr.popup.controller.dto.response.StatisticsResponse;
import com.oya.kr.popup.domain.Plan;
import com.oya.kr.popup.domain.Popup;
import com.oya.kr.popup.domain.enums.PopupSort;
import com.oya.kr.popup.mapper.dto.response.PopupDetailMapperResponse;
import com.oya.kr.popup.mapper.dto.response.StatisticsCommunityMapperResponse;
import com.oya.kr.popup.mapper.dto.response.StatisticsPlanMapperResponse;
import com.oya.kr.popup.mapper.dto.response.StatisticsPopupMapperResponse;
import com.oya.kr.popup.repository.PlanRepository;
import com.oya.kr.popup.repository.PopupRepository;
import com.oya.kr.user.domain.User;
Expand All @@ -39,6 +44,7 @@ public class PopupService {
private final UserRepository userRepository;
private final PlanRepository planRepository;
private final PopupRepository popupRepository;
private final CommunityRepository communityRepository;
private final S3Connector s3Connector;

/**
Expand Down Expand Up @@ -136,6 +142,23 @@ public void collect(String email, Long popupId) {
popupRepository.collect(savedPopup, savedUser);
}

/**
* 사업체 팝업스토어 현황 조회 기능 구현
*
* @parameter String
* @author 김유빈
* @since 2024.02.28
*/
public StatisticsResponse statistics(String email) {
User savedUser = userRepository.findByEmail(email);

StatisticsPlanMapperResponse planMapperResponse = planRepository.statistics(savedUser.getId());
StatisticsPopupMapperResponse popupMapperResponse = popupRepository.statistics(savedUser.getId());
StatisticsCommunityMapperResponse communityMapperResponse = communityRepository.statisticsForBusiness(savedUser.getId());

return StatisticsResponse.from(planMapperResponse, popupMapperResponse, communityMapperResponse);
}

private void validatePlanDoesNotHavePopup(Plan plan) {
if (!popupRepository.findAllByPlanId(plan.getId()).isEmpty()) {
throw new ApplicationException(PLAN_HAS_POPUP);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/oya/kr/user/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.oya.kr.user.controller.dto.request.DuplicatedNicknameRequest;
import com.oya.kr.user.controller.dto.request.JoinRequest;
import com.oya.kr.user.controller.dto.request.LoginRequest;
import com.oya.kr.user.controller.dto.response.AdUserDetailResponse;
import com.oya.kr.user.controller.dto.response.BasicUserResponse;
import com.oya.kr.user.controller.dto.response.JwtTokenResponse;
import com.oya.kr.user.service.UserService;
Expand Down Expand Up @@ -151,6 +152,20 @@ public ResponseEntity<ApplicationResponse<List<? extends BasicUserResponse>>> re
return ResponseEntity.ok(ApplicationResponse.success(userService.reads(type)));
}

/**
* 결제 주문자 상세정보 조회
*
* @parameter Principal
* @return ResponseEntity<ApplicationResponse<AdUserDetailResponse>>
* @author 김유빈
* @since 2024.02.28
*/
@GetMapping("/ad/users")
public ResponseEntity<ApplicationResponse<AdUserDetailResponse>> findMeForAb(Principal principal) {
AdUserDetailResponse response = userService.findMeForAb(principal.getName());
return ResponseEntity.ok(ApplicationResponse.success(response));
}

private String getAccessToken() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
return authentication.getCredentials().toString();
Expand Down
Loading

0 comments on commit 10354d8

Please sign in to comment.