From c5e00941b188ddf0b5758a640c723f0ac4aa7b84 Mon Sep 17 00:00:00 2001 From: Soyeon Cha <89539031+Soyeon-Cha@users.noreply.github.com> Date: Wed, 24 Jan 2024 19:33:59 +0900 Subject: [PATCH 01/87] =?UTF-8?q?chore:=20.gitignore=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index c2065bc..16cc330 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,7 @@ out/ ### VS Code ### .vscode/ + +### Application Settings ### +application.yml +*.env From 52980d13622801a9c8598c0bcc8fe7735b6e72be Mon Sep 17 00:00:00 2001 From: Soyeon Cha <89539031+Soyeon-Cha@users.noreply.github.com> Date: Wed, 24 Jan 2024 19:39:40 +0900 Subject: [PATCH 02/87] =?UTF-8?q?chore:=20.gitignore=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 16cc330..e28b249 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,5 @@ out/ ### Application Settings ### application.yml +application.properties *.env From 755803cb83d9bb4c5aff5c881f9a70b96c308a4a Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Wed, 24 Jan 2024 21:17:12 +0900 Subject: [PATCH 03/87] =?UTF-8?q?chore:=20application.properties=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.properties | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/main/resources/application.properties diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 8b13789..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - From 0a9e9139195567c4b716c8ce02a59a491662718a Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Wed, 24 Jan 2024 21:17:44 +0900 Subject: [PATCH 04/87] =?UTF-8?q?feat:=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Heart/domain/Heart.java | 33 ++++++++++++ .../CookSaveback/History/domain/History.java | 33 ++++++++++++ .../domain/HistoryIngredient.java | 36 +++++++++++++ .../CookSaveback/Icon/domain/Icon.java | 19 +++++++ .../Ingredient/domain/Ingredient.java | 52 +++++++++++++++++++ .../CookSaveback/Member/domain/Member.java | 29 +++++++++++ .../CookSaveback/Recipe/domain/Recipe.java | 31 +++++++++++ .../RecipeTag/domain/RecipeTag.java | 26 ++++++++++ .../CookSave/CookSaveback/Tag/domain/Tag.java | 19 +++++++ .../global/entity/BaseTimeEntity.java | 17 ++++++ 10 files changed, 295 insertions(+) create mode 100644 src/main/java/CookSave/CookSaveback/Heart/domain/Heart.java create mode 100644 src/main/java/CookSave/CookSaveback/History/domain/History.java create mode 100644 src/main/java/CookSave/CookSaveback/HistoryIngredient/domain/HistoryIngredient.java create mode 100644 src/main/java/CookSave/CookSaveback/Icon/domain/Icon.java create mode 100644 src/main/java/CookSave/CookSaveback/Ingredient/domain/Ingredient.java create mode 100644 src/main/java/CookSave/CookSaveback/Member/domain/Member.java create mode 100644 src/main/java/CookSave/CookSaveback/Recipe/domain/Recipe.java create mode 100644 src/main/java/CookSave/CookSaveback/RecipeTag/domain/RecipeTag.java create mode 100644 src/main/java/CookSave/CookSaveback/Tag/domain/Tag.java create mode 100644 src/main/java/CookSave/CookSaveback/global/entity/BaseTimeEntity.java diff --git a/src/main/java/CookSave/CookSaveback/Heart/domain/Heart.java b/src/main/java/CookSave/CookSaveback/Heart/domain/Heart.java new file mode 100644 index 0000000..9d2cc7b --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Heart/domain/Heart.java @@ -0,0 +1,33 @@ +package CookSave.CookSaveback.Heart.domain; + +import CookSave.CookSaveback.Member.domain.Member; +import CookSave.CookSaveback.Recipe.domain.Recipe; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Heart { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false, updatable = false) + private Long heartId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id", nullable = false) + private Member member; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "recipe_id", nullable = false) + private Recipe recipe; + + @Builder + public Heart(Member member, Recipe recipe){ + this.member = member; + this.recipe = recipe; + } +} diff --git a/src/main/java/CookSave/CookSaveback/History/domain/History.java b/src/main/java/CookSave/CookSaveback/History/domain/History.java new file mode 100644 index 0000000..3f9c8c2 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/History/domain/History.java @@ -0,0 +1,33 @@ +package CookSave.CookSaveback.History.domain; + +import CookSave.CookSaveback.Member.domain.Member; +import CookSave.CookSaveback.global.entity.BaseTimeEntity; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class History extends BaseTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false, updatable = false) + private Long historyId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id", nullable = false) + private Member member; + + @Column(nullable = false) + private String name; // 요리명 + + @Column(nullable = false) + private Integer total; // 사용한 재료값 총합 + + @Builder + public History(Member member, String name, Integer total){ + this.member = member; + this.name = name; + this.total = total; + } +} diff --git a/src/main/java/CookSave/CookSaveback/HistoryIngredient/domain/HistoryIngredient.java b/src/main/java/CookSave/CookSaveback/HistoryIngredient/domain/HistoryIngredient.java new file mode 100644 index 0000000..674f3b4 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/HistoryIngredient/domain/HistoryIngredient.java @@ -0,0 +1,36 @@ +package CookSave.CookSaveback.HistoryIngredient.domain; + +import CookSave.CookSaveback.History.domain.History; +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Getter @Setter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class HistoryIngredient { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false, updatable = false) + private Long historyIngId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "history_id", nullable = false) + private History history; + + @Column(nullable = false) + private String name; // 재료명 + + @Column(nullable = false) + private Float amount; + + @Column(nullable = false) + private Integer price; + + @Builder + public HistoryIngredient(History history, String name, Float amount, Integer price){ + this.history = history; + this.name = name; + this.amount = amount; + this.price = price; + } +} diff --git a/src/main/java/CookSave/CookSaveback/Icon/domain/Icon.java b/src/main/java/CookSave/CookSaveback/Icon/domain/Icon.java new file mode 100644 index 0000000..ce91c4d --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Icon/domain/Icon.java @@ -0,0 +1,19 @@ +package CookSave.CookSaveback.Icon.domain; + +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Icon { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false, updatable = false) + private Long iconId; + + @Column(nullable = false) + private String image; // 아이콘 이미지 URL +} diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/domain/Ingredient.java b/src/main/java/CookSave/CookSaveback/Ingredient/domain/Ingredient.java new file mode 100644 index 0000000..2e633f4 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Ingredient/domain/Ingredient.java @@ -0,0 +1,52 @@ +package CookSave.CookSaveback.Ingredient.domain; + +import CookSave.CookSaveback.Icon.domain.Icon; +import CookSave.CookSaveback.Member.domain.Member; +import CookSave.CookSaveback.Tag.domain.Tag; +import CookSave.CookSaveback.global.entity.BaseTimeEntity; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Ingredient extends BaseTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false, updatable = false) + private Long ingredientId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id", nullable = false) + private Member member; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "tag_id", nullable = false) + private Tag tag; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "icon_id", nullable = false) + private Icon icon; // 재료 아이콘 아이디 + + @Column(nullable = false) + private String name; // 재료명 + + @Column(nullable = false) + private Integer price; // 재료 한 개의 가격 + + @Column(nullable = false) + private Float amount; // 보유한 재료의 양 + + @Builder + public Ingredient(Member member, Tag tag, Icon icon, String name, Integer price, Float amount){ + this.member = member; + this.tag = tag; + this.icon = icon; + this.name = name; + this.price = price; + this.amount = amount; + } +} diff --git a/src/main/java/CookSave/CookSaveback/Member/domain/Member.java b/src/main/java/CookSave/CookSaveback/Member/domain/Member.java new file mode 100644 index 0000000..5211ed5 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Member/domain/Member.java @@ -0,0 +1,29 @@ +package CookSave.CookSaveback.Member.domain; + +import jakarta.persistence.*; +import lombok.*; + +@Entity +@Getter @Setter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Member { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false, updatable = false) + private Long memberId; + + @Column(nullable = false) + private String cooksaveId; + + @Column(nullable = false) + private String password; + + @Column + private Integer budget; // 사용자가 예산 설정하기 전까지 null 값 + + @Builder + public Member(String cooksaveId, String password){ + this.cooksaveId = cooksaveId; + this.password = password; + } +} diff --git a/src/main/java/CookSave/CookSaveback/Recipe/domain/Recipe.java b/src/main/java/CookSave/CookSaveback/Recipe/domain/Recipe.java new file mode 100644 index 0000000..2a0d354 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Recipe/domain/Recipe.java @@ -0,0 +1,31 @@ +package CookSave.CookSaveback.Recipe.domain; + +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Recipe { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false, updatable = false) + private Long recipeId; + + @Column(nullable = false) + private String name; // 요리 이름 + + @Column(nullable = false) + private String mainIng; // 주요 재료들 + + @Column(nullable = false) + private String content; // 레시피 내용 + + @Column + private String image; // 음식 사진 URL + + @Column + private String video; // 요리 영상 URL +} diff --git a/src/main/java/CookSave/CookSaveback/RecipeTag/domain/RecipeTag.java b/src/main/java/CookSave/CookSaveback/RecipeTag/domain/RecipeTag.java new file mode 100644 index 0000000..98aef17 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/RecipeTag/domain/RecipeTag.java @@ -0,0 +1,26 @@ +package CookSave.CookSaveback.RecipeTag.domain; + +import CookSave.CookSaveback.Recipe.domain.Recipe; +import CookSave.CookSaveback.Tag.domain.Tag; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class RecipeTag { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false, updatable = false) + private Integer recipeTagId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "recipe_id", nullable = false) + private Recipe recipe; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "tag_id", nullable = false) + private Tag tag; +} diff --git a/src/main/java/CookSave/CookSaveback/Tag/domain/Tag.java b/src/main/java/CookSave/CookSaveback/Tag/domain/Tag.java new file mode 100644 index 0000000..3e1a222 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Tag/domain/Tag.java @@ -0,0 +1,19 @@ +package CookSave.CookSaveback.Tag.domain; + +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class Tag { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(nullable = false, updatable = false) + private Integer tagId; + + @Column(nullable = false, length = 10) + private String name; +} diff --git a/src/main/java/CookSave/CookSaveback/global/entity/BaseTimeEntity.java b/src/main/java/CookSave/CookSaveback/global/entity/BaseTimeEntity.java new file mode 100644 index 0000000..cb1813e --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/global/entity/BaseTimeEntity.java @@ -0,0 +1,17 @@ +package CookSave.CookSaveback.global.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.EntityListeners; +import lombok.Getter; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.time.LocalDateTime; + +@Getter +@EntityListeners(AuditingEntityListener.class) +public class BaseTimeEntity { + @CreatedDate + @Column(updatable = false) + private LocalDateTime createdAt; +} From 7b842c3a22b2b0a83b08ae12275f6c12a2d1beb8 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Sun, 28 Jan 2024 13:38:09 +0900 Subject: [PATCH 05/87] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + .../Member/controller/MemberController.java | 22 +++++++ .../Member/dto/SignUpRequestDto.java | 13 ++++ .../Member/repository/MemberRepository.java | 11 ++++ .../Member/service/MemberService.java | 33 ++++++++++ .../CookSaveback/config/CORSConfig.java | 26 ++++++++ .../CookSaveback/config/EncoderConfig.java | 13 ++++ .../CookSaveback/config/JwtFilter.java | 60 +++++++++++++++++++ .../CookSaveback/config/SecurityConfig.java | 36 +++++++++++ .../CookSave/CookSaveback/utils/JwtUtil.java | 51 ++++++++++++++++ 10 files changed, 266 insertions(+) create mode 100644 src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java create mode 100644 src/main/java/CookSave/CookSaveback/Member/dto/SignUpRequestDto.java create mode 100644 src/main/java/CookSave/CookSaveback/Member/repository/MemberRepository.java create mode 100644 src/main/java/CookSave/CookSaveback/Member/service/MemberService.java create mode 100644 src/main/java/CookSave/CookSaveback/config/CORSConfig.java create mode 100644 src/main/java/CookSave/CookSaveback/config/EncoderConfig.java create mode 100644 src/main/java/CookSave/CookSaveback/config/JwtFilter.java create mode 100644 src/main/java/CookSave/CookSaveback/config/SecurityConfig.java create mode 100644 src/main/java/CookSave/CookSaveback/utils/JwtUtil.java diff --git a/build.gradle b/build.gradle index 6357db7..8e3140a 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'io.jsonwebtoken:jjwt:0.9.1' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' diff --git a/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java b/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java new file mode 100644 index 0000000..5bad69f --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java @@ -0,0 +1,22 @@ +package CookSave.CookSaveback.Member.controller; + +import CookSave.CookSaveback.Member.dto.SignUpRequestDto; +import CookSave.CookSaveback.Member.service.MemberService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/members") +public class MemberController { + private final MemberService memberService; + + @PostMapping("/signup") + public ResponseEntity signUp(@RequestBody SignUpRequestDto requestDto){ + return ResponseEntity.ok().body(memberService.signUp(requestDto.getCooksaveId(), requestDto.getPassword(), requestDto.getPasswordCheck())); + } +} diff --git a/src/main/java/CookSave/CookSaveback/Member/dto/SignUpRequestDto.java b/src/main/java/CookSave/CookSaveback/Member/dto/SignUpRequestDto.java new file mode 100644 index 0000000..eb6f4b8 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Member/dto/SignUpRequestDto.java @@ -0,0 +1,13 @@ +package CookSave.CookSaveback.Member.dto; + + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class SignUpRequestDto { + private String cooksaveId; + private String password; + private String passwordCheck; // 비밀번호 일치 확인을 위한 입력값 +} diff --git a/src/main/java/CookSave/CookSaveback/Member/repository/MemberRepository.java b/src/main/java/CookSave/CookSaveback/Member/repository/MemberRepository.java new file mode 100644 index 0000000..c864f24 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Member/repository/MemberRepository.java @@ -0,0 +1,11 @@ +package CookSave.CookSaveback.Member.repository; + +import CookSave.CookSaveback.Member.domain.Member; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface MemberRepository extends JpaRepository { + // 아이디 중복검사를 위한 메서드 + Boolean existsByCooksaveId(String cooksaveId); +} diff --git a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java new file mode 100644 index 0000000..1b6b95c --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java @@ -0,0 +1,33 @@ +package CookSave.CookSaveback.Member.service; + +import CookSave.CookSaveback.Member.domain.Member; +import CookSave.CookSaveback.Member.repository.MemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class MemberService { + private final MemberRepository memberRepository; + private final BCryptPasswordEncoder encoder; + + public String signUp(String cooksaveId, String password, String passwordCheck){ + if(existsByCooksaveId(cooksaveId)) throw new RuntimeException(cooksaveId + "은 이미 존재하는 아이디입니다."); + // else if (!(Objects.equals(password, passwordCheck))) throw new RuntimeException("비밀번호가 일치하지 않습니다."); + + memberRepository.save( + Member.builder() + .cooksaveId(cooksaveId) + .password(encoder.encode(password)) + .build() + ); + return "회원가입이 완료되었습니다."; + } + + @Transactional(readOnly = true) + public boolean existsByCooksaveId(String cooksaveId){ + return memberRepository.existsByCooksaveId(cooksaveId); + } +} diff --git a/src/main/java/CookSave/CookSaveback/config/CORSConfig.java b/src/main/java/CookSave/CookSaveback/config/CORSConfig.java new file mode 100644 index 0000000..918add8 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/config/CORSConfig.java @@ -0,0 +1,26 @@ +package CookSave.CookSaveback.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +@Configuration +public class CORSConfig { + @Bean + public CorsFilter corsFilter(){ + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration config = new CorsConfiguration(); + config.setAllowCredentials(true); + config.addAllowedOrigin("https://www.cooksave.com"); + config.addAllowedOrigin("http://localhost:3000"); + config.addAllowedHeader("*"); + config.addAllowedMethod("*"); + config.setMaxAge(3600L); + config.addExposedHeader("Location"); + config.addExposedHeader("Authorization"); + source.registerCorsConfiguration("/**", config); + return new CorsFilter(source); + } +} diff --git a/src/main/java/CookSave/CookSaveback/config/EncoderConfig.java b/src/main/java/CookSave/CookSaveback/config/EncoderConfig.java new file mode 100644 index 0000000..d27a11c --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/config/EncoderConfig.java @@ -0,0 +1,13 @@ +package CookSave.CookSaveback.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +@Configuration +public class EncoderConfig { + @Bean + public BCryptPasswordEncoder encoder(){ + return new BCryptPasswordEncoder(); + } +} diff --git a/src/main/java/CookSave/CookSaveback/config/JwtFilter.java b/src/main/java/CookSave/CookSaveback/config/JwtFilter.java new file mode 100644 index 0000000..8bac5a7 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/config/JwtFilter.java @@ -0,0 +1,60 @@ +package CookSave.CookSaveback.config; + +import CookSave.CookSaveback.utils.JwtUtil; +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpHeaders; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; +import org.springframework.web.filter.OncePerRequestFilter; + +import java.io.IOException; +import java.util.List; + +@Slf4j +@RequiredArgsConstructor +public class JwtFilter extends OncePerRequestFilter { + private final String secretKey; + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException{ + // header에서 token 가져오기 + final String authorization = request.getHeader(HttpHeaders.AUTHORIZATION); + log.info("authorization: {}", authorization); + + // token이 null이 아닌지, Bearer 로 시작하는지 확인 + if(authorization == null || !authorization.startsWith("Bearer ")){ + log.error("올바르지 않은 authorization입니다."); + filterChain.doFilter(request, response); + return; + } + + // token에서 Bearer 떼어내서 token만 남기기 + String token = authorization.split(" ")[1]; // authorization의 두 번째 단어 + + //token이 expire 되었는지 확인 + if(JwtUtil.isExpired(token, secretKey)){ + log.error("토큰이 만료되었습니다."); + filterChain.doFilter(request, response); + return; + } + + // token에서 cooksaveId 꺼내기 + String cooksaveId = JwtUtil.getCooksaveId(token, secretKey); + log.info("cooksaveId:{}", cooksaveId); + + // 권한 부여하기 + UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(cooksaveId, null, List.of(new SimpleGrantedAuthority("USER"))); + + // Detail 넣기 + authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); + SecurityContextHolder.getContext().setAuthentication(authenticationToken); + filterChain.doFilter(request, response); + } +} diff --git a/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java b/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java new file mode 100644 index 0000000..36e0bb6 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java @@ -0,0 +1,36 @@ +package CookSave.CookSaveback.config; + +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; +import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer; +import org.springframework.security.config.annotation.web.configurers.HttpBasicConfigurer; +import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; + +@Configuration +@EnableWebSecurity +@RequiredArgsConstructor +public class SecurityConfig { + @Value("${spring.jwt.secret-key}") + private String secretKey; + + @Bean + public SecurityFilterChain securityFilterChain (HttpSecurity httpSecurity) throws Exception { + return httpSecurity.httpBasic(HttpBasicConfigurer::disable) + .csrf(CsrfConfigurer::disable) + .cors(AbstractHttpConfigurer::disable) + .authorizeHttpRequests(authorize -> authorize + .requestMatchers("/members/signup", "/members/login", "/members/refreshtoken").permitAll() // 회원가입, 로그인은 무조건 허용 + .requestMatchers(HttpMethod.POST, "/members/**").authenticated()) // 모든 POST 요청과, /members/로 시작하는 다른 URI의 모든 요청은 인증 요구 + .sessionManagement(configurer -> configurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) // JWT를 사용하므로 stateless + .addFilterBefore(new JwtFilter(secretKey), UsernamePasswordAuthenticationFilter.class) + .build(); + } +} diff --git a/src/main/java/CookSave/CookSaveback/utils/JwtUtil.java b/src/main/java/CookSave/CookSaveback/utils/JwtUtil.java new file mode 100644 index 0000000..dcb3e46 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/utils/JwtUtil.java @@ -0,0 +1,51 @@ +package CookSave.CookSaveback.utils; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; + +import java.util.Date; + +public class JwtUtil { + // token이 expire 되었으면 true를 리턴하는 함수 + public static boolean isExpired(String token, String secretKey){ + return Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token) + .getBody().getExpiration().before(new Date()); + } + + // token에서 cooksaveId를 꺼내어 리턴하는 함수 + public static String getCooksaveId(String token, String secretKey) { + return Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token) + .getBody().get("cooksavdId", String.class); + } + + // token을 만드는 함수. createAccessToken과 createRefreshToken이 이 함수를 호출. + public static String createToken(String cooksaveId, String key, long expireTimeMs) { + Claims claims = Jwts.claims(); // 일종의 Map. 토큰 생성에 필요한 데이터를 담아두는 공간. + claims.put("cooksaveId", cooksaveId); // 아이디를 저장 + + return Jwts.builder() + .setClaims(claims) + .setIssuedAt(new Date(System.currentTimeMillis())) // 발행 시각 + .setExpiration(new Date(System.currentTimeMillis() + expireTimeMs)) // 만료 시각 + .signWith(SignatureAlgorithm.HS256, key) // HS256이라는 알고리즘과 주어진 key를 이용해 암호화 + .compact(); + } + + // AccessToken을 만드는 함수 + public static String createAccessToken(String cooksaveId, String key, long expireTimeMs) { + return createToken(cooksaveId, key, expireTimeMs); + } + + // RefreshToken을 만드는 함수 + public static String createRefreshToken (String cooksaveId, String key, long expireTimeMs) { + return createToken(cooksaveId, key, expireTimeMs); + } + + public static Claims parseRefreshToken(String value, String key) { + return Jwts.parser() + .setSigningKey(key) + .parseClaimsJws(value) + .getBody(); + } +} From 55e392a5fd1da3097d0981559008ab73d19debd7 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Sun, 28 Jan 2024 15:51:41 +0900 Subject: [PATCH 06/87] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + .../Member/controller/MemberController.java | 9 ++++ .../Member/domain/RefreshToken.java | 23 ++++++++ .../Member/dto/LoginRequestDto.java | 11 ++++ .../Member/dto/LoginResponseDto.java | 23 ++++++++ .../Member/repository/MemberRepository.java | 4 ++ .../repository/RefreshTokenRepository.java | 11 ++++ .../Member/service/MemberService.java | 53 ++++++++++++++++++- .../Member/service/RefreshTokenService.java | 16 ++++++ 9 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 src/main/java/CookSave/CookSaveback/Member/domain/RefreshToken.java create mode 100644 src/main/java/CookSave/CookSaveback/Member/dto/LoginRequestDto.java create mode 100644 src/main/java/CookSave/CookSaveback/Member/dto/LoginResponseDto.java create mode 100644 src/main/java/CookSave/CookSaveback/Member/repository/RefreshTokenRepository.java create mode 100644 src/main/java/CookSave/CookSaveback/Member/service/RefreshTokenService.java diff --git a/build.gradle b/build.gradle index 8e3140a..ddea179 100644 --- a/build.gradle +++ b/build.gradle @@ -27,6 +27,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'io.jsonwebtoken:jjwt:0.9.1' + implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' diff --git a/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java b/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java index 5bad69f..10a5787 100644 --- a/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java +++ b/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java @@ -1,5 +1,7 @@ package CookSave.CookSaveback.Member.controller; +import CookSave.CookSaveback.Member.dto.LoginRequestDto; +import CookSave.CookSaveback.Member.dto.LoginResponseDto; import CookSave.CookSaveback.Member.dto.SignUpRequestDto; import CookSave.CookSaveback.Member.service.MemberService; import lombok.RequiredArgsConstructor; @@ -19,4 +21,11 @@ public class MemberController { public ResponseEntity signUp(@RequestBody SignUpRequestDto requestDto){ return ResponseEntity.ok().body(memberService.signUp(requestDto.getCooksaveId(), requestDto.getPassword(), requestDto.getPasswordCheck())); } + + // 로그인 + // 성공적으로 로그인한 경우, 회원의 아이디, AccessToken 값, RefreshToken 값을 담은 DTO를 응답함 + @PostMapping("/login") + public LoginResponseDto login(@RequestBody LoginRequestDto requestDto){ + return memberService.login(requestDto.getCooksaveId(), requestDto.getPassword()); + } } diff --git a/src/main/java/CookSave/CookSaveback/Member/domain/RefreshToken.java b/src/main/java/CookSave/CookSaveback/Member/domain/RefreshToken.java new file mode 100644 index 0000000..12d783c --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Member/domain/RefreshToken.java @@ -0,0 +1,23 @@ +package CookSave.CookSaveback.Member.domain; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Entity +@Getter @Setter +@NoArgsConstructor +public class RefreshToken { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long refreshTokenId; + + // 토큰의 주인인 member의 고유 키 + @Column(nullable = false) + private Long memberId; + + // 토큰의 값 + @Column(nullable = false) + private String value; +} diff --git a/src/main/java/CookSave/CookSaveback/Member/dto/LoginRequestDto.java b/src/main/java/CookSave/CookSaveback/Member/dto/LoginRequestDto.java new file mode 100644 index 0000000..d293424 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Member/dto/LoginRequestDto.java @@ -0,0 +1,11 @@ +package CookSave.CookSaveback.Member.dto; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class LoginRequestDto { + private String cooksaveId; + private String password; +} diff --git a/src/main/java/CookSave/CookSaveback/Member/dto/LoginResponseDto.java b/src/main/java/CookSave/CookSaveback/Member/dto/LoginResponseDto.java new file mode 100644 index 0000000..8572aa0 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Member/dto/LoginResponseDto.java @@ -0,0 +1,23 @@ +package CookSave.CookSaveback.Member.dto; + +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class LoginResponseDto { + private Long memberId; + private String cooksaveId; + private String accessToken; + private String refreshToken; + + @Builder + public LoginResponseDto(Long memberId, String cooksaveId, String accessToken, String refreshToken){ + this.memberId = memberId; + this.cooksaveId = cooksaveId; + this.accessToken = accessToken; + this.refreshToken = refreshToken; + } +} diff --git a/src/main/java/CookSave/CookSaveback/Member/repository/MemberRepository.java b/src/main/java/CookSave/CookSaveback/Member/repository/MemberRepository.java index c864f24..483336b 100644 --- a/src/main/java/CookSave/CookSaveback/Member/repository/MemberRepository.java +++ b/src/main/java/CookSave/CookSaveback/Member/repository/MemberRepository.java @@ -4,8 +4,12 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.Optional; + @Repository public interface MemberRepository extends JpaRepository { // 아이디 중복검사를 위한 메서드 Boolean existsByCooksaveId(String cooksaveId); + + Optional findByCooksaveId(String cooksaveId); } diff --git a/src/main/java/CookSave/CookSaveback/Member/repository/RefreshTokenRepository.java b/src/main/java/CookSave/CookSaveback/Member/repository/RefreshTokenRepository.java new file mode 100644 index 0000000..bae2253 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Member/repository/RefreshTokenRepository.java @@ -0,0 +1,11 @@ +package CookSave.CookSaveback.Member.repository; + +import CookSave.CookSaveback.Member.domain.RefreshToken; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface RefreshTokenRepository extends JpaRepository { +} diff --git a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java index 1b6b95c..c23b55b 100644 --- a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java +++ b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java @@ -1,8 +1,13 @@ package CookSave.CookSaveback.Member.service; import CookSave.CookSaveback.Member.domain.Member; +import CookSave.CookSaveback.Member.domain.RefreshToken; +import CookSave.CookSaveback.Member.dto.LoginResponseDto; import CookSave.CookSaveback.Member.repository.MemberRepository; +import CookSave.CookSaveback.utils.JwtUtil; +import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -12,6 +17,19 @@ public class MemberService { private final MemberRepository memberRepository; private final BCryptPasswordEncoder encoder; + private final RefreshTokenService refreshTokenService; + + @Value("${spring.jwt.secret-key}") + private String accessKey; + + @Value("${spring.jwt.refresh-key}") + private String refreshKey; + + // Access 토큰 만료 시간을 1시간으로 설정 + private Long AccessExpireTimeMs = 1000 * 60 * 60L; + + // Refresh 토큰 만료 시간을 7일로 설정 + private Long RefreshExpireTimeMs = 7 * 24 * 1000 * 60 * 60L; public String signUp(String cooksaveId, String password, String passwordCheck){ if(existsByCooksaveId(cooksaveId)) throw new RuntimeException(cooksaveId + "은 이미 존재하는 아이디입니다."); @@ -24,10 +42,43 @@ public String signUp(String cooksaveId, String password, String passwordCheck){ .build() ); return "회원가입이 완료되었습니다."; - } + } + + // 로그인 + public LoginResponseDto login(String cooksaveId, String password){ + // 존재하지 않는 아이디로 로그인을 시도한 경우를 캐치 + Member member = findMemberByCooksaveId(cooksaveId); + + // 존재하는 아이디를 입력했지만 잘못된 비밀번호를 입력한 경우를 캐치 + if(!encoder.matches(password, member.getPassword())) throw new RuntimeException("잘못된 비밀번호를 입력했습니다."); + // 로그인 성공 -> 토큰 생성 + String accessToken = JwtUtil.createAccessToken(member.getCooksaveId(), accessKey, AccessExpireTimeMs); + String refreshToken = JwtUtil.createRefreshToken(member.getCooksaveId(), refreshKey, RefreshExpireTimeMs); + + RefreshToken refreshTokenEntity = new RefreshToken(); + refreshTokenEntity.setMemberId(member.getMemberId()); + refreshTokenEntity.setValue(refreshToken); + refreshTokenService.addRefreshToken(refreshTokenEntity); + + return LoginResponseDto.builder() + .memberId(member.getMemberId()) + .cooksaveId(member.getCooksaveId()) + .accessToken(accessToken) + .refreshToken(refreshToken) + .build(); + } + + // 회원 가입 시 입력한 아이디를 가진 member 존재 여부 확인 @Transactional(readOnly = true) public boolean existsByCooksaveId(String cooksaveId){ return memberRepository.existsByCooksaveId(cooksaveId); } + + // 아이디로 member 찾기 + @Transactional(readOnly = true) + public Member findMemberByCooksaveId(String cooksaveId){ + return memberRepository.findByCooksaveId(cooksaveId) + .orElseThrow(() -> new EntityNotFoundException("아이디가 " + cooksaveId + "인 회원이 존재하지 않습니다.")); + } } diff --git a/src/main/java/CookSave/CookSaveback/Member/service/RefreshTokenService.java b/src/main/java/CookSave/CookSaveback/Member/service/RefreshTokenService.java new file mode 100644 index 0000000..6b0c52e --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Member/service/RefreshTokenService.java @@ -0,0 +1,16 @@ +package CookSave.CookSaveback.Member.service; + +import CookSave.CookSaveback.Member.domain.RefreshToken; +import CookSave.CookSaveback.Member.repository.RefreshTokenRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class RefreshTokenService { + private final RefreshTokenRepository refreshTokenRepository; + + public void addRefreshToken(RefreshToken refreshToken){ + refreshTokenRepository.save(refreshToken); + } +} From 3c50c06b4ac8e1a4f80d0a4d978fbe0bf18bfa6e Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Mon, 5 Feb 2024 16:27:18 +0900 Subject: [PATCH 07/87] =?UTF-8?q?feat:=20=ED=86=A0=ED=81=B0=20=EB=A6=AC?= =?UTF-8?q?=ED=94=84=EB=A0=88=EC=8B=9C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Member/controller/MemberController.java | 6 ++++ .../Member/dto/RefreshRequestDto.java | 10 +++++++ .../repository/RefreshTokenRepository.java | 1 + .../Member/service/MemberService.java | 28 +++++++++++++++++++ .../Member/service/RefreshTokenService.java | 8 ++++++ 5 files changed, 53 insertions(+) create mode 100644 src/main/java/CookSave/CookSaveback/Member/dto/RefreshRequestDto.java diff --git a/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java b/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java index 10a5787..e736d70 100644 --- a/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java +++ b/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java @@ -2,6 +2,7 @@ import CookSave.CookSaveback.Member.dto.LoginRequestDto; import CookSave.CookSaveback.Member.dto.LoginResponseDto; +import CookSave.CookSaveback.Member.dto.RefreshRequestDto; import CookSave.CookSaveback.Member.dto.SignUpRequestDto; import CookSave.CookSaveback.Member.service.MemberService; import lombok.RequiredArgsConstructor; @@ -28,4 +29,9 @@ public ResponseEntity signUp(@RequestBody SignUpRequestDto requestDto){ public LoginResponseDto login(@RequestBody LoginRequestDto requestDto){ return memberService.login(requestDto.getCooksaveId(), requestDto.getPassword()); } + + @PostMapping("/refresh") + public LoginResponseDto refresh(@RequestBody RefreshRequestDto refreshRequestDto){ + return memberService.refresh(refreshRequestDto.getRefreshToken()); + } } diff --git a/src/main/java/CookSave/CookSaveback/Member/dto/RefreshRequestDto.java b/src/main/java/CookSave/CookSaveback/Member/dto/RefreshRequestDto.java new file mode 100644 index 0000000..063c826 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Member/dto/RefreshRequestDto.java @@ -0,0 +1,10 @@ +package CookSave.CookSaveback.Member.dto; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class RefreshRequestDto { + private String refreshToken; +} diff --git a/src/main/java/CookSave/CookSaveback/Member/repository/RefreshTokenRepository.java b/src/main/java/CookSave/CookSaveback/Member/repository/RefreshTokenRepository.java index bae2253..28998f2 100644 --- a/src/main/java/CookSave/CookSaveback/Member/repository/RefreshTokenRepository.java +++ b/src/main/java/CookSave/CookSaveback/Member/repository/RefreshTokenRepository.java @@ -8,4 +8,5 @@ @Repository public interface RefreshTokenRepository extends JpaRepository { + Optional findByValue(String value); } diff --git a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java index c23b55b..4cdfef1 100644 --- a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java +++ b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java @@ -5,6 +5,7 @@ import CookSave.CookSaveback.Member.dto.LoginResponseDto; import CookSave.CookSaveback.Member.repository.MemberRepository; import CookSave.CookSaveback.utils.JwtUtil; +import io.jsonwebtoken.Claims; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; @@ -69,6 +70,33 @@ public LoginResponseDto login(String cooksaveId, String password){ .build(); } + // 재발급 구현은 다 했는데 아직 포스트맨 테스트 안 했음 + // 코드 중간중간에 주석 아직 안 달았음 + public LoginResponseDto refresh(String refreshTokenValue){ + // 해당 RefreshToken이 유효한지 DB에서 탐색 + RefreshToken refreshToken = refreshTokenService.findRefreshToken(refreshTokenValue); + + // RefreshToken에 담긴 cooksaveId 값 가져오기 + Claims claims = JwtUtil.parseRefreshToken(refreshToken.getValue(), refreshKey); + String cooksaveId = claims.get("cooksaveId").toString(); + System.out.println("RefreshToken에 담긴 아이디 : " + cooksaveId); + + // 가져온 cooksaveId에 해당하는 member가 존재하는지 확인 + Member member = findMemberByCooksaveId(cooksaveId); + + // 새 AccessToken 생성 + String accessToken = JwtUtil.createAccessToken(member.getCooksaveId(), accessKey, AccessExpireTimeMs); + + // 새 AccessToken과 기존 RefreshToken을 DTO에 담아 리턴 + return LoginResponseDto + .builder() + .memberId(member.getMemberId()) + .cooksaveId(member.getCooksaveId()) + .accessToken(accessToken) + .refreshToken(refreshTokenValue) + .build(); + } + // 회원 가입 시 입력한 아이디를 가진 member 존재 여부 확인 @Transactional(readOnly = true) public boolean existsByCooksaveId(String cooksaveId){ diff --git a/src/main/java/CookSave/CookSaveback/Member/service/RefreshTokenService.java b/src/main/java/CookSave/CookSaveback/Member/service/RefreshTokenService.java index 6b0c52e..96c7773 100644 --- a/src/main/java/CookSave/CookSaveback/Member/service/RefreshTokenService.java +++ b/src/main/java/CookSave/CookSaveback/Member/service/RefreshTokenService.java @@ -2,8 +2,10 @@ import CookSave.CookSaveback.Member.domain.RefreshToken; import CookSave.CookSaveback.Member.repository.RefreshTokenRepository; +import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor @@ -13,4 +15,10 @@ public class RefreshTokenService { public void addRefreshToken(RefreshToken refreshToken){ refreshTokenRepository.save(refreshToken); } + + @Transactional(readOnly = true) + public RefreshToken findRefreshToken(String refreshTokenValue){ + return refreshTokenRepository.findByValue(refreshTokenValue) + .orElseThrow(() -> new EntityNotFoundException("존재하지 않는 RefreshToken입니다.")); + } } From c3f6da59515ab6b10b7a86cfda3cec5e2c459efe Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Mon, 5 Feb 2024 16:33:04 +0900 Subject: [PATCH 08/87] =?UTF-8?q?chore:=20MemberController=EC=97=90=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=ED=91=9C=EC=8B=9C=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Member/controller/MemberController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java b/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java index e736d70..ff7be68 100644 --- a/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java +++ b/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java @@ -18,6 +18,7 @@ public class MemberController { private final MemberService memberService; + // 회원가입 @PostMapping("/signup") public ResponseEntity signUp(@RequestBody SignUpRequestDto requestDto){ return ResponseEntity.ok().body(memberService.signUp(requestDto.getCooksaveId(), requestDto.getPassword(), requestDto.getPasswordCheck())); @@ -30,6 +31,7 @@ public LoginResponseDto login(@RequestBody LoginRequestDto requestDto){ return memberService.login(requestDto.getCooksaveId(), requestDto.getPassword()); } + // RefreshToken을 이용해 새 AccessToken 발급 요청 @PostMapping("/refresh") public LoginResponseDto refresh(@RequestBody RefreshRequestDto refreshRequestDto){ return memberService.refresh(refreshRequestDto.getRefreshToken()); From 6a5642811497c2b65cec8e51540458f78e1b8441 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Thu, 15 Feb 2024 16:59:21 +0900 Subject: [PATCH 09/87] =?UTF-8?q?fix:=20=ED=86=A0=ED=81=B0=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=95=84=EC=9D=B4=EB=94=94=20=EA=BA=BC=EB=82=B4?= =?UTF-8?q?=EC=84=9C=20=EB=A6=AC=ED=84=B4=ED=95=98=EB=8A=94=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/CookSave/CookSaveback/utils/JwtUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/utils/JwtUtil.java b/src/main/java/CookSave/CookSaveback/utils/JwtUtil.java index dcb3e46..8fdcf40 100644 --- a/src/main/java/CookSave/CookSaveback/utils/JwtUtil.java +++ b/src/main/java/CookSave/CookSaveback/utils/JwtUtil.java @@ -16,7 +16,7 @@ public static boolean isExpired(String token, String secretKey){ // token에서 cooksaveId를 꺼내어 리턴하는 함수 public static String getCooksaveId(String token, String secretKey) { return Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token) - .getBody().get("cooksavdId", String.class); + .getBody().get("cooksaveId", String.class); } // token을 만드는 함수. createAccessToken과 createRefreshToken이 이 함수를 호출. From 84877de9271ef5bdbbabfa83dbd3945be1464ba6 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Sun, 18 Feb 2024 20:14:02 +0900 Subject: [PATCH 10/87] =?UTF-8?q?fix:=20=EC=9D=B8=EC=A6=9D=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/CookSave/CookSaveback/config/SecurityConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java b/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java index 36e0bb6..3ad46e9 100644 --- a/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java +++ b/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java @@ -26,9 +26,9 @@ public SecurityFilterChain securityFilterChain (HttpSecurity httpSecurity) throw return httpSecurity.httpBasic(HttpBasicConfigurer::disable) .csrf(CsrfConfigurer::disable) .cors(AbstractHttpConfigurer::disable) - .authorizeHttpRequests(authorize -> authorize + .authorizeHttpRequests(request -> request .requestMatchers("/members/signup", "/members/login", "/members/refreshtoken").permitAll() // 회원가입, 로그인은 무조건 허용 - .requestMatchers(HttpMethod.POST, "/members/**").authenticated()) // 모든 POST 요청과, /members/로 시작하는 다른 URI의 모든 요청은 인증 요구 + .anyRequest().authenticated()) .sessionManagement(configurer -> configurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) // JWT를 사용하므로 stateless .addFilterBefore(new JwtFilter(secretKey), UsernamePasswordAuthenticationFilter.class) .build(); From 200a097a71ce1ef4ba8520f95ef2a58b417000ed Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Sun, 18 Feb 2024 20:23:25 +0900 Subject: [PATCH 11/87] =?UTF-8?q?feat:=20=EB=A1=9C=EA=B7=B8=EC=95=84?= =?UTF-8?q?=EC=9B=83=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Member/controller/MemberController.java | 15 +++++++++++---- .../Member/service/RefreshTokenService.java | 6 ++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java b/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java index ff7be68..40ecbab 100644 --- a/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java +++ b/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java @@ -5,18 +5,17 @@ import CookSave.CookSaveback.Member.dto.RefreshRequestDto; import CookSave.CookSaveback.Member.dto.SignUpRequestDto; import CookSave.CookSaveback.Member.service.MemberService; +import CookSave.CookSaveback.Member.service.RefreshTokenService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor @RequestMapping("/members") public class MemberController { private final MemberService memberService; + private final RefreshTokenService refreshTokenService; // 회원가입 @PostMapping("/signup") @@ -36,4 +35,12 @@ public LoginResponseDto login(@RequestBody LoginRequestDto requestDto){ public LoginResponseDto refresh(@RequestBody RefreshRequestDto refreshRequestDto){ return memberService.refresh(refreshRequestDto.getRefreshToken()); } + + // 로그아웃 + // 전달받은 RefreshToken을 DB에서 삭제 + @DeleteMapping("/logout") + public String logout(@RequestBody RefreshRequestDto refreshRequestDto) { + refreshTokenService.deleteRefreshToken(refreshRequestDto.getRefreshToken()); + return "로그아웃되었습니다."; + } } diff --git a/src/main/java/CookSave/CookSaveback/Member/service/RefreshTokenService.java b/src/main/java/CookSave/CookSaveback/Member/service/RefreshTokenService.java index 96c7773..078de94 100644 --- a/src/main/java/CookSave/CookSaveback/Member/service/RefreshTokenService.java +++ b/src/main/java/CookSave/CookSaveback/Member/service/RefreshTokenService.java @@ -21,4 +21,10 @@ public RefreshToken findRefreshToken(String refreshTokenValue){ return refreshTokenRepository.findByValue(refreshTokenValue) .orElseThrow(() -> new EntityNotFoundException("존재하지 않는 RefreshToken입니다.")); } + + public void deleteRefreshToken(String refreshTokenValue){ + RefreshToken refreshToken = refreshTokenRepository.findByValue(refreshTokenValue) + .orElseThrow(() -> new EntityNotFoundException("존재하지 않는 RefreshToken입니다.")); + refreshTokenRepository.delete(refreshToken); + } } From e63f35252e02216df42e3928625838f01166ac01 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Sun, 18 Feb 2024 20:25:49 +0900 Subject: [PATCH 12/87] =?UTF-8?q?style:=20=EC=82=AC=EC=9A=A9=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/CookSave/CookSaveback/config/SecurityConfig.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java b/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java index 3ad46e9..7fa67d8 100644 --- a/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java +++ b/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java @@ -4,7 +4,6 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpMethod; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; From 1ffdbf39782604fadf73bb78a374844bd6458358 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Sun, 18 Feb 2024 20:52:00 +0900 Subject: [PATCH 13/87] =?UTF-8?q?style:=20=EC=A3=BC=EC=84=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSave/CookSaveback/Member/service/MemberService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java index 4cdfef1..3ea1145 100644 --- a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java +++ b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java @@ -70,8 +70,6 @@ public LoginResponseDto login(String cooksaveId, String password){ .build(); } - // 재발급 구현은 다 했는데 아직 포스트맨 테스트 안 했음 - // 코드 중간중간에 주석 아직 안 달았음 public LoginResponseDto refresh(String refreshTokenValue){ // 해당 RefreshToken이 유효한지 DB에서 탐색 RefreshToken refreshToken = refreshTokenService.findRefreshToken(refreshTokenValue); From 22c5ee6dd2418a75cd23b7d9bcad340754df5b73 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Sun, 18 Feb 2024 21:06:24 +0900 Subject: [PATCH 14/87] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=ED=83=88?= =?UTF-8?q?=ED=87=B4=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Member/controller/MemberController.java | 6 +++++ .../Member/service/MemberService.java | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java b/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java index 40ecbab..271fe38 100644 --- a/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java +++ b/src/main/java/CookSave/CookSaveback/Member/controller/MemberController.java @@ -8,6 +8,7 @@ import CookSave.CookSaveback.Member.service.RefreshTokenService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.*; @RestController @@ -43,4 +44,9 @@ public String logout(@RequestBody RefreshRequestDto refreshRequestDto) { refreshTokenService.deleteRefreshToken(refreshRequestDto.getRefreshToken()); return "로그아웃되었습니다."; } + + @DeleteMapping("/delete") + public ResponseEntity deleteMember(Authentication authentication){ + return ResponseEntity.ok().body(memberService.delete(authentication)); + } } diff --git a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java index 3ea1145..df39183 100644 --- a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java +++ b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java @@ -9,9 +9,13 @@ import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.server.ResponseStatusException; @Service @RequiredArgsConstructor @@ -32,6 +36,7 @@ public class MemberService { // Refresh 토큰 만료 시간을 7일로 설정 private Long RefreshExpireTimeMs = 7 * 24 * 1000 * 60 * 60L; + // 회원가입 public String signUp(String cooksaveId, String password, String passwordCheck){ if(existsByCooksaveId(cooksaveId)) throw new RuntimeException(cooksaveId + "은 이미 존재하는 아이디입니다."); // else if (!(Objects.equals(password, passwordCheck))) throw new RuntimeException("비밀번호가 일치하지 않습니다."); @@ -70,6 +75,7 @@ public LoginResponseDto login(String cooksaveId, String password){ .build(); } + // AccessToken 재발급 public LoginResponseDto refresh(String refreshTokenValue){ // 해당 RefreshToken이 유효한지 DB에서 탐색 RefreshToken refreshToken = refreshTokenService.findRefreshToken(refreshTokenValue); @@ -95,6 +101,13 @@ public LoginResponseDto refresh(String refreshTokenValue){ .build(); } + // 회원탈퇴 + public String delete(Authentication authentication){ + Member member = getLoginMember(); + memberRepository.delete(member); + return "회원탈퇴가 완료되었습니다."; + } + // 회원 가입 시 입력한 아이디를 가진 member 존재 여부 확인 @Transactional(readOnly = true) public boolean existsByCooksaveId(String cooksaveId){ @@ -107,4 +120,13 @@ public Member findMemberByCooksaveId(String cooksaveId){ return memberRepository.findByCooksaveId(cooksaveId) .orElseThrow(() -> new EntityNotFoundException("아이디가 " + cooksaveId + "인 회원이 존재하지 않습니다.")); } + + // 현재 로그인한 member 불러오기 + public Member getLoginMember(){ + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + String cooksaveId = authentication.getName(); + System.out.println(cooksaveId + "getName에서 나온 거"); + return memberRepository.findByCooksaveId(cooksaveId) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.FORBIDDEN, "인증된 회원 정보가 없습니다.")); + } } From da1f0486d9d016a6431d3b8479fe20a67eb9dcff Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Sun, 18 Feb 2024 21:20:23 +0900 Subject: [PATCH 15/87] =?UTF-8?q?style:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/CookSave/CookSaveback/Member/service/MemberService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java index df39183..68d393c 100644 --- a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java +++ b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java @@ -125,7 +125,6 @@ public Member findMemberByCooksaveId(String cooksaveId){ public Member getLoginMember(){ Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String cooksaveId = authentication.getName(); - System.out.println(cooksaveId + "getName에서 나온 거"); return memberRepository.findByCooksaveId(cooksaveId) .orElseThrow(() -> new ResponseStatusException(HttpStatus.FORBIDDEN, "인증된 회원 정보가 없습니다.")); } From 20649fd2088fb120c389147bda62cc7fbc500803 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Sun, 18 Feb 2024 21:43:41 +0900 Subject: [PATCH 16/87] =?UTF-8?q?fix:=20=EC=9E=AC=EB=A3=8C=20=EC=A7=81?= =?UTF-8?q?=EC=A0=91=20=EB=93=B1=EB=A1=9D=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Icon/domain/Icon.java | 2 +- .../Icon/repository/IconRepository.java | 9 ++++ .../controller/IngredientController.java | 28 ++++++++++++ .../Ingredient/domain/Ingredient.java | 2 +- .../Ingredient/dto/IngredientRequestDto.java | 14 ++++++ .../repository/IngredientRepository.java | 9 ++++ .../Ingredient/service/IngredientService.java | 44 +++++++++++++++++++ 7 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 src/main/java/CookSave/CookSaveback/Icon/repository/IconRepository.java create mode 100644 src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java create mode 100644 src/main/java/CookSave/CookSaveback/Ingredient/dto/IngredientRequestDto.java create mode 100644 src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java create mode 100644 src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java diff --git a/src/main/java/CookSave/CookSaveback/Icon/domain/Icon.java b/src/main/java/CookSave/CookSaveback/Icon/domain/Icon.java index ce91c4d..be4f355 100644 --- a/src/main/java/CookSave/CookSaveback/Icon/domain/Icon.java +++ b/src/main/java/CookSave/CookSaveback/Icon/domain/Icon.java @@ -12,7 +12,7 @@ public class Icon { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(nullable = false, updatable = false) - private Long iconId; + private Integer iconId; @Column(nullable = false) private String image; // 아이콘 이미지 URL diff --git a/src/main/java/CookSave/CookSaveback/Icon/repository/IconRepository.java b/src/main/java/CookSave/CookSaveback/Icon/repository/IconRepository.java new file mode 100644 index 0000000..cc31867 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Icon/repository/IconRepository.java @@ -0,0 +1,9 @@ +package CookSave.CookSaveback.Icon.repository; + +import CookSave.CookSaveback.Icon.domain.Icon; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface IconRepository extends JpaRepository { +} diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java new file mode 100644 index 0000000..8d4f475 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java @@ -0,0 +1,28 @@ +package CookSave.CookSaveback.Ingredient.controller; + +import CookSave.CookSaveback.Ingredient.dto.IngredientRequestDto; +import CookSave.CookSaveback.Ingredient.service.IngredientService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Slf4j +@RestController +@RequiredArgsConstructor +@RequestMapping("/ingredients") +public class IngredientController { + private final IngredientService ingredientService; + + @PostMapping("/typing") + public ResponseEntity createIngredientList(@RequestBody List ingredientRequestDtoList){ + ingredientService.createIngredients(ingredientRequestDtoList); + return new ResponseEntity<>("재료가 등록되었습니다.", HttpStatus.CREATED); + } +} diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/domain/Ingredient.java b/src/main/java/CookSave/CookSaveback/Ingredient/domain/Ingredient.java index 2e633f4..b431ad2 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/domain/Ingredient.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/domain/Ingredient.java @@ -24,7 +24,7 @@ public class Ingredient extends BaseTimeEntity { private Member member; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "tag_id", nullable = false) + @JoinColumn(name = "tag_id") // 태그 지정 방식 정한 후 nullable=false 설정 여부 결정 private Tag tag; @ManyToOne(fetch = FetchType.LAZY) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/dto/IngredientRequestDto.java b/src/main/java/CookSave/CookSaveback/Ingredient/dto/IngredientRequestDto.java new file mode 100644 index 0000000..aca358f --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Ingredient/dto/IngredientRequestDto.java @@ -0,0 +1,14 @@ +package CookSave.CookSaveback.Ingredient.dto; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class IngredientRequestDto { + private Integer iconId; + private String name; + private Integer price; + private Float amount; +} diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java b/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java new file mode 100644 index 0000000..0d25644 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java @@ -0,0 +1,9 @@ +package CookSave.CookSaveback.Ingredient.repository; + +import CookSave.CookSaveback.Ingredient.domain.Ingredient; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface IngredientRepository extends JpaRepository { +} diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java new file mode 100644 index 0000000..bbdeda3 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -0,0 +1,44 @@ +package CookSave.CookSaveback.Ingredient.service; + +import CookSave.CookSaveback.Icon.domain.Icon; +import CookSave.CookSaveback.Icon.repository.IconRepository; +import CookSave.CookSaveback.Ingredient.domain.Ingredient; +import CookSave.CookSaveback.Ingredient.dto.IngredientRequestDto; +import CookSave.CookSaveback.Ingredient.repository.IngredientRepository; +import CookSave.CookSaveback.Member.domain.Member; +import CookSave.CookSaveback.Member.service.MemberService; +import jakarta.persistence.EntityNotFoundException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +@RequiredArgsConstructor +public class IngredientService { + private final MemberService memberService; + private final IconRepository iconRepository; + private final IngredientRepository ingredientRepository; + + public void createIngredients(List ingredientDtos){ + List ingredients = new ArrayList<>(); + + // 현재 로그인한 member 불러오기 + Member member = memberService.getLoginMember(); + + for (IngredientRequestDto ingredientDto : ingredientDtos){ + Icon icon = iconRepository.findById(ingredientDto.getIconId()) + .orElseThrow(() -> new EntityNotFoundException("iconId " + ingredientDto.getIconId() + "인 아이콘이 존재하지 않습니다.")); + Ingredient ingredient = Ingredient.builder() + .member(member) + .tag(null) // 태그 지정 방법 결정 후 수정 필요 + .icon(icon) + .name(ingredientDto.getName()) + .price(ingredientDto.getPrice()) + .amount(ingredientDto.getAmount()) + .build(); + ingredientRepository.save(ingredient); + } + } +} From 92083ab487af4a40e67e9692d8d1999eac146fec Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Mon, 19 Feb 2024 03:07:42 +0900 Subject: [PATCH 17/87] =?UTF-8?q?feat:=20=EC=A0=84=EC=B2=B4=20=EC=9E=AC?= =?UTF-8?q?=EB=A3=8C=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IngredientController.java | 14 +++++++--- .../Ingredient/dto/IngredientResponseDto.java | 27 +++++++++++++++++++ .../repository/IngredientRepository.java | 5 ++++ .../Ingredient/service/IngredientService.java | 15 +++++++++++ 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 src/main/java/CookSave/CookSaveback/Ingredient/dto/IngredientResponseDto.java diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java index 8d4f475..ac88287 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java @@ -1,15 +1,13 @@ package CookSave.CookSaveback.Ingredient.controller; import CookSave.CookSaveback.Ingredient.dto.IngredientRequestDto; +import CookSave.CookSaveback.Ingredient.dto.IngredientResponseDto; import CookSave.CookSaveback.Ingredient.service.IngredientService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -20,6 +18,14 @@ public class IngredientController { private final IngredientService ingredientService; + // 보유한 재료 목록 조회 + @GetMapping + @ResponseStatus(value = HttpStatus.OK) + public List getIngredientList(){ + return ingredientService.getIngredientList(); + } + + // 재료 직접 입력 @PostMapping("/typing") public ResponseEntity createIngredientList(@RequestBody List ingredientRequestDtoList){ ingredientService.createIngredients(ingredientRequestDtoList); diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/dto/IngredientResponseDto.java b/src/main/java/CookSave/CookSaveback/Ingredient/dto/IngredientResponseDto.java new file mode 100644 index 0000000..717ea3a --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Ingredient/dto/IngredientResponseDto.java @@ -0,0 +1,27 @@ +package CookSave.CookSaveback.Ingredient.dto; + +import CookSave.CookSaveback.Ingredient.domain.Ingredient; +import lombok.*; + +import java.time.LocalDateTime; + +@Getter +@NoArgsConstructor +public class IngredientResponseDto { + private Long ingredientId; + private Integer iconId; + private String name; + private Integer price; + private Float amount; + private LocalDateTime createdAt; + + @Builder + public IngredientResponseDto(Ingredient ingredient){ + this.ingredientId = ingredient.getIngredientId(); + this.iconId = ingredient.getIcon().getIconId(); + this.name = ingredient.getName(); + this.price = ingredient.getPrice(); + this.amount = ingredient.getAmount(); + this.createdAt = ingredient.getCreatedAt(); + } +} diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java b/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java index 0d25644..b4fe5cd 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java @@ -1,9 +1,14 @@ package CookSave.CookSaveback.Ingredient.repository; import CookSave.CookSaveback.Ingredient.domain.Ingredient; + +import CookSave.CookSaveback.Member.domain.Member; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface IngredientRepository extends JpaRepository { + List findAllByMember(Member member); } diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index bbdeda3..f1c759c 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -4,6 +4,7 @@ import CookSave.CookSaveback.Icon.repository.IconRepository; import CookSave.CookSaveback.Ingredient.domain.Ingredient; import CookSave.CookSaveback.Ingredient.dto.IngredientRequestDto; +import CookSave.CookSaveback.Ingredient.dto.IngredientResponseDto; import CookSave.CookSaveback.Ingredient.repository.IngredientRepository; import CookSave.CookSaveback.Member.domain.Member; import CookSave.CookSaveback.Member.service.MemberService; @@ -13,6 +14,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor @@ -21,6 +23,19 @@ public class IngredientService { private final IconRepository iconRepository; private final IngredientRepository ingredientRepository; + public List getIngredientList() { + List ingredients = new ArrayList<>(); + Member member = memberService.getLoginMember(); + ingredients = ingredientRepository.findAllByMember(member); + + List ingredientList = new ArrayList<>(); + for (Ingredient ingredient:ingredients){ + IngredientResponseDto ingredientResponseDto = new IngredientResponseDto(ingredient); + ingredientList.add(ingredientResponseDto); + } + return ingredientList; + } + public void createIngredients(List ingredientDtos){ List ingredients = new ArrayList<>(); From ac71f694f59679a83ba32dce584bfebf76cdfc0f Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Mon, 19 Feb 2024 03:32:24 +0900 Subject: [PATCH 18/87] =?UTF-8?q?fix:=20=EC=9E=AC=EB=A3=8C=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=EC=9D=BC=20=EC=A0=80=EC=9E=A5=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/CookSave/CookSaveback/CookSaveBackApplication.java | 2 ++ .../CookSave/CookSaveback/global/entity/BaseTimeEntity.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/main/java/CookSave/CookSaveback/CookSaveBackApplication.java b/src/main/java/CookSave/CookSaveback/CookSaveBackApplication.java index fb67e75..8c2922c 100644 --- a/src/main/java/CookSave/CookSaveback/CookSaveBackApplication.java +++ b/src/main/java/CookSave/CookSaveback/CookSaveBackApplication.java @@ -2,7 +2,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +@EnableJpaAuditing @SpringBootApplication public class CookSaveBackApplication { diff --git a/src/main/java/CookSave/CookSaveback/global/entity/BaseTimeEntity.java b/src/main/java/CookSave/CookSaveback/global/entity/BaseTimeEntity.java index cb1813e..b0ae552 100644 --- a/src/main/java/CookSave/CookSaveback/global/entity/BaseTimeEntity.java +++ b/src/main/java/CookSave/CookSaveback/global/entity/BaseTimeEntity.java @@ -2,6 +2,7 @@ import jakarta.persistence.Column; import jakarta.persistence.EntityListeners; +import jakarta.persistence.MappedSuperclass; import lombok.Getter; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; @@ -9,6 +10,7 @@ import java.time.LocalDateTime; @Getter +@MappedSuperclass @EntityListeners(AuditingEntityListener.class) public class BaseTimeEntity { @CreatedDate From 7e15efe1864fe073888eec9d79d9327a22bdce88 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Mon, 19 Feb 2024 03:33:35 +0900 Subject: [PATCH 19/87] =?UTF-8?q?style:=20=EC=A3=BC=EC=84=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95,=20=EC=82=AC=EC=9A=A9=EB=90=98=EC=A7=80=20=EC=95=8A?= =?UTF-8?q?=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Ingredient/service/IngredientService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index f1c759c..19bb8d9 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -14,7 +14,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; @Service @RequiredArgsConstructor @@ -23,6 +22,7 @@ public class IngredientService { private final IconRepository iconRepository; private final IngredientRepository ingredientRepository; + // 전체 재료 조회 public List getIngredientList() { List ingredients = new ArrayList<>(); Member member = memberService.getLoginMember(); From bd6be633baa56b686a8b0771de2f22b401904a69 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Mon, 19 Feb 2024 03:49:22 +0900 Subject: [PATCH 20/87] =?UTF-8?q?fix:=20=EC=83=9D=EC=84=B1=EC=9D=BC=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=EC=9D=84=20LocalDate=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Ingredient/dto/IngredientResponseDto.java | 4 ++-- .../CookSave/CookSaveback/global/entity/BaseTimeEntity.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/dto/IngredientResponseDto.java b/src/main/java/CookSave/CookSaveback/Ingredient/dto/IngredientResponseDto.java index 717ea3a..3f9fa06 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/dto/IngredientResponseDto.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/dto/IngredientResponseDto.java @@ -3,7 +3,7 @@ import CookSave.CookSaveback.Ingredient.domain.Ingredient; import lombok.*; -import java.time.LocalDateTime; +import java.time.LocalDate; @Getter @NoArgsConstructor @@ -13,7 +13,7 @@ public class IngredientResponseDto { private String name; private Integer price; private Float amount; - private LocalDateTime createdAt; + private LocalDate createdAt; @Builder public IngredientResponseDto(Ingredient ingredient){ diff --git a/src/main/java/CookSave/CookSaveback/global/entity/BaseTimeEntity.java b/src/main/java/CookSave/CookSaveback/global/entity/BaseTimeEntity.java index b0ae552..305229b 100644 --- a/src/main/java/CookSave/CookSaveback/global/entity/BaseTimeEntity.java +++ b/src/main/java/CookSave/CookSaveback/global/entity/BaseTimeEntity.java @@ -7,7 +7,7 @@ import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import java.time.LocalDateTime; +import java.time.LocalDate; @Getter @MappedSuperclass @@ -15,5 +15,5 @@ public class BaseTimeEntity { @CreatedDate @Column(updatable = false) - private LocalDateTime createdAt; + private LocalDate createdAt; } From fa212da13194431671da9dc563e584f2d7a6a438 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Tue, 20 Feb 2024 12:55:06 +0900 Subject: [PATCH 21/87] =?UTF-8?q?feat:=20=EC=9E=AC=EB=A3=8C=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IngredientController.java | 10 +++++++- .../Ingredient/domain/Ingredient.java | 5 ++++ .../Ingredient/dto/UpdateRequestDto.java | 10 ++++++++ .../repository/IngredientRepository.java | 1 + .../Ingredient/service/IngredientService.java | 24 +++++++++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/main/java/CookSave/CookSaveback/Ingredient/dto/UpdateRequestDto.java diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java index ac88287..1b6bd57 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java @@ -2,6 +2,7 @@ import CookSave.CookSaveback.Ingredient.dto.IngredientRequestDto; import CookSave.CookSaveback.Ingredient.dto.IngredientResponseDto; +import CookSave.CookSaveback.Ingredient.dto.UpdateRequestDto; import CookSave.CookSaveback.Ingredient.service.IngredientService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -19,7 +20,7 @@ public class IngredientController { private final IngredientService ingredientService; // 보유한 재료 목록 조회 - @GetMapping + @GetMapping("/list") @ResponseStatus(value = HttpStatus.OK) public List getIngredientList(){ return ingredientService.getIngredientList(); @@ -31,4 +32,11 @@ public ResponseEntity createIngredientList(@RequestBody List("재료가 등록되었습니다.", HttpStatus.CREATED); } + + @PatchMapping("/list") + @ResponseStatus(value = HttpStatus.OK) + public String updateIngredientList(@RequestBody List updateRequestDtoList){ + ingredientService.updateIngredients(updateRequestDtoList); + return "재료가 수정되었습니다."; + } } diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/domain/Ingredient.java b/src/main/java/CookSave/CookSaveback/Ingredient/domain/Ingredient.java index b431ad2..e46bdcc 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/domain/Ingredient.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/domain/Ingredient.java @@ -49,4 +49,9 @@ public Ingredient(Member member, Tag tag, Icon icon, String name, Integer price, this.price = price; this.amount = amount; } + + public void updateIngredient(Icon icon, Float amount){ + this.icon = icon; + this.amount = amount; + } } diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/dto/UpdateRequestDto.java b/src/main/java/CookSave/CookSaveback/Ingredient/dto/UpdateRequestDto.java new file mode 100644 index 0000000..67d1d7d --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Ingredient/dto/UpdateRequestDto.java @@ -0,0 +1,10 @@ +package CookSave.CookSaveback.Ingredient.dto; + +import lombok.Getter; + +@Getter +public class UpdateRequestDto { + private Long ingredientId; + private Integer iconId; + private Float amount; +} diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java b/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java index b4fe5cd..79ba7dd 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java @@ -11,4 +11,5 @@ @Repository public interface IngredientRepository extends JpaRepository { List findAllByMember(Member member); + Long countAllByMember(Member member); } diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index 19bb8d9..28d73b3 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -5,6 +5,7 @@ import CookSave.CookSaveback.Ingredient.domain.Ingredient; import CookSave.CookSaveback.Ingredient.dto.IngredientRequestDto; import CookSave.CookSaveback.Ingredient.dto.IngredientResponseDto; +import CookSave.CookSaveback.Ingredient.dto.UpdateRequestDto; import CookSave.CookSaveback.Ingredient.repository.IngredientRepository; import CookSave.CookSaveback.Member.domain.Member; import CookSave.CookSaveback.Member.service.MemberService; @@ -56,4 +57,27 @@ public void createIngredients(List ingredientDtos){ ingredientRepository.save(ingredient); } } + + public void updateIngredients(List updateRequestDtos){ + List ingredients = new ArrayList<>(); + + // 현재 로그인한 member 불러오기 + Member member = memberService.getLoginMember(); + + // 업데이트 할 ingredient 개수 구하기 + Long count = ingredientRepository.countAllByMember(member); + int intCount = (int)(long)count; + + List originalIngredients = ingredientRepository.findAllByMember(member); + + for (int i = 0; i new EntityNotFoundException("iconId " + iconId + "인 아이콘이 존재하지 않습니다.")); + Float amount = updateRequestDtos.get(i).getAmount(); + originalIngredients.get(i).updateIngredient(icon, amount); + ingredientRepository.save(originalIngredients.get(i)); + } + } } From 73226c54cebea686de967064e874106d1c4c5bb0 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Tue, 20 Feb 2024 12:57:44 +0900 Subject: [PATCH 22/87] =?UTF-8?q?style:=20=EC=A3=BC=EC=84=9D=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Ingredient/controller/IngredientController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java index 1b6bd57..e461718 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java @@ -33,6 +33,7 @@ public ResponseEntity createIngredientList(@RequestBody List("재료가 등록되었습니다.", HttpStatus.CREATED); } + // 재료 목록에서 iconId, amount 수정 @PatchMapping("/list") @ResponseStatus(value = HttpStatus.OK) public String updateIngredientList(@RequestBody List updateRequestDtoList){ From 225ed86d892d3f8c9967852cb3fb3dc2c3819a8c Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Tue, 20 Feb 2024 12:57:54 +0900 Subject: [PATCH 23/87] =?UTF-8?q?style:=20=EC=A3=BC=EC=84=9D=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Ingredient/service/IngredientService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index 28d73b3..7d52a5f 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -76,6 +76,7 @@ public void updateIngredients(List updateRequestDtos){ Icon icon = iconRepository.findById(iconId) .orElseThrow(() -> new EntityNotFoundException("iconId " + iconId + "인 아이콘이 존재하지 않습니다.")); Float amount = updateRequestDtos.get(i).getAmount(); + originalIngredients.get(i).updateIngredient(icon, amount); ingredientRepository.save(originalIngredients.get(i)); } From 4392c677bcdd6aec6d6056c8a940a1443edfea7d Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Tue, 20 Feb 2024 13:22:22 +0900 Subject: [PATCH 24/87] =?UTF-8?q?feat:=20=EC=9E=AC=EB=A3=8C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ingredient/controller/IngredientController.java | 8 ++++++++ .../Ingredient/repository/IngredientRepository.java | 2 ++ .../Ingredient/service/IngredientService.java | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java index e461718..4e9417d 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java @@ -40,4 +40,12 @@ public String updateIngredientList(@RequestBody List updateReq ingredientService.updateIngredients(updateRequestDtoList); return "재료가 수정되었습니다."; } + + // 재료 삭제 + @DeleteMapping("/list/{ingredient_id}") + @ResponseStatus(value=HttpStatus.OK) + public String deleteIngredient(@PathVariable("ingredient_id") Long ingredientId){ + ingredientService.deleteIngredient(ingredientId); + return "재료가 삭제되었습니다."; + } } diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java b/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java index 79ba7dd..5b890c7 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java @@ -7,9 +7,11 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.Optional; @Repository public interface IngredientRepository extends JpaRepository { List findAllByMember(Member member); Long countAllByMember(Member member); + Optional findByIngredientIdAndMember(Long ingredientId, Member member); } diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index 7d52a5f..6de3545 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -81,4 +81,11 @@ public void updateIngredients(List updateRequestDtos){ ingredientRepository.save(originalIngredients.get(i)); } } + + public void deleteIngredient(Long ingredientId){ + Member member = memberService.getLoginMember(); + Ingredient ingredient = ingredientRepository.findByIngredientIdAndMember(ingredientId, member) + .orElseThrow(() -> new IllegalArgumentException("잘못된 접근입니다.")); + ingredientRepository.delete(ingredient); + } } From ecbe795cc88ccaa3e774217709066ba5057c4448 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Tue, 20 Feb 2024 21:12:43 +0900 Subject: [PATCH 25/87] =?UTF-8?q?feat:=20=EC=A0=84=EC=B2=B4=20=EB=A0=88?= =?UTF-8?q?=EC=8B=9C=ED=94=BC=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Heart/repository/HeartRepository.java | 12 ++ .../Recipe/controller/RecipeController.java | 38 ++++++ .../Recipe/dto/RecipeResponseDto.java | 25 ++++ .../Recipe/repository/RecipeRepository.java | 9 ++ .../Recipe/service/RecipeService.java | 122 ++++++++++++++++++ .../repository/RecipeTagRepository.java | 12 ++ .../Tag/repository/TagRepository.java | 9 ++ 7 files changed, 227 insertions(+) create mode 100644 src/main/java/CookSave/CookSaveback/Heart/repository/HeartRepository.java create mode 100644 src/main/java/CookSave/CookSaveback/Recipe/controller/RecipeController.java create mode 100644 src/main/java/CookSave/CookSaveback/Recipe/dto/RecipeResponseDto.java create mode 100644 src/main/java/CookSave/CookSaveback/Recipe/repository/RecipeRepository.java create mode 100644 src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java create mode 100644 src/main/java/CookSave/CookSaveback/RecipeTag/repository/RecipeTagRepository.java create mode 100644 src/main/java/CookSave/CookSaveback/Tag/repository/TagRepository.java diff --git a/src/main/java/CookSave/CookSaveback/Heart/repository/HeartRepository.java b/src/main/java/CookSave/CookSaveback/Heart/repository/HeartRepository.java new file mode 100644 index 0000000..64f4f52 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Heart/repository/HeartRepository.java @@ -0,0 +1,12 @@ +package CookSave.CookSaveback.Heart.repository; + +import CookSave.CookSaveback.Heart.domain.Heart; +import CookSave.CookSaveback.Member.domain.Member; +import CookSave.CookSaveback.Recipe.domain.Recipe; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface HeartRepository extends JpaRepository { + boolean existsByMemberAndRecipe(Member member, Recipe recipe); +} diff --git a/src/main/java/CookSave/CookSaveback/Recipe/controller/RecipeController.java b/src/main/java/CookSave/CookSaveback/Recipe/controller/RecipeController.java new file mode 100644 index 0000000..c146b4b --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Recipe/controller/RecipeController.java @@ -0,0 +1,38 @@ +package CookSave.CookSaveback.Recipe.controller; + +import CookSave.CookSaveback.Member.domain.Member; +import CookSave.CookSaveback.Member.service.MemberService; +import CookSave.CookSaveback.Recipe.dto.RecipeResponseDto; +import CookSave.CookSaveback.Recipe.service.RecipeService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/recipes") +public class RecipeController { + private final RecipeService recipeService; + private final MemberService memberService; + + + // 전체 레시피 목록 조회 + @GetMapping + @ResponseStatus(value = HttpStatus.OK) + public List getRecipeList(){ + Member member = memberService.getLoginMember(); + return recipeService.getRecipeList(member); + } + + + /* + @GetMapping("/{recipe_id}") + @ResponseStatus(value = HttpStatus.OK) + public RecipeDetailResponseDto getRecipeDetail(@PathVariable("recipe_id") Long recipeId){ + Member member = memberService.getLoginMember(); + return recipeService.getRecipeDetail(recipeId, member); + } + */ +} diff --git a/src/main/java/CookSave/CookSaveback/Recipe/dto/RecipeResponseDto.java b/src/main/java/CookSave/CookSaveback/Recipe/dto/RecipeResponseDto.java new file mode 100644 index 0000000..36ada62 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Recipe/dto/RecipeResponseDto.java @@ -0,0 +1,25 @@ +package CookSave.CookSaveback.Recipe.dto; + +import CookSave.CookSaveback.Recipe.domain.Recipe; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class RecipeResponseDto { + private Long recipeId; + private String name; + private String image; + private String mainIng; + private boolean heart; + + @Builder + public RecipeResponseDto(Recipe recipe, boolean heart){ + this.recipeId = recipe.getRecipeId(); + this.name = recipe.getName(); + this.image = recipe.getImage(); + this.mainIng = recipe.getMainIng(); + this.heart = heart; + } +} diff --git a/src/main/java/CookSave/CookSaveback/Recipe/repository/RecipeRepository.java b/src/main/java/CookSave/CookSaveback/Recipe/repository/RecipeRepository.java new file mode 100644 index 0000000..2c22cc1 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Recipe/repository/RecipeRepository.java @@ -0,0 +1,9 @@ +package CookSave.CookSaveback.Recipe.repository; + +import CookSave.CookSaveback.Recipe.domain.Recipe; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface RecipeRepository extends JpaRepository { +} diff --git a/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java b/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java new file mode 100644 index 0000000..281a799 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java @@ -0,0 +1,122 @@ +package CookSave.CookSaveback.Recipe.service; + +import CookSave.CookSaveback.Heart.repository.HeartRepository; +import CookSave.CookSaveback.Ingredient.domain.Ingredient; +import CookSave.CookSaveback.Ingredient.dto.IngredientResponseDto; +import CookSave.CookSaveback.Ingredient.repository.IngredientRepository; +import CookSave.CookSaveback.Member.domain.Member; +import CookSave.CookSaveback.Member.service.MemberService; +import CookSave.CookSaveback.Recipe.domain.Recipe; +import CookSave.CookSaveback.Recipe.dto.RecipeDetailResponseDto; +import CookSave.CookSaveback.Recipe.dto.RecipeResponseDto; +import CookSave.CookSaveback.Recipe.repository.RecipeRepository; +import CookSave.CookSaveback.RecipeTag.repository.RecipeTagRepository; +import CookSave.CookSaveback.Tag.domain.Tag; +import CookSave.CookSaveback.Tag.repository.TagRepository; +import jakarta.persistence.EntityNotFoundException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class RecipeService { + private final RecipeRepository recipeRepository; + private final IngredientRepository ingredientRepository; + private final RecipeTagRepository recipeTagRepository; + private final HeartRepository heartRepository; + private final TagRepository tagRepository; + + // 전체 레시피 조회 + public List getRecipeList(Member member) { + List recipeList = new ArrayList<>(); + + List recipes = new ArrayList<>(); + recipes = recipeRepository.findAll(); + int recipeCount = recipes.size(); + + List ingredients = new ArrayList<>(); + ingredients = ingredientRepository.findAllByMember(member); + + List tags = new ArrayList<>(); + for (Ingredient ingredient : ingredients) { + tags.add(ingredient.getTag().getTagId()); + tags = tags.stream().distinct().collect(Collectors.toList()); + } + int tagCount = tags.size(); + + List recipeTagCount = new ArrayList<>(); + + for (int i = 0; i < recipeCount; i++) { + recipeTagCount.add(0); + } + + for (int i = 0; i < recipeCount; i++) { + for (Integer tagId : tags) { + Tag tag = tagRepository.findById(tagId) + .orElseThrow(() -> new EntityNotFoundException("해당되는 태그가 존재하지 않습니다.")); + if (recipeTagRepository.existsByRecipeAndTag(recipes.get(i), tag)) { + Integer currentCount = recipeTagCount.get(i); + Integer newCount = currentCount == null ? 0 : currentCount + 1; + recipeTagCount.set(i, newCount); + } + } + } + + List sortedRecipeList = new ArrayList<>(); + for (int i = 0; i < recipeCount; i++) { + sortedRecipeList.add(new RecipeTagSort(recipes.get(i), recipeTagCount.get(i))); + } + + Comparator recipeComparator = Comparator.comparingInt(RecipeTagSort::getTagCount).reversed(); + sortedRecipeList.sort(recipeComparator); + + for (RecipeTagSort recipeTagSort : sortedRecipeList){ + Recipe recipe = recipeTagSort.getRecipe(); + boolean heart = heartRepository.existsByMemberAndRecipe(member, recipe); + RecipeResponseDto recipeResponseDto = new RecipeResponseDto(recipe, heart); + recipeList.add(recipeResponseDto); + } + return recipeList; + } + + static class RecipeTagSort { + private Recipe recipe; + private int tagCount; + + public RecipeTagSort(Recipe recipe, int tagCount) { + this.recipe = recipe; + this.tagCount = tagCount; + } + + public Recipe getRecipe() { + return recipe; + } + + public int getTagCount() { + return tagCount; + } + } + + /* + public RecipeDetailResponseDto getRecipeDetail(Long recipeId, Member member){ + + Recipe recipe = recipeRepository.findById(recipeId) + .orElseThrow(() -> new EntityNotFoundException("recipeId가 " + recipeId + "인 레시피가 존재하지 않습니다.")); + + List memberIngredients = ingredientRepository.findAllByMember(member); + + for (Ingredient ingredient : memberIngredients){ + Tag tag = tagRepository.findById(ingredient.getTag().getTagId()) + .orElseThrow(() -> new EntityNotFoundException("tagId" + ingredient.getTag().getTagId() + "인 태그가 존재하지 않습니다.")); + if (recipeTagRepository.existsByRecipeAndTag(recipe, tag)){ + + } + } + + RecipeDetailResponseDto detailResponseDto = new RecipeDetailResponseDto(recipe, ingredients); + } + */ +} diff --git a/src/main/java/CookSave/CookSaveback/RecipeTag/repository/RecipeTagRepository.java b/src/main/java/CookSave/CookSaveback/RecipeTag/repository/RecipeTagRepository.java new file mode 100644 index 0000000..bbc94c6 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/RecipeTag/repository/RecipeTagRepository.java @@ -0,0 +1,12 @@ +package CookSave.CookSaveback.RecipeTag.repository; + +import CookSave.CookSaveback.Recipe.domain.Recipe; +import CookSave.CookSaveback.RecipeTag.domain.RecipeTag; +import CookSave.CookSaveback.Tag.domain.Tag; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface RecipeTagRepository extends JpaRepository { + boolean existsByRecipeAndTag(Recipe recipe, Tag tag); +} diff --git a/src/main/java/CookSave/CookSaveback/Tag/repository/TagRepository.java b/src/main/java/CookSave/CookSaveback/Tag/repository/TagRepository.java new file mode 100644 index 0000000..447984c --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Tag/repository/TagRepository.java @@ -0,0 +1,9 @@ +package CookSave.CookSaveback.Tag.repository; + +import CookSave.CookSaveback.Tag.domain.Tag; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface TagRepository extends JpaRepository{ +} From 803c6c17664e82937b00193602eba878eba0942d Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Tue, 20 Feb 2024 21:36:13 +0900 Subject: [PATCH 26/87] =?UTF-8?q?feat:=20=EB=A0=88=EC=8B=9C=ED=94=BC=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Recipe/controller/RecipeController.java | 5 ++-- .../Recipe/dto/RecipeDetailResponseDto.java | 30 +++++++++++++++++++ .../Recipe/service/RecipeService.java | 16 +++++++--- 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 src/main/java/CookSave/CookSaveback/Recipe/dto/RecipeDetailResponseDto.java diff --git a/src/main/java/CookSave/CookSaveback/Recipe/controller/RecipeController.java b/src/main/java/CookSave/CookSaveback/Recipe/controller/RecipeController.java index c146b4b..e92affb 100644 --- a/src/main/java/CookSave/CookSaveback/Recipe/controller/RecipeController.java +++ b/src/main/java/CookSave/CookSaveback/Recipe/controller/RecipeController.java @@ -2,6 +2,7 @@ import CookSave.CookSaveback.Member.domain.Member; import CookSave.CookSaveback.Member.service.MemberService; +import CookSave.CookSaveback.Recipe.dto.RecipeDetailResponseDto; import CookSave.CookSaveback.Recipe.dto.RecipeResponseDto; import CookSave.CookSaveback.Recipe.service.RecipeService; import lombok.RequiredArgsConstructor; @@ -26,13 +27,11 @@ public List getRecipeList(){ return recipeService.getRecipeList(member); } - - /* + // 레시피 상세 조회 @GetMapping("/{recipe_id}") @ResponseStatus(value = HttpStatus.OK) public RecipeDetailResponseDto getRecipeDetail(@PathVariable("recipe_id") Long recipeId){ Member member = memberService.getLoginMember(); return recipeService.getRecipeDetail(recipeId, member); } - */ } diff --git a/src/main/java/CookSave/CookSaveback/Recipe/dto/RecipeDetailResponseDto.java b/src/main/java/CookSave/CookSaveback/Recipe/dto/RecipeDetailResponseDto.java new file mode 100644 index 0000000..de686ec --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Recipe/dto/RecipeDetailResponseDto.java @@ -0,0 +1,30 @@ +package CookSave.CookSaveback.Recipe.dto; + +import CookSave.CookSaveback.Ingredient.dto.IngredientResponseDto; +import CookSave.CookSaveback.Recipe.domain.Recipe; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Getter +@NoArgsConstructor +public class RecipeDetailResponseDto { + private String image; + private String name; + private String mainIng; + private String content; + private List ingredients; + private String video; + + @Builder + public RecipeDetailResponseDto(Recipe recipe, List ingredients){ + this.image = recipe.getImage(); + this.name = recipe.getName(); + this.mainIng = recipe.getMainIng(); + this.content = recipe.getContent(); + this.ingredients = ingredients; + this.video = recipe.getVideo(); + } +} diff --git a/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java b/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java index 281a799..5e08cff 100644 --- a/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java +++ b/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java @@ -100,7 +100,7 @@ public int getTagCount() { } } - /* + // 레시피 상세 조회 public RecipeDetailResponseDto getRecipeDetail(Long recipeId, Member member){ Recipe recipe = recipeRepository.findById(recipeId) @@ -108,15 +108,23 @@ public RecipeDetailResponseDto getRecipeDetail(Long recipeId, Member member){ List memberIngredients = ingredientRepository.findAllByMember(member); + List recipeIngredients = new ArrayList<>(); + for (Ingredient ingredient : memberIngredients){ Tag tag = tagRepository.findById(ingredient.getTag().getTagId()) .orElseThrow(() -> new EntityNotFoundException("tagId" + ingredient.getTag().getTagId() + "인 태그가 존재하지 않습니다.")); if (recipeTagRepository.existsByRecipeAndTag(recipe, tag)){ - + recipeIngredients.add(ingredient); } } - RecipeDetailResponseDto detailResponseDto = new RecipeDetailResponseDto(recipe, ingredients); + List ingredients = new ArrayList<>(); + + for (Ingredient ingredient : recipeIngredients){ + IngredientResponseDto ingredientResponseDto = new IngredientResponseDto(ingredient); + ingredients.add(ingredientResponseDto); + } + + return new RecipeDetailResponseDto(recipe, ingredients); } - */ } From ceb5b8121d3e3de878cd2ec4e17dd636ff79f52b Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Wed, 21 Feb 2024 01:11:22 +0900 Subject: [PATCH 27/87] =?UTF-8?q?fix:=20ingredient=20service=EB=8B=A8?= =?UTF-8?q?=EC=9D=98=20MemberService=EB=A5=BC=20controller=EB=8B=A8?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IngredientController.java | 25 ++++++++++++------- .../Ingredient/service/IngredientService.java | 18 +++---------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java index 4e9417d..0f3dfe3 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java @@ -4,6 +4,8 @@ import CookSave.CookSaveback.Ingredient.dto.IngredientResponseDto; import CookSave.CookSaveback.Ingredient.dto.UpdateRequestDto; import CookSave.CookSaveback.Ingredient.service.IngredientService; +import CookSave.CookSaveback.Member.domain.Member; +import CookSave.CookSaveback.Member.service.MemberService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; @@ -15,37 +17,42 @@ @Slf4j @RestController @RequiredArgsConstructor -@RequestMapping("/ingredients") public class IngredientController { + private final MemberService memberService; private final IngredientService ingredientService; // 보유한 재료 목록 조회 - @GetMapping("/list") + @GetMapping("/ingredients/list") @ResponseStatus(value = HttpStatus.OK) public List getIngredientList(){ - return ingredientService.getIngredientList(); + // 현재 로그인한 member 불러오기 + Member member = memberService.getLoginMember(); + return ingredientService.getIngredientList(member); } // 재료 직접 입력 - @PostMapping("/typing") + @PostMapping("/ingredients/typing") public ResponseEntity createIngredientList(@RequestBody List ingredientRequestDtoList){ - ingredientService.createIngredients(ingredientRequestDtoList); + Member member = memberService.getLoginMember(); + ingredientService.createIngredients(member, ingredientRequestDtoList); return new ResponseEntity<>("재료가 등록되었습니다.", HttpStatus.CREATED); } // 재료 목록에서 iconId, amount 수정 - @PatchMapping("/list") + @PatchMapping("/ingredients/list") @ResponseStatus(value = HttpStatus.OK) public String updateIngredientList(@RequestBody List updateRequestDtoList){ - ingredientService.updateIngredients(updateRequestDtoList); + Member member = memberService.getLoginMember(); + ingredientService.updateIngredients(member, updateRequestDtoList); return "재료가 수정되었습니다."; } // 재료 삭제 - @DeleteMapping("/list/{ingredient_id}") + @DeleteMapping("/ingredients/list/{ingredient_id}") @ResponseStatus(value=HttpStatus.OK) public String deleteIngredient(@PathVariable("ingredient_id") Long ingredientId){ - ingredientService.deleteIngredient(ingredientId); + Member member = memberService.getLoginMember(); + ingredientService.deleteIngredient(member, ingredientId); return "재료가 삭제되었습니다."; } } diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index 6de3545..bb38370 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -8,7 +8,6 @@ import CookSave.CookSaveback.Ingredient.dto.UpdateRequestDto; import CookSave.CookSaveback.Ingredient.repository.IngredientRepository; import CookSave.CookSaveback.Member.domain.Member; -import CookSave.CookSaveback.Member.service.MemberService; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -19,14 +18,12 @@ @Service @RequiredArgsConstructor public class IngredientService { - private final MemberService memberService; private final IconRepository iconRepository; private final IngredientRepository ingredientRepository; // 전체 재료 조회 - public List getIngredientList() { + public List getIngredientList(Member member) { List ingredients = new ArrayList<>(); - Member member = memberService.getLoginMember(); ingredients = ingredientRepository.findAllByMember(member); List ingredientList = new ArrayList<>(); @@ -37,12 +34,9 @@ public List getIngredientList() { return ingredientList; } - public void createIngredients(List ingredientDtos){ + public void createIngredients(Member member, List ingredientDtos){ List ingredients = new ArrayList<>(); - // 현재 로그인한 member 불러오기 - Member member = memberService.getLoginMember(); - for (IngredientRequestDto ingredientDto : ingredientDtos){ Icon icon = iconRepository.findById(ingredientDto.getIconId()) .orElseThrow(() -> new EntityNotFoundException("iconId " + ingredientDto.getIconId() + "인 아이콘이 존재하지 않습니다.")); @@ -58,12 +52,9 @@ public void createIngredients(List ingredientDtos){ } } - public void updateIngredients(List updateRequestDtos){ + public void updateIngredients(Member member, List updateRequestDtos){ List ingredients = new ArrayList<>(); - // 현재 로그인한 member 불러오기 - Member member = memberService.getLoginMember(); - // 업데이트 할 ingredient 개수 구하기 Long count = ingredientRepository.countAllByMember(member); int intCount = (int)(long)count; @@ -82,8 +73,7 @@ public void updateIngredients(List updateRequestDtos){ } } - public void deleteIngredient(Long ingredientId){ - Member member = memberService.getLoginMember(); + public void deleteIngredient(Member member, Long ingredientId){ Ingredient ingredient = ingredientRepository.findByIngredientIdAndMember(ingredientId, member) .orElseThrow(() -> new IllegalArgumentException("잘못된 접근입니다.")); ingredientRepository.delete(ingredient); From 153767877bdaaebd41f33a8e48a525ee2c971fa9 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Wed, 21 Feb 2024 01:49:05 +0900 Subject: [PATCH 28/87] =?UTF-8?q?feat:=20=EB=93=B1=EB=A1=9D=EB=90=98?= =?UTF-8?q?=EC=96=B4=20=EC=9E=88=EB=8A=94=20=EB=A0=88=EC=8B=9C=ED=94=BC=20?= =?UTF-8?q?=EC=9E=AC=EB=A3=8C=20=EC=B0=A8=EA=B0=90=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IngredientController.java | 10 ++++++++++ .../Ingredient/domain/Ingredient.java | 4 ++++ .../Ingredient/dto/SubtractRequestDto.java | 9 +++++++++ .../Ingredient/service/IngredientService.java | 19 +++++++++++++++++-- 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/main/java/CookSave/CookSaveback/Ingredient/dto/SubtractRequestDto.java diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java index 0f3dfe3..4f22b37 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java @@ -2,6 +2,7 @@ import CookSave.CookSaveback.Ingredient.dto.IngredientRequestDto; import CookSave.CookSaveback.Ingredient.dto.IngredientResponseDto; +import CookSave.CookSaveback.Ingredient.dto.SubtractRequestDto; import CookSave.CookSaveback.Ingredient.dto.UpdateRequestDto; import CookSave.CookSaveback.Ingredient.service.IngredientService; import CookSave.CookSaveback.Member.domain.Member; @@ -55,4 +56,13 @@ public String deleteIngredient(@PathVariable("ingredient_id") Long ingredientId) ingredientService.deleteIngredient(member, ingredientId); return "재료가 삭제되었습니다."; } + + // 등록되어 있는 레시피 재료 차감 + @PatchMapping("/recipes/{recipe_id}/ingredients") + @ResponseStatus(value = HttpStatus.OK) + public String SubtractIngredient(@PathVariable("recipe_id") Long recipeId, @RequestBody List subtractDtoList){ + Member member = memberService.getLoginMember(); + ingredientService.subtractIngredient(member, subtractDtoList); + return "재료가 차감되었습니다."; + } } diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/domain/Ingredient.java b/src/main/java/CookSave/CookSaveback/Ingredient/domain/Ingredient.java index e46bdcc..1fbac2a 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/domain/Ingredient.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/domain/Ingredient.java @@ -54,4 +54,8 @@ public void updateIngredient(Icon icon, Float amount){ this.icon = icon; this.amount = amount; } + + public void updateSubtractedIngredient(Float amount){ + this.amount = amount; + } } diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/dto/SubtractRequestDto.java b/src/main/java/CookSave/CookSaveback/Ingredient/dto/SubtractRequestDto.java new file mode 100644 index 0000000..c23a9ea --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Ingredient/dto/SubtractRequestDto.java @@ -0,0 +1,9 @@ +package CookSave.CookSaveback.Ingredient.dto; + +import lombok.Getter; + +@Getter +public class SubtractRequestDto { + private Long ingredientId; + private Float amount; +} diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index bb38370..2a8cc0a 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -5,6 +5,7 @@ import CookSave.CookSaveback.Ingredient.domain.Ingredient; import CookSave.CookSaveback.Ingredient.dto.IngredientRequestDto; import CookSave.CookSaveback.Ingredient.dto.IngredientResponseDto; +import CookSave.CookSaveback.Ingredient.dto.SubtractRequestDto; import CookSave.CookSaveback.Ingredient.dto.UpdateRequestDto; import CookSave.CookSaveback.Ingredient.repository.IngredientRepository; import CookSave.CookSaveback.Member.domain.Member; @@ -53,8 +54,6 @@ public void createIngredients(Member member, List ingredie } public void updateIngredients(Member member, List updateRequestDtos){ - List ingredients = new ArrayList<>(); - // 업데이트 할 ingredient 개수 구하기 Long count = ingredientRepository.countAllByMember(member); int intCount = (int)(long)count; @@ -78,4 +77,20 @@ public void deleteIngredient(Member member, Long ingredientId){ .orElseThrow(() -> new IllegalArgumentException("잘못된 접근입니다.")); ingredientRepository.delete(ingredient); } + + public void subtractIngredient(Member member, List subtractRequestDtos){ + Long count = ingredientRepository.countAllByMember(member); + int intCount = (int)(long)count; + + List ingredients = ingredientRepository.findAllByMember(member); + + for (int i = 0; i Date: Wed, 21 Feb 2024 01:56:37 +0900 Subject: [PATCH 29/87] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EB=A0=88=EC=8B=9C=ED=94=BC=20=EC=9E=AC?= =?UTF-8?q?=EB=A3=8C=20=EC=B0=A8=EA=B0=90=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ingredient/controller/IngredientController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java index 4f22b37..404445a 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java @@ -65,4 +65,13 @@ public String SubtractIngredient(@PathVariable("recipe_id") Long recipeId, @Requ ingredientService.subtractIngredient(member, subtractDtoList); return "재료가 차감되었습니다."; } + + // 사용자 입력 레시피 재료 차감 + @PatchMapping("/recipes/input/ingredients") + @ResponseStatus(value = HttpStatus.OK) + public String SubtractIngredient(@RequestBody List subtractDtoList){ + Member member = memberService.getLoginMember(); + ingredientService.subtractIngredient(member, subtractDtoList); + return "재료가 차감되었습니다."; + } } From 62d8f87daf06479819106b920e219a0caacf8a63 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Wed, 21 Feb 2024 02:50:54 +0900 Subject: [PATCH 30/87] =?UTF-8?q?feat:=20=EB=A0=88=EC=8B=9C=ED=94=BC=20?= =?UTF-8?q?=EC=B0=9C=20=EB=93=B1=EB=A1=9D=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Heart/controller/HeartController.java | 28 +++++++++++++++ .../Heart/service/HeartService.java | 34 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/main/java/CookSave/CookSaveback/Heart/controller/HeartController.java create mode 100644 src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java diff --git a/src/main/java/CookSave/CookSaveback/Heart/controller/HeartController.java b/src/main/java/CookSave/CookSaveback/Heart/controller/HeartController.java new file mode 100644 index 0000000..3787e02 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Heart/controller/HeartController.java @@ -0,0 +1,28 @@ +package CookSave.CookSaveback.Heart.controller; + +import CookSave.CookSaveback.Heart.service.HeartService; +import CookSave.CookSaveback.Member.domain.Member; +import CookSave.CookSaveback.Member.service.MemberService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/recipes") +public class HeartController { + private final MemberService memberService; + private final HeartService heartService; + + // 레시피 찜 등록 + @PostMapping("/{recipe_id}/hearts") + public ResponseEntity heartRecipe(@PathVariable("recipe_id") Long recipeId){ + Member member = memberService.getLoginMember(); + String response = heartService.heartRecipe(member, recipeId); + return new ResponseEntity<>(response, HttpStatus.CREATED); + } +} diff --git a/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java b/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java new file mode 100644 index 0000000..1bcebd8 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java @@ -0,0 +1,34 @@ +package CookSave.CookSaveback.Heart.service; + +import CookSave.CookSaveback.Heart.domain.Heart; +import CookSave.CookSaveback.Heart.repository.HeartRepository; +import CookSave.CookSaveback.Member.domain.Member; +import CookSave.CookSaveback.Recipe.domain.Recipe; +import CookSave.CookSaveback.Recipe.repository.RecipeRepository; +import jakarta.persistence.EntityNotFoundException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class HeartService { + private final HeartRepository heartRepository; + private final RecipeRepository recipeRepository; + + @Transactional + public String heartRecipe(Member member, Long recipeId){ + Recipe recipe = recipeRepository.findById(recipeId) + .orElseThrow(() -> new EntityNotFoundException("recipeId가 " + recipeId + "인 레시피가 없습니다.")); + if(heartRepository.existsByMemberAndRecipe(member, recipe)){ + throw new RuntimeException("이미 저장 목록에 추가된 레시피입니다."); + } + else{ + Heart heart = new Heart(member, recipe); + heartRepository.save(heart); + return "recipeId가 " + recipeId + "인 레시피가 찜 목록에 추가되었습니다."; + } + } + + +} From fc5e231ba34cd48b9bcafc1cfe890f7fec398117 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Wed, 21 Feb 2024 03:02:30 +0900 Subject: [PATCH 31/87] =?UTF-8?q?feat:=20=EB=A0=88=EC=8B=9C=ED=94=BC=20?= =?UTF-8?q?=EC=B0=9C=20=EC=B7=A8=EC=86=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Heart/controller/HeartController.java | 13 +++++++++---- .../Heart/repository/HeartRepository.java | 3 +++ .../CookSaveback/Heart/service/HeartService.java | 10 +++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Heart/controller/HeartController.java b/src/main/java/CookSave/CookSaveback/Heart/controller/HeartController.java index 3787e02..c0fc171 100644 --- a/src/main/java/CookSave/CookSaveback/Heart/controller/HeartController.java +++ b/src/main/java/CookSave/CookSaveback/Heart/controller/HeartController.java @@ -6,10 +6,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor @@ -25,4 +22,12 @@ public ResponseEntity heartRecipe(@PathVariable("recipe_id") Long recipe String response = heartService.heartRecipe(member, recipeId); return new ResponseEntity<>(response, HttpStatus.CREATED); } + + // 레시피 찜 취소 + @DeleteMapping("/{recipe_id}/hearts") + public ResponseEntity cancelRecipeHeart(@PathVariable("recipe_id") Long recipeId){ + Member member = memberService.getLoginMember(); + String response = heartService.cancelRecipeHeart(member, recipeId); + return new ResponseEntity<>(response, HttpStatus.OK); + } } diff --git a/src/main/java/CookSave/CookSaveback/Heart/repository/HeartRepository.java b/src/main/java/CookSave/CookSaveback/Heart/repository/HeartRepository.java index 64f4f52..213f0c6 100644 --- a/src/main/java/CookSave/CookSaveback/Heart/repository/HeartRepository.java +++ b/src/main/java/CookSave/CookSaveback/Heart/repository/HeartRepository.java @@ -6,7 +6,10 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.Optional; + @Repository public interface HeartRepository extends JpaRepository { boolean existsByMemberAndRecipe(Member member, Recipe recipe); + Optional findByMemberAndRecipe(Member member, Recipe recipe); } diff --git a/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java b/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java index 1bcebd8..5bdeab7 100644 --- a/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java +++ b/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java @@ -30,5 +30,13 @@ public String heartRecipe(Member member, Long recipeId){ } } - + @Transactional + public String cancelRecipeHeart(Member member, Long recipeId){ + Recipe recipe = recipeRepository.findById(recipeId) + .orElseThrow(() -> new EntityNotFoundException("recipeId가 " + recipeId + "인 레시피가 없습니다.")); + Heart heart = heartRepository.findByMemberAndRecipe(member, recipe) + .orElseThrow(() -> new EntityNotFoundException("해당 레시피는 찜 목록에 존재하지 않습니다.")); + heartRepository.delete(heart); + return "recipeId가 " + recipeId + "인 레시피가 찜 목록에서 제거되었습니다."; + } } From ceb991a871b8a0289475f560ed618ae401aa27d4 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Wed, 21 Feb 2024 19:41:34 +0900 Subject: [PATCH 32/87] =?UTF-8?q?feat:=20=EC=B0=9C=ED=95=9C=20=EB=A0=88?= =?UTF-8?q?=EC=8B=9C=ED=94=BC=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Heart/controller/HeartController.java | 11 +++++ .../Heart/dto/HeartRecipeDto.java | 29 +++++++++++++ .../Heart/repository/HeartRepository.java | 2 + .../Heart/service/HeartService.java | 42 +++++++++++++++++++ .../repository/IngredientRepository.java | 2 + .../repository/RecipeTagRepository.java | 3 ++ 6 files changed, 89 insertions(+) create mode 100644 src/main/java/CookSave/CookSaveback/Heart/dto/HeartRecipeDto.java diff --git a/src/main/java/CookSave/CookSaveback/Heart/controller/HeartController.java b/src/main/java/CookSave/CookSaveback/Heart/controller/HeartController.java index c0fc171..329ec3d 100644 --- a/src/main/java/CookSave/CookSaveback/Heart/controller/HeartController.java +++ b/src/main/java/CookSave/CookSaveback/Heart/controller/HeartController.java @@ -1,5 +1,6 @@ package CookSave.CookSaveback.Heart.controller; +import CookSave.CookSaveback.Heart.dto.HeartRecipeDto; import CookSave.CookSaveback.Heart.service.HeartService; import CookSave.CookSaveback.Member.domain.Member; import CookSave.CookSaveback.Member.service.MemberService; @@ -8,6 +9,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.List; + @RestController @RequiredArgsConstructor @RequestMapping("/recipes") @@ -30,4 +33,12 @@ public ResponseEntity cancelRecipeHeart(@PathVariable("recipe_id") Long String response = heartService.cancelRecipeHeart(member, recipeId); return new ResponseEntity<>(response, HttpStatus.OK); } + + // 찜한 레시피 목록 조회 + @GetMapping("/saved") + @ResponseStatus(value = HttpStatus.OK) + public List getHeartRecipeList(){ + Member member = memberService.getLoginMember(); + return heartService.getHeartRecipeList(member); + } } diff --git a/src/main/java/CookSave/CookSaveback/Heart/dto/HeartRecipeDto.java b/src/main/java/CookSave/CookSaveback/Heart/dto/HeartRecipeDto.java new file mode 100644 index 0000000..478ffba --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Heart/dto/HeartRecipeDto.java @@ -0,0 +1,29 @@ +package CookSave.CookSaveback.Heart.dto; + +import CookSave.CookSaveback.Heart.domain.Heart; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Getter +@NoArgsConstructor +public class HeartRecipeDto { + private Long heartId; + private Long memberId; + private Long recipeId; + private String name; + private String image; + private List tags; + + @Builder + public HeartRecipeDto(Heart heart, List tags){ + this.heartId = heart.getHeartId(); + this.memberId = heart.getMember().getMemberId(); + this.recipeId = heart.getRecipe().getRecipeId(); + this.name = heart.getRecipe().getName(); + this.image = heart.getRecipe().getImage(); + this.tags = tags; + } +} diff --git a/src/main/java/CookSave/CookSaveback/Heart/repository/HeartRepository.java b/src/main/java/CookSave/CookSaveback/Heart/repository/HeartRepository.java index 213f0c6..e4fdea5 100644 --- a/src/main/java/CookSave/CookSaveback/Heart/repository/HeartRepository.java +++ b/src/main/java/CookSave/CookSaveback/Heart/repository/HeartRepository.java @@ -6,10 +6,12 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Optional; @Repository public interface HeartRepository extends JpaRepository { boolean existsByMemberAndRecipe(Member member, Recipe recipe); Optional findByMemberAndRecipe(Member member, Recipe recipe); + List findAllByMember(Member member); } diff --git a/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java b/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java index 5bdeab7..22409ce 100644 --- a/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java +++ b/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java @@ -1,20 +1,31 @@ package CookSave.CookSaveback.Heart.service; import CookSave.CookSaveback.Heart.domain.Heart; +import CookSave.CookSaveback.Heart.dto.HeartRecipeDto; import CookSave.CookSaveback.Heart.repository.HeartRepository; +import CookSave.CookSaveback.Ingredient.domain.Ingredient; +import CookSave.CookSaveback.Ingredient.repository.IngredientRepository; import CookSave.CookSaveback.Member.domain.Member; import CookSave.CookSaveback.Recipe.domain.Recipe; import CookSave.CookSaveback.Recipe.repository.RecipeRepository; +import CookSave.CookSaveback.RecipeTag.domain.RecipeTag; +import CookSave.CookSaveback.RecipeTag.repository.RecipeTagRepository; +import CookSave.CookSaveback.Tag.domain.Tag; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; +import java.util.List; + @Service @RequiredArgsConstructor public class HeartService { private final HeartRepository heartRepository; private final RecipeRepository recipeRepository; + private final IngredientRepository ingredientRepository; + private final RecipeTagRepository recipeTagRepository; @Transactional public String heartRecipe(Member member, Long recipeId){ @@ -39,4 +50,35 @@ public String cancelRecipeHeart(Member member, Long recipeId){ heartRepository.delete(heart); return "recipeId가 " + recipeId + "인 레시피가 찜 목록에서 제거되었습니다."; } + + public List getHeartRecipeList(Member member){ + List heartRecipeDtoList = new ArrayList<>(); + + List heartList = heartRepository.findAllByMember(member); + List ingredientList = ingredientRepository.findAllByMember(member); + List ingredientTagList = new ArrayList<>(); + + for(Ingredient ingredient : ingredientList){ + ingredientTagList.add(ingredient.getTag()); + } + + for(Heart heart : heartList){ + List tags = new ArrayList<>(); + Recipe recipe = heart.getRecipe(); + List recipeTagList = recipeTagRepository.findAllByRecipe(recipe); + + List tagList = new ArrayList<>(); + for(RecipeTag recipeTag : recipeTagList){ + tagList.add(recipeTag.getTag()); + } + + for(Tag tag : tagList){ + if(ingredientTagList.contains(tag)){ + tags.add(tag.getName()); + } + } + heartRecipeDtoList.add(new HeartRecipeDto(heart, tags)); + } + return heartRecipeDtoList; + } } diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java b/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java index 5b890c7..77769f6 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java @@ -3,6 +3,7 @@ import CookSave.CookSaveback.Ingredient.domain.Ingredient; import CookSave.CookSaveback.Member.domain.Member; +import CookSave.CookSaveback.Tag.domain.Tag; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -14,4 +15,5 @@ public interface IngredientRepository extends JpaRepository { List findAllByMember(Member member); Long countAllByMember(Member member); Optional findByIngredientIdAndMember(Long ingredientId, Member member); + boolean existsByMemberAndTag(Member member, Tag tag); } diff --git a/src/main/java/CookSave/CookSaveback/RecipeTag/repository/RecipeTagRepository.java b/src/main/java/CookSave/CookSaveback/RecipeTag/repository/RecipeTagRepository.java index bbc94c6..5ef07fa 100644 --- a/src/main/java/CookSave/CookSaveback/RecipeTag/repository/RecipeTagRepository.java +++ b/src/main/java/CookSave/CookSaveback/RecipeTag/repository/RecipeTagRepository.java @@ -6,7 +6,10 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface RecipeTagRepository extends JpaRepository { boolean existsByRecipeAndTag(Recipe recipe, Tag tag); + List findAllByRecipe(Recipe recipe); } From af3acad4bcdec6c1711ada49539824ac4eec59d9 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Thu, 22 Feb 2024 00:46:40 +0900 Subject: [PATCH 33/87] =?UTF-8?q?feat:=20=EC=98=88=EC=82=B0=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../History/controller/HistoryController.java | 27 +++++++++++++++++++ .../History/dto/BudgetRequestDto.java | 10 +++++++ .../History/service/HistoryService.java | 18 +++++++++++++ .../CookSaveback/Member/domain/Member.java | 4 +++ 4 files changed, 59 insertions(+) create mode 100644 src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java create mode 100644 src/main/java/CookSave/CookSaveback/History/dto/BudgetRequestDto.java create mode 100644 src/main/java/CookSave/CookSaveback/History/service/HistoryService.java diff --git a/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java b/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java new file mode 100644 index 0000000..dbe443d --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java @@ -0,0 +1,27 @@ +package CookSave.CookSaveback.History.controller; + +import CookSave.CookSaveback.History.dto.BudgetRequestDto; +import CookSave.CookSaveback.History.service.HistoryService; +import CookSave.CookSaveback.Member.domain.Member; +import CookSave.CookSaveback.Member.service.MemberService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +public class HistoryController { + private final MemberService memberService; + private final HistoryService historyService; + + // 예산 설정 + @PatchMapping("members/budget") + public ResponseEntity updateBudget(@RequestBody BudgetRequestDto budgetRequestDto){ + Member member = memberService.getLoginMember(); + historyService.updateBudget(member, budgetRequestDto); + return new ResponseEntity<>("예산이 설정되었습니다.", HttpStatus.OK); + } +} diff --git a/src/main/java/CookSave/CookSaveback/History/dto/BudgetRequestDto.java b/src/main/java/CookSave/CookSaveback/History/dto/BudgetRequestDto.java new file mode 100644 index 0000000..1a17ee6 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/History/dto/BudgetRequestDto.java @@ -0,0 +1,10 @@ +package CookSave.CookSaveback.History.dto; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class BudgetRequestDto { + private Integer budget; +} diff --git a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java new file mode 100644 index 0000000..f7573e6 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java @@ -0,0 +1,18 @@ +package CookSave.CookSaveback.History.service; + +import CookSave.CookSaveback.History.dto.BudgetRequestDto; +import CookSave.CookSaveback.Member.domain.Member; +import CookSave.CookSaveback.Member.repository.MemberRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class HistoryService { + private final MemberRepository memberRepository; + + public void updateBudget(Member member, BudgetRequestDto budgetRequestDto){ + member.updateBudget(budgetRequestDto.getBudget()); + memberRepository.save(member); + } +} diff --git a/src/main/java/CookSave/CookSaveback/Member/domain/Member.java b/src/main/java/CookSave/CookSaveback/Member/domain/Member.java index 5211ed5..d627e80 100644 --- a/src/main/java/CookSave/CookSaveback/Member/domain/Member.java +++ b/src/main/java/CookSave/CookSaveback/Member/domain/Member.java @@ -26,4 +26,8 @@ public Member(String cooksaveId, String password){ this.cooksaveId = cooksaveId; this.password = password; } + + public void updateBudget(Integer budget){ + this.budget = budget; + } } From 934316a33a2e4f0af6499a924b16358165a67b39 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Thu, 22 Feb 2024 01:54:07 +0900 Subject: [PATCH 34/87] =?UTF-8?q?feat:=20=EB=A0=88=EC=8B=9C=ED=94=BC=20?= =?UTF-8?q?=EC=9A=94=EB=A6=AC=20=EB=82=B4=EC=97=AD=20=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../History/controller/HistoryController.java | 13 +++++++-- .../History/dto/HistoryIngredientReqDto.java | 10 +++++++ .../History/dto/RecipeHistoryReqDto.java | 15 ++++++++++ .../History/repository/HistoryRepository.java | 10 +++++++ .../History/service/HistoryService.java | 29 +++++++++++++++++++ .../HistoryIngredientRepository.java | 9 ++++++ 6 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 src/main/java/CookSave/CookSaveback/History/dto/HistoryIngredientReqDto.java create mode 100644 src/main/java/CookSave/CookSaveback/History/dto/RecipeHistoryReqDto.java create mode 100644 src/main/java/CookSave/CookSaveback/History/repository/HistoryRepository.java create mode 100644 src/main/java/CookSave/CookSaveback/HistoryIngredient/repository/HistoryIngredientRepository.java diff --git a/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java b/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java index dbe443d..c5c29c5 100644 --- a/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java +++ b/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java @@ -1,15 +1,14 @@ package CookSave.CookSaveback.History.controller; import CookSave.CookSaveback.History.dto.BudgetRequestDto; +import CookSave.CookSaveback.History.dto.RecipeHistoryReqDto; import CookSave.CookSaveback.History.service.HistoryService; import CookSave.CookSaveback.Member.domain.Member; import CookSave.CookSaveback.Member.service.MemberService; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PatchMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor @@ -24,4 +23,12 @@ public ResponseEntity updateBudget(@RequestBody BudgetRequestDto budgetR historyService.updateBudget(member, budgetRequestDto); return new ResponseEntity<>("예산이 설정되었습니다.", HttpStatus.OK); } + + // 레시피 요리 내역 저장 + @PostMapping("/recipes/{recipe_id}/ingredients") + public ResponseEntity createRecipeHistory(@PathVariable("recipe_id") Long recipeId, @RequestBody RecipeHistoryReqDto recipeHistoryReqDto){ + Member member = memberService.getLoginMember(); + historyService.createRecipeHistory(member, recipeId, recipeHistoryReqDto); + return new ResponseEntity<>("요리 내역이 저장되었습니다.", HttpStatus.CREATED); + } } diff --git a/src/main/java/CookSave/CookSaveback/History/dto/HistoryIngredientReqDto.java b/src/main/java/CookSave/CookSaveback/History/dto/HistoryIngredientReqDto.java new file mode 100644 index 0000000..fb91442 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/History/dto/HistoryIngredientReqDto.java @@ -0,0 +1,10 @@ +package CookSave.CookSaveback.History.dto; + +import lombok.Getter; + +@Getter +public class HistoryIngredientReqDto { + private String name; + private Float amount; + private Integer price; // 수량이 반영된 가격 +} diff --git a/src/main/java/CookSave/CookSaveback/History/dto/RecipeHistoryReqDto.java b/src/main/java/CookSave/CookSaveback/History/dto/RecipeHistoryReqDto.java new file mode 100644 index 0000000..afa67f0 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/History/dto/RecipeHistoryReqDto.java @@ -0,0 +1,15 @@ +package CookSave.CookSaveback.History.dto; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Getter +@NoArgsConstructor +public class RecipeHistoryReqDto { + private Integer total; + private List ingredients; +} + + diff --git a/src/main/java/CookSave/CookSaveback/History/repository/HistoryRepository.java b/src/main/java/CookSave/CookSaveback/History/repository/HistoryRepository.java new file mode 100644 index 0000000..a9e66d6 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/History/repository/HistoryRepository.java @@ -0,0 +1,10 @@ +package CookSave.CookSaveback.History.repository; + + +import CookSave.CookSaveback.History.domain.History; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface HistoryRepository extends JpaRepository { +} diff --git a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java index f7573e6..f47b201 100644 --- a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java +++ b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java @@ -1,18 +1,47 @@ package CookSave.CookSaveback.History.service; +import CookSave.CookSaveback.History.domain.History; import CookSave.CookSaveback.History.dto.BudgetRequestDto; +import CookSave.CookSaveback.History.dto.HistoryIngredientReqDto; +import CookSave.CookSaveback.History.dto.RecipeHistoryReqDto; +import CookSave.CookSaveback.History.repository.HistoryRepository; +import CookSave.CookSaveback.HistoryIngredient.domain.HistoryIngredient; +import CookSave.CookSaveback.HistoryIngredient.repository.HistoryIngredientRepository; import CookSave.CookSaveback.Member.domain.Member; import CookSave.CookSaveback.Member.repository.MemberRepository; +import CookSave.CookSaveback.Recipe.domain.Recipe; +import CookSave.CookSaveback.Recipe.repository.RecipeRepository; +import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.List; + @Service @RequiredArgsConstructor public class HistoryService { private final MemberRepository memberRepository; + private final RecipeRepository recipeRepository; + private final HistoryRepository historyRepository; + private final HistoryIngredientRepository historyIngredientRepository; public void updateBudget(Member member, BudgetRequestDto budgetRequestDto){ member.updateBudget(budgetRequestDto.getBudget()); memberRepository.save(member); } + + public void createRecipeHistory(Member member, Long recipeId, RecipeHistoryReqDto recipeHistoryReqDto) { + // History 저장 + Recipe recipe = recipeRepository.findById(recipeId) + .orElseThrow(() -> new EntityNotFoundException("recipeId " + recipeId + "인 레시피가 존재하지 않습니다.")); + History history = new History(member, recipe.getName(), recipeHistoryReqDto.getTotal()); + historyRepository.save(history); + + // HistoryIngredient들 저장 + List historyIngredientReqDtos = recipeHistoryReqDto.getIngredients(); + for(HistoryIngredientReqDto ingredientReqDto : historyIngredientReqDtos){ + HistoryIngredient historyIngredient = new HistoryIngredient(history, ingredientReqDto.getName(), ingredientReqDto.getAmount(), ingredientReqDto.getPrice()); + historyIngredientRepository.save(historyIngredient); + } + } } diff --git a/src/main/java/CookSave/CookSaveback/HistoryIngredient/repository/HistoryIngredientRepository.java b/src/main/java/CookSave/CookSaveback/HistoryIngredient/repository/HistoryIngredientRepository.java new file mode 100644 index 0000000..61e2b1a --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/HistoryIngredient/repository/HistoryIngredientRepository.java @@ -0,0 +1,9 @@ +package CookSave.CookSaveback.HistoryIngredient.repository; + +import CookSave.CookSaveback.HistoryIngredient.domain.HistoryIngredient; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface HistoryIngredientRepository extends JpaRepository { +} From a530ff458a5d61e546ff12639c6173fb1a63f219 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Thu, 22 Feb 2024 02:10:14 +0900 Subject: [PATCH 35/87] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EB=A0=88=EC=8B=9C=ED=94=BC=20=EC=9A=94?= =?UTF-8?q?=EB=A6=AC=20=EB=82=B4=EC=97=AD=20=EC=A0=80=EC=9E=A5=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../History/controller/HistoryController.java | 9 +++++++++ .../History/dto/InputHistoryReqDto.java | 14 ++++++++++++++ .../History/service/HistoryService.java | 14 ++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 src/main/java/CookSave/CookSaveback/History/dto/InputHistoryReqDto.java diff --git a/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java b/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java index c5c29c5..eb86d95 100644 --- a/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java +++ b/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java @@ -1,6 +1,7 @@ package CookSave.CookSaveback.History.controller; import CookSave.CookSaveback.History.dto.BudgetRequestDto; +import CookSave.CookSaveback.History.dto.InputHistoryReqDto; import CookSave.CookSaveback.History.dto.RecipeHistoryReqDto; import CookSave.CookSaveback.History.service.HistoryService; import CookSave.CookSaveback.Member.domain.Member; @@ -31,4 +32,12 @@ public ResponseEntity createRecipeHistory(@PathVariable("recipe_id") Lon historyService.createRecipeHistory(member, recipeId, recipeHistoryReqDto); return new ResponseEntity<>("요리 내역이 저장되었습니다.", HttpStatus.CREATED); } + + // 사용자 입력 레시피 요리 내역 저장 + @PostMapping("/recipes/input/ingredients") + public ResponseEntity createInputHistory(@RequestBody InputHistoryReqDto inputHistoryReqDto){ + Member member = memberService.getLoginMember(); + historyService.createInputHistory(member, inputHistoryReqDto); + return new ResponseEntity<>("요리 내역이 저장되었습니다.", HttpStatus.CREATED); + } } diff --git a/src/main/java/CookSave/CookSaveback/History/dto/InputHistoryReqDto.java b/src/main/java/CookSave/CookSaveback/History/dto/InputHistoryReqDto.java new file mode 100644 index 0000000..cf9ecd5 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/History/dto/InputHistoryReqDto.java @@ -0,0 +1,14 @@ +package CookSave.CookSaveback.History.dto; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Getter +@NoArgsConstructor +public class InputHistoryReqDto { + private String name; // 사용자 지정 요리명 + private Integer total; + private List ingredients; +} diff --git a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java index f47b201..9ee5d7d 100644 --- a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java +++ b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java @@ -3,6 +3,7 @@ import CookSave.CookSaveback.History.domain.History; import CookSave.CookSaveback.History.dto.BudgetRequestDto; import CookSave.CookSaveback.History.dto.HistoryIngredientReqDto; +import CookSave.CookSaveback.History.dto.InputHistoryReqDto; import CookSave.CookSaveback.History.dto.RecipeHistoryReqDto; import CookSave.CookSaveback.History.repository.HistoryRepository; import CookSave.CookSaveback.HistoryIngredient.domain.HistoryIngredient; @@ -44,4 +45,17 @@ public void createRecipeHistory(Member member, Long recipeId, RecipeHistoryReqDt historyIngredientRepository.save(historyIngredient); } } + + public void createInputHistory(Member member, InputHistoryReqDto inputHistoryReqDto) { + // History 저장 + History history = new History(member, inputHistoryReqDto.getName(), inputHistoryReqDto.getTotal()); + historyRepository.save(history); + + // HistoryIngredient들 저장 + List historyIngredientReqDtos = inputHistoryReqDto.getIngredients(); + for(HistoryIngredientReqDto ingredientReqDto : historyIngredientReqDtos){ + HistoryIngredient historyIngredient = new HistoryIngredient(history, ingredientReqDto.getName(), ingredientReqDto.getAmount(), ingredientReqDto.getPrice()); + historyIngredientRepository.save(historyIngredient); + } + } } From 7f127a4b78a5997e3b439b5a2ada0ed1dd6a0eea Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Thu, 22 Feb 2024 02:17:52 +0900 Subject: [PATCH 36/87] =?UTF-8?q?style:=20=ED=95=A8=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ingredient/controller/IngredientController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java index 404445a..3a5bc30 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java @@ -60,7 +60,7 @@ public String deleteIngredient(@PathVariable("ingredient_id") Long ingredientId) // 등록되어 있는 레시피 재료 차감 @PatchMapping("/recipes/{recipe_id}/ingredients") @ResponseStatus(value = HttpStatus.OK) - public String SubtractIngredient(@PathVariable("recipe_id") Long recipeId, @RequestBody List subtractDtoList){ + public String subtractIngredient(@PathVariable("recipe_id") Long recipeId, @RequestBody List subtractDtoList){ Member member = memberService.getLoginMember(); ingredientService.subtractIngredient(member, subtractDtoList); return "재료가 차감되었습니다."; @@ -69,7 +69,7 @@ public String SubtractIngredient(@PathVariable("recipe_id") Long recipeId, @Requ // 사용자 입력 레시피 재료 차감 @PatchMapping("/recipes/input/ingredients") @ResponseStatus(value = HttpStatus.OK) - public String SubtractIngredient(@RequestBody List subtractDtoList){ + public String subtractIngredient(@RequestBody List subtractDtoList){ Member member = memberService.getLoginMember(); ingredientService.subtractIngredient(member, subtractDtoList); return "재료가 차감되었습니다."; From 18822caa5896123c3f39dc8ad6760567f8490f37 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Fri, 8 Mar 2024 15:54:25 +0900 Subject: [PATCH 37/87] =?UTF-8?q?feat:=20=EC=9A=94=EB=A6=AC=20=EB=82=B4?= =?UTF-8?q?=EC=97=AD=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../History/controller/HistoryController.java | 7 ++++++ .../History/dto/HistoryDetailResDto.java | 22 ++++++++++++++++++ .../History/dto/HistoryIngredientResDto.java | 23 +++++++++++++++++++ .../History/service/HistoryService.java | 19 +++++++++++---- .../HistoryIngredientRepository.java | 4 ++++ 5 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 src/main/java/CookSave/CookSaveback/History/dto/HistoryDetailResDto.java create mode 100644 src/main/java/CookSave/CookSaveback/History/dto/HistoryIngredientResDto.java diff --git a/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java b/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java index eb86d95..7ddc724 100644 --- a/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java +++ b/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java @@ -1,6 +1,7 @@ package CookSave.CookSaveback.History.controller; import CookSave.CookSaveback.History.dto.BudgetRequestDto; +import CookSave.CookSaveback.History.dto.HistoryDetailResDto; import CookSave.CookSaveback.History.dto.InputHistoryReqDto; import CookSave.CookSaveback.History.dto.RecipeHistoryReqDto; import CookSave.CookSaveback.History.service.HistoryService; @@ -40,4 +41,10 @@ public ResponseEntity createInputHistory(@RequestBody InputHistoryReqDto historyService.createInputHistory(member, inputHistoryReqDto); return new ResponseEntity<>("요리 내역이 저장되었습니다.", HttpStatus.CREATED); } + + @GetMapping("histories/{history_id}") + public HistoryDetailResDto getHistoryDetail(@PathVariable("history_id") Long historyId){ + Member member = memberService.getLoginMember(); + return historyService.getHistoryDetail(historyId, member); + } } diff --git a/src/main/java/CookSave/CookSaveback/History/dto/HistoryDetailResDto.java b/src/main/java/CookSave/CookSaveback/History/dto/HistoryDetailResDto.java new file mode 100644 index 0000000..38b1afb --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/History/dto/HistoryDetailResDto.java @@ -0,0 +1,22 @@ +package CookSave.CookSaveback.History.dto; + +import CookSave.CookSaveback.History.domain.History; +import CookSave.CookSaveback.HistoryIngredient.domain.HistoryIngredient; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Getter +@NoArgsConstructor +public class HistoryDetailResDto { + private Integer total; + private List ingredients; + + @Builder + public HistoryDetailResDto(History history, List ingredients){ + this.total = history.getTotal(); + this.ingredients = ingredients; + } +} diff --git a/src/main/java/CookSave/CookSaveback/History/dto/HistoryIngredientResDto.java b/src/main/java/CookSave/CookSaveback/History/dto/HistoryIngredientResDto.java new file mode 100644 index 0000000..5129d3b --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/History/dto/HistoryIngredientResDto.java @@ -0,0 +1,23 @@ +package CookSave.CookSaveback.History.dto; + +import CookSave.CookSaveback.HistoryIngredient.domain.HistoryIngredient; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class HistoryIngredientResDto { + private Long historyIngId; + private String name; + private Float amount; + private Integer price; + + @Builder + public HistoryIngredientResDto(HistoryIngredient historyIngredient){ + this.historyIngId = historyIngredient.getHistoryIngId(); + this.name = historyIngredient.getName(); + this.amount = historyIngredient.getAmount(); + this.price = historyIngredient.getPrice(); + } +} diff --git a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java index 9ee5d7d..fd0c488 100644 --- a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java +++ b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java @@ -1,10 +1,7 @@ package CookSave.CookSaveback.History.service; import CookSave.CookSaveback.History.domain.History; -import CookSave.CookSaveback.History.dto.BudgetRequestDto; -import CookSave.CookSaveback.History.dto.HistoryIngredientReqDto; -import CookSave.CookSaveback.History.dto.InputHistoryReqDto; -import CookSave.CookSaveback.History.dto.RecipeHistoryReqDto; +import CookSave.CookSaveback.History.dto.*; import CookSave.CookSaveback.History.repository.HistoryRepository; import CookSave.CookSaveback.HistoryIngredient.domain.HistoryIngredient; import CookSave.CookSaveback.HistoryIngredient.repository.HistoryIngredientRepository; @@ -16,6 +13,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; @Service @@ -58,4 +56,17 @@ public void createInputHistory(Member member, InputHistoryReqDto inputHistoryReq historyIngredientRepository.save(historyIngredient); } } + + public HistoryDetailResDto getHistoryDetail(Long historyId, Member member){ + History history = historyRepository.findById(historyId) + .orElseThrow(() -> new EntityNotFoundException("hisotoryId가 " + historyId + "인 요리 내역이 존재하지 않습니다.")); + List historyIngredients = historyIngredientRepository.findAllByHistory(history); + List ingredients = new ArrayList<>(); + + for(HistoryIngredient historyIngredient : historyIngredients){ + HistoryIngredientResDto ingredient = new HistoryIngredientResDto(historyIngredient); + ingredients.add(ingredient); + } + return new HistoryDetailResDto(history, ingredients); + } } diff --git a/src/main/java/CookSave/CookSaveback/HistoryIngredient/repository/HistoryIngredientRepository.java b/src/main/java/CookSave/CookSaveback/HistoryIngredient/repository/HistoryIngredientRepository.java index 61e2b1a..6ce0f64 100644 --- a/src/main/java/CookSave/CookSaveback/HistoryIngredient/repository/HistoryIngredientRepository.java +++ b/src/main/java/CookSave/CookSaveback/HistoryIngredient/repository/HistoryIngredientRepository.java @@ -1,9 +1,13 @@ package CookSave.CookSaveback.HistoryIngredient.repository; +import CookSave.CookSaveback.History.domain.History; import CookSave.CookSaveback.HistoryIngredient.domain.HistoryIngredient; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface HistoryIngredientRepository extends JpaRepository { + List findAllByHistory(History history); } From 11a50133f3ef4b777e004d39317259d2e21af05e Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Fri, 8 Mar 2024 16:42:41 +0900 Subject: [PATCH 38/87] =?UTF-8?q?feat:=20=EC=9A=94=EB=A6=AC=20=EB=82=B4?= =?UTF-8?q?=EC=97=AD=20=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../History/controller/HistoryController.java | 8 ++++++++ .../History/repository/HistoryRepository.java | 4 ++++ .../CookSaveback/History/service/HistoryService.java | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java b/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java index 7ddc724..c3c4041 100644 --- a/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java +++ b/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java @@ -47,4 +47,12 @@ public HistoryDetailResDto getHistoryDetail(@PathVariable("history_id") Long his Member member = memberService.getLoginMember(); return historyService.getHistoryDetail(historyId, member); } + + @DeleteMapping("histories/{history_id}") + @ResponseStatus(value=HttpStatus.OK) + public String deleteHistory(@PathVariable("history_id") Long historyId){ + Member member = memberService.getLoginMember(); + historyService.deleteHistory(member, historyId); + return "요리 내역이 삭제되었습니다."; + } } diff --git a/src/main/java/CookSave/CookSaveback/History/repository/HistoryRepository.java b/src/main/java/CookSave/CookSaveback/History/repository/HistoryRepository.java index a9e66d6..2d578d1 100644 --- a/src/main/java/CookSave/CookSaveback/History/repository/HistoryRepository.java +++ b/src/main/java/CookSave/CookSaveback/History/repository/HistoryRepository.java @@ -2,9 +2,13 @@ import CookSave.CookSaveback.History.domain.History; +import CookSave.CookSaveback.Member.domain.Member; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.Optional; + @Repository public interface HistoryRepository extends JpaRepository { + Optional findByHistoryIdAndMember(Long historyId, Member member); } diff --git a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java index fd0c488..0053e76 100644 --- a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java +++ b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java @@ -69,4 +69,12 @@ public HistoryDetailResDto getHistoryDetail(Long historyId, Member member){ } return new HistoryDetailResDto(history, ingredients); } + + public void deleteHistory(Member member, Long historyId){ + History history = historyRepository.findByHistoryIdAndMember(historyId, member) + .orElseThrow(() -> new IllegalArgumentException("잘못된 접근입니다.")); + List historyIngredients = historyIngredientRepository.findAllByHistory(history); + historyIngredientRepository.deleteAll(historyIngredients); + historyRepository.delete(history); + } } From af3902c29ced33cebff75791ff61b34f69c9201c Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Fri, 8 Mar 2024 16:44:25 +0900 Subject: [PATCH 39/87] =?UTF-8?q?style:=20HistoryController=20=EC=A3=BC?= =?UTF-8?q?=EC=84=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/History/controller/HistoryController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java b/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java index c3c4041..4f65c88 100644 --- a/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java +++ b/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java @@ -42,12 +42,14 @@ public ResponseEntity createInputHistory(@RequestBody InputHistoryReqDto return new ResponseEntity<>("요리 내역이 저장되었습니다.", HttpStatus.CREATED); } + // 요리 내역 상세 조회 @GetMapping("histories/{history_id}") public HistoryDetailResDto getHistoryDetail(@PathVariable("history_id") Long historyId){ Member member = memberService.getLoginMember(); return historyService.getHistoryDetail(historyId, member); } + // 요리 내역 삭제 @DeleteMapping("histories/{history_id}") @ResponseStatus(value=HttpStatus.OK) public String deleteHistory(@PathVariable("history_id") Long historyId){ From 68c969afb152dffef04998d1f9fbff92f0edaa0c Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Wed, 20 Mar 2024 21:00:28 +0900 Subject: [PATCH 40/87] =?UTF-8?q?chore:=20build=20=EC=8B=9C=20-plain.jar?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC=20=EC=83=9D=EC=84=B1=EB=90=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EB=8F=84=EB=A1=9D=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.gradle b/build.gradle index ddea179..f4559fd 100644 --- a/build.gradle +++ b/build.gradle @@ -35,6 +35,10 @@ dependencies { testImplementation 'org.springframework.security:spring-security-test' } +jar { + enabled = false +} + tasks.named('bootBuildImage') { builder = 'paketobuildpacks/builder-jammy-base:latest' } From 8c323edbc4a52e0389c32a8bd433ee5316268a9f Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Thu, 21 Mar 2024 10:01:21 +0900 Subject: [PATCH 41/87] =?UTF-8?q?chore:=20appspec.yml=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appspec.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 appspec.yml diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 0000000..46b3f84 --- /dev/null +++ b/appspec.yml @@ -0,0 +1,25 @@ +version: 0.0 +os: linux + +files: + - source: / + destination: /home/ubuntu/cooksave + overwrite: yes +file_exists_behavior: OVERWRITE + +permissions: + - object: / + pattern: "**" + owner: ubuntu + group: ubuntu + +hooks: + AfterInstall: + - location: scripts/stop.sh + timeout: 60 + runas: ubuntu + + ApplicationStart: + - location: scripts/start.sh + timeout: 60 + runas: ubuntu \ No newline at end of file From 3afed3743e42a867040cdb060239b53b6ec19f0e Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Thu, 21 Mar 2024 10:07:28 +0900 Subject: [PATCH 42/87] =?UTF-8?q?chore:=20start.sh=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/start.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 scripts/start.sh diff --git a/scripts/start.sh b/scripts/start.sh new file mode 100644 index 0000000..0108b2c --- /dev/null +++ b/scripts/start.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +PROJECT_ROOT="/home/ubuntu/cooksave" +JAR_FILE="$PROJECT_ROOT/cooksave-app.jar" + +APP_LOG="$PROJECT_ROOT/application.log" +ERROR_LOG="$PROJECT_ROOT/error.log" +DEPLOY_LOG="$PROJECT_ROOT/deploy.log" + +TIME_NOW=$(date +%c) + +# build 파일 복사 +echo "$TIME_NOW > $JAR_FILE 파일 복사" >> $DEPLOY_LOG +cp $PROJECT_ROOT/build/libs/*.jar $JAR_FILE + +# jar 파일 실행 +echo "$TIME_NOW > $JAR_FILE 파일 실행" >> $DEPLOY_LOG +nohup java -jar $JAR_FILE > $APP_LOG 2> $ERROR_LOG & + +CURRENT_PID=$(pgrep -f $JAR_FILE) +echo "$TIME_NOW > 실행된 프로세스 아이디 $CURRENT_PID 입니다." >> $DEPLOY_LOG \ No newline at end of file From 02121ab3b2aefc183c56c95696fde35802b696d2 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Thu, 21 Mar 2024 10:09:09 +0900 Subject: [PATCH 43/87] =?UTF-8?q?chore:=20stop.sh=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/stop.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 scripts/stop.sh diff --git a/scripts/stop.sh b/scripts/stop.sh new file mode 100644 index 0000000..7b52fd2 --- /dev/null +++ b/scripts/stop.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +PROJECT_ROOT="/home/ubuntu/cooksave" +JAR_FILE="$PROJECT_ROOT/cooksave-app.jar" + +DEPLOY_LOG="$PROJECT_ROOT/deploy.log" + +TIME_NOW=$(date +%c) + +# 현재 구동 중인 애플리케이션 pid 확인 +CURRENT_PID=$(pgrep -f $JAR_FILE) + +# 프로세스가 켜져 있으면 종료 +if [ -z $CURRENT_PID ]; then + echo "$TIME_NOW > 현재 실행중인 애플리케이션이 없습니다" >> $DEPLOY_LOG +else + echo "$TIME_NOW > 실행중인 $CURRENT_PID 애플리케이션 종료" >> $DEPLOY_LOG + kill -15 $CURRENT_PID +fi \ No newline at end of file From cf874e77278921cbdec5d8c853589da86e749ee0 Mon Sep 17 00:00:00 2001 From: Soyeon Cha <89539031+Soyeon-Cha@users.noreply.github.com> Date: Thu, 21 Mar 2024 10:20:47 +0900 Subject: [PATCH 44/87] =?UTF-8?q?chore:=20deploy.yml=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 66 ++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..5f827fb --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,66 @@ +name: Deploy to Amazon EC2 + +on: + push: + branches: [ "develop" ] + +env: + AWS_REGION: ap-northeast-2 + S3_BUCKET_NAME: cooksave-github-actions-s3-bucket + CODE_DEPLOY_APPLICATION_NAME: cooksave-codedeploy-app + CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: cooksave-codedeploy-deployment-group + APPLICATION: ${{ secrets.APPLICATION }} + +permissions: + contents: read + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + environment: production + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + + - name: make application.yml + run: | + mkdir ./src/main/resources + cd ./src/main/resources + touch ./application.yml + echo "${{ secrets.APPLICATION_YML }}" > ./application.yml + + - name: Build with Gradle + run: | + chmod +x ./gradlew + ./gradlew build -x test + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + + - name: Upload to AWS S3 + run: | + aws deploy push \ + --application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ + --ignore-hidden-files \ + --s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \ + --source . + + - name: Deploy to AWS EC2 from S3 + run: | + aws deploy create-deployment \ + --application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ + --deployment-config-name CodeDeployDefault.AllAtOnce \ + --deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \ + --s3-location bucket=$S3_BUCKET_NAME,key=$GITHUB_SHA.zip,bundleType=zip From bcced2058e7429436ed6bf5f51788970d57ee50c Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Thu, 21 Mar 2024 11:30:06 +0900 Subject: [PATCH 45/87] =?UTF-8?q?chore:=20=EB=8F=84=EB=A9=94=EC=9D=B8=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/CookSave/CookSaveback/config/CORSConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/config/CORSConfig.java b/src/main/java/CookSave/CookSaveback/config/CORSConfig.java index 918add8..ea82740 100644 --- a/src/main/java/CookSave/CookSaveback/config/CORSConfig.java +++ b/src/main/java/CookSave/CookSaveback/config/CORSConfig.java @@ -13,7 +13,7 @@ public CorsFilter corsFilter(){ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = new CorsConfiguration(); config.setAllowCredentials(true); - config.addAllowedOrigin("https://www.cooksave.com"); + config.addAllowedOrigin("https://www.cooksave.co.kr"); config.addAllowedOrigin("http://localhost:3000"); config.addAllowedHeader("*"); config.addAllowedMethod("*"); From 872fb32356a6212512a5582664ef5af91b3afa52 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Fri, 22 Mar 2024 09:43:49 +0900 Subject: [PATCH 46/87] =?UTF-8?q?fix:=20CORSConfig=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/CookSave/CookSaveback/config/CORSConfig.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/CookSave/CookSaveback/config/CORSConfig.java b/src/main/java/CookSave/CookSaveback/config/CORSConfig.java index ea82740..60956a6 100644 --- a/src/main/java/CookSave/CookSaveback/config/CORSConfig.java +++ b/src/main/java/CookSave/CookSaveback/config/CORSConfig.java @@ -14,6 +14,8 @@ public CorsFilter corsFilter(){ CorsConfiguration config = new CorsConfiguration(); config.setAllowCredentials(true); config.addAllowedOrigin("https://www.cooksave.co.kr"); + config.addAllowedOrigin("http://api.cooksave.co.kr"); + config.addAllowedOrigin("https://api.cooksave.co.kr"); config.addAllowedOrigin("http://localhost:3000"); config.addAllowedHeader("*"); config.addAllowedMethod("*"); From 06f09b9ec34bb8d5b8350dff76367416f49e4d94 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Fri, 22 Mar 2024 14:30:17 +0900 Subject: [PATCH 47/87] =?UTF-8?q?fix:=20timeout=20=EC=8B=9C=EA=B0=84=20?= =?UTF-8?q?=EC=A6=9D=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appspec.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appspec.yml b/appspec.yml index 46b3f84..831ba09 100644 --- a/appspec.yml +++ b/appspec.yml @@ -16,10 +16,10 @@ permissions: hooks: AfterInstall: - location: scripts/stop.sh - timeout: 60 + timeout: 65 runas: ubuntu ApplicationStart: - location: scripts/start.sh - timeout: 60 + timeout: 65 runas: ubuntu \ No newline at end of file From cd4138f2c24390a0756fcd642db80ba57fed19d9 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Mon, 1 Apr 2024 11:34:08 +0900 Subject: [PATCH 48/87] =?UTF-8?q?fix:=20=ED=86=A0=ED=81=B0=20=EB=A7=8C?= =?UTF-8?q?=EB=A3=8C=20=EC=8B=9C=EA=B0=84=20=EC=A6=9D=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/CookSave/CookSaveback/config/CORSConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/config/CORSConfig.java b/src/main/java/CookSave/CookSaveback/config/CORSConfig.java index 60956a6..b5a4053 100644 --- a/src/main/java/CookSave/CookSaveback/config/CORSConfig.java +++ b/src/main/java/CookSave/CookSaveback/config/CORSConfig.java @@ -19,7 +19,7 @@ public CorsFilter corsFilter(){ config.addAllowedOrigin("http://localhost:3000"); config.addAllowedHeader("*"); config.addAllowedMethod("*"); - config.setMaxAge(3600L); + config.setMaxAge(259200L); config.addExposedHeader("Location"); config.addExposedHeader("Authorization"); source.registerCorsConfiguration("/**", config); From aa62c1646ae7edeb2fdd65c70926e911aff90e91 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Mon, 1 Apr 2024 20:01:01 +0900 Subject: [PATCH 49/87] =?UTF-8?q?fix:=20config=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/config/CORSConfig.java | 28 ----------- .../CookSaveback/config/SecurityConfig.java | 46 ++++++++++++++----- 2 files changed, 35 insertions(+), 39 deletions(-) delete mode 100644 src/main/java/CookSave/CookSaveback/config/CORSConfig.java diff --git a/src/main/java/CookSave/CookSaveback/config/CORSConfig.java b/src/main/java/CookSave/CookSaveback/config/CORSConfig.java deleted file mode 100644 index b5a4053..0000000 --- a/src/main/java/CookSave/CookSaveback/config/CORSConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -package CookSave.CookSaveback.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import org.springframework.web.filter.CorsFilter; - -@Configuration -public class CORSConfig { - @Bean - public CorsFilter corsFilter(){ - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - CorsConfiguration config = new CorsConfiguration(); - config.setAllowCredentials(true); - config.addAllowedOrigin("https://www.cooksave.co.kr"); - config.addAllowedOrigin("http://api.cooksave.co.kr"); - config.addAllowedOrigin("https://api.cooksave.co.kr"); - config.addAllowedOrigin("http://localhost:3000"); - config.addAllowedHeader("*"); - config.addAllowedMethod("*"); - config.setMaxAge(259200L); - config.addExposedHeader("Location"); - config.addExposedHeader("Authorization"); - source.registerCorsConfiguration("/**", config); - return new CorsFilter(source); - } -} diff --git a/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java b/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java index 7fa67d8..6bf83d9 100644 --- a/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java +++ b/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java @@ -7,11 +7,15 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; -import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer; -import org.springframework.security.config.annotation.web.configurers.HttpBasicConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.CorsConfigurationSource; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; + +import java.util.Arrays; +import java.util.List; @Configuration @EnableWebSecurity @@ -20,16 +24,36 @@ public class SecurityConfig { @Value("${spring.jwt.secret-key}") private String secretKey; + @Bean + CorsConfigurationSource corsConfigurationSource() { + CorsConfiguration config = new CorsConfiguration(); + config.setAllowedOrigins(Arrays.asList( + "https://www.cooksave.co.kr", "http://api.cooksave.co.kr", "https://api.cooksave.co.kr", + "http://localhost:3000")); + config.setAllowedMethods(List.of("*")); + config.setAllowedHeaders(List.of("*")); + config.setAllowCredentials(true); + config.setMaxAge(259200L); + config.addExposedHeader("Authorization"); + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", config); + return (source); + } + @Bean public SecurityFilterChain securityFilterChain (HttpSecurity httpSecurity) throws Exception { - return httpSecurity.httpBasic(HttpBasicConfigurer::disable) - .csrf(CsrfConfigurer::disable) - .cors(AbstractHttpConfigurer::disable) - .authorizeHttpRequests(request -> request - .requestMatchers("/members/signup", "/members/login", "/members/refreshtoken").permitAll() // 회원가입, 로그인은 무조건 허용 - .anyRequest().authenticated()) - .sessionManagement(configurer -> configurer.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) // JWT를 사용하므로 stateless - .addFilterBefore(new JwtFilter(secretKey), UsernamePasswordAuthenticationFilter.class) - .build(); + httpSecurity.csrf(AbstractHttpConfigurer::disable); + httpSecurity.cors(corsConfigurer -> corsConfigurer.configurationSource(corsConfigurationSource())); + httpSecurity.sessionManagement( + sessionManagement -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS)); + httpSecurity.formLogin(AbstractHttpConfigurer::disable); + httpSecurity.httpBasic(AbstractHttpConfigurer::disable); + + httpSecurity.authorizeHttpRequests(authorize -> authorize + .requestMatchers("/members/signup", "/members/login", "/members/refreshtoken").permitAll() + .anyRequest().permitAll() + ); + httpSecurity.addFilterBefore(new JwtFilter(secretKey), UsernamePasswordAuthenticationFilter.class); + return httpSecurity.build(); } } From c8671e3fbfc6a374eaa00769976b4aa46a8c39c7 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Tue, 2 Apr 2024 13:18:05 +0900 Subject: [PATCH 50/87] =?UTF-8?q?feat:=201=EB=85=84=20=ED=86=B5=EA=B3=84?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../History/controller/HistoryController.java | 22 ++++-- .../History/dto/AnnualHistoryResDto.java | 18 +++++ .../History/dto/MonthlyCountDto.java | 18 +++++ .../History/dto/MonthlyExpenseDto.java | 18 +++++ .../History/repository/HistoryRepository.java | 2 + .../History/service/HistoryService.java | 69 +++++++++++++++++++ 6 files changed, 140 insertions(+), 7 deletions(-) create mode 100644 src/main/java/CookSave/CookSaveback/History/dto/AnnualHistoryResDto.java create mode 100644 src/main/java/CookSave/CookSaveback/History/dto/MonthlyCountDto.java create mode 100644 src/main/java/CookSave/CookSaveback/History/dto/MonthlyExpenseDto.java diff --git a/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java b/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java index 4f65c88..1eb8da0 100644 --- a/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java +++ b/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java @@ -1,17 +1,17 @@ package CookSave.CookSaveback.History.controller; -import CookSave.CookSaveback.History.dto.BudgetRequestDto; -import CookSave.CookSaveback.History.dto.HistoryDetailResDto; -import CookSave.CookSaveback.History.dto.InputHistoryReqDto; -import CookSave.CookSaveback.History.dto.RecipeHistoryReqDto; +import CookSave.CookSaveback.History.dto.*; import CookSave.CookSaveback.History.service.HistoryService; import CookSave.CookSaveback.Member.domain.Member; import CookSave.CookSaveback.Member.service.MemberService; import lombok.RequiredArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.time.LocalDate; + @RestController @RequiredArgsConstructor public class HistoryController { @@ -19,7 +19,7 @@ public class HistoryController { private final HistoryService historyService; // 예산 설정 - @PatchMapping("members/budget") + @PatchMapping("/members/budget") public ResponseEntity updateBudget(@RequestBody BudgetRequestDto budgetRequestDto){ Member member = memberService.getLoginMember(); historyService.updateBudget(member, budgetRequestDto); @@ -43,18 +43,26 @@ public ResponseEntity createInputHistory(@RequestBody InputHistoryReqDto } // 요리 내역 상세 조회 - @GetMapping("histories/{history_id}") + @GetMapping("/histories/{history_id}") public HistoryDetailResDto getHistoryDetail(@PathVariable("history_id") Long historyId){ Member member = memberService.getLoginMember(); return historyService.getHistoryDetail(historyId, member); } // 요리 내역 삭제 - @DeleteMapping("histories/{history_id}") + @DeleteMapping("/histories/{history_id}") @ResponseStatus(value=HttpStatus.OK) public String deleteHistory(@PathVariable("history_id") Long historyId){ Member member = memberService.getLoginMember(); historyService.deleteHistory(member, historyId); return "요리 내역이 삭제되었습니다."; } + + // 1년 통계 조회 + @GetMapping("/histories") + @ResponseStatus(HttpStatus.OK) + public AnnualHistoryResDto getAnnualHistory(@RequestParam(required = false) LocalDate date){ + Member member = memberService.getLoginMember(); + return historyService.getAnnualHistory(member, date); + } } diff --git a/src/main/java/CookSave/CookSaveback/History/dto/AnnualHistoryResDto.java b/src/main/java/CookSave/CookSaveback/History/dto/AnnualHistoryResDto.java new file mode 100644 index 0000000..dda4152 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/History/dto/AnnualHistoryResDto.java @@ -0,0 +1,18 @@ +package CookSave.CookSaveback.History.dto; + +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +@Getter +public class AnnualHistoryResDto { + private List expenseDtoList; + private List countDtoList; + + @Builder + public AnnualHistoryResDto(List expenseDtoList, List countDtoList){ + this.expenseDtoList = expenseDtoList; + this.countDtoList = countDtoList; + } +} diff --git a/src/main/java/CookSave/CookSaveback/History/dto/MonthlyCountDto.java b/src/main/java/CookSave/CookSaveback/History/dto/MonthlyCountDto.java new file mode 100644 index 0000000..ee6fd79 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/History/dto/MonthlyCountDto.java @@ -0,0 +1,18 @@ +package CookSave.CookSaveback.History.dto; + +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class MonthlyCountDto { + private String month; + private Integer count; + + @Builder + public MonthlyCountDto(String month, Integer count){ + this.month = month; + this.count = count; + } +} diff --git a/src/main/java/CookSave/CookSaveback/History/dto/MonthlyExpenseDto.java b/src/main/java/CookSave/CookSaveback/History/dto/MonthlyExpenseDto.java new file mode 100644 index 0000000..58a7f6a --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/History/dto/MonthlyExpenseDto.java @@ -0,0 +1,18 @@ +package CookSave.CookSaveback.History.dto; + +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class MonthlyExpenseDto { + private String month; + private Integer expense; + + @Builder + public MonthlyExpenseDto(String month, Integer expense){ + this.month = month; + this.expense = expense; + } +} diff --git a/src/main/java/CookSave/CookSaveback/History/repository/HistoryRepository.java b/src/main/java/CookSave/CookSaveback/History/repository/HistoryRepository.java index 2d578d1..4ac8d84 100644 --- a/src/main/java/CookSave/CookSaveback/History/repository/HistoryRepository.java +++ b/src/main/java/CookSave/CookSaveback/History/repository/HistoryRepository.java @@ -6,9 +6,11 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Optional; @Repository public interface HistoryRepository extends JpaRepository { Optional findByHistoryIdAndMember(Long historyId, Member member); + List findAllByMember(Member member); } diff --git a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java index 0053e76..4ce433f 100644 --- a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java +++ b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java @@ -13,6 +13,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; @@ -77,4 +79,71 @@ public void deleteHistory(Member member, Long historyId){ historyIngredientRepository.deleteAll(historyIngredients); historyRepository.delete(history); } + + // 1년 통계 조회 + public AnnualHistoryResDto getAnnualHistory(Member member, LocalDate date) { + // 비용 합산을 위해 현재 로그인한 member의 모든 history 불러오기 + List histories = historyRepository.findAllByMember(member); + LocalDate searchingDate = date; + LocalDate startDate; + + List expenseDtoList = new ArrayList<>(); + List countDtoList = new ArrayList<>(); + + // 현재 날짜에 해당하는 달의 dto 생성 후 리스트에 추가 + // (현재 날짜의 YYYY-MM)-01 <= createdAt <= 현재 날짜 + Integer expense = 0; + Integer count = 0; + + // date가 null일 경우 현재 날짜를 기준으로 통계 조회 + if (date == null){ + searchingDate = LocalDate.now(); + String cutDate = searchingDate.toString().substring(0, 7); + startDate = LocalDate.parse(cutDate+"-01", DateTimeFormatter.ofPattern("yyyy-MM-dd")); + for (History history : histories) { + LocalDate createdAt = history.getCreatedAt(); + if ((createdAt.isEqual(startDate) | createdAt.isAfter(startDate)) && (createdAt.isEqual(searchingDate) | createdAt.isBefore(searchingDate))) { + expense += history.getTotal(); + count++; + } + } + expenseDtoList.add(new MonthlyExpenseDto(cutDate, expense)); + countDtoList.add(new MonthlyCountDto(cutDate, count)); + } + else{ + String cutDate = searchingDate.toString().substring(0, 7); + startDate = LocalDate.parse(cutDate+"-01", DateTimeFormatter.ofPattern("yyyy-MM-dd")); + for (History history : histories) { + LocalDate createdAt = history.getCreatedAt(); + if ((createdAt.isEqual(date) | createdAt.isAfter(date)) && (createdAt.isBefore(date.minusMonths(1)))) { + expense += history.getTotal(); + count++; + } + } + expenseDtoList.add(new MonthlyExpenseDto(cutDate, expense)); + countDtoList.add(new MonthlyCountDto(cutDate, count)); + } + + // 현재 이전의 11개월의 값으로 dto 리스트를 만드는 for문 + // ((YYYY-MM)-(0000-01))-01 <= createdAt < YYYY-MM-01 + Integer expense2 = 0; + Integer count2 = 0; + for (int i=1; i<12; i++){ + LocalDate newStartDate = startDate.minusMonths(i); + LocalDate endDate = newStartDate.plusMonths(1); + expense2 = 0; + count2 = 0; + for (History history : histories){ + LocalDate createdAt = history.getCreatedAt(); + if ((createdAt.isEqual(newStartDate)|createdAt.isAfter(newStartDate))&&(createdAt.isBefore(endDate))){ + expense2 += history.getTotal(); + count2 ++; + } + } + String month = newStartDate.toString().substring(0, 7); + expenseDtoList.add(new MonthlyExpenseDto(month, expense2)); + countDtoList.add(new MonthlyCountDto(month, count2)); + } + return new AnnualHistoryResDto(expenseDtoList, countDtoList); + } } From 2602b233ee1be67c866ee2ec3deecd031c8d8df4 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Tue, 2 Apr 2024 20:02:38 +0900 Subject: [PATCH 51/87] =?UTF-8?q?feat:=20=EC=9E=AC=EB=A3=8C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=EC=9D=84=20=EC=9E=AC=EB=A3=8C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EA=B8=B0=EB=8A=A5=EC=97=90=20=ED=86=B5?= =?UTF-8?q?=ED=95=A9=ED=95=B4=EC=84=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IngredientController.java | 9 ---- .../Ingredient/service/IngredientService.java | 48 ++++++++++++------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java index 3a5bc30..da1d977 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java @@ -48,15 +48,6 @@ public String updateIngredientList(@RequestBody List updateReq return "재료가 수정되었습니다."; } - // 재료 삭제 - @DeleteMapping("/ingredients/list/{ingredient_id}") - @ResponseStatus(value=HttpStatus.OK) - public String deleteIngredient(@PathVariable("ingredient_id") Long ingredientId){ - Member member = memberService.getLoginMember(); - ingredientService.deleteIngredient(member, ingredientId); - return "재료가 삭제되었습니다."; - } - // 등록되어 있는 레시피 재료 차감 @PatchMapping("/recipes/{recipe_id}/ingredients") @ResponseStatus(value = HttpStatus.OK) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index 2a8cc0a..9b375a0 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Objects; @Service @RequiredArgsConstructor @@ -54,28 +55,39 @@ public void createIngredients(Member member, List ingredie } public void updateIngredients(Member member, List updateRequestDtos){ - // 업데이트 할 ingredient 개수 구하기 - Long count = ingredientRepository.countAllByMember(member); - int intCount = (int)(long)count; + List ingredients = ingredientRepository.findAllByMember(member); - List originalIngredients = ingredientRepository.findAllByMember(member); + List existIngs = new ArrayList<>(ingredients.size()); + for (int i=0; i new EntityNotFoundException("iconId " + iconId + "인 아이콘이 존재하지 않습니다.")); - Float amount = updateRequestDtos.get(i).getAmount(); - - originalIngredients.get(i).updateIngredient(icon, amount); - ingredientRepository.save(originalIngredients.get(i)); + for (int i=0; i new EntityNotFoundException("iconId " + iconId + "인 아이콘이 존재하지 않습니다.")); + Float amount = updateRequestDtos.get(j).getAmount(); + + ingredients.get(i).updateIngredient(icon, amount); + ingredientRepository.save(ingredients.get(i)); + } + } } - } - public void deleteIngredient(Member member, Long ingredientId){ - Ingredient ingredient = ingredientRepository.findByIngredientIdAndMember(ingredientId, member) - .orElseThrow(() -> new IllegalArgumentException("잘못된 접근입니다.")); - ingredientRepository.delete(ingredient); + // request에 존재하지 않는 ingredient는 삭제 + for (int i=0; i subtractRequestDtos){ From f39496bcb94d08e69aa8a5c887ac40d7fe2ec62e Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Tue, 2 Apr 2024 20:06:57 +0900 Subject: [PATCH 52/87] =?UTF-8?q?style:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Ingredient/service/IngredientService.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index 9b375a0..bf29489 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -91,12 +91,9 @@ public void updateIngredients(Member member, List updateReques } public void subtractIngredient(Member member, List subtractRequestDtos){ - Long count = ingredientRepository.countAllByMember(member); - int intCount = (int)(long)count; - List ingredients = ingredientRepository.findAllByMember(member); - for (int i = 0; i Date: Tue, 2 Apr 2024 20:23:57 +0900 Subject: [PATCH 53/87] =?UTF-8?q?fix:=20=EC=9E=AC=EB=A3=8C=20=EC=B0=A8?= =?UTF-8?q?=EA=B0=90=20=ED=9B=84=20=EC=88=98=EB=9F=89=EC=9D=B4=200?= =?UTF-8?q?=EC=9D=B8=20=EC=9E=AC=EB=A3=8C=EB=8A=94=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ingredient/service/IngredientService.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index bf29489..138e574 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -93,13 +93,25 @@ public void updateIngredients(Member member, List updateReques public void subtractIngredient(Member member, List subtractRequestDtos){ List ingredients = ingredientRepository.findAllByMember(member); - for (int i = 0; i ingredientList = ingredientRepository.findAllByMember(member); + for (Ingredient ingredient : ingredientList){ + if (ingredient.getAmount()==0){ + ingredientRepository.delete(ingredient); + } } } } From ee49f161045dc0bee2d24039ad67302aa61af477 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Tue, 2 Apr 2024 20:52:39 +0900 Subject: [PATCH 54/87] =?UTF-8?q?fix:=20=EC=B0=9C=ED=95=9C=20=EB=A0=88?= =?UTF-8?q?=EC=8B=9C=ED=94=BC=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=EC=9D=98=20response=20=ED=95=AD=EB=AA=A9=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSave/CookSaveback/Heart/dto/HeartRecipeDto.java | 8 +++++--- .../CookSaveback/Heart/service/HeartService.java | 9 ++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Heart/dto/HeartRecipeDto.java b/src/main/java/CookSave/CookSaveback/Heart/dto/HeartRecipeDto.java index 478ffba..5fc8a5e 100644 --- a/src/main/java/CookSave/CookSaveback/Heart/dto/HeartRecipeDto.java +++ b/src/main/java/CookSave/CookSaveback/Heart/dto/HeartRecipeDto.java @@ -15,15 +15,17 @@ public class HeartRecipeDto { private Long recipeId; private String name; private String image; - private List tags; + private String mainIng; + private Boolean isHeart; @Builder - public HeartRecipeDto(Heart heart, List tags){ + public HeartRecipeDto(Heart heart){ this.heartId = heart.getHeartId(); this.memberId = heart.getMember().getMemberId(); this.recipeId = heart.getRecipe().getRecipeId(); this.name = heart.getRecipe().getName(); this.image = heart.getRecipe().getImage(); - this.tags = tags; + this.mainIng = heart.getRecipe().getMainIng(); + this.isHeart = true; } } diff --git a/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java b/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java index 22409ce..92eb579 100644 --- a/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java +++ b/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java @@ -55,6 +55,12 @@ public List getHeartRecipeList(Member member){ List heartRecipeDtoList = new ArrayList<>(); List heartList = heartRepository.findAllByMember(member); + + for (Heart heart : heartList){ + heartRecipeDtoList.add(new HeartRecipeDto(heart)); + } + return heartRecipeDtoList; + /* List ingredientList = ingredientRepository.findAllByMember(member); List ingredientTagList = new ArrayList<>(); @@ -77,8 +83,9 @@ public List getHeartRecipeList(Member member){ tags.add(tag.getName()); } } - heartRecipeDtoList.add(new HeartRecipeDto(heart, tags)); + heartRecipeDtoList.add(new HeartRecipeDto(heart)); } return heartRecipeDtoList; + */ } } From 7701221a10eaa159e26af15f3d911079bfd2734b Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Tue, 2 Apr 2024 20:53:13 +0900 Subject: [PATCH 55/87] =?UTF-8?q?style:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Heart/service/HeartService.java | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java b/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java index 92eb579..9d93bc4 100644 --- a/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java +++ b/src/main/java/CookSave/CookSaveback/Heart/service/HeartService.java @@ -60,32 +60,5 @@ public List getHeartRecipeList(Member member){ heartRecipeDtoList.add(new HeartRecipeDto(heart)); } return heartRecipeDtoList; - /* - List ingredientList = ingredientRepository.findAllByMember(member); - List ingredientTagList = new ArrayList<>(); - - for(Ingredient ingredient : ingredientList){ - ingredientTagList.add(ingredient.getTag()); - } - - for(Heart heart : heartList){ - List tags = new ArrayList<>(); - Recipe recipe = heart.getRecipe(); - List recipeTagList = recipeTagRepository.findAllByRecipe(recipe); - - List tagList = new ArrayList<>(); - for(RecipeTag recipeTag : recipeTagList){ - tagList.add(recipeTag.getTag()); - } - - for(Tag tag : tagList){ - if(ingredientTagList.contains(tag)){ - tags.add(tag.getName()); - } - } - heartRecipeDtoList.add(new HeartRecipeDto(heart)); - } - return heartRecipeDtoList; - */ } } From 531eb65baf027c62a7486e024062662b049b8bb5 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Wed, 3 Apr 2024 11:10:41 +0900 Subject: [PATCH 56/87] =?UTF-8?q?fix:=20=ED=86=A0=ED=81=B0=20=EB=A7=8C?= =?UTF-8?q?=EB=A3=8C=20=EC=8B=9C=EA=B0=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Member/service/MemberService.java | 8 ++++---- .../java/CookSave/CookSaveback/config/SecurityConfig.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java index 68d393c..28103b4 100644 --- a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java +++ b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java @@ -30,11 +30,11 @@ public class MemberService { @Value("${spring.jwt.refresh-key}") private String refreshKey; - // Access 토큰 만료 시간을 1시간으로 설정 - private Long AccessExpireTimeMs = 1000 * 60 * 60L; + // Access 토큰 만료 시간을 1분으로 설정 + private Long AccessExpireTimeMs = 1000 * 1 * 60L; - // Refresh 토큰 만료 시간을 7일로 설정 - private Long RefreshExpireTimeMs = 7 * 24 * 1000 * 60 * 60L; + // Refresh 토큰 만료 시간을 10분으로 설정 + private Long RefreshExpireTimeMs = 1000 * 10 * 60L; // 회원가입 public String signUp(String cooksaveId, String password, String passwordCheck){ diff --git a/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java b/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java index 6bf83d9..9c5306c 100644 --- a/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java +++ b/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java @@ -33,7 +33,7 @@ CorsConfigurationSource corsConfigurationSource() { config.setAllowedMethods(List.of("*")); config.setAllowedHeaders(List.of("*")); config.setAllowCredentials(true); - config.setMaxAge(259200L); + config.setMaxAge(3600L); config.addExposedHeader("Authorization"); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", config); From a0da7411b36810d35e2a6a34571a82ef775159a4 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Fri, 5 Apr 2024 21:03:27 +0900 Subject: [PATCH 57/87] =?UTF-8?q?fix:=20directory=EB=AA=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appspec.yml b/appspec.yml index 831ba09..49fb0d5 100644 --- a/appspec.yml +++ b/appspec.yml @@ -3,7 +3,7 @@ os: linux files: - source: / - destination: /home/ubuntu/cooksave + destination: /home/ubuntu/spring overwrite: yes file_exists_behavior: OVERWRITE From 44557df47a12073453ef018215b412a391cdd96b Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Fri, 5 Apr 2024 21:10:02 +0900 Subject: [PATCH 58/87] =?UTF-8?q?fix:=20directory=EB=AA=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/start.sh | 2 +- scripts/stop.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/start.sh b/scripts/start.sh index 0108b2c..0e25a34 100644 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -PROJECT_ROOT="/home/ubuntu/cooksave" +PROJECT_ROOT="/home/ubuntu/spring" JAR_FILE="$PROJECT_ROOT/cooksave-app.jar" APP_LOG="$PROJECT_ROOT/application.log" diff --git a/scripts/stop.sh b/scripts/stop.sh index 7b52fd2..a14d4cb 100644 --- a/scripts/stop.sh +++ b/scripts/stop.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -PROJECT_ROOT="/home/ubuntu/cooksave" +PROJECT_ROOT="/home/ubuntu/spring" JAR_FILE="$PROJECT_ROOT/cooksave-app.jar" DEPLOY_LOG="$PROJECT_ROOT/deploy.log" From a32788855f29c6ec02d6adc01557230e4c00cc4c Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Sat, 6 Apr 2024 08:25:13 +0900 Subject: [PATCH 59/87] =?UTF-8?q?fix:=20History=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=EC=97=90=20image=20=EC=BB=AC=EB=9F=BC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/CookSave/CookSaveback/History/domain/History.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/History/domain/History.java b/src/main/java/CookSave/CookSaveback/History/domain/History.java index 3f9c8c2..04ef3cc 100644 --- a/src/main/java/CookSave/CookSaveback/History/domain/History.java +++ b/src/main/java/CookSave/CookSaveback/History/domain/History.java @@ -21,13 +21,17 @@ public class History extends BaseTimeEntity { @Column(nullable = false) private String name; // 요리명 + @Column + private String image; // 요리 사진 URL + @Column(nullable = false) private Integer total; // 사용한 재료값 총합 @Builder - public History(Member member, String name, Integer total){ + public History(Member member, String name, String image, Integer total){ this.member = member; this.name = name; + this.image = image; this.total = total; } } From b2b80d319913760a5c7c759ababbf97ea57c1ca0 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Sat, 6 Apr 2024 08:27:54 +0900 Subject: [PATCH 60/87] =?UTF-8?q?fix:=20=EC=B6=94=EA=B0=80=EB=90=9C=20imag?= =?UTF-8?q?e=20=EC=BB=AC=EB=9F=BC=EC=9D=84=20History=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20=EA=B3=BC=EC=A0=95=EC=97=90=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSave/CookSaveback/History/service/HistoryService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java index 4ce433f..0270e18 100644 --- a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java +++ b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java @@ -35,7 +35,7 @@ public void createRecipeHistory(Member member, Long recipeId, RecipeHistoryReqDt // History 저장 Recipe recipe = recipeRepository.findById(recipeId) .orElseThrow(() -> new EntityNotFoundException("recipeId " + recipeId + "인 레시피가 존재하지 않습니다.")); - History history = new History(member, recipe.getName(), recipeHistoryReqDto.getTotal()); + History history = new History(member, recipe.getName(), recipe.getImage(), recipeHistoryReqDto.getTotal()); historyRepository.save(history); // HistoryIngredient들 저장 @@ -48,7 +48,7 @@ public void createRecipeHistory(Member member, Long recipeId, RecipeHistoryReqDt public void createInputHistory(Member member, InputHistoryReqDto inputHistoryReqDto) { // History 저장 - History history = new History(member, inputHistoryReqDto.getName(), inputHistoryReqDto.getTotal()); + History history = new History(member, inputHistoryReqDto.getName(), null, inputHistoryReqDto.getTotal()); historyRepository.save(history); // HistoryIngredient들 저장 From fbc85ae0fff373a2aefc55daf16a9c907024ce55 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Sat, 6 Apr 2024 10:46:30 +0900 Subject: [PATCH 61/87] =?UTF-8?q?feat:=20=ED=86=B5=EA=B3=84=20=EC=9A=94?= =?UTF-8?q?=EC=95=BD=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../History/controller/HistoryController.java | 8 +++ .../History/dto/HighlightHistoryDto.java | 23 +++++++ .../History/dto/HistoryHighlightResDto.java | 19 ++++++ .../History/service/HistoryService.java | 64 ++++++++++++++++++- 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 src/main/java/CookSave/CookSaveback/History/dto/HighlightHistoryDto.java create mode 100644 src/main/java/CookSave/CookSaveback/History/dto/HistoryHighlightResDto.java diff --git a/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java b/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java index 1eb8da0..ab80690 100644 --- a/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java +++ b/src/main/java/CookSave/CookSaveback/History/controller/HistoryController.java @@ -65,4 +65,12 @@ public AnnualHistoryResDto getAnnualHistory(@RequestParam(required = false) Loca Member member = memberService.getLoginMember(); return historyService.getAnnualHistory(member, date); } + + // 통계 요약 조회 + @GetMapping("/highlight") + @ResponseStatus(HttpStatus.OK) + public HistoryHighlightResDto getHistoryHighlight(@RequestParam(required = false) LocalDate date){ + Member member = memberService.getLoginMember(); + return historyService.getHistoryHighlight(member, date); + } } diff --git a/src/main/java/CookSave/CookSaveback/History/dto/HighlightHistoryDto.java b/src/main/java/CookSave/CookSaveback/History/dto/HighlightHistoryDto.java new file mode 100644 index 0000000..e83570e --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/History/dto/HighlightHistoryDto.java @@ -0,0 +1,23 @@ +package CookSave.CookSaveback.History.dto; + +import CookSave.CookSaveback.History.domain.History; +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDate; + +@Getter +public class HighlightHistoryDto { + private String image; + private String name; + private Integer total; + private LocalDate createdAt; + + @Builder + public HighlightHistoryDto(History history){ + this.image = history.getImage(); + this.name = history.getName(); + this.total = history.getTotal(); + this.createdAt = history.getCreatedAt(); + } +} diff --git a/src/main/java/CookSave/CookSaveback/History/dto/HistoryHighlightResDto.java b/src/main/java/CookSave/CookSaveback/History/dto/HistoryHighlightResDto.java new file mode 100644 index 0000000..62aa6cf --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/History/dto/HistoryHighlightResDto.java @@ -0,0 +1,19 @@ +package CookSave.CookSaveback.History.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.List; + +@Getter +@AllArgsConstructor +public class HistoryHighlightResDto { + private Integer percentage; + private Integer count; + private Integer budget; + private Integer monthExpense; + private Integer balance; + private Integer average; + private Integer previousAverage; + private List highlightHistoryDtoList; +} diff --git a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java index 0270e18..449de65 100644 --- a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java +++ b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java @@ -95,7 +95,7 @@ public AnnualHistoryResDto getAnnualHistory(Member member, LocalDate date) { Integer expense = 0; Integer count = 0; - // date가 null일 경우 현재 날짜를 기준으로 통계 조회 + // date가 null인 경우 현재 날짜를 기준으로 통계 조회 if (date == null){ searchingDate = LocalDate.now(); String cutDate = searchingDate.toString().substring(0, 7); @@ -146,4 +146,66 @@ public AnnualHistoryResDto getAnnualHistory(Member member, LocalDate date) { } return new AnnualHistoryResDto(expenseDtoList, countDtoList); } + + // 통계 요약 조회 + public HistoryHighlightResDto getHistoryHighlight(Member member, LocalDate date){ + List histories = historyRepository.findAllByMember(member); + List monthHistories = new ArrayList<>(); + List highlightHistoryDtoList = new ArrayList<>(); + Integer count = 0; + Integer expense = 0; + Integer previousCount = 0; + Integer previousExpense = 0; + + // date가 null인 경우 현재 달의 1일로 시작일 설정 + if (date == null){ + date = LocalDate.now(); + String cutDate = date.toString().substring(0, 7); + date = LocalDate.parse(cutDate+"-01", DateTimeFormatter.ofPattern("yyyy-MM-dd")); + } + + LocalDate endDate = date.plusMonths(1); + + for (History history : histories){ + LocalDate createdAt = history.getCreatedAt(); + if ((createdAt.isEqual(date)|createdAt.isAfter(date))&&(createdAt.isBefore(endDate))){ + count++; + expense += history.getTotal(); + monthHistories.add(history); + } + + // 지난 달 사용 금액 구하기 + else if ((createdAt.isEqual(date.minusMonths(1))|createdAt.isAfter(date.minusMonths(1)))&&(createdAt.isBefore(date))){ + previousCount++; + previousExpense += history.getTotal(); + } + } + + Integer budget = member.getBudget(); + double percentage = 0; + if (budget!=0){ + percentage = (expense.doubleValue())/(budget.doubleValue())*100.0; + } + + Integer balance = budget-expense; + if (balance<=0){ + balance = 0; + } + + Integer average = 0; + if (count!=0){ + average = expense/count; + } + + Integer previousAverage = 0; + if (previousCount!=0){ + previousAverage = previousExpense/previousCount; + } + + for (History history : monthHistories){ + highlightHistoryDtoList.add(new HighlightHistoryDto(history)); + } + + return new HistoryHighlightResDto((int) percentage, count, budget, expense, balance, average, previousAverage, highlightHistoryDtoList); + } } From 164f35b2948befd07fd6fbf11aab858641058764 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Sat, 6 Apr 2024 11:04:49 +0900 Subject: [PATCH 62/87] =?UTF-8?q?fix:=20=EC=98=88=EC=82=B0=EC=9D=84=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=ED=95=98=EC=A7=80=20=EC=95=8A=EC=9D=80=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/History/service/HistoryService.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java index 449de65..59b30ea 100644 --- a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java +++ b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java @@ -183,7 +183,10 @@ else if ((createdAt.isEqual(date.minusMonths(1))|createdAt.isAfter(date.minusMon Integer budget = member.getBudget(); double percentage = 0; - if (budget!=0){ + if (budget==null){ + budget = 0; + } + else if (budget!=0){ percentage = (expense.doubleValue())/(budget.doubleValue())*100.0; } From f2bac0f5273677ee4bd17bc1ca18dd6c64212269 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Sat, 6 Apr 2024 15:02:54 +0900 Subject: [PATCH 63/87] =?UTF-8?q?fix:=20=ED=86=A0=ED=81=B0=20=EB=A7=8C?= =?UTF-8?q?=EB=A3=8C=20=EC=8B=9C=EA=B0=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Member/service/MemberService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java index 28103b4..da78755 100644 --- a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java +++ b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java @@ -30,11 +30,11 @@ public class MemberService { @Value("${spring.jwt.refresh-key}") private String refreshKey; - // Access 토큰 만료 시간을 1분으로 설정 - private Long AccessExpireTimeMs = 1000 * 1 * 60L; + // Access 토큰 만료 시간을 3일로 설정 + private Long AccessExpireTimeMs = 3 * 24 * 1000 * 60 * 60L; - // Refresh 토큰 만료 시간을 10분으로 설정 - private Long RefreshExpireTimeMs = 1000 * 10 * 60L; + // Refresh 토큰 만료 시간을 7일로 설정 + private Long RefreshExpireTimeMs = 7 * 24 * 1000 * 60 * 60L; // 회원가입 public String signUp(String cooksaveId, String password, String passwordCheck){ From 271a9417e5bc7cd3afc8d56a2ab29f5c5583e437 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Fri, 12 Apr 2024 14:46:15 +0900 Subject: [PATCH 64/87] =?UTF-8?q?fix:=20HighlightHistoryDto=EC=97=90=20his?= =?UTF-8?q?toryId=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSave/CookSaveback/History/dto/HighlightHistoryDto.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/CookSave/CookSaveback/History/dto/HighlightHistoryDto.java b/src/main/java/CookSave/CookSaveback/History/dto/HighlightHistoryDto.java index e83570e..8043f96 100644 --- a/src/main/java/CookSave/CookSaveback/History/dto/HighlightHistoryDto.java +++ b/src/main/java/CookSave/CookSaveback/History/dto/HighlightHistoryDto.java @@ -8,6 +8,7 @@ @Getter public class HighlightHistoryDto { + private Long historyId; private String image; private String name; private Integer total; @@ -15,6 +16,7 @@ public class HighlightHistoryDto { @Builder public HighlightHistoryDto(History history){ + this.historyId = history.getHistoryId(); this.image = history.getImage(); this.name = history.getName(); this.total = history.getTotal(); From 75fe23a2aafa75d35e06c57852a6f8b666d334ef Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Fri, 12 Apr 2024 15:05:58 +0900 Subject: [PATCH 65/87] =?UTF-8?q?fix:=20highlightHistoryDtoList=EC=9D=98?= =?UTF-8?q?=20=EC=9A=94=EB=A6=AC=20=EB=82=B4=EC=97=AD=EC=9D=84=20=EC=B5=9C?= =?UTF-8?q?=EC=8B=A0=EC=88=9C=EC=9C=BC=EB=A1=9C=20=EC=A0=95=EB=A0=AC?= =?UTF-8?q?=ED=95=B4=EC=84=9C=20=EC=A0=84=EB=8B=AC=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/History/repository/HistoryRepository.java | 1 + .../CookSave/CookSaveback/History/service/HistoryService.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/History/repository/HistoryRepository.java b/src/main/java/CookSave/CookSaveback/History/repository/HistoryRepository.java index 4ac8d84..56169ce 100644 --- a/src/main/java/CookSave/CookSaveback/History/repository/HistoryRepository.java +++ b/src/main/java/CookSave/CookSaveback/History/repository/HistoryRepository.java @@ -13,4 +13,5 @@ public interface HistoryRepository extends JpaRepository { Optional findByHistoryIdAndMember(Long historyId, Member member); List findAllByMember(Member member); + List findAllByMemberOrderByHistoryIdDesc(Member member); } diff --git a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java index 59b30ea..e22c7dd 100644 --- a/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java +++ b/src/main/java/CookSave/CookSaveback/History/service/HistoryService.java @@ -149,7 +149,7 @@ public AnnualHistoryResDto getAnnualHistory(Member member, LocalDate date) { // 통계 요약 조회 public HistoryHighlightResDto getHistoryHighlight(Member member, LocalDate date){ - List histories = historyRepository.findAllByMember(member); + List histories = historyRepository.findAllByMemberOrderByHistoryIdDesc(member); List monthHistories = new ArrayList<>(); List highlightHistoryDtoList = new ArrayList<>(); Integer count = 0; From dfa6ac869b42d7a54bc7f3a8bb57d221a3b31e65 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Fri, 12 Apr 2024 16:24:59 +0900 Subject: [PATCH 66/87] =?UTF-8?q?fix:=20heart=20=EC=97=AC=EB=B6=80=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/CookSave/CookSaveback/Heart/dto/HeartRecipeDto.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Heart/dto/HeartRecipeDto.java b/src/main/java/CookSave/CookSaveback/Heart/dto/HeartRecipeDto.java index 5fc8a5e..8bdd6d1 100644 --- a/src/main/java/CookSave/CookSaveback/Heart/dto/HeartRecipeDto.java +++ b/src/main/java/CookSave/CookSaveback/Heart/dto/HeartRecipeDto.java @@ -16,7 +16,7 @@ public class HeartRecipeDto { private String name; private String image; private String mainIng; - private Boolean isHeart; + private Boolean heart; @Builder public HeartRecipeDto(Heart heart){ @@ -26,6 +26,6 @@ public HeartRecipeDto(Heart heart){ this.name = heart.getRecipe().getName(); this.image = heart.getRecipe().getImage(); this.mainIng = heart.getRecipe().getMainIng(); - this.isHeart = true; + this.heart = true; } } From 7a3cf3728361036dc0a563d82d5a3e87b734c084 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Sun, 14 Apr 2024 21:30:26 +0900 Subject: [PATCH 67/87] =?UTF-8?q?fix:=20=EC=9E=AC=EB=A3=8C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ingredient/service/IngredientService.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index 138e574..d83748b 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -11,12 +11,14 @@ import CookSave.CookSaveback.Member.domain.Member; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; import java.util.Objects; +@Slf4j @Service @RequiredArgsConstructor public class IngredientService { @@ -57,18 +59,28 @@ public void createIngredients(Member member, List ingredie public void updateIngredients(Member member, List updateRequestDtos){ List ingredients = ingredientRepository.findAllByMember(member); + // member의 재료 개수에 맞게 배열 생성 후 각 요소로 0 넣기 + // existIngs 배열에는 해당 ingredientId에 해당하는 ingredient의 개수 세는 용도. 결과적으로 0 아니면 1이어야 됨 + // 이 배열로 dto에 없는 ingredient 확인해서 db에서 없애기 List existIngs = new ArrayList<>(ingredients.size()); for (int i=0; i Date: Sun, 14 Apr 2024 21:32:52 +0900 Subject: [PATCH 68/87] =?UTF-8?q?style:=20=EC=9E=AC=EB=A3=8C=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EC=A3=BC=EC=84=9D=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ingredient/controller/IngredientController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java index da1d977..70a7ba5 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java @@ -39,7 +39,7 @@ public ResponseEntity createIngredientList(@RequestBody List("재료가 등록되었습니다.", HttpStatus.CREATED); } - // 재료 목록에서 iconId, amount 수정 + // 재료 목록에서 iconId, amount 수정 및 재료 삭제 @PatchMapping("/ingredients/list") @ResponseStatus(value = HttpStatus.OK) public String updateIngredientList(@RequestBody List updateRequestDtoList){ From 253fae15a9e879c900def7f49839c712ded7d5e2 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Mon, 15 Apr 2024 20:15:36 +0900 Subject: [PATCH 69/87] =?UTF-8?q?style:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Ingredient/service/IngredientService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index d83748b..e91e34e 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -74,8 +74,6 @@ public void updateIngredients(Member member, List updateReques for (int j=0; j Date: Mon, 15 Apr 2024 20:42:54 +0900 Subject: [PATCH 70/87] =?UTF-8?q?feat:=20=EC=82=AC=EB=AC=BC=20=EC=9D=B8?= =?UTF-8?q?=EC=8B=9D=20=EA=B2=B0=EA=B3=BC=EB=A5=BC=20=EC=9D=B4=EC=9A=A9?= =?UTF-8?q?=ED=95=9C=20=EC=9E=AC=EB=A3=8C=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IngredientController.java | 14 +++++++--- .../dto/ODIngredientRequestDto.java | 15 ++++++++++ .../Ingredient/service/IngredientService.java | 28 ++++++++++++++++--- .../Tag/repository/TagRepository.java | 3 ++ 4 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 src/main/java/CookSave/CookSaveback/Ingredient/dto/ODIngredientRequestDto.java diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java index 70a7ba5..adf30e6 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java @@ -1,9 +1,6 @@ package CookSave.CookSaveback.Ingredient.controller; -import CookSave.CookSaveback.Ingredient.dto.IngredientRequestDto; -import CookSave.CookSaveback.Ingredient.dto.IngredientResponseDto; -import CookSave.CookSaveback.Ingredient.dto.SubtractRequestDto; -import CookSave.CookSaveback.Ingredient.dto.UpdateRequestDto; +import CookSave.CookSaveback.Ingredient.dto.*; import CookSave.CookSaveback.Ingredient.service.IngredientService; import CookSave.CookSaveback.Member.domain.Member; import CookSave.CookSaveback.Member.service.MemberService; @@ -39,6 +36,15 @@ public ResponseEntity createIngredientList(@RequestBody List("재료가 등록되었습니다.", HttpStatus.CREATED); } + // 사물 인식을 이용한 재료 등록 + // Object Detection + @PostMapping("/ingredients/object") + public ResponseEntity createODIngredientList(@RequestBody List odIngredientRequestDtoList){ + Member member = memberService.getLoginMember(); + ingredientService.createODIngredients(member, odIngredientRequestDtoList); + return new ResponseEntity<>("재료가 등록되었습니다.", HttpStatus.CREATED); + } + // 재료 목록에서 iconId, amount 수정 및 재료 삭제 @PatchMapping("/ingredients/list") @ResponseStatus(value = HttpStatus.OK) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/dto/ODIngredientRequestDto.java b/src/main/java/CookSave/CookSaveback/Ingredient/dto/ODIngredientRequestDto.java new file mode 100644 index 0000000..9bc201f --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Ingredient/dto/ODIngredientRequestDto.java @@ -0,0 +1,15 @@ +package CookSave.CookSaveback.Ingredient.dto; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class ODIngredientRequestDto { + private Integer iconId; + private String name; + private Integer price; + private Float amount; + private String tag; +} diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index e91e34e..f636e7b 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -3,12 +3,11 @@ import CookSave.CookSaveback.Icon.domain.Icon; import CookSave.CookSaveback.Icon.repository.IconRepository; import CookSave.CookSaveback.Ingredient.domain.Ingredient; -import CookSave.CookSaveback.Ingredient.dto.IngredientRequestDto; -import CookSave.CookSaveback.Ingredient.dto.IngredientResponseDto; -import CookSave.CookSaveback.Ingredient.dto.SubtractRequestDto; -import CookSave.CookSaveback.Ingredient.dto.UpdateRequestDto; +import CookSave.CookSaveback.Ingredient.dto.*; import CookSave.CookSaveback.Ingredient.repository.IngredientRepository; import CookSave.CookSaveback.Member.domain.Member; +import CookSave.CookSaveback.Tag.domain.Tag; +import CookSave.CookSaveback.Tag.repository.TagRepository; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -24,6 +23,7 @@ public class IngredientService { private final IconRepository iconRepository; private final IngredientRepository ingredientRepository; + private final TagRepository tagRepository; // 전체 재료 조회 public List getIngredientList(Member member) { @@ -56,6 +56,26 @@ public void createIngredients(Member member, List ingredie } } + public void createODIngredients(Member member, List ingredientDtos){ + List ingredients = new ArrayList<>(); + + for (ODIngredientRequestDto ingredientDto : ingredientDtos){ + Tag tag = tagRepository.findByName(ingredientDto.getTag()) + .orElseThrow(() -> new EntityNotFoundException("name이 " + ingredientDto.getTag() + "인 태그가 존재하지 않습니다.")); + Icon icon = iconRepository.findById(ingredientDto.getIconId()) + .orElseThrow(() -> new EntityNotFoundException("iconId가 " + ingredientDto.getIconId() + "인 아이콘이 존재하지 않습니다.")); + Ingredient ingredient = Ingredient.builder() + .member(member) + .tag(tag) + .icon(icon) + .name(ingredientDto.getName()) + .price(ingredientDto.getPrice()) + .amount(ingredientDto.getAmount()) + .build(); + ingredientRepository.save(ingredient); + } + } + public void updateIngredients(Member member, List updateRequestDtos){ List ingredients = ingredientRepository.findAllByMember(member); diff --git a/src/main/java/CookSave/CookSaveback/Tag/repository/TagRepository.java b/src/main/java/CookSave/CookSaveback/Tag/repository/TagRepository.java index 447984c..d132170 100644 --- a/src/main/java/CookSave/CookSaveback/Tag/repository/TagRepository.java +++ b/src/main/java/CookSave/CookSaveback/Tag/repository/TagRepository.java @@ -4,6 +4,9 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.Optional; + @Repository public interface TagRepository extends JpaRepository{ + Optional findByName(String name); } From 8270c8ddecf08d13dd9a3ccd017af4a19746cc25 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Tue, 16 Apr 2024 12:53:56 +0900 Subject: [PATCH 71/87] =?UTF-8?q?fix:=20=ED=86=A0=ED=81=B0=20=EB=A7=8C?= =?UTF-8?q?=EB=A3=8C=20=EC=8B=9C=EA=B0=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Member/service/MemberService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java index da78755..5e9f6de 100644 --- a/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java +++ b/src/main/java/CookSave/CookSaveback/Member/service/MemberService.java @@ -30,11 +30,11 @@ public class MemberService { @Value("${spring.jwt.refresh-key}") private String refreshKey; - // Access 토큰 만료 시간을 3일로 설정 - private Long AccessExpireTimeMs = 3 * 24 * 1000 * 60 * 60L; + // Access 토큰 만료 시간을 30일로 설정 + private Long AccessExpireTimeMs = 30 * 24 * 1000 * 60 * 60L; - // Refresh 토큰 만료 시간을 7일로 설정 - private Long RefreshExpireTimeMs = 7 * 24 * 1000 * 60 * 60L; + // Refresh 토큰 만료 시간을 60일로 설정 + private Long RefreshExpireTimeMs = 60 * 24 * 1000 * 60 * 60L; // 회원가입 public String signUp(String cooksaveId, String password, String passwordCheck){ From ac96beb7fa91c9df7e868b9ce740324a119a5004 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Wed, 17 Apr 2024 19:58:50 +0900 Subject: [PATCH 72/87] =?UTF-8?q?style:=20=EB=A0=88=EC=8B=9C=ED=94=BC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B4=80=EB=A0=A8=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSave/CookSaveback/Recipe/service/RecipeService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java b/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java index 5e08cff..1f203ec 100644 --- a/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java +++ b/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java @@ -33,13 +33,16 @@ public class RecipeService { public List getRecipeList(Member member) { List recipeList = new ArrayList<>(); + // 전체 recipe 리스트 List recipes = new ArrayList<>(); recipes = recipeRepository.findAll(); int recipeCount = recipes.size(); + // 해당 member가 보유한 ingredient 리스트 List ingredients = new ArrayList<>(); ingredients = ingredientRepository.findAllByMember(member); + // 해당 member가 보유한 ingredient에 대응되는 tag의 tagId 리스트 List tags = new ArrayList<>(); for (Ingredient ingredient : ingredients) { tags.add(ingredient.getTag().getTagId()); @@ -47,12 +50,15 @@ public List getRecipeList(Member member) { } int tagCount = tags.size(); + // tags 중 각 recipe에 포함되는 태그의 개수 List recipeTagCount = new ArrayList<>(); + // recipeTagCount의 값들을 0으로 초기화 for (int i = 0; i < recipeCount; i++) { recipeTagCount.add(0); } + // recipeTagCount 값 구하기 for (int i = 0; i < recipeCount; i++) { for (Integer tagId : tags) { Tag tag = tagRepository.findById(tagId) From a5585ca38b9dcc46b9f97eb4db64435d9ad81a32 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Wed, 17 Apr 2024 20:14:40 +0900 Subject: [PATCH 73/87] =?UTF-8?q?fix:=20=EC=A0=84=EC=B2=B4=20=EB=A0=88?= =?UTF-8?q?=EC=8B=9C=ED=94=BC=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=EC=97=90=EC=84=9C=20ingredient=EC=9D=98=20tag=EA=B0=80=20null?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Recipe/service/RecipeService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java b/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java index 1f203ec..8996267 100644 --- a/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java +++ b/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java @@ -45,7 +45,13 @@ public List getRecipeList(Member member) { // 해당 member가 보유한 ingredient에 대응되는 tag의 tagId 리스트 List tags = new ArrayList<>(); for (Ingredient ingredient : ingredients) { - tags.add(ingredient.getTag().getTagId()); + // ingredient의 tag + Tag tag = ingredient.getTag(); + if(tag != null){ + tags.add(tag.getTagId()); + } + + // 중복되는 tagId 제거 tags = tags.stream().distinct().collect(Collectors.toList()); } int tagCount = tags.size(); From 4116df2040af1ca65bd0590a3052d9e6925a3cd6 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Fri, 19 Apr 2024 15:00:02 +0900 Subject: [PATCH 74/87] =?UTF-8?q?fix:=20=EB=A0=88=EC=8B=9C=ED=94=BC=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=EC=97=90=EC=84=9C=20ingredient=EC=9D=98=20tag=EA=B0=80=20null?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Recipe/service/RecipeService.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java b/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java index 8996267..f96f067 100644 --- a/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java +++ b/src/main/java/CookSave/CookSaveback/Recipe/service/RecipeService.java @@ -123,10 +123,12 @@ public RecipeDetailResponseDto getRecipeDetail(Long recipeId, Member member){ List recipeIngredients = new ArrayList<>(); for (Ingredient ingredient : memberIngredients){ - Tag tag = tagRepository.findById(ingredient.getTag().getTagId()) - .orElseThrow(() -> new EntityNotFoundException("tagId" + ingredient.getTag().getTagId() + "인 태그가 존재하지 않습니다.")); - if (recipeTagRepository.existsByRecipeAndTag(recipe, tag)){ - recipeIngredients.add(ingredient); + if(ingredient.getTag() != null){ + Tag tag = tagRepository.findById(ingredient.getTag().getTagId()) + .orElseThrow(() -> new EntityNotFoundException("tagId" + ingredient.getTag().getTagId() + "인 태그가 존재하지 않습니다.")); + if (recipeTagRepository.existsByRecipeAndTag(recipe, tag)){ + recipeIngredients.add(ingredient); + } } } From aad6806cf96c2114e004ad975e2369816e354037 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Tue, 23 Apr 2024 01:28:57 +0900 Subject: [PATCH 75/87] =?UTF-8?q?fix:=20=EC=A0=84=EC=B2=B4=20=EC=9E=AC?= =?UTF-8?q?=EB=A3=8C=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EC=9E=AC=EB=A3=8C?= =?UTF-8?q?=20=EB=93=B1=EB=A1=9D=EC=9D=BC=20=EA=B8=B0=EC=A4=80=20=EC=B5=9C?= =?UTF-8?q?=EC=8B=A0=EC=88=9C=EC=9C=BC=EB=A1=9C=20=EC=A0=95=EB=A0=AC?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ingredient/repository/IngredientRepository.java | 1 + .../CookSaveback/Ingredient/service/IngredientService.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java b/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java index 77769f6..8537bab 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/repository/IngredientRepository.java @@ -13,6 +13,7 @@ @Repository public interface IngredientRepository extends JpaRepository { List findAllByMember(Member member); + List findAllByMemberOrderByIngredientIdDesc(Member member); Long countAllByMember(Member member); Optional findByIngredientIdAndMember(Long ingredientId, Member member); boolean existsByMemberAndTag(Member member, Tag tag); diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index f636e7b..bc981cf 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -28,7 +28,7 @@ public class IngredientService { // 전체 재료 조회 public List getIngredientList(Member member) { List ingredients = new ArrayList<>(); - ingredients = ingredientRepository.findAllByMember(member); + ingredients = ingredientRepository.findAllByMemberOrderByIngredientIdDesc(member); List ingredientList = new ArrayList<>(); for (Ingredient ingredient:ingredients){ From 85502d0f77c05bac76c431e3751c76b665dced15 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Mon, 20 May 2024 14:47:48 +0900 Subject: [PATCH 76/87] =?UTF-8?q?style:=20=ED=95=84=EC=9A=94=20=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EC=A3=BC=EC=84=9D=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Ingredient/controller/IngredientController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java index adf30e6..e5f736d 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java @@ -37,7 +37,6 @@ public ResponseEntity createIngredientList(@RequestBody List createODIngredientList(@RequestBody List odIngredientRequestDtoList){ Member member = memberService.getLoginMember(); From d5f42f23048283947d13b52cbe54c35554e15cfe Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Mon, 20 May 2024 17:15:37 +0900 Subject: [PATCH 77/87] =?UTF-8?q?chore:=20config=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/{ => global}/config/EncoderConfig.java | 2 +- .../CookSave/CookSaveback/{ => global}/config/JwtFilter.java | 2 +- .../CookSaveback/{ => global}/config/SecurityConfig.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/main/java/CookSave/CookSaveback/{ => global}/config/EncoderConfig.java (88%) rename src/main/java/CookSave/CookSaveback/{ => global}/config/JwtFilter.java (98%) rename src/main/java/CookSave/CookSaveback/{ => global}/config/SecurityConfig.java (98%) diff --git a/src/main/java/CookSave/CookSaveback/config/EncoderConfig.java b/src/main/java/CookSave/CookSaveback/global/config/EncoderConfig.java similarity index 88% rename from src/main/java/CookSave/CookSaveback/config/EncoderConfig.java rename to src/main/java/CookSave/CookSaveback/global/config/EncoderConfig.java index d27a11c..435b253 100644 --- a/src/main/java/CookSave/CookSaveback/config/EncoderConfig.java +++ b/src/main/java/CookSave/CookSaveback/global/config/EncoderConfig.java @@ -1,4 +1,4 @@ -package CookSave.CookSaveback.config; +package CookSave.CookSaveback.global.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/CookSave/CookSaveback/config/JwtFilter.java b/src/main/java/CookSave/CookSaveback/global/config/JwtFilter.java similarity index 98% rename from src/main/java/CookSave/CookSaveback/config/JwtFilter.java rename to src/main/java/CookSave/CookSaveback/global/config/JwtFilter.java index 8bac5a7..d87f9c0 100644 --- a/src/main/java/CookSave/CookSaveback/config/JwtFilter.java +++ b/src/main/java/CookSave/CookSaveback/global/config/JwtFilter.java @@ -1,4 +1,4 @@ -package CookSave.CookSaveback.config; +package CookSave.CookSaveback.global.config; import CookSave.CookSaveback.utils.JwtUtil; import jakarta.servlet.FilterChain; diff --git a/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java b/src/main/java/CookSave/CookSaveback/global/config/SecurityConfig.java similarity index 98% rename from src/main/java/CookSave/CookSaveback/config/SecurityConfig.java rename to src/main/java/CookSave/CookSaveback/global/config/SecurityConfig.java index 9c5306c..bf47b6d 100644 --- a/src/main/java/CookSave/CookSaveback/config/SecurityConfig.java +++ b/src/main/java/CookSave/CookSaveback/global/config/SecurityConfig.java @@ -1,4 +1,4 @@ -package CookSave.CookSaveback.config; +package CookSave.CookSaveback.global.config; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; From f3c9e1adaece20e505c2c8b52f3fb358bc11164d Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Tue, 21 May 2024 14:57:14 +0900 Subject: [PATCH 78/87] =?UTF-8?q?feat:=20CLOVA=20OCR=20API=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=EB=B0=9B=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + .../controller/IngredientController.java | 13 +++ .../Ingredient/dto/OcrResponseDto.java | 20 ++++ .../Ingredient/service/ClovaOcrApi.java | 104 ++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 src/main/java/CookSave/CookSaveback/Ingredient/dto/OcrResponseDto.java create mode 100644 src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java diff --git a/build.gradle b/build.gradle index f4559fd..0920ebb 100644 --- a/build.gradle +++ b/build.gradle @@ -28,6 +28,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'io.jsonwebtoken:jjwt:0.9.1' implementation 'javax.xml.bind:jaxb-api:2.4.0-b180830.0359' + implementation 'com.googlecode.json-simple:json-simple:1.1.1' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java index e5f736d..fd570c3 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java @@ -1,15 +1,19 @@ package CookSave.CookSaveback.Ingredient.controller; import CookSave.CookSaveback.Ingredient.dto.*; +import CookSave.CookSaveback.Ingredient.service.ClovaOcrApi; import CookSave.CookSaveback.Ingredient.service.IngredientService; import CookSave.CookSaveback.Member.domain.Member; import CookSave.CookSaveback.Member.service.MemberService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; import java.util.List; @Slf4j @@ -18,6 +22,7 @@ public class IngredientController { private final MemberService memberService; private final IngredientService ingredientService; + private final ClovaOcrApi clovaOcrApi; // 보유한 재료 목록 조회 @GetMapping("/ingredients/list") @@ -44,6 +49,14 @@ public ResponseEntity createODIngredientList(@RequestBody List("재료가 등록되었습니다.", HttpStatus.CREATED); } + // 텍스트 인식을 이용한 재료 등록 + @PostMapping(value = "/ingredients/text", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + @ResponseStatus(value = HttpStatus.CREATED) + public List createLostItemPost(@RequestPart(value = "image") MultipartFile multipartFile) throws IOException { + Member member = memberService.getLoginMember(); + return clovaOcrApi.getOcrList(member, multipartFile); + } + // 재료 목록에서 iconId, amount 수정 및 재료 삭제 @PatchMapping("/ingredients/list") @ResponseStatus(value = HttpStatus.OK) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/dto/OcrResponseDto.java b/src/main/java/CookSave/CookSaveback/Ingredient/dto/OcrResponseDto.java new file mode 100644 index 0000000..d0a8835 --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Ingredient/dto/OcrResponseDto.java @@ -0,0 +1,20 @@ +package CookSave.CookSaveback.Ingredient.dto; + +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class OcrResponseDto { + private String name; + private Integer price; + private Float amount; + + @Builder + public OcrResponseDto(String name, Integer price, Float amount){ + this.name = name; + this.price = price; + this.amount = amount; + } +} diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java new file mode 100644 index 0000000..77a5a2c --- /dev/null +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java @@ -0,0 +1,104 @@ +package CookSave.CookSaveback.Ingredient.service; + +import CookSave.CookSaveback.Ingredient.dto.OcrResponseDto; +import CookSave.CookSaveback.Member.domain.Member; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.Base64; +import java.util.List; +import java.util.UUID; + +@Slf4j +@Service +@Component +@RequiredArgsConstructor +public class ClovaOcrApi { + @Value("${naver.service.url}") + private String apiUrl; + @Value("${naver.service.secretKey}") + private String secretKey; + @Value("${cloud.aws.s3.bucket") + private String bucket; + + public List getOcrList(Member member, MultipartFile multipartFile) { + + List ocrResultList = new ArrayList<>(); + StringBuffer result = getResult(multipartFile); + return ocrResultList; + } + + public StringBuffer getResult(MultipartFile multipartFile) { + try { + URL url = new URL(apiUrl); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setUseCaches(false); + con.setDoInput(true); + con.setDoOutput(true); + con.setRequestMethod("POST"); + con.setRequestProperty("Content-Type", "application/json; charset=utf-8"); + con.setRequestProperty("X-OCR-SECRET", secretKey); + + JSONObject json = new JSONObject(); + json.put("version", "V2"); + json.put("requestId", UUID.randomUUID().toString()); + json.put("timestamp", System.currentTimeMillis()); + JSONObject image = new JSONObject(); + image.put("format", "png"); + + String imageByte = encode(multipartFile); + image.put("data", imageByte); + image.put("name", "demo"); + JSONArray images = new JSONArray(); + images.add(image); + json.put("images", images); + String postParams = json.toString(); + + DataOutputStream wr = new DataOutputStream(con.getOutputStream()); + wr.writeBytes(postParams); + wr.flush(); + wr.close(); + + int responseCode = con.getResponseCode(); + BufferedReader br; + if (responseCode == 200) { + br = new BufferedReader(new InputStreamReader(con.getInputStream())); + } else { + br = new BufferedReader(new InputStreamReader(con.getErrorStream())); + } + String inputLine; + StringBuffer response = new StringBuffer(); + while ((inputLine = br.readLine()) != null) { + response.append(inputLine); + } + System.out.println(response); + br.close(); + return response; + } catch (Exception e) { + System.out.println(e); + StringBuffer a = null; + a.append(e); + return a; + } + } + + public String encode(MultipartFile file) throws IOException { + try { + byte[] fileBytes = file.getBytes(); + return Base64.getEncoder().encodeToString(fileBytes); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } +} From a6a923ab2861ecaea2adcfd7bd91718ecc2974d3 Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Tue, 21 May 2024 20:12:25 +0900 Subject: [PATCH 79/87] =?UTF-8?q?style:=20=ED=95=A8=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EB=B0=8F=20=EC=A3=BC=EC=84=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ingredient/controller/IngredientController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java index fd570c3..ccd2e81 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/controller/IngredientController.java @@ -49,10 +49,10 @@ public ResponseEntity createODIngredientList(@RequestBody List("재료가 등록되었습니다.", HttpStatus.CREATED); } - // 텍스트 인식을 이용한 재료 등록 + // 텍스트 인식을 이용한 재료 정보 조회 @PostMapping(value = "/ingredients/text", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @ResponseStatus(value = HttpStatus.CREATED) - public List createLostItemPost(@RequestPart(value = "image") MultipartFile multipartFile) throws IOException { + public List getOcrIngredientList(@RequestPart(value = "image") MultipartFile multipartFile) throws IOException { Member member = memberService.getLoginMember(); return clovaOcrApi.getOcrList(member, multipartFile); } From 99ecd685fc160533b940fe42ae6151a44b5e3e1c Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Tue, 21 May 2024 20:44:51 +0900 Subject: [PATCH 80/87] =?UTF-8?q?style:=20=ED=95=84=EC=9A=94=20=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java index 77a5a2c..87f7d08 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java @@ -28,8 +28,6 @@ public class ClovaOcrApi { private String apiUrl; @Value("${naver.service.secretKey}") private String secretKey; - @Value("${cloud.aws.s3.bucket") - private String bucket; public List getOcrList(Member member, MultipartFile multipartFile) { From c98497763e4d6e4498c3512f5176181cf71b410f Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Wed, 22 May 2024 13:51:20 +0900 Subject: [PATCH 81/87] =?UTF-8?q?fix:=20=EC=9E=84=EC=9D=98=EC=9D=98=20?= =?UTF-8?q?=EC=9E=AC=EB=A3=8C=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=B0=98?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java index 87f7d08..15df683 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java @@ -33,6 +33,9 @@ public List getOcrList(Member member, MultipartFile multipartFil List ocrResultList = new ArrayList<>(); StringBuffer result = getResult(multipartFile); + ocrResultList.add(new OcrResponseDto("밤고구마", 1460, 1F)); + ocrResultList.add(new OcrResponseDto("감자", 690, 1F)); + ocrResultList.add(new OcrResponseDto("골드키위", 1500, 2F)); return ocrResultList; } From 8c5811c363c777c429121f5fb3dcadd0f81e8b3c Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Thu, 6 Jun 2024 03:57:56 +0900 Subject: [PATCH 82/87] =?UTF-8?q?fix:=20OCR=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java index 15df683..b345d2e 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java @@ -32,7 +32,7 @@ public class ClovaOcrApi { public List getOcrList(Member member, MultipartFile multipartFile) { List ocrResultList = new ArrayList<>(); - StringBuffer result = getResult(multipartFile); + // StringBuffer result = getResult(multipartFile); ocrResultList.add(new OcrResponseDto("밤고구마", 1460, 1F)); ocrResultList.add(new OcrResponseDto("감자", 690, 1F)); ocrResultList.add(new OcrResponseDto("골드키위", 1500, 2F)); From 27192ec688eb1db7d01f967e8d012e8d8312243d Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Thu, 6 Jun 2024 04:07:41 +0900 Subject: [PATCH 83/87] =?UTF-8?q?fix:=20OCR=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java index b345d2e..15df683 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/ClovaOcrApi.java @@ -32,7 +32,7 @@ public class ClovaOcrApi { public List getOcrList(Member member, MultipartFile multipartFile) { List ocrResultList = new ArrayList<>(); - // StringBuffer result = getResult(multipartFile); + StringBuffer result = getResult(multipartFile); ocrResultList.add(new OcrResponseDto("밤고구마", 1460, 1F)); ocrResultList.add(new OcrResponseDto("감자", 690, 1F)); ocrResultList.add(new OcrResponseDto("골드키위", 1500, 2F)); From 5ee7f7774096874bbbd8284b7d72a247421cb90c Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Mon, 17 Jun 2024 15:48:28 +0900 Subject: [PATCH 84/87] =?UTF-8?q?fix:=20=EC=98=A4=EB=A5=98=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0=EC=9D=84=20=EC=9C=84=ED=95=9C=20print=EB=AC=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Ingredient/service/IngredientService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index bc981cf..51d0d75 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -92,13 +92,14 @@ public void updateIngredients(Member member, List updateReques // ingredient 하나 붙잡고 dto 전체랑 비교시켜서 같은 거 있는지 확인 for (int j=0; j ingredientId가 같은 dto 존재"); // 업데이트 할 iconId, amount 값 불러오기 Integer iconId = updateRequestDtos.get(j).getIconId(); @@ -109,6 +110,9 @@ public void updateIngredients(Member member, List updateReques ingredients.get(i).updateIngredient(icon, amount); ingredientRepository.save(ingredients.get(i)); } + else{ + System.out.println("-> 다름"); + } } } From e97fc28cfe524f725cc5252e9ab8cc512e890f8b Mon Sep 17 00:00:00 2001 From: Soyeon-Cha <7103sy@naver.com> Date: Mon, 17 Jun 2024 16:49:39 +0900 Subject: [PATCH 85/87] =?UTF-8?q?fix:=20=EC=9E=AC=EB=A3=8C=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95=20=EA=B4=80=EB=A0=A8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CookSaveback/Ingredient/service/IngredientService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index 51d0d75..6369ae0 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -94,7 +94,7 @@ public void updateIngredients(Member member, List updateReques for (int j=0; j Date: Mon, 17 Jun 2024 17:28:07 +0900 Subject: [PATCH 86/87] =?UTF-8?q?style:=20=ED=95=84=EC=9A=94=20=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ingredient/service/IngredientService.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java index 6369ae0..fab1a44 100644 --- a/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java +++ b/src/main/java/CookSave/CookSaveback/Ingredient/service/IngredientService.java @@ -87,19 +87,17 @@ public void updateIngredients(Member member, List updateReques existIngs.add(0); } - // member가 가지고 있는 ingredient들 모두에 대해서 돌아야 됨 + // member가 가지고 있는 모든 ingredient들을 dto와 비교 for (int i=0; i ingredientId가 같은 dto 존재"); // 업데이트 할 iconId, amount 값 불러오기 Integer iconId = updateRequestDtos.get(j).getIconId(); @@ -110,9 +108,6 @@ public void updateIngredients(Member member, List updateReques ingredients.get(i).updateIngredient(icon, amount); ingredientRepository.save(ingredients.get(i)); } - else{ - System.out.println("-> 다름"); - } } } From a084d7924c01ea709d07ed38c82f585e27437b80 Mon Sep 17 00:00:00 2001 From: Soyeon Cha <89539031+Soyeon-Cha@users.noreply.github.com> Date: Thu, 20 Jun 2024 20:34:43 +0900 Subject: [PATCH 87/87] =?UTF-8?q?fix:=20main=EC=97=90=20push=20=EC=8B=9C?= =?UTF-8?q?=20actions=20=EC=88=98=ED=96=89=ED=95=98=EB=8A=94=20=EA=B2=83?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5f827fb..0dfe763 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,7 +2,7 @@ name: Deploy to Amazon EC2 on: push: - branches: [ "develop" ] + branches: [ "main" ] env: AWS_REGION: ap-northeast-2