220919_광고 관리 플랫폼 대행사 센터 제작 22_광고 관리(캠페인/소재) 정렬, 페이징 기능 추가

창고·2022년 9월 20일
0

해당 게시글은 개인 프로젝트인 "광고 관리 플랫폼 대행사 센터 제작"
#65 "광고 관리 (캠페인/소재) 정렬/페이징 기능 구현" 이슈를 다루고 있습니다.

1. 진행 사항

(1) 요약

  • 컨트롤러 리팩토링 : Pageable 타입으로 하위 객체를 생성할 수 있도록 변경
    • 캠페인
    • 소재
  • 페이징 및 정렬 기능 구현
    • 캠페인 : 예산순, ON/OFF 상태 정렬
    • 소재 : 소진액, 입찰가, 노출수, 클릭수, 전환수, 구매액수, ON/OFF 상태 정렬

(2) 세부

  • 이전에는 기능 구현 단계에서 이해도가 낮아 광고주 > 캠페인, 캠페인 > 소재 확인 시 하위 객체를 Page 타입이 아닌 단순 Optional 객체로 반환했었음
  • 이에 대해 Page 타입으로 반환하게 변경하고 Controller, Service, Repository 수정을 진행하였음
  • CampaignController 변경 전
    public String creatives(
            @PathVariable("clientId") String clientId,
            @PathVariable Long campaignId,
            ModelMap map
    ) {
        CampaignWithCreativesResponse campaignWithCreatives = CampaignWithCreativesResponse.from(campaignService.getCampaignWithCreatives(campaignId));
        ClientUserWithCampaignsResponse clientUserWithCampaignsResponse = ClientUserWithCampaignsResponse.from(manageService.getClientUserWithCampaigns(clientId));

        map.addAttribute("clientUser", clientUserWithCampaignsResponse);
        map.addAttribute("campaign", campaignWithCreatives);
        map.addAttribute("creatives", campaignWithCreatives.creativeResponses());
  • CampaignController 변경 후
    public String creatives(
            @PathVariable("clientId") String clientId,
            @PathVariable Long campaignId,
            @PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable,
            ModelMap map
    ) {
        Page<CreativeResponse> creatives = creativeService.searchCreatives(pageable, campaignId).map(CreativeResponse::from);
        CampaignResponse campaign = CampaignResponse.from(campaignService.getCampaign(campaignId));
        ClientUserWithCampaignsResponse clientUserWithCampaignsResponse = ClientUserWithCampaignsResponse.from(manageService.getClientUserWithCampaigns(clientId));
        List<Integer> barNumbers = paginationService.getPaginationBarNumbers(pageable.getPageNumber(), creatives.getTotalPages());

        map.addAttribute("clientUser", clientUserWithCampaignsResponse);
        map.addAttribute("campaign", campaign);
        map.addAttribute("creatives", creatives);
        map.addAttribute("paginationBarNumbers", barNumbers);
        map.addAttribute("totalCount", creativeService.getCreativeCount());
  • CreativeService 변경 전
    @Transactional(readOnly = true)
    public Page<CreativeDto> searchCreatives(Pageable pageable) {
        return creativeRepository.findByDeletedFalse(pageable).map(CreativeDto::from);
    }
  • CreativeService 변경 후
    @Transactional(readOnly = true)
    public Page<CreativeDto> searchCreatives(Pageable pageable, Long campaignId) {
        return creativeRepository.findByDeletedFalseAndCampaign_Id(pageable, campaignId).map(CreativeDto::from);
    }

2. 결과

3. 개선이 필요한 점

  • 기능 구현 도중 광고주 - 캠페인 - 소재가 매칭되지 않는 잘못된 URI로 접근을 하여도 오류가 발생하지 않고 페이지를 확인할 수 있는 버그를 발견하였음
  • CRUD 역시 가능하나, 원본에 대해서만 반영이 되므로 잘못된 상위 객체 (광고주 / 캠페인) 로 접근하더라도 잘못된 상위 객체에는 반영이 되지 않는 점 확인
  • 긴급 이슈로 Controller / Service 영역에서 validation을 강화할 예정
profile
공부했던 내용들을 모아둔 창고입니다.

0개의 댓글