Skip to content

Commit

Permalink
Merge pull request #247 from LearnsMate/feature/campaign
Browse files Browse the repository at this point in the history
♻️ 코드 수정: CampaignTemplateController -> listTemplates 수정
  • Loading branch information
YuJeeun authored Nov 25, 2024
2 parents aa38bd4 + d109bef commit b176df4
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package intbyte4.learnsmate.campaign_template.controller;

import intbyte4.learnsmate.campaign_template.domain.dto.CampaignTemplateDTO;
import intbyte4.learnsmate.campaign_template.domain.dto.FindAllCampaignTemplatesDTO;
import intbyte4.learnsmate.campaign_template.domain.vo.request.RequestEditTemplateVO;
import intbyte4.learnsmate.campaign_template.domain.vo.request.RequestRegisterTemplateVO;
import intbyte4.learnsmate.campaign_template.domain.vo.response.ResponseEditTemplateVO;
Expand Down Expand Up @@ -96,10 +97,10 @@ public ResponseEntity<?> deleteTemplate(@PathVariable("campaignTemplateCode") Lo
@Operation(summary = "직원 - 캠페인 템플릿 전체 조회")
@GetMapping("/list")
public ResponseEntity<List<ResponseFindTemplateVO>> listTemplates() {
List<CampaignTemplateDTO> campaignTemplateDTOList = campaignTemplateService.findAllByTemplate();
List<FindAllCampaignTemplatesDTO> campaignTemplateDTOList = campaignTemplateService.findAllByTemplate();
List<ResponseFindTemplateVO> response = new ArrayList<>();
for (CampaignTemplateDTO campaignTemplateDTO : campaignTemplateDTOList) {
ResponseFindTemplateVO vocVO = campaignTemplateMapper.fromDtoToFindResponseVO(campaignTemplateDTO);
for (FindAllCampaignTemplatesDTO findAllCampaignTemplateDTO : campaignTemplateDTOList) {
ResponseFindTemplateVO vocVO = campaignTemplateMapper.fromFindAllDtoToFindResponseVO(findAllCampaignTemplateDTO);
response.add(vocVO);
}
return ResponseEntity.status(HttpStatus.OK).body(response);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package intbyte4.learnsmate.campaign_template.domain.dto;

import lombok.*;

import java.time.LocalDateTime;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@ToString
@Builder
public class FindAllCampaignTemplatesDTO {
private Long campaignTemplateCode;
private String campaignTemplateTitle;
private String campaignTemplateContents;
private Boolean campaignTemplateFlag;
private LocalDateTime createdAt;
private LocalDateTime updatedAt;
private Long adminCode;
private String adminName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ public class ResponseFindTemplateVO {

@JsonProperty("admin_code")
private final Long adminCode;

@JsonProperty("admin_name")
private final String adminName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import intbyte4.learnsmate.admin.domain.entity.Admin;
import intbyte4.learnsmate.campaign_template.domain.CampaignTemplate;
import intbyte4.learnsmate.campaign_template.domain.dto.CampaignTemplateDTO;
import intbyte4.learnsmate.campaign_template.domain.dto.FindAllCampaignTemplatesDTO;
import intbyte4.learnsmate.campaign_template.domain.vo.request.RequestEditTemplateVO;
import intbyte4.learnsmate.campaign_template.domain.vo.request.RequestRegisterTemplateVO;
import intbyte4.learnsmate.campaign_template.domain.vo.response.ResponseEditTemplateVO;
Expand Down Expand Up @@ -83,4 +84,30 @@ public CampaignTemplate toEntity(CampaignTemplateDTO campaignTemplateDTO, Admin
.admin(admin)
.build();
}

public FindAllCampaignTemplatesDTO fromEntityToFindAllDTO(CampaignTemplate entity, String adminName) {
return FindAllCampaignTemplatesDTO.builder()
.campaignTemplateCode(entity.getCampaignTemplateCode())
.campaignTemplateTitle(entity.getCampaignTemplateTitle())
.campaignTemplateContents(entity.getCampaignTemplateContents())
.campaignTemplateFlag(entity.getCampaignTemplateFlag())
.createdAt(entity.getCreatedAt())
.updatedAt(entity.getUpdatedAt())
.adminCode(entity.getAdmin().getAdminCode())
.adminName(adminName)
.build();
}

public ResponseFindTemplateVO fromFindAllDtoToFindResponseVO(FindAllCampaignTemplatesDTO dto) {
return ResponseFindTemplateVO.builder()
.campaignTemplateCode(dto.getCampaignTemplateCode())
.campaignTemplateTitle(dto.getCampaignTemplateTitle())
.campaignTemplateContents(dto.getCampaignTemplateContents())
.campaignTemplateFlag(dto.getCampaignTemplateFlag())
.createdAt(dto.getCreatedAt())
.updatedAt(dto.getUpdatedAt())
.adminCode(dto.getAdminCode())
.adminName(dto.getAdminName())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package intbyte4.learnsmate.campaign_template.service;

import intbyte4.learnsmate.campaign_template.domain.dto.CampaignTemplateDTO;
import intbyte4.learnsmate.campaign_template.domain.dto.FindAllCampaignTemplatesDTO;

import java.util.List;

Expand All @@ -11,7 +12,7 @@ public interface CampaignTemplateService {

void deleteTemplate(CampaignTemplateDTO campaignTemplateDTO);

List<CampaignTemplateDTO> findAllByTemplate();
List<FindAllCampaignTemplatesDTO> findAllByTemplate();

CampaignTemplateDTO findByTemplateCode(Long campaignTemplateCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import intbyte4.learnsmate.admin.service.AdminService;
import intbyte4.learnsmate.campaign_template.domain.CampaignTemplate;
import intbyte4.learnsmate.campaign_template.domain.dto.CampaignTemplateDTO;
import intbyte4.learnsmate.campaign_template.domain.dto.FindAllCampaignTemplatesDTO;
import intbyte4.learnsmate.campaign_template.mapper.CampaignTemplateMapper;
import intbyte4.learnsmate.campaign_template.repository.CampaignTemplateRepository;
import intbyte4.learnsmate.common.exception.CommonException;
Expand Down Expand Up @@ -70,15 +71,18 @@ public void deleteTemplate(CampaignTemplateDTO campaignTemplateDTO) {
}

@Override
public List<CampaignTemplateDTO> findAllByTemplate() {
public List<FindAllCampaignTemplatesDTO> findAllByTemplate() {
log.info("템플릿 전체 조회 중");
List<CampaignTemplate> campaignTemplateList = campaignTemplateRepository.findAll();
List<CampaignTemplateDTO> campaignTemplateVOList = new ArrayList<>();
List<FindAllCampaignTemplatesDTO> findAllCampaignTemplatesDTOList = new ArrayList<>();

for (CampaignTemplate campaignTemplate : campaignTemplateList) {
campaignTemplateVOList.add(campaignTemplateMapper.fromEntityToDTO(campaignTemplate));
CampaignTemplateDTO campaignTemplateDTO = campaignTemplateMapper.fromEntityToDTO(campaignTemplate);
AdminDTO adminDTO = adminService.findByAdminCode(campaignTemplateDTO.getAdminCode());
findAllCampaignTemplatesDTOList.add(campaignTemplateMapper.fromEntityToFindAllDTO(campaignTemplate, adminDTO.getAdminName()));
}
return campaignTemplateVOList;

return findAllCampaignTemplatesDTOList;
}

@Override
Expand Down

0 comments on commit b176df4

Please sign in to comment.