Skip to content

Commit

Permalink
Merge branch 'dev' into feature/mail
Browse files Browse the repository at this point in the history
  • Loading branch information
qormoon authored Jul 4, 2024
2 parents 6e783a3 + 06e8ee5 commit b32e3c3
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.fiurinee.domain.anniversary.dto;

import com.example.fiurinee.domain.anniversary.entity.Anniversary;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

import java.util.ArrayList;
Expand All @@ -18,6 +19,8 @@ public class AnniversaryResponseDTO {
private String name;
private String anniversaryDate;
private String type;

@JsonProperty("dDays")
private List<Map<String, Integer>> dDays;

public static AnniversaryResponseDTO of(Anniversary anniversary, List<Map<String, Integer>> dDays) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public Anniversary addAnniversary(Long memberId, AnniversaryRequestDTO requestDT
throw new IllegalArgumentException("Invalid anniversary type");
}

LocalDate requestDate = requestDTO.getDate();
LocalDate currentDate = LocalDate.now(ZoneId.of("UTC"));
if (requestDate.isAfter(currentDate)) {
throw new IllegalArgumentException("Date cannot be in the future");
}

ZonedDateTime zonedDateTime = requestDTO.getDate().atStartOfDay(ZoneId.of("UTC"));
Timestamp timestamp = Timestamp.from(zonedDateTime.toInstant());

Expand All @@ -68,6 +74,12 @@ public Anniversary updateAnniversary(Long memberId, Long anniversaryId, Annivers

validateAnniversaryType(requestDTO.getType());

LocalDate requestDate = requestDTO.getDate();
LocalDate currentDate = LocalDate.now(ZoneId.of("UTC"));
if (requestDate.isAfter(currentDate)) {
throw new IllegalArgumentException("Date cannot be in the future");
}

ZonedDateTime zonedDateTime = requestDTO.getDate().atStartOfDay(ZoneId.of("UTC"));
Timestamp timestamp = Timestamp.from(zonedDateTime.toInstant());

Expand Down Expand Up @@ -97,55 +109,56 @@ private void validateAnniversaryType(String type) {


public List<Map<String, Integer>> calculateDDay(Anniversary anniversary) {
List<Map<String, Integer>> dDayList = new ArrayList<>();
ZoneId koreaZoneId = ZoneId.of("Asia/Seoul");
LocalDate today = LocalDate.now(koreaZoneId);
LocalDateTime anniversaryDateTime = anniversary.getAnniversaryDate().toLocalDateTime();
LocalDate anniversaryDate = anniversaryDateTime.toLocalDate(); //기념일의 날짜 부분만 추출
long yearsDifference = ChronoUnit.YEARS.between(anniversaryDate, today); //기념일 날짜와 오늘 날짜 사이의 년 차이를 계산

if (anniversary.getType() == AnniversaryType.연인) {
int daysPassed = (int) ChronoUnit.DAYS.between(anniversaryDate, today); //기념일 이후 오늘까지 경과된 일 수를 계산
int nextDay = ((daysPassed / 100) + 1) * 100;

for (int i = 0; i < 2; i++) {
LocalDate hundredDays = anniversaryDate.plusDays(nextDay + i * 100);
if (!hundredDays.isBefore(today)) {
Map<String, Integer> dDay = new HashMap<>();
dDay.put((nextDay + i * 100) + "days", (int) ChronoUnit.DAYS.between(today, hundredDays) - 1);
dDayList.add(dDay);
List<Map<String, Integer>> dDayList = new ArrayList<>();
LocalDate today = LocalDate.now();
LocalDateTime anniversaryDateTime = anniversary.getAnniversaryDate().toLocalDateTime();
LocalDate anniversaryDate = anniversaryDateTime.toLocalDate();

Map<String, Integer> closestDDay = null;
int minDays = Integer.MAX_VALUE;

if (anniversary.getType() == AnniversaryType.연인) {
int daysPassed = (int) ChronoUnit.DAYS.between(anniversaryDate, today);
int nextDay = ((daysPassed / 100) + 1) * 100;

for (int i = 0; i < 1; i++) { // Only find the next closest 100-day anniversary
LocalDate hundredDays = anniversaryDate.plusDays(nextDay + i * 100);
if (!hundredDays.isBefore(today)) {
int daysToHundredDays = (int) ChronoUnit.DAYS.between(today, hundredDays) - 1;
if (daysToHundredDays < minDays) {
minDays = daysToHundredDays;
closestDDay = new HashMap<>();
closestDDay.put((nextDay + i * 100) + "days", daysToHundredDays);
}
}
}

boolean isTodayAnniversary = false;
for (int i = 1; i <= yearsDifference + 1; i++) {
LocalDate yearAnniversary = anniversaryDate.plusYears(i);
int daysBetween = (int) ChronoUnit.DAYS.between(today, yearAnniversary);
if (daysBetween == 0) {
Map<String, Integer> dDay = new HashMap<>();
dDay.put("year", daysBetween);
dDayList.add(dDay);
isTodayAnniversary = true;
break;
}
}
}

if (!isTodayAnniversary) {
for (int i = 1; i <= yearsDifference + 1; i++) {
LocalDate yearAnniversary = anniversaryDate.plusYears(i);
if (!yearAnniversary.isBefore(today)) {
Map<String, Integer> dDay = new HashMap<>();
dDay.put("year", (int) ChronoUnit.DAYS.between(today, yearAnniversary));
dDayList.add(dDay);
break;
}
long yearsDifference = ChronoUnit.YEARS.between(anniversaryDate, today);
for (int i = 1; i <= yearsDifference + 1; i++) {
LocalDate yearAnniversary = anniversaryDate.plusYears(i);
if (!yearAnniversary.isBefore(today)) {
int daysToYearAnniversary = (int) ChronoUnit.DAYS.between(today, yearAnniversary);
if (daysToYearAnniversary < minDays) {
minDays = daysToYearAnniversary;
closestDDay = new HashMap<>();
closestDDay.put("year", daysToYearAnniversary);
}
break;
}
}

return dDayList;
if (closestDDay != null) {
dDayList.add(closestDDay);
}


return dDayList;
}



public List<AnniversaryResponseDTO> getDDayZeroAnniversaries(List<Anniversary> anniversaries) {
List<AnniversaryResponseDTO> dDayZeroList = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,22 @@ public ResponseEntity<List<ResponseMentDto>> inputMentNotMember(@RequestBody Str
String url = "http://localhost:8080/model/test";

int value = LocalDateTime.now().getMonth().getValue();
System.out.println("value = " + value);

List<ModelMentResponseDto> re = CallApiService.mentApi(url, new MentDto(ment, value));
System.out.println("re.get(0).getName() = " + re.get(0).getName());
System.out.println("re.get(0).getFlowerLanguage() = " + re.get(0).getFlowerLanguage());

Flower byName0 = flowerService.findByNameAndFlowerLanguage(re.get(0).getName(),re.get(0).getFlowerLanguage());
Flower byName1 = flowerService.findByNameAndFlowerLanguage(re.get(1).getName(),re.get(1).getFlowerLanguage());
Flower byName2 = flowerService.findByNameAndFlowerLanguage(re.get(2).getName(),re.get(2).getFlowerLanguage());


List<ResponseMentDto> re2 = new ArrayList<>();
ResponseMentDto responseMentDto0 = new ResponseMentDto(byName0);
ResponseMentDto responseMentDto1 = new ResponseMentDto(byName1);
ResponseMentDto responseMentDto2 = new ResponseMentDto(byName2);

re2.add(responseMentDto0);
re2.add(responseMentDto1);
re2.add(responseMentDto2);


return ResponseEntity.ok(re2);
Expand All @@ -91,17 +92,33 @@ public ResponseEntity<ResponseHarmonyWitnMentDto> selectFlower(@PathVariable ("m
re.add(responseHarmonyDto0);
re.add(responseHarmonyDto1);

return ResponseEntity.ok(new ResponseHarmonyWitnMentDto("추천 멘트",re));
return ResponseEntity.ok(new ResponseHarmonyWitnMentDto("추천은 recommend, recommend는 영어로 추천, 내 너무 피곤하다,, 인생이란 뭘까",re));
}

@PostMapping("/{flowerId}/non")
public ResponseEntity<ResponseHarmonyWitnMentDto> selectFlowerNonMember(@PathVariable ("flowerId") Long flowerId,
@RequestBody String ment){
ResponseHarmonyDto responseHarmonyDto0 = new ResponseHarmonyDto(flowerService.findByNameAndFlowerLanguage("토마토", "완성된 아름다움"));
ResponseHarmonyDto responseHarmonyDto1 = new ResponseHarmonyDto(flowerService.findByNameAndFlowerLanguage("토레니아", "가련한 욕망"));

List<ResponseHarmonyDto> re = new ArrayList<>();
re.add(responseHarmonyDto0);
re.add(responseHarmonyDto1);

return ResponseEntity.ok(new ResponseHarmonyWitnMentDto("추천은 recommend, recommend는 영어로 추천, 내 너무 피곤하다,, 인생이란 뭘까",re));
}

@PostMapping("/test")
public List<ModelMentResponseDto> modelTest(@RequestBody MentDto mentDto) {
List<ModelMentResponseDto> re = new ArrayList<>();
ModelMentResponseDto modelMentResponseDto0 = new ModelMentResponseDto("토레니아", "가련한 욕망");
ModelMentResponseDto modelMentResponseDto1 = new ModelMentResponseDto("토마토", "완성된 아름다움");
ModelMentResponseDto modelMentResponseDto2 = new ModelMentResponseDto("겹 캄파눌라", "따뜻한 사람");


re.add(modelMentResponseDto0);
re.add(modelMentResponseDto1);
re.add(modelMentResponseDto2);

return re;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,14 @@ public ResponseEntity<List<ResponseMentDto>> inputMent(@Parameter(description =
public ResponseEntity<ResponseHarmonyWitnMentDto> selectFlower(@Parameter(description = "회원의 아이디") @PathVariable ("memberId") Long memberId,
@Parameter(description = "선택한 꽃의 아이디") @PathVariable ("flowerId") Long flowerId,
@Parameter(description = "입력했던 멘트") @RequestBody String ment);
@Operation(
summary = "비회원 사용자가 꽃을 선택했을 시 호출",
description = "꽃을 선택했을 시 선택한 꽃의 id 그리고 이전에 입력했던 사용자의 멘트를 보내주세요",
security = @SecurityRequirement(name = "bearerAuth")
)
@ApiResponse(responseCode = "200", description = "멘트 추천 및 어울리는 꽃 추천 성공")
@PostMapping("/{flowerId}/non")
public ResponseEntity<ResponseHarmonyWitnMentDto> selectFlowerNonMember(@Parameter(description = "꽃의 아이디") @PathVariable ("flowerId") Long flowerId,
@Parameter(description = "회원이 입력 했던 멘트") @RequestBody String ment);
}

Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,48 @@ public ResponseEntity<List<HarmonyRecentDto>> preferHarmony(@PathVariable("id")
// public boolean test(){
// MatchingFlower build1 = MatchingFlower.builder()
// .flower(flowerService.findByNameAndFlowerLanguage("검은포플라", "용기"))
// .recommendFlower(recommendFlowerService.findById(3L))
// .recommendFlower(recommendFlowerService.findById(1L))
// .build();
//
// matchingFlowerService.save(build1);
//
// MatchingFlower build2 = MatchingFlower.builder()
// .flower(flowerService.findByNameAndFlowerLanguage("군자란", "고귀"))
// .recommendFlower(recommendFlowerService.findById(3L))
// .recommendFlower(recommendFlowerService.findById(1L))
// .build();
//
// matchingFlowerService.save(build2);
//
// MatchingFlower build3 = MatchingFlower.builder()
// .flower(flowerService.findByNameAndFlowerLanguage("나도풍란", "인내"))
// .recommendFlower(recommendFlowerService.findById(2L))
// .build();
//
// matchingFlowerService.save(build3);
//
// MatchingFlower build4 = MatchingFlower.builder()
// .flower(flowerService.findByNameAndFlowerLanguage("노랑 히야신", "승부"))
// .recommendFlower(recommendFlowerService.findById(2L))
// .build();
//
// matchingFlowerService.save(build4);
//
// MatchingFlower build5 = MatchingFlower.builder()
// .flower(flowerService.findByNameAndFlowerLanguage("노랑수선화", "사랑에 답하여"))
// .recommendFlower(recommendFlowerService.findById(3L))
// .build();
//
// matchingFlowerService.save(build5);
//
// MatchingFlower build6 = MatchingFlower.builder()
// .flower(flowerService.findByNameAndFlowerLanguage("노랑제비꽃", "수줍은 사랑"))
// .recommendFlower(recommendFlowerService.findById(3L))
// .build();
//
// matchingFlowerService.save(build6);
//
//
//
// return true;
//
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@ public static MemberResponseDTO of(Member member) {
.profileImage(member.getProfileImage())
.alarm(member.isAlarm())
.anniversaries(member.getAnniversaries().stream()
.map(anniversary -> Map.<String, Object>of(
"id", anniversary.getId(),
"name", anniversary.getName(),
"anniversaryDate", anniversary.getAnniversaryDate().toString().substring(0,10),
"type", anniversary.getType().name(),
"d-day", anniversaryService.calculateDDay(anniversary)
))
.map(anniversary -> {
List<Map<String, Integer>> dDays = anniversaryService.calculateDDay(anniversary);
return Map.of(
"id", anniversary.getId(),
"name", anniversary.getName(),
"anniversaryDate", anniversary.getAnniversaryDate().toString().substring(0, 10),
"type", anniversary.getType().name(),
"dDays", dDays
);
})
.sorted((a1, a2) -> {
Integer dDay1 = (Integer) ((Map<String, Integer>) ((List<?>) a1.get("dDays")).get(0)).values().iterator().next();
Integer dDay2 = (Integer) ((Map<String, Integer>) ((List<?>) a2.get("dDays")).get(0)).values().iterator().next();
return dDay1.compareTo(dDay2);
})
.collect(Collectors.toList()))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.example.fiurinee.domain.preferList.controller.api.PreferListApi;
import com.example.fiurinee.domain.preferList.entity.PreferList;
import com.example.fiurinee.domain.preferList.service.PreferListService;
import com.example.fiurinee.domain.recommendFlower.entity.RecommendFlower;
import com.example.fiurinee.domain.recommendFlower.service.RecommendFlowerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
Expand All @@ -18,6 +20,7 @@ public class PreferListController implements PreferListApi {

private final MemberService memberService;
private final PreferListService preferListService;
private final RecommendFlowerService recommendFlowerService;

@GetMapping("/{id}/{order}")
public Boolean savePrefer(@PathVariable("id") Long id,
Expand All @@ -29,6 +32,12 @@ public Boolean savePrefer(@PathVariable("id") Long id,
.build();
preferListService.save(build);

int size = byId.getRecommendFlowers().size();

RecommendFlower recommendFlower = byId.getRecommendFlowers().get(size - Math.toIntExact(order));

recommendFlowerService.editPrefer(recommendFlower,true);

return true;

}
Expand All @@ -40,6 +49,12 @@ public Boolean deletePrefer(@PathVariable("id") Long id,

preferListService.delete(preferListService.findByMemberAndOrder(byId,order));

int size = byId.getRecommendFlowers().size();

RecommendFlower recommendFlower = byId.getRecommendFlowers().get(size - Math.toIntExact(order));

recommendFlowerService.editPrefer(recommendFlower,false);

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static RecommendFlowerDto of(Long order, Member member){
RecommendComment recommendComment = recommendComments.get(recommendComments.size() - order.intValue());

recommendFlowerDto.recommendMessage = recommendComment.getContent();
recommendFlowerDto.prefer = recommendComment.getPrefer();
recommendFlowerDto.prefer = recommendFlower.getPrefer();

return recommendFlowerDto;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ public class RecommendFlower {

@OneToMany(mappedBy = "recommendFlower", cascade = CascadeType.ALL)
private List<MatchingFlower> matchingFlowers;

public void editPrefer(Boolean value){
this.prefer = value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public RecommendFlower findById(Long id){
return recommendFlower;

}

@Transactional
public void editPrefer(RecommendFlower recommendFlower, Boolean value){
recommendFlower.editPrefer(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.requestMatchers("/oauth2/login", "/login/oauth2/code/**", "/oauth2/authorization/**","/login/oauth2/code/google","/member/*/refresh","/model/test",
"/swagger-ui/index.html", "/swagger-ui/**", "/v3/api-docs/**","/swagger-resources/**", "/v3/api-docs").permitAll()
//비회원 전용 api
.requestMatchers("/main/today","/main/season","model/ment").permitAll()
.requestMatchers("/main/today","/main/season","/model/ment","/model/*/non").permitAll()
.anyRequest().authenticated());

http.addFilterBefore(jwtVerifyFilter(), UsernamePasswordAuthenticationFilter.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class JwtVerifyFilter extends OncePerRequestFilter {
//Swagger
"/swagger-ui/index.html", "/swagger-ui/**", "/v3/api-docs/**", "/swagger-resources/**", "/v3/api-docs",
//비회원 전용 api
"/main/today","/main/season","model/ment"};
"/main/today","/main/season","/model/ment","/model/*/non"};
private final RedisUtil redisUtil;


Expand Down

0 comments on commit b32e3c3

Please sign in to comment.