File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed
src/main/java/com/taehee/bot/domain/question Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .taehee .bot .domain .question .application ;
2
+
3
+ import com .taehee .bot .domain .member .model .Member ;
4
+ import com .taehee .bot .domain .member .repository .MemberRepository ;
5
+ import com .taehee .bot .domain .question .dto .response .SendQuestionResponse ;
6
+ import com .taehee .bot .domain .question .model .QuestionGenerator ;
7
+ import com .taehee .bot .global .sender .QuestionSender ;
8
+ import lombok .RequiredArgsConstructor ;
9
+ import org .springframework .stereotype .Service ;
10
+
11
+ import javax .transaction .Transactional ;
12
+ import java .util .List ;
13
+
14
+ @ Service
15
+ @ RequiredArgsConstructor
16
+ public class QuestionService {
17
+
18
+ private final QuestionGenerator questionGenerator ;
19
+ private final QuestionSender questionSender ;
20
+ private final MemberRepository memberRepository ;
21
+
22
+ @ Transactional
23
+ public void sendQuestion () {
24
+ List <Member > members = memberRepository .findAll ();
25
+ members .forEach (
26
+ member -> generateAndSend (member .getCategory ().name (), member .getEmail ())
27
+ );
28
+ }
29
+
30
+ private void generateAndSend (String categoryName , String toAddress ){
31
+ SendQuestionResponse generatedQuestions = questionGenerator .generate (categoryName );
32
+ questionSender .send (toAddress , generatedQuestions .combineToSting ());
33
+ }
34
+ }
Original file line number Diff line number Diff line change
1
+ package com .taehee .bot .domain .question .dto .response ;
2
+
3
+ import com .taehee .bot .global .feign .openai .dto .response .OpenAiResponse ;
4
+
5
+ import java .util .List ;
6
+ import java .util .stream .Collectors ;
7
+
8
+ public record SendQuestionResponse (
9
+ List <String > questions
10
+ ) {
11
+
12
+ public static SendQuestionResponse toSendQuestionResponse (OpenAiResponse openAiResponse ) {
13
+ return new SendQuestionResponse (
14
+ openAiResponse .choices ().stream ()
15
+ .map (choice -> choice .message ().content ())
16
+ .collect (Collectors .toList ())
17
+ );
18
+ }
19
+
20
+ public String combineToSting () {
21
+ return questions .stream ()
22
+ .map (String ::valueOf )
23
+ .collect (Collectors .joining ("/n" ));
24
+ }
25
+
26
+ }
You can’t perform that action at this time.
0 commit comments