Skip to content

Commit

Permalink
Feat: 새로운 Campaign을 등록하고 결과값을 반환 받는 로직 구현
Browse files Browse the repository at this point in the history
[#46]
  • Loading branch information
MuseopKim committed Jun 27, 2021
1 parent d2b7779 commit d116685
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/careerzip/controller/AdminController.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public ApiResponse<CampaignsResponse> findAllCampaigns() {
return ApiResponse.success(campaigns);
}

@PostMapping("/news-letter/campaigns/reminders")
public void addRemindersCampaign() {
newsLetterService.addRemindersCampaign();
}

@PostMapping("/news-letter/campaigns/main/contacts")
public ApiResponse<List<ContactSummary>> addContactsToMainCampaign() {
List<ContactSummary> contacts = newsLetterService.addContactsToMainCampaign();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@

import com.careerzip.domain.account.entity.Account;
import com.careerzip.domain.account.repository.AccountRepository;
import com.careerzip.domain.questionpaper.entity.QuestionPaper;
import com.careerzip.domain.questionpaper.repository.QuestionPaperRepository;
import com.careerzip.global.admin.dto.response.CampaignDetail;
import com.careerzip.global.admin.dto.response.CampaignsResponse;
import com.careerzip.global.admin.dto.response.ContactSummary;
import com.careerzip.global.error.exception.entity.QuestionPaperNotFoundException;
import com.careerzip.global.newsletter.GetResponseClient;
import com.careerzip.global.newsletter.GetResponseProperties;
import com.careerzip.global.newsletter.JsonTranslator;
import com.careerzip.global.newsletter.dto.request.CampaignRequest;
import com.careerzip.global.newsletter.dto.request.ContactRequest;
import com.careerzip.global.newsletter.dto.request.CreateCampaignRequest;
import com.careerzip.global.newsletter.dto.response.Campaign;
import com.careerzip.global.newsletter.dto.response.NewCampaign;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;

import java.time.LocalDateTime;
import java.util.List;
Expand All @@ -22,6 +28,7 @@
public class NewsLetterService {

private final AccountRepository accountRepository;
private final QuestionPaperRepository questionPaperRepository;
private final GetResponseClient getResponseClient;
private final GetResponseProperties getResponseProperties;
private final JsonTranslator jsonTranslator;
Expand All @@ -43,4 +50,10 @@ public List<ContactSummary> addContactsToMainCampaign() {
requests.forEach(request -> getResponseClient.postRequest("/contacts", request, Void.class));
return ContactSummary.listOf(accounts);
}

public void addRemindersCampaign() {
QuestionPaper questionPaper = questionPaperRepository.findLatest().orElseThrow(QuestionPaperNotFoundException::new);
CreateCampaignRequest request = CreateCampaignRequest.from(questionPaper);
NewCampaign createdCampaign = getResponseClient.postRequest("/campaigns", request, NewCampaign.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers("/admin/login").permitAll()
// 원활한 GetResponse API 연동 테스트를 위해 잠시 권한을 오픈 합니다.
.antMatchers("/admin/news-letter/campaigns").permitAll()
.antMatchers("/admin/news-letter/campaigns/reminders").permitAll()
.antMatchers("/admin/news-letter/campaigns/main/contacts").permitAll()
.antMatchers("/admin/**").hasRole(ADMIN.name())
.anyRequest().authenticated();
Expand Down

0 comments on commit d116685

Please sign in to comment.