Skip to content

Commit 6e4ce56

Browse files
authored
Merge pull request #33 from studio-recoding/feat-main-api
[🔧fix] 카테고리 넘버 수정 및 Github workflow 수정
2 parents 1070eb3 + 852d894 commit 6e4ce56

26 files changed

+525
-65
lines changed

.github/workflows/dev-deploy.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ jobs:
2121
- name: Grant execute permission for gradlew
2222
run: chmod +x gradlew
2323

24+
## Copy properties files
25+
- name: Make application.yml
26+
run: |
27+
touch ./src/main/resources/application.yml
28+
echo "PROFILE_DEV" > ./src/main/resources/application.yml
29+
# Make env file
30+
env:
31+
PROPERTIES_PROD: ${{ secrets.PROFILE_DEV }}
32+
2433
## Copy properties files
2534
- name: Make application-dev.yml
2635
run: |

.github/workflows/prod-deploy.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ jobs:
2222
- name: Grant execute permission for gradlew
2323
run: chmod +x gradlew
2424

25+
## Copy properties files
26+
- name: Make application.yml
27+
run: |
28+
touch ./src/main/resources/application.yml
29+
echo "PROFILE_PROD" > ./src/main/resources/application.yml
30+
# Make env file
31+
env:
32+
PROPERTIES_PROD: ${{ secrets.PROFILE_PROD }}
33+
2534
## Copy properties files
2635
- name: Make application-prod.yml
2736
run: |

src/main/java/Ness/Backend/domain/auth/security/SecurityConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
2222

2323
import java.time.Duration;
24+
import java.util.Arrays;
2425

2526
@Configuration
2627
@EnableWebSecurity
@@ -58,6 +59,9 @@ public CorsConfigurationSource corsConfigurationSource() {
5859
//configuration.addAllowedOrigin("*"); // 모든 오리진 허용-주의! 나중에 FE와 BE에 대해서만 열어주기
5960
configuration.addAllowedOrigin("http://localhost:3000");
6061
configuration.addAllowedOrigin("http://localhost:8080");
62+
//configuration.addAllowedOriginPattern("https://*.nessplanning.com");
63+
//configuration.addAllowedOriginPattern("https://*.nessplanning.com:3000");
64+
//configuration.addAllowedOriginPattern("https://api.nessplanning.com:8080");
6165
configuration.addAllowedMethod("*"); //모든 Method 허용(POST, GET, ...)
6266
configuration.addAllowedHeader("*"); //모든 Header 허용
6367
configuration.setMaxAge(Duration.ofSeconds(3600)); //브라우저가 응답을 캐싱해도 되는 시간(1시간)

src/main/java/Ness/Backend/domain/chat/ChatService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ public PostFastApiAiChatDto postNewAiChat(Long id, String text){
8787
.build();
8888

8989
//Fast API에 전송하기
90-
PostFastApiAiChatDto AiDto = fastApiChatApi.creatFastApiChat(userDto);
90+
PostFastApiAiChatDto aiDto = fastApiChatApi.creatFastApiChat(userDto);
9191

92-
return AiDto;
92+
return aiDto;
9393
}
9494
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
11
package Ness.Backend.domain.report;
22

3+
import Ness.Backend.domain.chat.entity.Chat;
34
import Ness.Backend.domain.report.entity.ReportMemory;
5+
import Ness.Backend.domain.report.entity.ReportRecommend;
46
import org.springframework.data.jpa.repository.JpaRepository;
7+
import org.springframework.data.jpa.repository.Query;
8+
import org.springframework.data.repository.query.Param;
59

610
import java.time.ZonedDateTime;
711
import java.util.List;
812

913
public interface ReportMemoryRepository extends JpaRepository<ReportMemory, Long>{
14+
// 특정 맴버의 오늘 하루 생성된 데이터만 반환
15+
@Query( value = "SELECT * FROM report_memory " +
16+
"WHERE member_id = :memberId " +
17+
"AND DATE(created_date) = CURDATE() " +
18+
"ORDER BY created_date ASC",
19+
nativeQuery = true)
20+
ReportMemory findTodayReportMemoryByMember_Id(
21+
@Param("memberId") Long memberId);
22+
23+
@Query( value = "SELECT * FROM report_memory " +
24+
"WHERE member_id = :memberId " +
25+
"AND created_date >= DATE_SUB(NOW(), INTERVAL 2 WEEK) " +
26+
"ORDER BY created_date ASC",
27+
nativeQuery = true)
28+
List<ReportMemory> findTwoWeekUserMemoryByMember_Id(
29+
@Param("memberId") Long memberId);
30+
1031
List<ReportMemory> findReportMemoriesByMember_idAndCreatedDateBetweenOrderByCreatedDateAsc(Long id, ZonedDateTime startOfWeek, ZonedDateTime now);
1132
}

src/main/java/Ness/Backend/domain/report/ReportRecommendRepository.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
package Ness.Backend.domain.report;
22

3-
import Ness.Backend.domain.chat.entity.Chat;
43
import Ness.Backend.domain.report.entity.ReportRecommend;
54
import org.springframework.data.jpa.repository.JpaRepository;
65
import org.springframework.data.jpa.repository.Query;
76
import org.springframework.data.repository.query.Param;
87

9-
import java.time.ZonedDateTime;
10-
import java.util.List;
11-
128
public interface ReportRecommendRepository extends JpaRepository<ReportRecommend, Long> {
139
// 특정 맴버의 오늘 하루 생성된 데이터만 반환
1410
@Query( value = "SELECT * FROM report_recommend " +
Lines changed: 122 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
package Ness.Backend.domain.report;
22

3-
import Ness.Backend.domain.chat.dto.request.PostFastApiUserChatDto;
4-
import Ness.Backend.domain.chat.dto.response.PostFastApiAiChatDto;
53
import Ness.Backend.domain.member.MemberRepository;
64
import Ness.Backend.domain.member.entity.Member;
5+
import Ness.Backend.domain.report.dto.request.PostFastApiUserMemoryDto;
76
import Ness.Backend.domain.report.dto.request.PostFastApiUserRecommendDto;
7+
import Ness.Backend.domain.report.dto.request.PostFastApiUserTagDto;
88
import Ness.Backend.domain.report.dto.response.*;
99
import Ness.Backend.domain.report.entity.ReportMemory;
1010
import Ness.Backend.domain.report.entity.ReportRecommend;
1111
import Ness.Backend.domain.report.entity.ReportTag;
12+
import Ness.Backend.global.fastApi.FastApiMemoryApi;
1213
import Ness.Backend.global.fastApi.FastApiRecommendApi;
14+
import Ness.Backend.global.fastApi.FastApiTagApi;
1315
import lombok.RequiredArgsConstructor;
1416
import lombok.extern.slf4j.Slf4j;
1517
import org.springframework.stereotype.Service;
1618

1719
import java.time.DayOfWeek;
18-
import java.time.LocalTime;
1920
import java.time.ZoneId;
2021
import java.time.ZonedDateTime;
2122
import java.util.List;
@@ -28,89 +29,148 @@ public class ReportService {
2829
private final ReportTagRepository reportTagRepository;
2930
private final ReportRecommendRepository reportRecommendRepository;
3031
private final FastApiRecommendApi fastApiRecommendApi;
32+
private final FastApiTagApi fastApiTagApi;
33+
private final FastApiMemoryApi fastApiMemoryApi;
3134
private final MemberRepository memberRepository;
3235

3336
public GetReportMemoryListDto getMemory(Long id){
34-
// 2주치의 데이터 가져오기
35-
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Seoul"));
36-
ZonedDateTime startOfWeek = now.with(DayOfWeek.MONDAY).withHour(0).withMinute(0).withSecond(0).withNano(0);
37-
ZonedDateTime startOfLastWeek = startOfWeek.minusWeeks(1);
37+
// 오늘 날짜 가져오기
38+
ZonedDateTime now = getToday();
3839

39-
List<ReportMemory> reportMemories = reportMemoryRepository.findReportMemoriesByMember_idAndCreatedDateBetweenOrderByCreatedDateAsc(id, startOfLastWeek, now);
40+
ReportMemory reportMemory = reportMemoryRepository.findTodayReportMemoryByMember_Id(id);
4041

41-
//ReportMemoryListResponseDto에 매핑
42-
List<GetReportMemoryDto> getReportMemoryDtos = reportMemories.stream()
43-
.map(memory -> GetReportMemoryDto.builder()
44-
.id(memory.getId())
45-
.createdDate(memory.getCreatedDate().toString())
46-
.pictureUrl(memory.getPictureUrl())
47-
.build())
48-
.toList();
42+
if (reportMemory == null){
43+
// 오늘치가 없다면 새롭게 생성하기
44+
String memory = postNewAiMemory(id, now);
4945

50-
return new GetReportMemoryListDto(getReportMemoryDtos);
46+
Member memberEntity = memberRepository.findMemberById(id);
47+
48+
ReportMemory newMemory = ReportMemory.builder()
49+
.createdDate(now)
50+
.memory(memory)
51+
.member(memberEntity)
52+
.build();
53+
54+
reportMemoryRepository.save(newMemory);
55+
}
56+
57+
// 2주치의 데이터 가져오기
58+
List<ReportMemory> reportMemories = reportMemoryRepository.findTwoWeekUserMemoryByMember_Id(id);
59+
return createReportMemoryListDto(reportMemories);
5160
}
5261

5362
public GetReportTagListDto getTag(Long id){
54-
// 지난 달 10일~이번 달 9일 간의 데이터 가져오기
55-
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Seoul"));
56-
ZonedDateTime lastMonth10 = now.withMonth(now.getMonthValue() - 1).withDayOfMonth(10).withHour(0).withMinute(0).withSecond(0).withNano(0);
57-
ZonedDateTime thisMonth9 = now.withMonth(now.getMonthValue()).withDayOfMonth(9).withHour(0).withMinute(0).withSecond(0).withNano(0);
58-
List<ReportTag> reportTags = reportTagRepository.findReportTagsByMember_idAndCreatedDateBetweenOrderByCreatedDateAsc(id, lastMonth10, thisMonth9);
63+
// 오늘 날짜 가져오기
64+
ZonedDateTime now = getToday();
5965

60-
//ReportTagListResponseDto에 매핑
61-
List<GetReportTagDto> getReportTagDtos = reportTags.stream()
62-
.map(tag -> GetReportTagDto.builder()
63-
.id(tag.getId())
64-
.createdDate(tag.getCreatedDate().toString())
65-
.tagTitle(tag.getTagTitle())
66-
.tagDesc(tag.getTagDesc())
67-
.build())
68-
.toList();
66+
List<ReportTag> reportTags = reportTagRepository.findLastMonthReportTagByMember_Id(id);
6967

70-
return new GetReportTagListDto(getReportTagDtos);
68+
if (reportTags == null) {
69+
PostFastApiAiTagDto aiDto = postNewAiTag(id, getToday());
70+
71+
Member memberEntity = memberRepository.findMemberById(id);
72+
/*
73+
for (String tag : aiDto.getTags()) {
74+
ReportTag reportTag = ReportTag.builder()
75+
.tagTitle()
76+
.tagDesc()
77+
.createdDate(now.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0).withNano(0))
78+
.member(memberEntity)
79+
.build();
80+
81+
reportTagRepository.save(reportTag);
82+
}
83+
*/
84+
}
85+
86+
return createReportTagListDto(reportTags);
7187
}
7288

7389
public GetReportRecommendDto getRecommend(Long id){
74-
// 이번 달의 데이터 가져오기
75-
ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Seoul"));
76-
ZonedDateTime today = now.toLocalDate().atStartOfDay(now.getZone());
90+
// 오늘 날짜 가져오기
91+
ZonedDateTime now = getToday();
7792

7893
ReportRecommend reportRecommend = reportRecommendRepository.findTodayReportRecommendByMember_Id(id);
7994

8095
if(reportRecommend == null){
8196
//새로운 한 줄 추천 생성하기
82-
String answer = postNewAiRecommend(id, today);
97+
String answer = postNewAiRecommend(id, now);
8398
String parsedAnswer = parseAiRecommend(answer);
8499

85100
Member memberEntity = memberRepository.findMemberById(id);
86101

87102
ReportRecommend newRecommend = ReportRecommend.builder()
88-
.createdDate(today)
89-
.recommendText(answer)
103+
.createdDate(now)
104+
.recommendText(parsedAnswer)
90105
.member(memberEntity)
91106
.build();
92107

93108
//새롭게 생성된 한 줄 추천 저장하기
94109
reportRecommendRepository.save(newRecommend);
95110

96-
return GetReportRecommendDto.builder()
97-
.id(newRecommend.getId())
98-
.createdDate(newRecommend.getCreatedDate().toString())
99-
.recommendText(newRecommend.getRecommendText())
100-
.build();
111+
return createReportRecommendDto(newRecommend.getId(), newRecommend.getCreatedDate().toString(), newRecommend.getRecommendText());
101112
} else{
102-
return GetReportRecommendDto.builder()
103-
.id(reportRecommend.getId())
104-
.createdDate(reportRecommend.getCreatedDate().toString())
105-
.recommendText(reportRecommend.getRecommendText())
106-
.build();
113+
return createReportRecommendDto(reportRecommend.getId(), reportRecommend.getCreatedDate().toString(), reportRecommend.getRecommendText());
107114
}
108115
}
109116

117+
public ZonedDateTime getToday(){
118+
return ZonedDateTime.now(ZoneId.of("Asia/Seoul"));
119+
}
120+
121+
public GetReportMemoryListDto createReportMemoryListDto(List<ReportMemory> reportMemories) {
122+
//ReportMemoryListResponseDto에 매핑
123+
List<GetReportMemoryDto> getReportMemoryDtos = reportMemories.stream()
124+
.map(memory -> GetReportMemoryDto.builder()
125+
.id(memory.getId())
126+
.createdDate(memory.getCreatedDate().toString())
127+
.memory(memory.getMemory())
128+
.build())
129+
.toList();
130+
131+
return new GetReportMemoryListDto(getReportMemoryDtos);
132+
}
133+
134+
public GetReportTagListDto createReportTagListDto(List<ReportTag> reportTags) {
135+
136+
List<GetReportTagDto> getReportTagDtos = reportTags.stream()
137+
.map(tag -> GetReportTagDto.builder()
138+
.id(tag.getId())
139+
.createdDate(tag.getCreatedDate().toString())
140+
.tagTitle(tag.getTagTitle())
141+
.tagDesc(tag.getTagDesc())
142+
.build())
143+
.toList();
144+
145+
return new GetReportTagListDto(getReportTagDtos);
146+
}
147+
148+
public GetReportRecommendDto createReportRecommendDto(Long id, String date, String text){
149+
return GetReportRecommendDto.builder()
150+
.id(id)
151+
.createdDate(date)
152+
.recommendText(text)
153+
.build();
154+
}
155+
110156
public String parseAiRecommend(String text){
111157
return text.replace("\"", "");
112158
}
113159

160+
public String postNewAiMemory(Long id, ZonedDateTime today){
161+
PostFastApiUserMemoryDto userDto = PostFastApiUserMemoryDto.builder()
162+
.member_id(id.intValue())
163+
.user_persona("")
164+
.schedule_datetime_start(today)
165+
.schedule_datetime_end(today)
166+
.build();
167+
168+
//Fast API에 전송하기
169+
PostFastApiAiMemoryDto aiDto = fastApiMemoryApi.creatFastApiMemory(userDto);
170+
171+
return aiDto.getMemory();
172+
}
173+
114174
public String postNewAiRecommend(Long id, ZonedDateTime today){
115175
PostFastApiUserRecommendDto userDto = PostFastApiUserRecommendDto.builder()
116176
.member_id(id.intValue())
@@ -120,8 +180,20 @@ public String postNewAiRecommend(Long id, ZonedDateTime today){
120180
.build();
121181

122182
//Fast API에 전송하기
123-
PostFastApiAiRecommendDto AiDto = fastApiRecommendApi.creatFastApiRecommend(userDto);
183+
PostFastApiAiRecommendDto aiDto = fastApiRecommendApi.creatFastApiRecommend(userDto);
184+
185+
return aiDto.getAnswer();
186+
}
187+
188+
public PostFastApiAiTagDto postNewAiTag(Long id, ZonedDateTime today){
189+
PostFastApiUserTagDto userDto = PostFastApiUserTagDto.builder()
190+
.member_id(id.intValue())
191+
.user_persona("")
192+
.schedule_datetime_start(today)
193+
.schedule_datetime_end(today)
194+
.build();
124195

125-
return AiDto.getAnswer();
196+
//Fast API에 전송하고 값 받아오기
197+
return fastApiTagApi.creatFastApiTag(userDto);
126198
}
127199
}

src/main/java/Ness/Backend/domain/report/ReportTagRepository.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22

33
import Ness.Backend.domain.report.entity.ReportTag;
44
import org.springframework.data.jpa.repository.JpaRepository;
5+
import org.springframework.data.jpa.repository.Query;
6+
import org.springframework.data.repository.query.Param;
57

6-
import java.time.ZonedDateTime;
78
import java.util.List;
89

910
public interface ReportTagRepository extends JpaRepository<ReportTag, Long> {
10-
List<ReportTag> findReportTagsByMember_idAndCreatedDateBetweenOrderByCreatedDateAsc(Long id, ZonedDateTime startOfMonth, ZonedDateTime now);
11+
//매 월 1일마다 특정 멤버가 생성한 보고서 태그 데이터를 가져오는 역할
12+
@Query( value = "SELECT * FROM report_tag " +
13+
"WHERE member_id = :memberId " +
14+
"AND EXTRACT(YEAR_MONTH FROM created_date) = EXTRACT(YEAR_MONTH FROM NOW()) " +
15+
"AND EXTRACT(DAY FROM created_date) = 1;",
16+
nativeQuery = true)
17+
List<ReportTag> findLastMonthReportTagByMember_Id(
18+
@Param("memberId") Long memberId);
19+
20+
//List<ReportTag> findReportTagsByMember_idAndCreatedDateBetweenOrderByCreatedDateAsc(Long id, ZonedDateTime startOfMonth, ZonedDateTime now);
1121
}

0 commit comments

Comments
 (0)