Skip to content

Commit

Permalink
Merge pull request #37 from studio-recoding/feat-main-api
Browse files Browse the repository at this point in the history
[🚀feat] 리포트 tag 기능 개발 완료
  • Loading branch information
JeonHaeseung authored Apr 12, 2024
2 parents 7ab67fd + e1b1d49 commit 253505f
Show file tree
Hide file tree
Showing 14 changed files with 169 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import Ness.Backend.domain.report.dto.response.GetReportMemoryListDto;
import Ness.Backend.domain.report.dto.response.GetReportRecommendDto;
import Ness.Backend.domain.report.dto.response.GetReportTagListDto;
import Ness.Backend.domain.report.dto.response.PostFastApiAiTagListDto;
import Ness.Backend.domain.report.entity.ReportTag;
import Ness.Backend.global.auth.AuthUser;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/report")
Expand Down
78 changes: 39 additions & 39 deletions src/main/java/Ness/Backend/domain/report/ReportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.DayOfWeek;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
Expand Down Expand Up @@ -58,32 +57,34 @@ public GetReportMemoryListDto getMemory(Long id){
List<ReportMemory> reportMemories = reportMemoryRepository.findTwoWeekUserMemoryByMember_Id(id);
return createReportMemoryListDto(reportMemories);
}
public PostFastApiAiTagListDto getAiTag(Long id){
return postNewAiTag(id, getToday());
}

public GetReportTagListDto getTag(Long id){
// 오늘 날짜 가져오기
ZonedDateTime now = getToday();

List<ReportTag> reportTags = reportTagRepository.findLastMonthReportTagByMember_Id(id);

if (reportTags == null) {
PostFastApiAiTagDto aiDto = postNewAiTag(id, getToday());
if (reportTags == null || reportTags.isEmpty()) {
PostFastApiAiTagListDto aiDto = postNewAiTag(id, getToday());

Member memberEntity = memberRepository.findMemberById(id);
/*
for (String tag : aiDto.getTags()) {

for (PostFastApiAiTagDto tag : aiDto.getTags()) {
ReportTag reportTag = ReportTag.builder()
.tagTitle()
.tagDesc()
.tagTitle(tag.getTitle())
.tagDesc(tag.getDesc())
.createdDate(now.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0).withNano(0))
.member(memberEntity)
.build();
reportTagRepository.save(reportTag);
}
*/
return createReportTagListDto(reportTagRepository.findLastMonthReportTagByMember_Id(id));
} else {
return createReportTagListDto(reportTags);
}

return createReportTagListDto(reportTags);
}

public GetReportRecommendDto getRecommend(Long id){
Expand Down Expand Up @@ -118,6 +119,19 @@ public ZonedDateTime getToday(){
return ZonedDateTime.now(ZoneId.of("Asia/Seoul"));
}

public GetReportTagListDto createReportTagListDto(List<ReportTag> reportTags){
List<GetReportTagDto> getReportTagDtos = reportTags.stream()
.map(tag -> GetReportTagDto.builder()
.id(tag.getId())
.createdDate(tag.getCreatedDate().toString())
.tagTitle(tag.getTagTitle())
.tagDesc(tag.getTagDesc())
.build())
.toList();

return new GetReportTagListDto(getReportTagDtos);
}

public GetReportMemoryListDto createReportMemoryListDto(List<ReportMemory> reportMemories) {
//ReportMemoryListResponseDto에 매핑
List<GetReportMemoryDto> getReportMemoryDtos = reportMemories.stream()
Expand All @@ -131,20 +145,6 @@ public GetReportMemoryListDto createReportMemoryListDto(List<ReportMemory> repor
return new GetReportMemoryListDto(getReportMemoryDtos);
}

public GetReportTagListDto createReportTagListDto(List<ReportTag> reportTags) {

List<GetReportTagDto> getReportTagDtos = reportTags.stream()
.map(tag -> GetReportTagDto.builder()
.id(tag.getId())
.createdDate(tag.getCreatedDate().toString())
.tagTitle(tag.getTagTitle())
.tagDesc(tag.getTagDesc())
.build())
.toList();

return new GetReportTagListDto(getReportTagDtos);
}

public GetReportRecommendDto createReportRecommendDto(Long id, String date, String text){
return GetReportRecommendDto.builder()
.id(id)
Expand All @@ -153,8 +153,16 @@ public GetReportRecommendDto createReportRecommendDto(Long id, String date, Stri
.build();
}

public String parseAiRecommend(String text){
return text.replace("\"", "");
public PostFastApiAiTagListDto postNewAiTag(Long id, ZonedDateTime today){
PostFastApiUserTagDto userDto = PostFastApiUserTagDto.builder()
.member_id(id.intValue())
.user_persona("")
.schedule_datetime_start(today)
.schedule_datetime_end(today)
.build();

//Fast API에 전송하고 값 받아오기
return fastApiTagApi.creatFastApiTag(userDto);
}

public String postNewAiMemory(Long id, ZonedDateTime today){
Expand All @@ -171,6 +179,10 @@ public String postNewAiMemory(Long id, ZonedDateTime today){
return aiDto.getMemory();
}

public String parseAiRecommend(String text){
return text.replace("\"", "");
}

public String postNewAiRecommend(Long id, ZonedDateTime today){
PostFastApiUserRecommendDto userDto = PostFastApiUserRecommendDto.builder()
.member_id(id.intValue())
Expand All @@ -184,16 +196,4 @@ public String postNewAiRecommend(Long id, ZonedDateTime today){

return aiDto.getAnswer();
}

public PostFastApiAiTagDto postNewAiTag(Long id, ZonedDateTime today){
PostFastApiUserTagDto userDto = PostFastApiUserTagDto.builder()
.member_id(id.intValue())
.user_persona("")
.schedule_datetime_start(today)
.schedule_datetime_end(today)
.build();

//Fast API에 전송하고 값 받아오기
return fastApiTagApi.creatFastApiTag(userDto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public interface ReportTagRepository extends JpaRepository<ReportTag, Long> {
//매 월 1일마다 특정 멤버가 생성한 보고서 태그 데이터를 가져오는 역할
@Query( value = "SELECT * FROM report_tag " +
"WHERE member_id = :memberId " +
"AND EXTRACT(YEAR_MONTH FROM created_date) = EXTRACT(YEAR_MONTH FROM NOW()) " +
"AND EXTRACT(DAY FROM created_date) = 1;",
"AND EXTRACT(YEAR_MONTH FROM CONVERT_TZ(created_date, 'UTC', 'Asia/Seoul')) = EXTRACT(YEAR_MONTH FROM NOW()) " +
"AND EXTRACT(DAY FROM CONVERT_TZ(created_date, 'UTC', 'Asia/Seoul')) = 1;",
nativeQuery = true)
List<ReportTag> findLastMonthReportTagByMember_Id(
@Param("memberId") Long memberId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package Ness.Backend.domain.report.dto.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PostFastApiAiTagDto {
private List<String> tags;
@JsonProperty("tag")
private String title;

@JsonProperty("desc")
private String desc;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package Ness.Backend.domain.report.dto.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PostFastApiAiTagListDto {
@JsonProperty("tagList")
private List<PostFastApiAiTagDto> tags;
}
43 changes: 13 additions & 30 deletions src/main/java/Ness/Backend/domain/weather/WeatherService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package Ness.Backend.domain.weather;

import Ness.Backend.domain.weather.dto.response.GetPublicDataWeatherDto;
import Ness.Backend.domain.weather.dto.response.PublicDataWeather;
import Ness.Backend.global.publicData.PublicDataWeatherApi;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -20,45 +20,28 @@ public class WeatherService {
@Value("${api-key.public-weather}")
private String publicWeatherApiKey;

public GetPublicDataWeatherDto getWeather(){
public PublicDataWeather getWeather(){
return getPublicDataWeather();
}

public ZonedDateTime getToday(){
return ZonedDateTime.now(ZoneId.of("Asia/Seoul"));
}

public int findBaseTime(){
/* 가능한 Base_time 0200, 0500, 0800, 1100, 1400, 1700, 2000, 2300
02:10, 05:10, 08:10, 11:10, 14:10, 17:10, 20:10, 23:10
*/
return 0;
}

public GetPublicDataWeatherDto getPublicDataWeather(){
log.info(getToday().format(DateTimeFormatter.ofPattern("yyyyMMdd")));
log.info(getToday().format(DateTimeFormatter.ofPattern("Hm")));
return publicDataWeatherApi.getPublicDataWeather(
"application/json",
publicWeatherApiKey, 2, 2, "JSON",
getToday().format(DateTimeFormatter.ofPattern("yyyyMMdd")),
"0630",
//getToday().format(DateTimeFormatter.ofPattern("Hm")),
126.999641666666, 37.5610027777777); //테스트용 값
}

//단기 예보 조회 호출
/*
public GetPublicDataWeatherDto getPublicDataWeather(){
log.info(getToday().format(DateTimeFormatter.ofPattern("yyyyMMdd")));
log.info(getToday().format(DateTimeFormatter.ofPattern("Hm")));
* Map<String, Double> categoryAverages = items.stream()
.collect(Collectors.groupingBy(
WeatherItemDto::getCategory,
Collectors.averagingDouble(item -> Double.parseDouble(item.getFcstValue()))
));
* */

public PublicDataWeather getPublicDataWeather(){
return publicDataWeatherApi.getPublicDataWeather(
"application/json",
publicWeatherApiKey, 2, 2, "JSON",
publicWeatherApiKey, 60, 1, "JSON",
getToday().format(DateTimeFormatter.ofPattern("yyyyMMdd")),
"0630",
//getToday().format(DateTimeFormatter.ofPattern("Hm")),
126.999641666666, 37.5610027777777); //테스트용 값
getToday().format(DateTimeFormatter.ofPattern("Hm")),
59, 127); // 우선은 서울 서대문구로 하드코딩
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,9 @@ public class PublicDataBody {
@JsonProperty("totalCount")
private int totalCount;

@JsonProperty("resultCode")
private int resultCode;

@JsonProperty("resultMsg")
private String resultMsg;

@JsonProperty("dataType")
private String dataType;

@JsonProperty("baseDate")
private int baseDate;

@JsonProperty("baseTime")
private int baseTime;

@JsonProperty("nx")
private int nx;

@JsonProperty("ny")
private int ny;

@JsonProperty("category")
private String category;

@JsonProperty("fcstDate")
private int fcstDate;

@JsonProperty("fcstTime")
private int fcstTime;

@JsonProperty("fcstValue")
private int fcstValue;
@JsonProperty("items")
PublicDataItemList publicDataItemList;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package Ness.Backend.domain.weather.dto.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
public class PublicDataHeader {
@JsonProperty("resultCode")
private int resultCode;

@JsonProperty("resultMsg")
private String resultMsg;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package Ness.Backend.domain.weather.dto.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
public class PublicDataItem {
@JsonProperty("baseDate")
private int baseDate;

@JsonProperty("baseTime")
private int baseTime;

@JsonProperty("nx")
private int nx;

@JsonProperty("ny")
private int ny;

@JsonProperty("category")
private String category;

@JsonProperty("fcstDate")
private int fcstDate;

@JsonProperty("fcstTime")
private int fcstTime;

@JsonProperty("fcstValue")
private String fcstValue;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package Ness.Backend.domain.weather.dto.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
public class PublicDataItemList {
@JsonProperty("item")
List<PublicDataItem> publicDataItems;
}
Loading

0 comments on commit 253505f

Please sign in to comment.