Skip to content

Commit

Permalink
Merge pull request #82 from Bamdoliro/feat/#81
Browse files Browse the repository at this point in the history
Feat/#81
  • Loading branch information
jyj1289 authored Jun 1, 2024
2 parents 7126186 + ce3304e commit 9fefb8b
Show file tree
Hide file tree
Showing 11 changed files with 317 additions and 36 deletions.
25 changes: 23 additions & 2 deletions src/docs/asciidoc/message.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
== 그룹별 메세지 보내기

=== 메시지 보내기
=== 상태에 따른 메시지 보내기
메세지를 보낼 원서의 상태를 입력해 메시지를 보낼 수 있습니다.

==== 요청 형식
Expand All @@ -21,4 +21,25 @@ include::{snippets}/message-controller-test/조회할_상태의_원서를_가진
include::{snippets}/message-controller-test/조회할_상태의_원서를_가진_학생들에게/http-response.adoc[]

===== 입력한 상태의 원서가 없거나 상태를 잘못 입력한 경우
include::{snippets}/message-controller-test/해당제출상태인_원서가_없으면_오류가난다/http-response.adoc[]
include::{snippets}/message-controller-test/해당제출상태인_원서가_없으면_오류가난다/http-response.adoc[]

=== 전형에 따른 메시지 보내기
메세지를 보낼 원서의 전형을 입력해 메시지를 보낼 수 있습니다.

=== 요청 형식

==== Request Header
include::{snippets}/message-controller-test/마이스터전형과_마이스터에서_일반전형으로_바뀐_합격자를_제외한_1차_합격자들에게_메시지를_보낸다/request-headers.adoc[]

==== Request Body
include::{snippets}/message-controller-test/마이스터전형과_마이스터에서_일반전형으로_바뀐_합격자를_제외한_1차_합격자들에게_메시지를_보낸다/request-fields.adoc[]

==== 요청
===== 일반전형(마이스터전형 & 마이스터 -> 일반을 제외한 모든 전형) 1차 합격자에게 메시지를 보내는 경우
include::{snippets}/message-controller-test/마이스터전형과_마이스터에서_일반전형으로_바뀐_합격자를_제외한_1차_합격자들에게_메시지를_보낸다/http-request.adoc[]

===== 마이스터 -> 일반 전형으로 바뀐 1차 합격자들에게 메시지를 보내는 경우
include::{snippets}/message-controller-test/마이스터전형에서_일반전형으로_바뀐_1차_합격자들에게_메시지를_보낸다/http-request.adoc[]

===== 마이스터전형 1차 합격자들에게 메시지를 보내는 경우
include::{snippets}/message-controller-test/마이스터_전형_1차_합격자들에게_메시지를_보낸다/http-request.adoc[]https://xxx[]
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.bamdoliro.maru.application.message;

import com.bamdoliro.maru.domain.form.domain.Form;
import com.bamdoliro.maru.domain.form.domain.type.FormType;
import com.bamdoliro.maru.infrastructure.message.SendMessageService;
import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository;
import com.bamdoliro.maru.presentation.message.dto.request.SendMessageRequest;
import com.bamdoliro.maru.presentation.message.dto.request.SendMessageByStatusRequest;
import com.bamdoliro.maru.presentation.message.dto.request.SendMessageByTypeRequest;
import com.bamdoliro.maru.shared.annotation.UseCase;
import lombok.RequiredArgsConstructor;

Expand All @@ -16,11 +18,43 @@ public class SendMessageUseCase {
private final FormRepository formRepository;
private final SendMessageService sendMessageService;

public void execute(SendMessageRequest request) {
public void execute(SendMessageByStatusRequest request) {
List<Form> formList = formRepository.findByStatus(request.getStatus());
List<String> phoneNumberList = formList.stream()
List<String> phoneNumberList = phoneNumberListConvert(formList);

sendMessageService.execute(phoneNumberList, request.getText(), request.getTitle());
}

public void execute(SendMessageByTypeRequest request) {
List<Form> formList = formListFilter(request.getFormType(), request.getIsChangeToRegular());
List<String> phoneNumberList = phoneNumberListConvert(formList);

sendMessageService.execute(phoneNumberList, request.getText(), request.getTitle());
}

private List<Form> formListFilter(FormType formType, Boolean isChangeToRegular) {
List<Form> formList;
if (formType.isMeister()) {
formList = formRepository.findMeisterTalentFirstRoundForm();
} else {
formList = formRepository.findNotExistsMeisterTalentFirstRoundForm();
if (isChangeToRegular) {
formList = formList.stream()
.filter(Form::getChangedToRegular)
.toList();
} else {
formList = formList.stream()
.filter(form -> !form.getChangedToRegular())
.toList();
}
}

return formList;
}

private List<String> phoneNumberListConvert(List<Form> formList) {
return formList.stream()
.map(form -> form.getUser().getPhoneNumber())
.toList();
sendMessageService.execute(phoneNumberList, request.getText(), request.getTitle());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public boolean isFailedNow() {

public void changeToRegular(CalculateFormScoreService calculateFormScoreService) {
this.changedToRegular = true;
this.type = FormType.REGULAR;

Double subjectGradeScore = calculateFormScoreService.calculateSubjectGradeScore(this);
this.score.updateSubjectScore(subjectGradeScore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class SendMessageService {

private final MessageProperties messageProperties;
private final DefaultMessageService messageService;
private final FormRepository formRepository;

public void execute(String to, String text) {
Message message = createMessage(to, text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public interface FormRepositoryCustom {
List<Form> findReceivedSpecialForm();
List<Form> findReceivedRegularOrSupernumeraryForm();
List<Form> findFirstRoundForm();
List<Form> findMeisterTalentFirstRoundForm();
List<Form> findNotExistsMeisterTalentFirstRoundForm();
List<Form> findSecondRoundForm();
List<Form> findByFormIdList(List<Long> idList);
List<FormUrlVo> findFormUrlByFormIdList(List<Long> idList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ public List<Form> findFirstRoundForm() {
.fetch();
}

@Override
public List<Form> findMeisterTalentFirstRoundForm() {
return queryFactory
.selectFrom(form)
.where(form.status.eq(FormStatus.FIRST_PASSED)
.and(form.type.eq(FormType.MEISTER_TALENT))
)
.fetch();
}

@Override
public List<Form> findNotExistsMeisterTalentFirstRoundForm() {
return queryFactory
.selectFrom(form)
.where(form.status.eq(FormStatus.FIRST_PASSED)
.and(form.type.ne(FormType.MEISTER_TALENT))
)
.fetch();
}

@Override
public List<Form> findSecondRoundForm() {
return queryFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.bamdoliro.maru.application.message.SendMessageUseCase;
import com.bamdoliro.maru.domain.user.domain.User;
import com.bamdoliro.maru.infrastructure.message.SendMessageService;
import com.bamdoliro.maru.presentation.message.dto.request.SendMessageRequest;
import com.bamdoliro.maru.presentation.message.dto.request.SendMessageByStatusRequest;
import com.bamdoliro.maru.presentation.message.dto.request.SendMessageByTypeRequest;
import com.bamdoliro.maru.shared.auth.AuthenticationPrincipal;
import com.bamdoliro.maru.shared.auth.Authority;
import jakarta.validation.Valid;
Expand All @@ -22,7 +22,16 @@ public class MessageController {
@PostMapping("/status")
public void sendMessageByStatus(
@AuthenticationPrincipal(authority = Authority.ADMIN) User user,
@RequestBody @Valid SendMessageRequest request
@RequestBody @Valid SendMessageByStatusRequest request
) {
sendMessageUseCase.execute(request);
}

@ResponseStatus(HttpStatus.NO_CONTENT)
@PostMapping("/type")
public void sendMessageByType(
@AuthenticationPrincipal(authority = Authority.ADMIN) User user,
@RequestBody @Valid SendMessageByTypeRequest request
) {
sendMessageUseCase.execute(request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class SendMessageRequest {
public class SendMessageByStatusRequest {

@NotBlank(message = "필수값입니다.")
private String title;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.bamdoliro.maru.presentation.message.dto.request;

import com.bamdoliro.maru.domain.form.domain.type.FormType;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class SendMessageByTypeRequest {

@NotBlank(message = "필수값입니다.")
private String title;

@NotBlank(message = "필수값입니다.")
private String text;

@NotNull(message = "필수값입니다.")
private FormType formType;

@NotNull(message = "필수값입니다.")
private Boolean isChangeToRegular;
}

Loading

0 comments on commit 9fefb8b

Please sign in to comment.