Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

커밋 유실기록 복구 #85

Merged
merged 34 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
86dac3b
feat : MessageController
jyj1289 May 1, 2024
9d04ef8
feat(#75):send message by group service
jyj1289 May 1, 2024
9b737c7
docs:add cors url
jyj1289 May 1, 2024
71538fa
feat(#75):MessageControllerTest
jyj1289 May 3, 2024
92012f5
docs(#75):MessageController asciidocs
jyj1289 May 3, 2024
f738bac
fix(#75) : remove verify()
jyj1289 May 7, 2024
2e785fe
refactor(#75) : 주석 제거
jyj1289 May 7, 2024
8bc31ad
refactor(#75) : 중복 코드 제거
jyj1289 May 7, 2024
64a20e1
refactor(#75) : 자동 정렬
jyj1289 May 9, 2024
30cfb0e
feat(#75) : SendMessageUseCase
jyj1289 May 9, 2024
b67cec0
refact(#75) : MessageUseCase 사용
jyj1289 May 9, 2024
de4965e
refact(#75) : MessageUseCase 사용
jyj1289 May 9, 2024
5ea895a
refactor(#75) : stream 컨벤션 사용
jyj1289 May 15, 2024
5ed2f44
refactor(#75) : sendMessage 메서드 이름 변경 및 엔드포인트 변경
jyj1289 May 16, 2024
411cad3
test(#75) : 엔드포인트 변경 및 BDDMockito 메서드로 변경
jyj1289 May 16, 2024
fddf9a3
test(#75) : status별 단위 테스트 작성
jyj1289 May 16, 2024
d8b3e46
Merge pull request #80 from Bamdoliro/feat/#75
jyj1289 May 28, 2024
e57d2a9
feat(#81) : 불필요한 코드 개선
jyj1289 May 28, 2024
53e18ec
feat(#81) : 메서드 추가
jyj1289 May 30, 2024
626a4ee
feat(#81) : formRepository 메서드 구현
jyj1289 May 30, 2024
1eb26e2
feat(#81) : 전형별 메세지 메서드 추가
jyj1289 May 30, 2024
d6e12fd
refactor(#81) : DTO 이름 변경
jyj1289 May 30, 2024
13a9a70
feat(#81) : execute 메서드 추가 및 개선
jyj1289 May 30, 2024
7126186
docs : message.adoc 변경
jyj1289 May 30, 2024
5beb8ba
Merge branch 'develop' of https://github.com/Bamdoliro/marubase into …
jyj1289 May 30, 2024
68b8f9a
feat(#81) : SendMessageByTypeRequest 추가
jyj1289 May 30, 2024
135cf36
fix(#81) : SendMessageRequest 이름 변경
jyj1289 May 30, 2024
79cec34
refactor(#81) : import 제거
jyj1289 May 30, 2024
2c1470f
fix(#81) : 로직 수정
jyj1289 May 30, 2024
48f997e
fix(#81) : boolean 타입 변경
jyj1289 May 30, 2024
1fe3954
docs(#81) : message.adoc
jyj1289 May 31, 2024
7d8f19e
feat(#81) : messageControllerTest 추가
jyj1289 May 31, 2024
dc71040
fix(#81) : 테스트 코드 삭제
jyj1289 May 31, 2024
ce3304e
feat(#81) : 전형별 메시지 보내기 테스트 코드 작성
jyj1289 May 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ include::form.adoc[]

include::fair.adoc[]

include::message.adoc[]

include::enum.adoc[]
45 changes: 45 additions & 0 deletions src/docs/asciidoc/message.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
== 그룹별 메세지 보내기

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

==== 요청 형식

===== Request Header
include::{snippets}/message-controller-test/조회할_상태의_원서를_가진_학생들에게/request-headers.adoc[]

===== Request Body
include::{snippets}/message-controller-test/조회할_상태의_원서를_가진_학생들에게/request-fields.adoc[]

==== 요청
===== 접수된 원서를 가진 사용자에게 메시지 보내기
include::{snippets}/message-controller-test/조회할_상태의_원서를_가진_학생들에게/http-request.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
@@ -0,0 +1,60 @@
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.SendMessageByStatusRequest;
import com.bamdoliro.maru.presentation.message.dto.request.SendMessageByTypeRequest;
import com.bamdoliro.maru.shared.annotation.UseCase;
import lombok.RequiredArgsConstructor;

import java.util.List;

@RequiredArgsConstructor
@UseCase
public class SendMessageUseCase {

private final FormRepository formRepository;
private final SendMessageService sendMessageService;

public void execute(SendMessageByStatusRequest request) {
List<Form> formList = formRepository.findByStatus(request.getStatus());
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();
}
}
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
@@ -1,6 +1,7 @@
package com.bamdoliro.maru.infrastructure.message;

import com.bamdoliro.maru.infrastructure.message.exception.FailedToSendException;
import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository;
import com.bamdoliro.maru.shared.config.properties.MessageProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -9,6 +10,8 @@
import net.nurigo.sdk.message.service.DefaultMessageService;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
@Service
Expand All @@ -28,6 +31,13 @@ public void execute(String to, String text, String title) {
sendOneMessage(message);
}

public void execute(List<String> phoneNumberList, String text, String title) {
List<Message> messageList = phoneNumberList.stream()
.map(phoneNumber -> createMessage(phoneNumber, text))
.peek(message -> message.setSubject(title)).toList();
sendManyMessages(messageList);
}

private Message createMessage(String to, String text) {
Message message = new Message();
message.setFrom(messageProperties.getFrom());
Expand All @@ -38,9 +48,16 @@ private Message createMessage(String to, String text) {

private void sendOneMessage(Message message) {
try {
messageService.sendOne(
new SingleMessageSendingRequest(message)
);
messageService.sendOne(new SingleMessageSendingRequest(message));
} catch (Exception e) {
log.error(e.getMessage());
throw new FailedToSendException();
}
}

private void sendManyMessages(List<Message> messageList) {
try {
messageService.send(messageList, false, false);
} catch (Exception e) {
log.error(e.getMessage());
throw new FailedToSendException();
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
@@ -0,0 +1,38 @@
package com.bamdoliro.maru.presentation.message;

import com.bamdoliro.maru.application.message.SendMessageUseCase;
import com.bamdoliro.maru.domain.user.domain.User;
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;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@RequestMapping("/message")
@RestController
public class MessageController {

private final SendMessageUseCase sendMessageUseCase;

@ResponseStatus(HttpStatus.NO_CONTENT)
@PostMapping("/status")
public void sendMessageByStatus(
@AuthenticationPrincipal(authority = Authority.ADMIN) User user,
@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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.bamdoliro.maru.presentation.message.dto.request;

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

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class SendMessageByStatusRequest {

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

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

@NotNull(message = "필수값입니다.")
private FormStatus status;
}
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;
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public void addCorsMappings(CorsRegistry registry) {
"http://localhost:3001",
"http://localhost:3002",
"https://maru.bamdoliro.com",
"https://admin.maru.bamdoliro.com"
"https://admin.maru.bamdoliro.com",
"https://maru-user.vercel.app",
"https://maru-admin.vercel.app"
)
.allowedMethods(
HttpMethod.GET.name(),
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/banner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|
"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'

Contributors - @gimhanul, @hsem4717
Contributors - @gimhanul, @hsem4717, @jyj1289, @cabbage16
SpringBoot - ${spring-boot.version}
Java - ${java.version}

Loading
Loading