From 2ef49326e614db87f35beb090c9f0198e400b8af Mon Sep 17 00:00:00 2001 From: Kwon Min A Date: Tue, 11 Jul 2023 02:19:38 +0900 Subject: [PATCH 001/153] =?UTF-8?q?feat:=20Entity=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/day/dday/entity/DDay.java | 16 ++++++++++++++++ .../edayback/domain/day/info/entity/Info.java | 16 ++++++++++++++++ .../domain/day/info/entity/InfoImage.java | 16 ++++++++++++++++ .../edayback/domain/day/quiz/entity/Options.java | 16 ++++++++++++++++ .../edayback/domain/day/quiz/entity/Quiz.java | 16 ++++++++++++++++ .../edayback/domain/day/title/entity/Title.java | 16 ++++++++++++++++ .../edayback/domain/member/entity/Member.java | 16 ++++++++++++++++ .../domain/member/entity/MemberQuiz.java | 16 ++++++++++++++++ .../domain/member/entity/MemberTitle.java | 16 ++++++++++++++++ .../eday/edayback/domain/query/entity/Query.java | 16 ++++++++++++++++ 10 files changed, 160 insertions(+) create mode 100644 src/main/java/efub/eday/edayback/domain/day/dday/entity/DDay.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java create mode 100644 src/main/java/efub/eday/edayback/domain/member/entity/Member.java create mode 100644 src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java create mode 100644 src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java create mode 100644 src/main/java/efub/eday/edayback/domain/query/entity/Query.java diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/DDay.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/DDay.java new file mode 100644 index 0000000..5a2532e --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/dday/entity/DDay.java @@ -0,0 +1,16 @@ +package efub.eday.edayback.domain.day.dday.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class DDay { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "d_day_id") + private Long id; +} diff --git a/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java b/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java new file mode 100644 index 0000000..4da90c9 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java @@ -0,0 +1,16 @@ +package efub.eday.edayback.domain.day.info.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class Info { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "info_id") + private Long id; +} diff --git a/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java b/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java new file mode 100644 index 0000000..9d39a6a --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java @@ -0,0 +1,16 @@ +package efub.eday.edayback.domain.day.info.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class InfoImage { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "info_image_id") + private Long id; +} diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java new file mode 100644 index 0000000..5f8a004 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java @@ -0,0 +1,16 @@ +package efub.eday.edayback.domain.day.quiz.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class Options { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "option_id") + private Long id; +} diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java new file mode 100644 index 0000000..42935da --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java @@ -0,0 +1,16 @@ +package efub.eday.edayback.domain.day.quiz.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class Quiz { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "quiz_id") + private Long id; +} diff --git a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java new file mode 100644 index 0000000..094a6b5 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java @@ -0,0 +1,16 @@ +package efub.eday.edayback.domain.day.title.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class Title { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "title_id") + private Long id; +} diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java new file mode 100644 index 0000000..84f894f --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java @@ -0,0 +1,16 @@ +package efub.eday.edayback.domain.member.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class Member { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "member_id") + private Long id; +} diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java new file mode 100644 index 0000000..61d8af6 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java @@ -0,0 +1,16 @@ +package efub.eday.edayback.domain.member.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class MemberQuiz { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "member_quiz_id") + private Long id; +} diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java new file mode 100644 index 0000000..bc40999 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java @@ -0,0 +1,16 @@ +package efub.eday.edayback.domain.member.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class MemberTitle { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "member_title_id") + private Long id; +} diff --git a/src/main/java/efub/eday/edayback/domain/query/entity/Query.java b/src/main/java/efub/eday/edayback/domain/query/entity/Query.java new file mode 100644 index 0000000..c2a28ba --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/query/entity/Query.java @@ -0,0 +1,16 @@ +package efub.eday.edayback.domain.query.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class Query { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "query_id") + private Long id; +} From 1131e21ede9df494d4b1f6044832a84e3752a4cf Mon Sep 17 00:00:00 2001 From: Kwon Min A Date: Tue, 11 Jul 2023 02:39:01 +0900 Subject: [PATCH 002/153] =?UTF-8?q?feat:=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=EB=B0=8F=20=ED=85=8C=EC=9D=B4=EB=B8=94=20=EB=A7=A4=ED=95=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/day/dday/entity/DDay.java | 6 ++++++ .../edayback/domain/day/info/entity/Info.java | 7 +++++++ .../domain/day/info/entity/InfoImage.java | 9 +++++++++ .../domain/day/quiz/entity/Options.java | 12 +++++++++++ .../edayback/domain/day/quiz/entity/Quiz.java | 16 +++++++++++++++ .../domain/day/title/entity/Title.java | 13 ++++++++++++ .../edayback/domain/member/entity/Member.java | 20 +++++++++++++++++++ .../domain/member/entity/MemberQuiz.java | 14 +++++++++++++ .../domain/member/entity/MemberTitle.java | 14 +++++++++++++ .../edayback/domain/query/entity/Query.java | 15 ++++++++++++++ 10 files changed, 126 insertions(+) diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/DDay.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/DDay.java index 5a2532e..1c989cd 100644 --- a/src/main/java/efub/eday/edayback/domain/day/dday/entity/DDay.java +++ b/src/main/java/efub/eday/edayback/domain/day/dday/entity/DDay.java @@ -13,4 +13,10 @@ public class DDay { @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "d_day_id") private Long id; + + @Column(name = "d_day", nullable = false) + private int dDay; + + @Column(nullable = false) + private String topic; } diff --git a/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java b/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java index 4da90c9..7d25cba 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java @@ -1,10 +1,13 @@ package efub.eday.edayback.domain.day.info.entity; +import efub.eday.edayback.domain.day.dday.entity.DDay; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; @Entity public class Info { @@ -13,4 +16,8 @@ public class Info { @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "info_id") private Long id; + + @OneToOne + @JoinColumn(name = "d_day_id") + private DDay dDay; } diff --git a/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java b/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java index 9d39a6a..f000665 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java @@ -5,6 +5,8 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; @Entity public class InfoImage { @@ -13,4 +15,11 @@ public class InfoImage { @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "info_image_id") private Long id; + + @Column(name = "image_url") + private String url; + + @OneToOne + @JoinColumn(name = "info_id") + private Info info; } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java index 5f8a004..56e346e 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java @@ -5,6 +5,8 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; @Entity public class Options { @@ -13,4 +15,14 @@ public class Options { @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "option_id") private Long id; + + @Column(nullable = false) + private String content; + + @Column(nullable = false) + private Boolean isAnswer; + + @ManyToOne + @JoinColumn(name = "quiz_id") + private Quiz quiz; } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java index 42935da..9c5c879 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java @@ -1,10 +1,13 @@ package efub.eday.edayback.domain.day.quiz.entity; +import efub.eday.edayback.domain.day.dday.entity.DDay; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; @Entity public class Quiz { @@ -13,4 +16,17 @@ public class Quiz { @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "quiz_id") private Long id; + + @Column(nullable = false) + private String content; + + @Column(nullable = false) + private String description; + + @Column(name = "image_url") + private String imageUrl; + + @OneToOne + @JoinColumn(name = "d_day_id", nullable = false) + private DDay dDay; } diff --git a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java index 094a6b5..306ab9d 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java @@ -1,10 +1,13 @@ package efub.eday.edayback.domain.day.title.entity; +import efub.eday.edayback.domain.day.dday.entity.DDay; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToOne; @Entity public class Title { @@ -13,4 +16,14 @@ public class Title { @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "title_id") private Long id; + + @Column(nullable = false) + private String name; + + @Column(name = "image_url", nullable = false) + private String imageUrl; + + @OneToOne + @JoinColumn(name = "d_day_id", nullable = false) + private DDay dDay; } diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java index 84f894f..bc301e2 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java @@ -1,5 +1,7 @@ package efub.eday.edayback.domain.member.entity; +import java.time.LocalDate; + import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -13,4 +15,22 @@ public class Member { @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "member_id") private Long id; + + @Column(nullable = false) + private String nickname; + + @Column(nullable = false) + private String email; + + @Column(name = "profile_image_url", nullable = false) + private String profileImageUrl; + + @Column(nullable = false) + private Integer level; + + @Column(nullable = false) + private LocalDate createdDate; + + @Column(nullable = false) + private Boolean isActive; } diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java index 61d8af6..48b3d18 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java @@ -1,10 +1,13 @@ package efub.eday.edayback.domain.member.entity; +import efub.eday.edayback.domain.day.quiz.entity.Quiz; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; @Entity public class MemberQuiz { @@ -13,4 +16,15 @@ public class MemberQuiz { @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "member_quiz_id") private Long id; + + @Column(nullable = false) + private Boolean isCorrect; + + @ManyToOne + @JoinColumn(name = "member_id", nullable = false) + private Member member; + + @ManyToOne + @JoinColumn(name = "quiz_id", nullable = false) + private Quiz quiz; } diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java index bc40999..bc63414 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java @@ -1,10 +1,13 @@ package efub.eday.edayback.domain.member.entity; +import efub.eday.edayback.domain.day.title.entity.Title; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; @Entity public class MemberTitle { @@ -13,4 +16,15 @@ public class MemberTitle { @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "member_title_id") private Long id; + + @Column(nullable = false) + private Boolean getTitle; + + @ManyToOne + @JoinColumn(name = "member_id", nullable = false) + private Member member; + + @ManyToOne + @JoinColumn(name = "title_id", nullable = false) + private Title title; } diff --git a/src/main/java/efub/eday/edayback/domain/query/entity/Query.java b/src/main/java/efub/eday/edayback/domain/query/entity/Query.java index c2a28ba..d6737cc 100644 --- a/src/main/java/efub/eday/edayback/domain/query/entity/Query.java +++ b/src/main/java/efub/eday/edayback/domain/query/entity/Query.java @@ -1,10 +1,14 @@ package efub.eday.edayback.domain.query.entity; +import efub.eday.edayback.domain.day.dday.entity.DDay; +import efub.eday.edayback.domain.member.entity.Member; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; @Entity public class Query { @@ -13,4 +17,15 @@ public class Query { @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "query_id") private Long id; + + @Column(nullable = false) + private String content; + + @ManyToOne + @JoinColumn(name = "member_id", nullable = false) + private Member writer; + + @ManyToOne + @JoinColumn(name = "d_day_id", nullable = false) + private DDay dDay; } From 18b69a12ac34649d5a4392fd29c1234bc050f3be Mon Sep 17 00:00:00 2001 From: choiyounji Date: Fri, 14 Jul 2023 21:46:43 +0900 Subject: [PATCH 003/153] =?UTF-8?q?feat:=20Dockerfile=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bd0a0de --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +# Base 이미지 설정 +FROM openjdk:17-jdk +LABEL authors="mingulmangul" + +# 메인 애플리케이션 디렉토리 설정 +WORKDIR /app + +# 애플리케이션 빌드를 위해 필요한 파일 복사 +COPY build.gradle . +COPY gradlew . +COPY gradle ./gradle +COPY src ./src + +# gradlew 파일 실행 권한 설정 +RUN chmod +x ./gradlew + +# 빌드된 JAR 파일을 컨테이너 내부로 복사 +COPY build/libs/*.jar app.jar + +# 컨테이너 실행 명령 +CMD ["java", "-jar", "app.jar"] From fe4195cc7c2f0a0d401181ce98731bf7bf84d49d Mon Sep 17 00:00:00 2001 From: choiyounji Date: Fri, 14 Jul 2023 21:48:05 +0900 Subject: [PATCH 004/153] =?UTF-8?q?feat:=20docker-compose.yml=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..bc03eb6 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,41 @@ +version: '3.9' +services: + app: + build: + context: . + dockerfile: Dockerfile + ports: + - "8080:8080" + depends_on: + db: + condition: service_healthy + volumes: + - type: bind + source: ./src + target: /src + environment: + SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/${MYSQL_DATABASE} + SPRING_DATASOURCE_USERNAME: ${MYSQL_ROOT_USER} + SPRING_DATASOURCE_PASSWORD: ${MYSQL_ROOT_PASSWORD} + + db: + image: mysql:8.0 + ports: + - "3306:3306" + volumes: + - mysql-data:/var/lib/mysql + - mysql-config:/etc/mysql/conf.d + environment: + MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} + MYSQL_DATABASE: ${MYSQL_DATABASE} + MYSQL_USER: ${MYSQL_USER} + MYSQL_PASSWORD: ${MYSQL_PASSWORD} + healthcheck: + test: [ "CMD-SHELL", "mysqladmin ping -h db -u root --password=$$MYSQL_ROOT_PASSWORD" ] + interval: 10s + timeout: 2s + retries: 30 + +volumes: + mysql-data: + mysql-config: From 57024b808ffbd6f6172bf706af6aab01543a3b51 Mon Sep 17 00:00:00 2001 From: chhaewxn Date: Sat, 15 Jul 2023 04:43:15 +0900 Subject: [PATCH 005/153] =?UTF-8?q?feat:=20Info(=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EC=A0=95=EB=B3=B4)=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= =?UTF-8?q?=20#6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../day/info/controller/InfoController.java | 27 +++++++++++++ .../domain/day/info/dto/ImageDto.java | 11 ++++++ .../edayback/domain/day/info/dto/InfoDto.java | 39 +++++++++++++++++++ .../edayback/domain/day/info/entity/Info.java | 20 +++++++++- .../domain/day/info/entity/InfoImage.java | 16 +++++++- .../day/info/repository/InfoRepository.java | 9 +++++ .../domain/day/info/service/InfoService.java | 20 ++++++++++ 7 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/info/dto/ImageDto.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/info/dto/InfoDto.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java diff --git a/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java b/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java new file mode 100644 index 0000000..5693fe0 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java @@ -0,0 +1,27 @@ +package efub.eday.edayback.domain.day.info.controller; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import efub.eday.edayback.domain.day.info.dto.InfoDto; +import efub.eday.edayback.domain.day.info.entity.Info; +import efub.eday.edayback.domain.day.info.service.InfoService; +import lombok.RequiredArgsConstructor; + +@RestController +@RequestMapping("/infos") +@RequiredArgsConstructor +public class InfoController { + private final InfoService infoService; + + @GetMapping("/{d_day}") + @ResponseStatus(value = HttpStatus.OK) + public InfoDto getInfoByDDay(@PathVariable("d_day") int dDay) { + Info info = infoService.getInfoByDDay(dDay); + return InfoDto.from(info); + } +} diff --git a/src/main/java/efub/eday/edayback/domain/day/info/dto/ImageDto.java b/src/main/java/efub/eday/edayback/domain/day/info/dto/ImageDto.java new file mode 100644 index 0000000..fd87620 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/info/dto/ImageDto.java @@ -0,0 +1,11 @@ +package efub.eday.edayback.domain.day.info.dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ImageDto { + private Long imageId; + private String imageUrl; +} diff --git a/src/main/java/efub/eday/edayback/domain/day/info/dto/InfoDto.java b/src/main/java/efub/eday/edayback/domain/day/info/dto/InfoDto.java new file mode 100644 index 0000000..065472e --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/info/dto/InfoDto.java @@ -0,0 +1,39 @@ +package efub.eday.edayback.domain.day.info.dto; + +import java.util.ArrayList; +import java.util.List; + +import efub.eday.edayback.domain.day.info.entity.Info; +import efub.eday.edayback.domain.day.info.entity.InfoImage; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class InfoDto { + private Long infoId; + private Long infoImageId; + private int dDay; + private List imageList; + + public static InfoDto from(Info info) { + InfoDto infoDto = new InfoDto(); + infoDto.setInfoId(info.getId()); + infoDto.setDDay(info.getDDay().getDDay()); + + List imageList = new ArrayList<>(); + for (InfoImage infoImage : info.getInfoImageList()) { + ImageDto imageDto = new ImageDto(); + imageDto.setImageId(infoImage.getId()); + imageDto.setImageUrl(infoImage.getUrl()); + imageList.add(imageDto); + } + infoDto.setImageList(imageList); + + return infoDto; + } +} + diff --git a/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java b/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java index 7d25cba..811a8ea 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java @@ -1,5 +1,7 @@ package efub.eday.edayback.domain.day.info.entity; +import java.util.List; + import efub.eday.edayback.domain.day.dday.entity.DDay; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -7,9 +9,15 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToMany; import jakarta.persistence.OneToOne; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; @Entity +@NoArgsConstructor +@Getter public class Info { @Id @@ -17,7 +25,17 @@ public class Info { @Column(name = "info_id") private Long id; - @OneToOne + @OneToOne(mappedBy = "info") @JoinColumn(name = "d_day_id") private DDay dDay; + + @OneToMany(mappedBy = "info") + private List infoImageList; + + @Builder + public Info(Long id, DDay dDay, List infoImageList) { + this.id = id; + this.dDay = dDay; + this.infoImageList = infoImageList; + } } diff --git a/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java b/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java index f000665..7bfbe2f 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java @@ -6,9 +6,14 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; -import jakarta.persistence.OneToOne; +import jakarta.persistence.ManyToOne; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; @Entity +@NoArgsConstructor +@Getter public class InfoImage { @Id @@ -19,7 +24,14 @@ public class InfoImage { @Column(name = "image_url") private String url; - @OneToOne + @ManyToOne @JoinColumn(name = "info_id") private Info info; + + @Builder + public InfoImage(Long id, String url, Info info) { + this.id = id; + this.url = url; + this.info = info; + } } diff --git a/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java b/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java new file mode 100644 index 0000000..8b438b0 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java @@ -0,0 +1,9 @@ +package efub.eday.edayback.domain.day.info.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import efub.eday.edayback.domain.day.info.entity.Info; + +public interface InfoRepository extends JpaRepository { + Info findByDDay_DDay(int dDay); +} diff --git a/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java b/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java new file mode 100644 index 0000000..cd77a50 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java @@ -0,0 +1,20 @@ +package efub.eday.edayback.domain.day.info.service; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import efub.eday.edayback.domain.day.info.entity.Info; +import efub.eday.edayback.domain.day.info.repository.InfoRepository; +import lombok.RequiredArgsConstructor; + +@Service +@Transactional +@RequiredArgsConstructor +public class InfoService { + private final InfoRepository infoRepository; + + @Transactional(readOnly = true) + public Info getInfoByDDay(int dDay) { + return infoRepository.findByDDay_DDay(dDay); + } +} From 564ee81bb3aca9c08dc6f8906284e5a18a243066 Mon Sep 17 00:00:00 2001 From: chhaewxn Date: Sat, 15 Jul 2023 10:09:18 +0900 Subject: [PATCH 006/153] =?UTF-8?q?chore:=20Info(=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EC=A0=95=EB=B3=B4)=20api=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20#6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/day/info/repository/InfoRepository.java | 4 +++- .../eday/edayback/domain/day/info/service/InfoService.java | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java b/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java index 8b438b0..8eab9a1 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java @@ -1,9 +1,11 @@ package efub.eday.edayback.domain.day.info.repository; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; import efub.eday.edayback.domain.day.info.entity.Info; public interface InfoRepository extends JpaRepository { - Info findByDDay_DDay(int dDay); + Optional findByDDay_DDay(int dDay); } diff --git a/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java b/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java index cd77a50..f69d693 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java @@ -15,6 +15,7 @@ public class InfoService { @Transactional(readOnly = true) public Info getInfoByDDay(int dDay) { - return infoRepository.findByDDay_DDay(dDay); + return infoRepository.findByDDay_DDay(dDay) + .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 추가정보입니다.")); } } From 72423309165edd243232c69cd2991f5325b851a2 Mon Sep 17 00:00:00 2001 From: Kwon Min A Date: Sat, 15 Jul 2023 20:34:16 +0900 Subject: [PATCH 007/153] =?UTF-8?q?fix:=20DDay=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=EB=AA=85=20Subject=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 - 첫글자만 소문자인 경우 자바 빈 네이밍 규칙에 어긋나 에러 발생 - DDay 엔티티는 Subject로 이름 변경 - dDay 필드는 dday로 이름 변경 --- .../domain/day/dday/entity/Subject.java | 25 +++++++++++++++++++ .../edayback/domain/day/info/entity/Info.java | 12 ++++----- .../edayback/domain/day/quiz/entity/Quiz.java | 6 ++--- .../domain/day/title/entity/Title.java | 6 ++--- .../edayback/domain/query/entity/Query.java | 6 ++--- 5 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java new file mode 100644 index 0000000..75bb015 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java @@ -0,0 +1,25 @@ +package efub.eday.edayback.domain.day.dday.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +@Entity +public class Subject { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "subject_id") + private Long id; + + @Enumerated(value = EnumType.ORDINAL) + @Column(name = "d_day", nullable = false) + private int dday; + + @Column(nullable = false) + private String headline; +} diff --git a/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java b/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java index 811a8ea..78ee0a6 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java @@ -2,7 +2,7 @@ import java.util.List; -import efub.eday.edayback.domain.day.dday.entity.DDay; +import efub.eday.edayback.domain.day.dday.entity.Subject; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -25,17 +25,17 @@ public class Info { @Column(name = "info_id") private Long id; - @OneToOne(mappedBy = "info") - @JoinColumn(name = "d_day_id") - private DDay dDay; + @OneToOne + @JoinColumn(name = "subject_id", nullable = false) + private Subject subject; @OneToMany(mappedBy = "info") private List infoImageList; @Builder - public Info(Long id, DDay dDay, List infoImageList) { + public Info(Long id, Subject subject, List infoImageList) { this.id = id; - this.dDay = dDay; + this.subject = subject; this.infoImageList = infoImageList; } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java index 9c5c879..725298e 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java @@ -1,6 +1,6 @@ package efub.eday.edayback.domain.day.quiz.entity; -import efub.eday.edayback.domain.day.dday.entity.DDay; +import efub.eday.edayback.domain.day.dday.entity.Subject; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -27,6 +27,6 @@ public class Quiz { private String imageUrl; @OneToOne - @JoinColumn(name = "d_day_id", nullable = false) - private DDay dDay; + @JoinColumn(nullable = false) + private Subject subject; } diff --git a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java index 306ab9d..e5f784c 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java @@ -1,6 +1,6 @@ package efub.eday.edayback.domain.day.title.entity; -import efub.eday.edayback.domain.day.dday.entity.DDay; +import efub.eday.edayback.domain.day.dday.entity.Subject; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -24,6 +24,6 @@ public class Title { private String imageUrl; @OneToOne - @JoinColumn(name = "d_day_id", nullable = false) - private DDay dDay; + @JoinColumn(nullable = false) + private Subject subject; } diff --git a/src/main/java/efub/eday/edayback/domain/query/entity/Query.java b/src/main/java/efub/eday/edayback/domain/query/entity/Query.java index d6737cc..5a2d393 100644 --- a/src/main/java/efub/eday/edayback/domain/query/entity/Query.java +++ b/src/main/java/efub/eday/edayback/domain/query/entity/Query.java @@ -1,6 +1,6 @@ package efub.eday.edayback.domain.query.entity; -import efub.eday.edayback.domain.day.dday.entity.DDay; +import efub.eday.edayback.domain.day.dday.entity.Subject; import efub.eday.edayback.domain.member.entity.Member; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -26,6 +26,6 @@ public class Query { private Member writer; @ManyToOne - @JoinColumn(name = "d_day_id", nullable = false) - private DDay dDay; + @JoinColumn(nullable = false) + private Subject subject; } From 8e297ebb9283b325926f02d9d302443c2a9ebcc3 Mon Sep 17 00:00:00 2001 From: Kwon Min A Date: Sat, 15 Jul 2023 20:35:46 +0900 Subject: [PATCH 008/153] =?UTF-8?q?feat:=20Subject=EC=9D=98=20dday=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=EB=A5=BC=20Dday=20enum=20=ED=83=80=EC=9E=85?= =?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 - 디데이를 관리하는 Dday enum 추가 --- .../edayback/domain/day/dday/entity/DDay.java | 31 +++++++++---------- .../domain/day/dday/entity/Subject.java | 6 +++- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/DDay.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/DDay.java index 1c989cd..587b100 100644 --- a/src/main/java/efub/eday/edayback/domain/day/dday/entity/DDay.java +++ b/src/main/java/efub/eday/edayback/domain/day/dday/entity/DDay.java @@ -1,22 +1,21 @@ package efub.eday.edayback.domain.day.dday.entity; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +public enum Dday { + SEVEN(7), + SIX(6), + FIVE(5), + FOUR(4), + THREE(3), + TWO(2), + ONE(1); -@Entity -public class DDay { + private final int remainingDays; - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "d_day_id") - private Long id; + Dday(int remainingDays) { + this.remainingDays = remainingDays; + } - @Column(name = "d_day", nullable = false) - private int dDay; - - @Column(nullable = false) - private String topic; + public int getRemainingDays() { + return remainingDays; + } } diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java index 75bb015..449ebe0 100644 --- a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java +++ b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java @@ -18,8 +18,12 @@ public class Subject { @Enumerated(value = EnumType.ORDINAL) @Column(name = "d_day", nullable = false) - private int dday; + private Dday dday; @Column(nullable = false) private String headline; + + public int getDday() { + return dday.getRemainingDays(); + } } From a3e65263eb3b6a65310719dcbd827ce12a1f9389 Mon Sep 17 00:00:00 2001 From: Kwon Min A Date: Sat, 15 Jul 2023 20:37:03 +0900 Subject: [PATCH 009/153] =?UTF-8?q?fix:=20dDay=EB=A5=BC=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8A=94=20=EB=B3=80=EC=88=98=20=EB=B0=8F=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=9D=B4=EB=A6=84=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 --- .../edayback/domain/day/info/controller/InfoController.java | 4 ++-- .../java/efub/eday/edayback/domain/day/info/dto/InfoDto.java | 2 +- .../edayback/domain/day/info/repository/InfoRepository.java | 2 +- .../eday/edayback/domain/day/info/service/InfoService.java | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java b/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java index 5693fe0..34c9c5a 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java @@ -20,8 +20,8 @@ public class InfoController { @GetMapping("/{d_day}") @ResponseStatus(value = HttpStatus.OK) - public InfoDto getInfoByDDay(@PathVariable("d_day") int dDay) { - Info info = infoService.getInfoByDDay(dDay); + public InfoDto getInfoByDDay(@PathVariable("d_day") int dday) { + Info info = infoService.getInfoByDday(dday); return InfoDto.from(info); } } diff --git a/src/main/java/efub/eday/edayback/domain/day/info/dto/InfoDto.java b/src/main/java/efub/eday/edayback/domain/day/info/dto/InfoDto.java index 065472e..5c3f9bc 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/dto/InfoDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/dto/InfoDto.java @@ -22,7 +22,7 @@ public class InfoDto { public static InfoDto from(Info info) { InfoDto infoDto = new InfoDto(); infoDto.setInfoId(info.getId()); - infoDto.setDDay(info.getDDay().getDDay()); + infoDto.setDDay(info.getSubject().getDday()); List imageList = new ArrayList<>(); for (InfoImage infoImage : info.getInfoImageList()) { diff --git a/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java b/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java index 8eab9a1..9c91c31 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java @@ -7,5 +7,5 @@ import efub.eday.edayback.domain.day.info.entity.Info; public interface InfoRepository extends JpaRepository { - Optional findByDDay_DDay(int dDay); + Optional findInfoBySubject_Dday(int dday); } diff --git a/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java b/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java index f69d693..454a6d7 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java @@ -14,8 +14,8 @@ public class InfoService { private final InfoRepository infoRepository; @Transactional(readOnly = true) - public Info getInfoByDDay(int dDay) { - return infoRepository.findByDDay_DDay(dDay) + public Info getInfoByDday(int dday) { + return infoRepository.findInfoBySubject_Dday(dday) .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 추가정보입니다.")); } } From e98e21846287689a2542e96309f0ad816de5dc51 Mon Sep 17 00:00:00 2001 From: hannah0226 Date: Sat, 15 Jul 2023 21:32:54 +0900 Subject: [PATCH 010/153] =?UTF-8?q?feat:=20git=20ignore=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 94f15a7..3c72271 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,11 @@ .idea/**/dictionaries .idea/**/shelf +application.yaml +.env +docker-compose.yaml +Dockerfile + # AWS User-specific .idea/**/aws.xml From 3085dd9a74ac0cbcb037318eb2b7df02f34b458b Mon Sep 17 00:00:00 2001 From: hannah0226 Date: Sat, 15 Jul 2023 21:35:37 +0900 Subject: [PATCH 011/153] =?UTF-8?q?docs:=20git=20ignore=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 3c72271..c054f2a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,10 +12,7 @@ .idea/**/dictionaries .idea/**/shelf -application.yaml -.env -docker-compose.yaml -Dockerfile + # AWS User-specific .idea/**/aws.xml @@ -179,7 +176,9 @@ gradle-app.setting *.hprof .idea/ -application.yml +application.yaml .env +docker-compose.yaml +Dockerfile # End of https://www.toptal.com/developers/gitignore/api/java,gradle,intellij,macos,windows From bf9ef82a7a0ed29cc5a16b0d753c77f3ce0d617f Mon Sep 17 00:00:00 2001 From: hannah0226 Date: Fri, 14 Jul 2023 02:52:54 +0900 Subject: [PATCH 012/153] =?UTF-8?q?feat:=20=ED=80=B4=EC=A6=88=20=EB=82=B4?= =?UTF-8?q?=EC=9A=A9=EB=B3=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../day/quiz/controller/QuizController.java | 24 ++++++++++++ .../day/quiz/dto/OptionsResponseDto.java | 25 ++++++++++++ .../domain/day/quiz/dto/QuizRequestDto.java | 8 ++++ .../domain/day/quiz/dto/QuizResponseDto.java | 39 +++++++++++++++++++ .../domain/day/quiz/entity/Options.java | 12 ++++++ .../edayback/domain/day/quiz/entity/Quiz.java | 26 +++++++++---- .../day/quiz/repository/QuizRepository.java | 10 +++++ .../domain/day/quiz/service/QuizService.java | 21 ++++++++++ 8 files changed, 158 insertions(+), 7 deletions(-) create mode 100644 src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizRequestDto.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/quiz/repository/QuizRepository.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java new file mode 100644 index 0000000..ce25bb7 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java @@ -0,0 +1,24 @@ +package efub.eday.edayback.domain.day.quiz.controller; + +import efub.eday.edayback.domain.day.quiz.dto.QuizRequestDto; +import efub.eday.edayback.domain.day.quiz.dto.QuizResponseDto; +import efub.eday.edayback.domain.day.quiz.entity.Quiz; +import efub.eday.edayback.domain.day.quiz.service.QuizService; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/quiz/{d_day}") +@RequiredArgsConstructor +public class QuizController { + private final QuizService quizService; + + //퀴즈 내용 조회 + @GetMapping + @ResponseStatus(value = HttpStatus.OK) + public QuizResponseDto quizFind(@PathVariable Long d_day){ + Quiz quiz = quizService.findQuiz(d_day); + return QuizResponseDto.from(quiz); + } +} diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java new file mode 100644 index 0000000..604ac78 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java @@ -0,0 +1,25 @@ +package efub.eday.edayback.domain.day.quiz.dto; + +import efub.eday.edayback.domain.day.quiz.entity.Options; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class OptionsResponseDto { + private Long id; + private String content; + + public OptionsResponseDto(Long id, String content){ + this.id=id; + this.content=content; + } + + public static OptionsResponseDto from(Options options){ + return new OptionsResponseDto( + options.getId(), + options.getContent() + ); + } +} diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizRequestDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizRequestDto.java new file mode 100644 index 0000000..f9973f5 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizRequestDto.java @@ -0,0 +1,8 @@ +package efub.eday.edayback.domain.day.quiz.dto; + +import lombok.Getter; + +@Getter +public class QuizRequestDto { + private Long optionId; +} diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java new file mode 100644 index 0000000..4dad5aa --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java @@ -0,0 +1,39 @@ +package efub.eday.edayback.domain.day.quiz.dto; + +import efub.eday.edayback.domain.day.quiz.entity.Quiz; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.stream.Collectors; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class QuizResponseDto { + private Long dDay; + private String topic; + private String quizContent; + private List optionList; + + public QuizResponseDto(Long dDay, String topic, String quizContent, List optionList){ + this.dDay=dDay; + this.topic=topic; + this.quizContent=quizContent; + this.optionList=optionList; + } + + public static QuizResponseDto from(Quiz quiz){ + List optionList = quiz.getOptionsList() + .stream() + .map(OptionsResponseDto::from) + .collect(Collectors.toList()); + return new QuizResponseDto( + quiz.getDDay(), + quiz.getDDay().getTopic(), + quiz.getContent(), + optionList + ); + } + +} diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java index 56e346e..00bc8ad 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java @@ -1,5 +1,6 @@ package efub.eday.edayback.domain.day.quiz.entity; +import efub.eday.edayback.domain.day.quiz.dto.QuizResponseDto; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -7,8 +8,11 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import lombok.Builder; +import lombok.Getter; @Entity +@Getter public class Options { @Id @@ -25,4 +29,12 @@ public class Options { @ManyToOne @JoinColumn(name = "quiz_id") private Quiz quiz; + + @Builder + public Options(Long id, String content, Boolean isAnswer, Quiz quiz){ + this.id=id; + this.content=content; + this.isAnswer=isAnswer; + this.quiz=quiz; + } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java index 9c5c879..d0f13c2 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java @@ -1,15 +1,14 @@ package efub.eday.edayback.domain.day.quiz.entity; import efub.eday.edayback.domain.day.dday.entity.DDay; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.OneToOne; +import jakarta.persistence.*; +import lombok.Builder; +import lombok.Getter; + +import java.util.List; @Entity +@Getter public class Quiz { @Id @@ -29,4 +28,17 @@ public class Quiz { @OneToOne @JoinColumn(name = "d_day_id", nullable = false) private DDay dDay; + + @OneToMany(mappedBy = "quiz") + private List optionsList; + + @Builder + public Quiz(Long id, String content, String description, String imageUrl, DDay dDay, List optionsList){ + this.id=id; + this.content=content; + this.description=description; + this.imageUrl=imageUrl; + this.dDay=dDay; + this.optionsList=optionsList; + } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/repository/QuizRepository.java b/src/main/java/efub/eday/edayback/domain/day/quiz/repository/QuizRepository.java new file mode 100644 index 0000000..a717639 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/repository/QuizRepository.java @@ -0,0 +1,10 @@ +package efub.eday.edayback.domain.day.quiz.repository; + +import efub.eday.edayback.domain.day.quiz.entity.Quiz; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface QuizRepository extends JpaRepository { + Optional findByDDayId(Long dDayId); +} diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java new file mode 100644 index 0000000..396c823 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java @@ -0,0 +1,21 @@ +package efub.eday.edayback.domain.day.quiz.service; + +import efub.eday.edayback.domain.day.quiz.entity.Quiz; +import efub.eday.edayback.domain.day.quiz.repository.QuizRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class QuizService { + private final QuizRepository quizRepository; + + //퀴즈 내용 조회 + @Transactional(readOnly = true) + public Quiz findQuiz(Long d_day){ + return quizRepository.findByDDayId(d_day) + .orElseThrow(()-> new IllegalArgumentException("퀴즈를 찾을 수 없습니다.")); + } +} From 4b5ab1802ba05a1379486d737ec8e5d6a5d36746 Mon Sep 17 00:00:00 2001 From: hannah0226 Date: Sun, 16 Jul 2023 19:07:25 +0900 Subject: [PATCH 013/153] =?UTF-8?q?fix:=20DDay=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=EB=B0=8F=20=ED=95=84=EB=93=9C,=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eday/edayback/domain/day/dday/entity/Subject.java | 2 ++ .../edayback/domain/day/quiz/dto/QuizResponseDto.java | 10 +++++----- .../eday/edayback/domain/day/quiz/entity/Quiz.java | 8 ++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java index 449ebe0..e752112 100644 --- a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java +++ b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java @@ -7,8 +7,10 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import lombok.Getter; @Entity +@Getter public class Subject { @Id diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java index 4dad5aa..d420d97 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java @@ -11,13 +11,13 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class QuizResponseDto { - private Long dDay; + private int dday; private String topic; private String quizContent; private List optionList; - public QuizResponseDto(Long dDay, String topic, String quizContent, List optionList){ - this.dDay=dDay; + public QuizResponseDto(int dday, String topic, String quizContent, List optionList){ + this.dday=dday; this.topic=topic; this.quizContent=quizContent; this.optionList=optionList; @@ -29,8 +29,8 @@ public static QuizResponseDto from(Quiz quiz){ .map(OptionsResponseDto::from) .collect(Collectors.toList()); return new QuizResponseDto( - quiz.getDDay(), - quiz.getDDay().getTopic(), + quiz.getDday().getDday(), + quiz.getDday().getHeadline(), quiz.getContent(), optionList ); diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java index d0f13c2..80134de 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java @@ -1,6 +1,6 @@ package efub.eday.edayback.domain.day.quiz.entity; -import efub.eday.edayback.domain.day.dday.entity.DDay; +import efub.eday.edayback.domain.day.dday.entity.Subject; import jakarta.persistence.*; import lombok.Builder; import lombok.Getter; @@ -27,18 +27,18 @@ public class Quiz { @OneToOne @JoinColumn(name = "d_day_id", nullable = false) - private DDay dDay; + private Subject dday; @OneToMany(mappedBy = "quiz") private List optionsList; @Builder - public Quiz(Long id, String content, String description, String imageUrl, DDay dDay, List optionsList){ + public Quiz(Long id, String content, String description, String imageUrl, Subject dday, List optionsList){ this.id=id; this.content=content; this.description=description; this.imageUrl=imageUrl; - this.dDay=dDay; + this.dday=dday; this.optionsList=optionsList; } } From 0d64fadf6fa531046e9666e059f5ef6fd94dcee5 Mon Sep 17 00:00:00 2001 From: chhaewxn Date: Mon, 17 Jul 2023 03:06:43 +0900 Subject: [PATCH 014/153] =?UTF-8?q?chore:=20Info(=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EC=A0=95=EB=B3=B4)=20api=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20#6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/day/info/controller/InfoController.java | 3 ++- .../edayback/domain/day/info/repository/InfoRepository.java | 3 ++- .../eday/edayback/domain/day/info/service/InfoService.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java b/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java index 34c9c5a..f9a5a70 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.info.dto.InfoDto; import efub.eday.edayback.domain.day.info.entity.Info; import efub.eday.edayback.domain.day.info.service.InfoService; @@ -20,7 +21,7 @@ public class InfoController { @GetMapping("/{d_day}") @ResponseStatus(value = HttpStatus.OK) - public InfoDto getInfoByDDay(@PathVariable("d_day") int dday) { + public InfoDto getInfoByDDay(@PathVariable("d_day") Dday dday) { Info info = infoService.getInfoByDday(dday); return InfoDto.from(info); } diff --git a/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java b/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java index 9c91c31..68770e6 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java @@ -4,8 +4,9 @@ import org.springframework.data.jpa.repository.JpaRepository; +import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.info.entity.Info; public interface InfoRepository extends JpaRepository { - Optional findInfoBySubject_Dday(int dday); + Optional findInfoBySubject_Dday(Dday dday); } diff --git a/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java b/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java index 454a6d7..b7b63b5 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java @@ -3,6 +3,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.info.entity.Info; import efub.eday.edayback.domain.day.info.repository.InfoRepository; import lombok.RequiredArgsConstructor; @@ -14,7 +15,7 @@ public class InfoService { private final InfoRepository infoRepository; @Transactional(readOnly = true) - public Info getInfoByDday(int dday) { + public Info getInfoByDday(Dday dday) { // Dday 엔티티를 인자로 받도록 수정 return infoRepository.findInfoBySubject_Dday(dday) .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 추가정보입니다.")); } From 2fdc76a7029d2caa9ecfb6f10895825bd1f61182 Mon Sep 17 00:00:00 2001 From: chhaewxn Date: Tue, 18 Jul 2023 01:02:17 +0900 Subject: [PATCH 015/153] =?UTF-8?q?chore:=20=EC=97=B4=EA=B1=B0=ED=98=95=20?= =?UTF-8?q?=EB=B3=80=ED=99=98=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20#6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/day/dday/entity/DDay.java | 21 ------------- .../edayback/domain/day/dday/entity/Dday.java | 30 +++++++++++++++++++ .../day/info/controller/InfoController.java | 5 ++-- 3 files changed, 33 insertions(+), 23 deletions(-) delete mode 100644 src/main/java/efub/eday/edayback/domain/day/dday/entity/DDay.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/dday/entity/Dday.java diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/DDay.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/DDay.java deleted file mode 100644 index 587b100..0000000 --- a/src/main/java/efub/eday/edayback/domain/day/dday/entity/DDay.java +++ /dev/null @@ -1,21 +0,0 @@ -package efub.eday.edayback.domain.day.dday.entity; - -public enum Dday { - SEVEN(7), - SIX(6), - FIVE(5), - FOUR(4), - THREE(3), - TWO(2), - ONE(1); - - private final int remainingDays; - - Dday(int remainingDays) { - this.remainingDays = remainingDays; - } - - public int getRemainingDays() { - return remainingDays; - } -} diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Dday.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Dday.java new file mode 100644 index 0000000..f53432c --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Dday.java @@ -0,0 +1,30 @@ +package efub.eday.edayback.domain.day.dday.entity; + +public enum Dday { + SEVEN(7), + SIX(6), + FIVE(5), + FOUR(4), + THREE(3), + TWO(2), + ONE(1); + + private final int remainingDays; + + Dday(int remainingDays) { + this.remainingDays = remainingDays; + } + + public int getRemainingDays() { + return remainingDays; + } + + public static Dday fromRemainingDays(int remainingDays) { // 문자열 값을 열거형으로 변환하는 메소드를 추가 + for (Dday dday : Dday.values()) { + if (dday.getRemainingDays() == remainingDays) { + return dday; + } + } + throw new IllegalArgumentException("Invalid remaining days value: " + remainingDays); + } +} diff --git a/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java b/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java index f9a5a70..d461520 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java @@ -21,8 +21,9 @@ public class InfoController { @GetMapping("/{d_day}") @ResponseStatus(value = HttpStatus.OK) - public InfoDto getInfoByDDay(@PathVariable("d_day") Dday dday) { - Info info = infoService.getInfoByDday(dday); + public InfoDto getInfoByDday(@PathVariable("d_day") int dday) { + Dday ddayEnum = Dday.fromRemainingDays(dday); + Info info = infoService.getInfoByDday(ddayEnum); return InfoDto.from(info); } } From ab270ac0ddd2d7224232ab084709e0508c59a94a Mon Sep 17 00:00:00 2001 From: chhaewxn Date: Tue, 18 Jul 2023 01:04:51 +0900 Subject: [PATCH 016/153] =?UTF-8?q?chore:=20Info(=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EC=A0=95=EB=B3=B4)=20api=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20#6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eday/edayback/domain/day/info/dto/InfoDto.java | 12 +++++++----- .../eday/edayback/domain/day/info/entity/Info.java | 3 +-- .../edayback/domain/day/info/entity/InfoImage.java | 8 -------- .../domain/day/info/service/InfoService.java | 2 +- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/info/dto/InfoDto.java b/src/main/java/efub/eday/edayback/domain/day/info/dto/InfoDto.java index 5c3f9bc..bfd4916 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/dto/InfoDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/dto/InfoDto.java @@ -14,15 +14,17 @@ @Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class InfoDto { - private Long infoId; - private Long infoImageId; - private int dDay; + // private Long infoId; + // private Long infoImageId; + private int dday; + private String headline; private List imageList; public static InfoDto from(Info info) { InfoDto infoDto = new InfoDto(); - infoDto.setInfoId(info.getId()); - infoDto.setDDay(info.getSubject().getDday()); + + infoDto.setDday(info.getSubject().getDday()); + infoDto.setHeadline(info.getSubject().getHeadline()); List imageList = new ArrayList<>(); for (InfoImage infoImage : info.getInfoImageList()) { diff --git a/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java b/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java index 78ee0a6..ff31988 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java @@ -33,8 +33,7 @@ public class Info { private List infoImageList; @Builder - public Info(Long id, Subject subject, List infoImageList) { - this.id = id; + public Info(Subject subject, List infoImageList) { this.subject = subject; this.infoImageList = infoImageList; } diff --git a/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java b/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java index 7bfbe2f..535d295 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java @@ -7,7 +7,6 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -27,11 +26,4 @@ public class InfoImage { @ManyToOne @JoinColumn(name = "info_id") private Info info; - - @Builder - public InfoImage(Long id, String url, Info info) { - this.id = id; - this.url = url; - this.info = info; - } } diff --git a/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java b/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java index b7b63b5..990ef12 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java @@ -15,7 +15,7 @@ public class InfoService { private final InfoRepository infoRepository; @Transactional(readOnly = true) - public Info getInfoByDday(Dday dday) { // Dday 엔티티를 인자로 받도록 수정 + public Info getInfoByDday(Dday dday) { return infoRepository.findInfoBySubject_Dday(dday) .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 추가정보입니다.")); } From 62e747102b56f9d1b705650c620ada7cd9838567 Mon Sep 17 00:00:00 2001 From: chhaewxn Date: Tue, 18 Jul 2023 01:05:33 +0900 Subject: [PATCH 017/153] =?UTF-8?q?chore:=20Getter=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80=20#6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eday/edayback/domain/day/dday/entity/Subject.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java index 449ebe0..74b7640 100644 --- a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java +++ b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java @@ -7,8 +7,12 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import lombok.Getter; +import lombok.NoArgsConstructor; @Entity +@NoArgsConstructor +@Getter public class Subject { @Id @@ -26,4 +30,8 @@ public class Subject { public int getDday() { return dday.getRemainingDays(); } + + public String getHeadline() { + return headline; + } } From e08588154e4267accee70c7d94ceb8f64962eb8e Mon Sep 17 00:00:00 2001 From: choiyounji Date: Tue, 18 Jul 2023 02:16:31 +0900 Subject: [PATCH 018/153] =?UTF-8?q?feat:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=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 | 24 ++++ .../edayback/domain/member/entity/Member.java | 13 ++ .../member/entity/oauth/KakaoProfile.java | 38 ++++++ .../member/entity/oauth/OAuthToken.java | 13 ++ .../member/repository/MemberRepository.java | 9 ++ .../domain/member/service/MemberService.java | 113 ++++++++++++++++++ 6 files changed, 210 insertions(+) create mode 100644 src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java create mode 100644 src/main/java/efub/eday/edayback/domain/member/entity/oauth/KakaoProfile.java create mode 100644 src/main/java/efub/eday/edayback/domain/member/entity/oauth/OAuthToken.java create mode 100644 src/main/java/efub/eday/edayback/domain/member/repository/MemberRepository.java create mode 100644 src/main/java/efub/eday/edayback/domain/member/service/MemberService.java diff --git a/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java b/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java new file mode 100644 index 0000000..61f7c8d --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java @@ -0,0 +1,24 @@ +package efub.eday.edayback.domain.member.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +import efub.eday.edayback.domain.member.entity.Member; +import efub.eday.edayback.domain.member.service.MemberService; +import lombok.RequiredArgsConstructor; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/members") +public class MemberController { + private final MemberService memberService; + + @GetMapping("/oauth") + public @ResponseBody String kakaoLogin(String code) { + Member member = memberService.getAccessToken(code); + return "카카오 인증 완료: " + code; + } + +} diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java index bc301e2..7cab7e2 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java @@ -2,11 +2,14 @@ import java.time.LocalDate; +import org.hibernate.annotations.CreationTimestamp; + import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import lombok.Builder; @Entity public class Member { @@ -28,9 +31,19 @@ public class Member { @Column(nullable = false) private Integer level; + @CreationTimestamp //insert할 때 자동 날짜 적용 @Column(nullable = false) private LocalDate createdDate; @Column(nullable = false) private Boolean isActive; + + @Builder + public Member(String nickname, String email, String profileImageUrl, Integer level, Boolean isActive) { + this.nickname = nickname; + this.email = email; + this.profileImageUrl = profileImageUrl; + this.level = level; + this.isActive = isActive; + } } diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/oauth/KakaoProfile.java b/src/main/java/efub/eday/edayback/domain/member/entity/oauth/KakaoProfile.java new file mode 100644 index 0000000..4750e1c --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/entity/oauth/KakaoProfile.java @@ -0,0 +1,38 @@ +package efub.eday.edayback.domain.member.entity.oauth; + +import lombok.Data; + +@Data +public class KakaoProfile { + public Long id = null; + public String connected_at; + public Properties properties; + public KakaoAccount kakao_account; + + @Data + public class Properties { + public String nickname; + public String profile_image; + public String thumbnail_image; + } + + @Data + public class KakaoAccount { + public Boolean profile_nickname_needs_agreement; + public Boolean profile_image_needs_agreement; + public Profile profile; + public Boolean has_email; + public Boolean email_needs_agreement; + public Boolean is_email_valid; + public Boolean is_email_verified; + public String email; + + @Data + public class Profile { + public String nickname; + public String thumbnail_image_url; + public String profile_image_url; + public Boolean is_default_image; + } + } +} diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/oauth/OAuthToken.java b/src/main/java/efub/eday/edayback/domain/member/entity/oauth/OAuthToken.java new file mode 100644 index 0000000..f2ee8a9 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/entity/oauth/OAuthToken.java @@ -0,0 +1,13 @@ +package efub.eday.edayback.domain.member.entity.oauth; + +import lombok.Data; + +@Data +public class OAuthToken { + private String access_token; + private String token_type; + private String refresh_token; + private int expires_in; + private String scope; + private int refresh_token_expires_in; +} diff --git a/src/main/java/efub/eday/edayback/domain/member/repository/MemberRepository.java b/src/main/java/efub/eday/edayback/domain/member/repository/MemberRepository.java new file mode 100644 index 0000000..538a96d --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/repository/MemberRepository.java @@ -0,0 +1,9 @@ +package efub.eday.edayback.domain.member.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import efub.eday.edayback.domain.member.entity.Member; + +public interface MemberRepository extends JpaRepository { + Member findByEmail(String email); +} diff --git a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java new file mode 100644 index 0000000..ae5e3b5 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java @@ -0,0 +1,113 @@ +package efub.eday.edayback.domain.member.service; + +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.client.RestTemplate; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import efub.eday.edayback.domain.member.entity.Member; +import efub.eday.edayback.domain.member.entity.oauth.KakaoProfile; +import efub.eday.edayback.domain.member.entity.oauth.OAuthToken; +import efub.eday.edayback.domain.member.repository.MemberRepository; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +@Service +public class MemberService { + + private final MemberRepository memberRepository; + + public Member getAccessToken(String code) { + + RestTemplate rt = new RestTemplate(); + + HttpHeaders headers = new HttpHeaders(); + headers.add("Content-type", "application/x-www-form-urlencoded;charset=utf-8"); + + MultiValueMap params = new LinkedMultiValueMap<>(); + params.add("grant_type", "authorization_code"); + params.add("client_id", "24964b4a10d417e6a957b25423a635a5"); + params.add("redirect_uri", "http://localhost:8080/members/oauth"); + params.add("code", code); + + //아래 exchange 함수에 하나의 object로 넣기 위해 합치기 + HttpEntity> kakaoTokenRequest = new HttpEntity<>(params, headers); + + ResponseEntity response = rt.exchange( + "https://kauth.kakao.com/oauth/token", + HttpMethod.POST, + kakaoTokenRequest, + String.class + ); + + ObjectMapper objectMapper = new ObjectMapper(); + OAuthToken oauthToken = null; + try { + oauthToken = objectMapper.readValue(response.getBody(), OAuthToken.class); + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + + return findProfile(oauthToken); + + } + + private Member findProfile(OAuthToken oauthToken) { + //토큰 이용하여 사용자 정보 조회 + RestTemplate rt2 = new RestTemplate(); + + HttpHeaders headers2 = new HttpHeaders(); + headers2.add("Authorization", "Bearer " + oauthToken.getAccess_token()); + headers2.add("Content-type", "application/x-www-form-urlencoded;charset=utf-8"); + + HttpEntity> kakaoProfileRequest2 = new HttpEntity<>(headers2); + + ResponseEntity response2 = rt2.exchange( + "https://kapi.kakao.com/v2/user/me", + HttpMethod.POST, + kakaoProfileRequest2, + String.class + ); + + ObjectMapper objectMapper2 = new ObjectMapper(); + KakaoProfile kakaoProfile = null; + try { + kakaoProfile = objectMapper2.readValue(response2.getBody(), KakaoProfile.class); + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return saveMember(kakaoProfile); + } + + public Member saveMember(@RequestBody KakaoProfile kakaoProfile) { + //Member 저장 + Member kakaoMember = memberRepository.findByEmail(kakaoProfile.getKakao_account().getEmail()); + + if (kakaoMember == null) { + //기존 회원이 아닐경우 자동으로 회원가입 + kakaoMember = Member.builder() + .nickname(kakaoProfile.getKakao_account().profile.nickname) + .email(kakaoProfile.getKakao_account().getEmail()) + .profileImageUrl(kakaoProfile.getKakao_account().profile.profile_image_url) + .level(0) //level은 0에서부터 시작 + .isActive(true) //처음 회원가입하면 활성 상태로 시작 + .build(); + memberRepository.save(kakaoMember); + } + return kakaoMember; + } + +} From fea00a7884aec071d5ee4f5e479890410e9d0cf5 Mon Sep 17 00:00:00 2001 From: choiyounji Date: Tue, 18 Jul 2023 02:43:43 +0900 Subject: [PATCH 019/153] =?UTF-8?q?feat:=20MemberResponseDto=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 --- .../member/controller/MemberController.java | 9 ++++----- .../domain/member/dto/MemberResponseDto.java | 16 ++++++++++++++++ .../edayback/domain/member/entity/Member.java | 4 ++++ .../domain/member/service/MemberService.java | 9 +++++---- 4 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 src/main/java/efub/eday/edayback/domain/member/dto/MemberResponseDto.java diff --git a/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java b/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java index 61f7c8d..f89593e 100644 --- a/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java +++ b/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java @@ -2,10 +2,9 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; -import efub.eday.edayback.domain.member.entity.Member; +import efub.eday.edayback.domain.member.dto.MemberResponseDto; import efub.eday.edayback.domain.member.service.MemberService; import lombok.RequiredArgsConstructor; @@ -16,9 +15,9 @@ public class MemberController { private final MemberService memberService; @GetMapping("/oauth") - public @ResponseBody String kakaoLogin(String code) { - Member member = memberService.getAccessToken(code); - return "카카오 인증 완료: " + code; + public MemberResponseDto kakaoLogin(String code) { + MemberResponseDto member = memberService.getAccessToken(code); + return member; } } diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/MemberResponseDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/MemberResponseDto.java new file mode 100644 index 0000000..6ff47bb --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/dto/MemberResponseDto.java @@ -0,0 +1,16 @@ +package efub.eday.edayback.domain.member.dto; + +import efub.eday.edayback.domain.member.entity.Member; +import lombok.Getter; + +@Getter +public class MemberResponseDto { + private String nickname; + private String profileImageUrl; + + public MemberResponseDto(Member member) { + this.nickname = member.getNickname(); + this.profileImageUrl = member.getProfileImageUrl(); + } + +} diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java index 7cab7e2..1349aae 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java @@ -10,8 +10,12 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; @Entity +@Getter +@NoArgsConstructor public class Member { @Id diff --git a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java index ae5e3b5..7e6f518 100644 --- a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java +++ b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java @@ -14,6 +14,7 @@ import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import efub.eday.edayback.domain.member.dto.MemberResponseDto; import efub.eday.edayback.domain.member.entity.Member; import efub.eday.edayback.domain.member.entity.oauth.KakaoProfile; import efub.eday.edayback.domain.member.entity.oauth.OAuthToken; @@ -26,7 +27,7 @@ public class MemberService { private final MemberRepository memberRepository; - public Member getAccessToken(String code) { + public MemberResponseDto getAccessToken(String code) { RestTemplate rt = new RestTemplate(); @@ -63,7 +64,7 @@ public Member getAccessToken(String code) { } - private Member findProfile(OAuthToken oauthToken) { + private MemberResponseDto findProfile(OAuthToken oauthToken) { //토큰 이용하여 사용자 정보 조회 RestTemplate rt2 = new RestTemplate(); @@ -92,7 +93,7 @@ private Member findProfile(OAuthToken oauthToken) { return saveMember(kakaoProfile); } - public Member saveMember(@RequestBody KakaoProfile kakaoProfile) { + public MemberResponseDto saveMember(@RequestBody KakaoProfile kakaoProfile) { //Member 저장 Member kakaoMember = memberRepository.findByEmail(kakaoProfile.getKakao_account().getEmail()); @@ -107,7 +108,7 @@ public Member saveMember(@RequestBody KakaoProfile kakaoProfile) { .build(); memberRepository.save(kakaoMember); } - return kakaoMember; + return new MemberResponseDto(kakaoMember); } } From e5ddc5a56b2d4f279333e32c7b2ec0965afffeab Mon Sep 17 00:00:00 2001 From: hannah0226 Date: Tue, 18 Jul 2023 03:33:23 +0900 Subject: [PATCH 020/153] =?UTF-8?q?fix:=20=ED=94=BC=EB=93=9C=EB=B0=B1=20?= =?UTF-8?q?=EC=88=98=EC=9A=A9=20=EB=B0=8F=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/day/dday/entity/Dday.java | 9 --------- .../day/quiz/controller/QuizController.java | 3 ++- .../day/quiz/dto/OptionsResponseDto.java | 2 +- .../domain/day/quiz/dto/QuizResponseDto.java | 6 ++++-- .../domain/day/quiz/entity/Options.java | 3 +-- .../edayback/domain/day/quiz/entity/Quiz.java | 7 +++---- .../day/quiz/repository/QuizRepository.java | 2 +- .../domain/day/quiz/service/QuizService.java | 19 ++++++++++++++++++- 8 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Dday.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Dday.java index f53432c..587b100 100644 --- a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Dday.java +++ b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Dday.java @@ -18,13 +18,4 @@ public enum Dday { public int getRemainingDays() { return remainingDays; } - - public static Dday fromRemainingDays(int remainingDays) { // 문자열 값을 열거형으로 변환하는 메소드를 추가 - for (Dday dday : Dday.values()) { - if (dday.getRemainingDays() == remainingDays) { - return dday; - } - } - throw new IllegalArgumentException("Invalid remaining days value: " + remainingDays); - } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java index ce25bb7..b27e865 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java @@ -1,5 +1,6 @@ package efub.eday.edayback.domain.day.quiz.controller; +import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.quiz.dto.QuizRequestDto; import efub.eday.edayback.domain.day.quiz.dto.QuizResponseDto; import efub.eday.edayback.domain.day.quiz.entity.Quiz; @@ -17,7 +18,7 @@ public class QuizController { //퀴즈 내용 조회 @GetMapping @ResponseStatus(value = HttpStatus.OK) - public QuizResponseDto quizFind(@PathVariable Long d_day){ + public QuizResponseDto Findquiz(@PathVariable Long d_day){ Quiz quiz = quizService.findQuiz(d_day); return QuizResponseDto.from(quiz); } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java index 604ac78..1cda2eb 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java @@ -11,7 +11,7 @@ public class OptionsResponseDto { private Long id; private String content; - public OptionsResponseDto(Long id, String content){ + private OptionsResponseDto(Long id, String content){ this.id=id; this.content=content; } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java index d420d97..c3e0f62 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java @@ -4,11 +4,13 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; import java.util.List; import java.util.stream.Collectors; @Getter +@Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class QuizResponseDto { private int dday; @@ -29,8 +31,8 @@ public static QuizResponseDto from(Quiz quiz){ .map(OptionsResponseDto::from) .collect(Collectors.toList()); return new QuizResponseDto( - quiz.getDday().getDday(), - quiz.getDday().getHeadline(), + quiz.getSubject().getDday(), + quiz.getSubject().getHeadline(), quiz.getContent(), optionList ); diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java index 00bc8ad..ecb0d7e 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java @@ -31,8 +31,7 @@ public class Options { private Quiz quiz; @Builder - public Options(Long id, String content, Boolean isAnswer, Quiz quiz){ - this.id=id; + public Options(String content, Boolean isAnswer, Quiz quiz){ this.content=content; this.isAnswer=isAnswer; this.quiz=quiz; diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java index 80134de..6f8a39a 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java @@ -27,18 +27,17 @@ public class Quiz { @OneToOne @JoinColumn(name = "d_day_id", nullable = false) - private Subject dday; + private Subject subject; @OneToMany(mappedBy = "quiz") private List optionsList; @Builder - public Quiz(Long id, String content, String description, String imageUrl, Subject dday, List optionsList){ - this.id=id; + public Quiz(String content, String description, String imageUrl, Subject subject, List optionsList){ this.content=content; this.description=description; this.imageUrl=imageUrl; - this.dday=dday; + this.subject=subject; this.optionsList=optionsList; } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/repository/QuizRepository.java b/src/main/java/efub/eday/edayback/domain/day/quiz/repository/QuizRepository.java index a717639..e22b2eb 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/repository/QuizRepository.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/repository/QuizRepository.java @@ -6,5 +6,5 @@ import java.util.Optional; public interface QuizRepository extends JpaRepository { - Optional findByDDayId(Long dDayId); + Optional findBySubject_Dday(Long dDayId); } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java index 396c823..9af0b80 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java @@ -1,10 +1,13 @@ package efub.eday.edayback.domain.day.quiz.service; +import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.quiz.entity.Quiz; import efub.eday.edayback.domain.day.quiz.repository.QuizRepository; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.server.ResponseStatusException; @Service @Transactional @@ -15,7 +18,21 @@ public class QuizService { //퀴즈 내용 조회 @Transactional(readOnly = true) public Quiz findQuiz(Long d_day){ - return quizRepository.findByDDayId(d_day) + Dday[] validDdays = Dday.values(); + boolean isValidDday = false; + + for (Dday dday : validDdays) { + if (dday.getRemainingDays() == d_day) { + isValidDday = true; + break; + } + } + + if (!isValidDday) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "올바르지 않은 D-day 값입니다."); + } + + return quizRepository.findBySubject_Dday(d_day) .orElseThrow(()-> new IllegalArgumentException("퀴즈를 찾을 수 없습니다.")); } } From 49a745cd89a43f237bca0602de6534f39dccf524 Mon Sep 17 00:00:00 2001 From: Kwon Min A Date: Tue, 18 Jul 2023 10:14:31 +0900 Subject: [PATCH 021/153] =?UTF-8?q?refactor:=20=EB=94=94=EB=8D=B0=EC=9D=B4?= =?UTF-8?q?=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20QuizService=20->?= =?UTF-8?q?=20Dday=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/day/dday/entity/Dday.java | 9 +++++ .../day/quiz/controller/QuizController.java | 27 +++++++------- .../day/quiz/repository/QuizRepository.java | 10 +++--- .../domain/day/quiz/service/QuizService.java | 36 ++++++------------- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Dday.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Dday.java index 587b100..f53432c 100644 --- a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Dday.java +++ b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Dday.java @@ -18,4 +18,13 @@ public enum Dday { public int getRemainingDays() { return remainingDays; } + + public static Dday fromRemainingDays(int remainingDays) { // 문자열 값을 열거형으로 변환하는 메소드를 추가 + for (Dday dday : Dday.values()) { + if (dday.getRemainingDays() == remainingDays) { + return dday; + } + } + throw new IllegalArgumentException("Invalid remaining days value: " + remainingDays); + } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java index b27e865..6b4f1dc 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java @@ -1,25 +1,28 @@ package efub.eday.edayback.domain.day.quiz.controller; -import efub.eday.edayback.domain.day.dday.entity.Dday; -import efub.eday.edayback.domain.day.quiz.dto.QuizRequestDto; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + import efub.eday.edayback.domain.day.quiz.dto.QuizResponseDto; import efub.eday.edayback.domain.day.quiz.entity.Quiz; import efub.eday.edayback.domain.day.quiz.service.QuizService; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/quiz/{d_day}") @RequiredArgsConstructor public class QuizController { - private final QuizService quizService; + private final QuizService quizService; - //퀴즈 내용 조회 - @GetMapping - @ResponseStatus(value = HttpStatus.OK) - public QuizResponseDto Findquiz(@PathVariable Long d_day){ - Quiz quiz = quizService.findQuiz(d_day); - return QuizResponseDto.from(quiz); - } + //퀴즈 내용 조회 + @GetMapping + @ResponseStatus(value = HttpStatus.OK) + public QuizResponseDto findQuiz(@PathVariable int d_day) { + Quiz quiz = quizService.findQuiz(d_day); + return QuizResponseDto.from(quiz); + } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/repository/QuizRepository.java b/src/main/java/efub/eday/edayback/domain/day/quiz/repository/QuizRepository.java index e22b2eb..4b40bad 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/repository/QuizRepository.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/repository/QuizRepository.java @@ -1,10 +1,12 @@ package efub.eday.edayback.domain.day.quiz.repository; -import efub.eday.edayback.domain.day.quiz.entity.Quiz; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; -import java.util.Optional; +import efub.eday.edayback.domain.day.dday.entity.Dday; +import efub.eday.edayback.domain.day.quiz.entity.Quiz; -public interface QuizRepository extends JpaRepository { - Optional findBySubject_Dday(Long dDayId); +public interface QuizRepository extends JpaRepository { + Optional findBySubject_Dday(Dday dday); } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java index 9af0b80..b4947c6 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java @@ -1,38 +1,24 @@ package efub.eday.edayback.domain.day.quiz.service; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.quiz.entity.Quiz; import efub.eday.edayback.domain.day.quiz.repository.QuizRepository; import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.server.ResponseStatusException; @Service @Transactional @RequiredArgsConstructor public class QuizService { - private final QuizRepository quizRepository; - - //퀴즈 내용 조회 - @Transactional(readOnly = true) - public Quiz findQuiz(Long d_day){ - Dday[] validDdays = Dday.values(); - boolean isValidDday = false; - - for (Dday dday : validDdays) { - if (dday.getRemainingDays() == d_day) { - isValidDday = true; - break; - } - } - - if (!isValidDday) { - throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "올바르지 않은 D-day 값입니다."); - } + private final QuizRepository quizRepository; - return quizRepository.findBySubject_Dday(d_day) - .orElseThrow(()-> new IllegalArgumentException("퀴즈를 찾을 수 없습니다.")); - } + //퀴즈 내용 조회 + @Transactional(readOnly = true) + public Quiz findQuiz(int d_day) { + Dday dday = Dday.fromRemainingDays(d_day); + return quizRepository.findBySubject_Dday(dday) + .orElseThrow(() -> new IllegalArgumentException("퀴즈를 찾을 수 없습니다.")); + } } From be9be64b8dccec3ff43461328ccfcc4fabf7307d Mon Sep 17 00:00:00 2001 From: Kwon Min A Date: Tue, 18 Jul 2023 10:30:14 +0900 Subject: [PATCH 022/153] =?UTF-8?q?chore:=20=EB=8F=84=EC=BB=A4=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 21 --------------------- docker-compose.yml | 41 ----------------------------------------- 2 files changed, 62 deletions(-) delete mode 100644 Dockerfile delete mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index bd0a0de..0000000 --- a/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -# Base 이미지 설정 -FROM openjdk:17-jdk -LABEL authors="mingulmangul" - -# 메인 애플리케이션 디렉토리 설정 -WORKDIR /app - -# 애플리케이션 빌드를 위해 필요한 파일 복사 -COPY build.gradle . -COPY gradlew . -COPY gradle ./gradle -COPY src ./src - -# gradlew 파일 실행 권한 설정 -RUN chmod +x ./gradlew - -# 빌드된 JAR 파일을 컨테이너 내부로 복사 -COPY build/libs/*.jar app.jar - -# 컨테이너 실행 명령 -CMD ["java", "-jar", "app.jar"] diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index bc03eb6..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,41 +0,0 @@ -version: '3.9' -services: - app: - build: - context: . - dockerfile: Dockerfile - ports: - - "8080:8080" - depends_on: - db: - condition: service_healthy - volumes: - - type: bind - source: ./src - target: /src - environment: - SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/${MYSQL_DATABASE} - SPRING_DATASOURCE_USERNAME: ${MYSQL_ROOT_USER} - SPRING_DATASOURCE_PASSWORD: ${MYSQL_ROOT_PASSWORD} - - db: - image: mysql:8.0 - ports: - - "3306:3306" - volumes: - - mysql-data:/var/lib/mysql - - mysql-config:/etc/mysql/conf.d - environment: - MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} - MYSQL_DATABASE: ${MYSQL_DATABASE} - MYSQL_USER: ${MYSQL_USER} - MYSQL_PASSWORD: ${MYSQL_PASSWORD} - healthcheck: - test: [ "CMD-SHELL", "mysqladmin ping -h db -u root --password=$$MYSQL_ROOT_PASSWORD" ] - interval: 10s - timeout: 2s - retries: 30 - -volumes: - mysql-data: - mysql-config: From 2eb0d928a2036c8eeadc34d4a80c4c544d574426 Mon Sep 17 00:00:00 2001 From: hannah0226 Date: Tue, 18 Jul 2023 20:17:57 +0900 Subject: [PATCH 023/153] =?UTF-8?q?feat:=20=ED=80=B4=EC=A6=88=20=EC=A0=95?= =?UTF-8?q?=EB=8B=B5=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../day/quiz/controller/QuizController.java | 23 +++++++++++++++---- .../day/quiz/dto/OptionsResponseDto.java | 5 +--- .../day/quiz/dto/QuizAnswerResponseDto.java | 18 +++++++++++++++ .../domain/day/quiz/entity/Options.java | 3 ++- .../edayback/domain/day/quiz/entity/Quiz.java | 2 ++ .../domain/day/quiz/service/QuizService.java | 19 +++++++++++++++ 6 files changed, 60 insertions(+), 10 deletions(-) create mode 100644 src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java index 6b4f1dc..69309b3 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java @@ -1,11 +1,9 @@ package efub.eday.edayback.domain.day.quiz.controller; +import efub.eday.edayback.domain.day.quiz.dto.QuizAnswerResponseDto; +import efub.eday.edayback.domain.day.quiz.dto.QuizRequestDto; import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import efub.eday.edayback.domain.day.quiz.dto.QuizResponseDto; import efub.eday.edayback.domain.day.quiz.entity.Quiz; @@ -25,4 +23,19 @@ public QuizResponseDto findQuiz(@PathVariable int d_day) { Quiz quiz = quizService.findQuiz(d_day); return QuizResponseDto.from(quiz); } + + //퀴즈 정답 확인 + @PostMapping + public QuizAnswerResponseDto checkAnswer( + @PathVariable int d_day, + @RequestBody QuizRequestDto quizRequestDto + ) { + boolean isCorrect = quizService.checkAnswer(d_day, quizRequestDto.getOptionId()); + String quizDescription = null; + if (isCorrect) { + quizDescription = quizService.getQuizDescription(d_day); + } + QuizAnswerResponseDto responseDto = new QuizAnswerResponseDto(isCorrect, quizDescription); + return responseDto; + } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java index 1cda2eb..50d37cb 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java @@ -8,17 +8,14 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class OptionsResponseDto { - private Long id; private String content; - private OptionsResponseDto(Long id, String content){ - this.id=id; + private OptionsResponseDto(String content){ this.content=content; } public static OptionsResponseDto from(Options options){ return new OptionsResponseDto( - options.getId(), options.getContent() ); } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java new file mode 100644 index 0000000..12b6a79 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java @@ -0,0 +1,18 @@ +package efub.eday.edayback.domain.day.quiz.dto; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class QuizAnswerResponseDto { + private boolean isAnswer; + private String quizDescription; + + public QuizAnswerResponseDto(boolean isAnswer, String quizDescription) { + this.isAnswer = isAnswer; + this.quizDescription = quizDescription; + } +} diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java index ecb0d7e..209daa8 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java @@ -1,6 +1,5 @@ package efub.eday.edayback.domain.day.quiz.entity; -import efub.eday.edayback.domain.day.quiz.dto.QuizResponseDto; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -10,9 +9,11 @@ import jakarta.persistence.ManyToOne; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; @Entity @Getter +@NoArgsConstructor public class Options { @Id diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java index 6f8a39a..f82dd7f 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java @@ -4,11 +4,13 @@ import jakarta.persistence.*; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; import java.util.List; @Entity @Getter +@NoArgsConstructor public class Quiz { @Id diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java index b4947c6..b2913ba 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java @@ -1,5 +1,6 @@ package efub.eday.edayback.domain.day.quiz.service; +import efub.eday.edayback.domain.day.quiz.entity.Options; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -21,4 +22,22 @@ public Quiz findQuiz(int d_day) { return quizRepository.findBySubject_Dday(dday) .orElseThrow(() -> new IllegalArgumentException("퀴즈를 찾을 수 없습니다.")); } + + //퀴즈 정답 확인 + public boolean checkAnswer(int d_day, Long optionId){ + Quiz quiz = findQuiz(d_day); + + for (Options option : quiz.getOptionsList()) { + if (option.getId().equals(optionId)) { + return option.getIsAnswer(); + } + } + throw new IllegalArgumentException("올바르지 않은 optionId입니다."); + } + + //퀴즈 설명 가져오기 + public String getQuizDescription(int d_day) { + Quiz quiz = findQuiz(d_day); + return quiz.getDescription(); + } } From c86c49d2528ce34f71a16f2df8ca6b748f6a827f Mon Sep 17 00:00:00 2001 From: hannah0226 Date: Tue, 18 Jul 2023 20:56:04 +0900 Subject: [PATCH 024/153] =?UTF-8?q?fix:=20=ED=80=B4=EC=A6=88=20=EC=A0=95?= =?UTF-8?q?=EB=8B=B5=20=ED=99=95=EC=9D=B8=20Options=EC=97=90=20=EC=A0=95?= =?UTF-8?q?=EB=8B=B5=20=EB=B9=84=EA=B5=90=EC=9A=A9=20optionNumber=20Column?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eday/edayback/domain/day/quiz/dto/QuizRequestDto.java | 2 +- .../efub/eday/edayback/domain/day/quiz/entity/Options.java | 6 +++++- .../eday/edayback/domain/day/quiz/service/QuizService.java | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizRequestDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizRequestDto.java index f9973f5..f8e4961 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizRequestDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizRequestDto.java @@ -4,5 +4,5 @@ @Getter public class QuizRequestDto { - private Long optionId; + private int optionId; } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java index 209daa8..ca81376 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java @@ -27,14 +27,18 @@ public class Options { @Column(nullable = false) private Boolean isAnswer; + @Column(nullable = false) + private int optionNumber; + @ManyToOne @JoinColumn(name = "quiz_id") private Quiz quiz; @Builder - public Options(String content, Boolean isAnswer, Quiz quiz){ + public Options(String content, Boolean isAnswer, Quiz quiz, int optionNumber){ this.content=content; this.isAnswer=isAnswer; this.quiz=quiz; + this.optionNumber=optionNumber; } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java index b2913ba..5230b23 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java @@ -24,11 +24,11 @@ public Quiz findQuiz(int d_day) { } //퀴즈 정답 확인 - public boolean checkAnswer(int d_day, Long optionId){ + public boolean checkAnswer(int d_day, int option_id){ Quiz quiz = findQuiz(d_day); for (Options option : quiz.getOptionsList()) { - if (option.getId().equals(optionId)) { + if (option.getOptionNumber() == option_id) { return option.getIsAnswer(); } } From 993694571d75c38329618815078462ded0709b24 Mon Sep 17 00:00:00 2001 From: choiyounji Date: Wed, 19 Jul 2023 21:49:28 +0900 Subject: [PATCH 025/153] =?UTF-8?q?feat:=20Exception=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20package=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/CustomErrorCode.java | 17 ++++++++++ .../global/exception/CustomErrorResponse.java | 33 +++++++++++++++++++ .../global/exception/CustomException.java | 12 +++++++ .../exception/CustomExceptionHandler.java | 17 ++++++++++ 4 files changed, 79 insertions(+) create mode 100644 src/main/java/efub/eday/edayback/domain/global/exception/CustomErrorCode.java create mode 100644 src/main/java/efub/eday/edayback/domain/global/exception/CustomErrorResponse.java create mode 100644 src/main/java/efub/eday/edayback/domain/global/exception/CustomException.java create mode 100644 src/main/java/efub/eday/edayback/domain/global/exception/CustomExceptionHandler.java diff --git a/src/main/java/efub/eday/edayback/domain/global/exception/CustomErrorCode.java b/src/main/java/efub/eday/edayback/domain/global/exception/CustomErrorCode.java new file mode 100644 index 0000000..19ef9fb --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/global/exception/CustomErrorCode.java @@ -0,0 +1,17 @@ +package efub.eday.edayback.domain.global.exception; + +import org.springframework.http.HttpStatus; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum CustomErrorCode { + SUCCESS(HttpStatus.OK, "OK"), + + INVALID_AUTH(HttpStatus.BAD_REQUEST, "JWT를 입력해주세요."); + + private final HttpStatus status; + private final String message; +} diff --git a/src/main/java/efub/eday/edayback/domain/global/exception/CustomErrorResponse.java b/src/main/java/efub/eday/edayback/domain/global/exception/CustomErrorResponse.java new file mode 100644 index 0000000..16aea31 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/global/exception/CustomErrorResponse.java @@ -0,0 +1,33 @@ +package efub.eday.edayback.domain.global.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@Builder +@RequiredArgsConstructor +public class CustomErrorResponse { + private final HttpStatus status; + private final String code; + private final String message; + + public CustomErrorResponse(CustomErrorCode errorCode) { + this.status = errorCode.getStatus(); + this.code = errorCode.name(); + this.message = errorCode.getMessage(); + } + + public static ResponseEntity error(CustomException e) { + return ResponseEntity + .status(e.getErrorCode().getStatus()) + .body(CustomErrorResponse.builder() + .status(e.getErrorCode().getStatus()) + .code(e.getErrorCode().name()) + .message(e.getErrorCode().getMessage()) + .build()); + } +} diff --git a/src/main/java/efub/eday/edayback/domain/global/exception/CustomException.java b/src/main/java/efub/eday/edayback/domain/global/exception/CustomException.java new file mode 100644 index 0000000..3f3be0e --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/global/exception/CustomException.java @@ -0,0 +1,12 @@ +package efub.eday.edayback.domain.global.exception; + +import lombok.Getter; + +@Getter +public class CustomException extends RuntimeException { + private CustomErrorCode errorCode; + + public CustomException(CustomErrorCode errorCode) { + this.errorCode = errorCode; + } +} diff --git a/src/main/java/efub/eday/edayback/domain/global/exception/CustomExceptionHandler.java b/src/main/java/efub/eday/edayback/domain/global/exception/CustomExceptionHandler.java new file mode 100644 index 0000000..4d25190 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/global/exception/CustomExceptionHandler.java @@ -0,0 +1,17 @@ +package efub.eday.edayback.domain.global.exception; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RestControllerAdvice +public class CustomExceptionHandler { + @ExceptionHandler(value = CustomException.class) + public ResponseEntity handleCustomException(CustomException e) { + log.error("[handleCustomException] {} : {}", e.getErrorCode().name(), e.getErrorCode().getMessage()); + return CustomErrorResponse.error(e); + } +} From 9638d31d7e9d11a237eda24605a0607cdf49bde9 Mon Sep 17 00:00:00 2001 From: choiyounji Date: Wed, 19 Jul 2023 21:50:26 +0900 Subject: [PATCH 026/153] =?UTF-8?q?feat:=20JWT=20=EA=B5=AC=ED=98=84(?= =?UTF-8?q?=EC=95=84=EC=A7=81=20ing)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 21 ----- build.gradle | 4 + docker-compose.yml | 41 --------- .../domain/config/AuthenticationConfig.java | 45 ++++++++++ .../domain/config/JwtExceptionFilter.java | 77 ++++++++++++++++ .../edayback/domain/config/JwtFilter.java | 87 ++++++++++++++++++ .../member/controller/MemberController.java | 3 +- .../domain/member/dto/MemberResponseDto.java | 2 + .../member/repository/MemberRepository.java | 4 + .../domain/member/service/JwtProvider.java | 89 +++++++++++++++++++ 10 files changed, 310 insertions(+), 63 deletions(-) delete mode 100644 Dockerfile delete mode 100644 docker-compose.yml create mode 100644 src/main/java/efub/eday/edayback/domain/config/AuthenticationConfig.java create mode 100644 src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java create mode 100644 src/main/java/efub/eday/edayback/domain/config/JwtFilter.java create mode 100644 src/main/java/efub/eday/edayback/domain/member/service/JwtProvider.java diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index bd0a0de..0000000 --- a/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -# Base 이미지 설정 -FROM openjdk:17-jdk -LABEL authors="mingulmangul" - -# 메인 애플리케이션 디렉토리 설정 -WORKDIR /app - -# 애플리케이션 빌드를 위해 필요한 파일 복사 -COPY build.gradle . -COPY gradlew . -COPY gradle ./gradle -COPY src ./src - -# gradlew 파일 실행 권한 설정 -RUN chmod +x ./gradlew - -# 빌드된 JAR 파일을 컨테이너 내부로 복사 -COPY build/libs/*.jar app.jar - -# 컨테이너 실행 명령 -CMD ["java", "-jar", "app.jar"] diff --git a/build.gradle b/build.gradle index 25e97a6..56d917d 100644 --- a/build.gradle +++ b/build.gradle @@ -25,6 +25,10 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-web' + + implementation 'io.jsonwebtoken:jjwt:0.9.1' + implementation 'org.springframework.boot:spring-boot-starter-security' + compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index bc03eb6..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,41 +0,0 @@ -version: '3.9' -services: - app: - build: - context: . - dockerfile: Dockerfile - ports: - - "8080:8080" - depends_on: - db: - condition: service_healthy - volumes: - - type: bind - source: ./src - target: /src - environment: - SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/${MYSQL_DATABASE} - SPRING_DATASOURCE_USERNAME: ${MYSQL_ROOT_USER} - SPRING_DATASOURCE_PASSWORD: ${MYSQL_ROOT_PASSWORD} - - db: - image: mysql:8.0 - ports: - - "3306:3306" - volumes: - - mysql-data:/var/lib/mysql - - mysql-config:/etc/mysql/conf.d - environment: - MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} - MYSQL_DATABASE: ${MYSQL_DATABASE} - MYSQL_USER: ${MYSQL_USER} - MYSQL_PASSWORD: ${MYSQL_PASSWORD} - healthcheck: - test: [ "CMD-SHELL", "mysqladmin ping -h db -u root --password=$$MYSQL_ROOT_PASSWORD" ] - interval: 10s - timeout: 2s - retries: 30 - -volumes: - mysql-data: - mysql-config: diff --git a/src/main/java/efub/eday/edayback/domain/config/AuthenticationConfig.java b/src/main/java/efub/eday/edayback/domain/config/AuthenticationConfig.java new file mode 100644 index 0000000..9cd35ce --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/config/AuthenticationConfig.java @@ -0,0 +1,45 @@ +package efub.eday.edayback.domain.config; + +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.http.SessionCreationPolicy; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import efub.eday.edayback.domain.member.service.MemberService; + +@Configuration +@EnableWebSecurity +public class AuthenticationConfig { + MemberService memberService; + + @Value("${jwt.secret}") + private String secretKey; + + private final ObjectMapper objectMapper = new ObjectMapper(); + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception { + return httpSecurity + .httpBasic().disable() + .csrf().disable() + .cors().and() + .authorizeRequests() + .antMatchers("카카오 로그인 요청 API").permitAll() + .antMatchers(HttpMethod.GET, "/api/*").authenticated() + .and() + .sessionManagement() + .sessionCreationPolicy(SessionCreationPolicy.STATELESS) // jwt 사용하는 경우 사용 + .and() + .addFilterBefore(new JwtFilter(secretKey), UsernamePasswordAuthenticationFilter.class) + .addFilterBefore(new JwtExceptionFilter(objectMapper), JwtFilter.class) + .build() + ; + } +} diff --git a/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java b/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java new file mode 100644 index 0000000..385266c --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java @@ -0,0 +1,77 @@ +package efub.eday.edayback.domain.config; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.web.filter.OncePerRequestFilter; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import efub.eday.edayback.domain.global.exception.CustomErrorCode; +import efub.eday.edayback.domain.global.exception.CustomException; +import io.jsonwebtoken.JwtException; +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; + +@RequiredArgsConstructor +@Slf4j +public class JwtExceptionFilter extends OncePerRequestFilter { + private final ObjectMapper objectMapper; + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, + FilterChain filterChain) throws + ServletException, IOException { + try { + filterChain.doFilter(request, response); + } catch (JwtException e) { + log.error("[-] Invalid Token"); + + // 오류 내용 기입 + BaseResponse baseResponse = new BaseResponse(BaseResponseStatus.INVALID_JWT); + + Map errorDetails = setErrorDetails(baseResponse); + + sendErrorMessage(response, errorDetails); + } catch (CustomException e) { + log.error(e.getMessage()); + + // 헤더에 토큰이 비어있거나 잘못된 정보가 기입되었을 경우 + if (e.getErrorCode().equals(CustomErrorCode.INVALID_AUTH)) { + BaseResponse baseResponse = new BaseResponse(BaseResponseStatus.EMPTY_JWT); + + Map errorDetails = setErrorDetails(baseResponse); + + sendErrorMessage(response, errorDetails); + } + } + } + + // Set Error Json + private Map setErrorDetails(BaseResponse baseResponse) { + Map errorDetails = new HashMap<>(); + + errorDetails.put("isSuccess", baseResponse.getIsSuccess()); + errorDetails.put("code", baseResponse.getCode()); + errorDetails.put("message", baseResponse.getMessage()); + + return errorDetails; + } + + // Send Error Message to Client + private void sendErrorMessage(HttpServletResponse response, Map errorDetails) throws IOException { + + response.setStatus(HttpStatus.UNAUTHORIZED.value()); + response.setContentType(MediaType.APPLICATION_JSON_VALUE); + response.setCharacterEncoding("UTF-8"); + + objectMapper.writeValue(response.getWriter(), errorDetails); + } +} diff --git a/src/main/java/efub/eday/edayback/domain/config/JwtFilter.java b/src/main/java/efub/eday/edayback/domain/config/JwtFilter.java new file mode 100644 index 0000000..75c9e66 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/config/JwtFilter.java @@ -0,0 +1,87 @@ +package efub.eday.edayback.domain.config; + +import java.io.IOException; +import java.util.List; + +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 efub.eday.edayback.domain.global.exception.CustomErrorCode; +import efub.eday.edayback.domain.global.exception.CustomException; +import efub.eday.edayback.domain.member.service.JwtProvider; +import io.jsonwebtoken.JwtException; +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; + +@RequiredArgsConstructor +@Slf4j +public class JwtFilter extends OncePerRequestFilter { + private final String secretKey; + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, + FilterChain filterChain) throws ServletException, IOException { + + String path = request.getServletPath(); + + // 로그인일 경우 건너뛰기 + if ( + path.startsWith("로그인 요청 API") + ) { + filterChain.doFilter(request, response); + return; + } + + final String authorization = request.getHeader(HttpHeaders.AUTHORIZATION); + log.info("authorization : {}", authorization); + + if (authorization == null || !authorization.startsWith("Bearer ")) { + throw new CustomException(CustomErrorCode.INVALID_AUTH); + } + + // Token 꺼내기 + String token = authorization.split(" ")[1]; + + // Token Expired 되었는지 여부 + if (JwtProvider.isExpired(token, secretKey)) { + filterChain.doFilter(request, response); + return; + } + + // UserId Token에서 꺼내기 + Long userId = JwtProvider.getUserId(token, secretKey); + log.info("userName: {}", userId); + + // 토큰 재발급일 경우 리프레쉬 토큰 확인 + // 위에서 만료됐는지 확인했기 때문에 따로 만료확인 필요 없음 + // 리프레쉬 토큰이 유효한지와 path 정보를 통해 확인이 끝났기 때문에 컨트롤러에서는 바로 토큰 재발행해주고 보내주면 됨 + if ( + !( + (path.startsWith("토큰 재발행 API") && JwtProvider.isRefreshToken(token, secretKey)) + || JwtProvider.isAccessToken(token, secretKey) + ) + ) { + // 재발행 요청 api인데, access token을 전달했을 경우 + // 아니면 access token을 넣어줘야하는데, 다른 토큰을 넣었을 경우 + throw new JwtException(""); + } + + // 권한 부여 + UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(userId, null, + List.of(new SimpleGrantedAuthority("USER"))); + + // Detail을 넣어줌 + authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); + SecurityContextHolder.getContext().setAuthentication(authenticationToken); + log.info("[+] Token in SecurityContextHolder"); + filterChain.doFilter(request, response); + } +} diff --git a/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java b/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java index f89593e..d635440 100644 --- a/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java +++ b/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java @@ -2,6 +2,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import efub.eday.edayback.domain.member.dto.MemberResponseDto; @@ -15,7 +16,7 @@ public class MemberController { private final MemberService memberService; @GetMapping("/oauth") - public MemberResponseDto kakaoLogin(String code) { + public MemberResponseDto kakaoLogin(@RequestParam String code) { MemberResponseDto member = memberService.getAccessToken(code); return member; } diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/MemberResponseDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/MemberResponseDto.java index 6ff47bb..5f9abb1 100644 --- a/src/main/java/efub/eday/edayback/domain/member/dto/MemberResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/dto/MemberResponseDto.java @@ -7,10 +7,12 @@ public class MemberResponseDto { private String nickname; private String profileImageUrl; + private Integer level; public MemberResponseDto(Member member) { this.nickname = member.getNickname(); this.profileImageUrl = member.getProfileImageUrl(); + this.level = member.getLevel(); } } diff --git a/src/main/java/efub/eday/edayback/domain/member/repository/MemberRepository.java b/src/main/java/efub/eday/edayback/domain/member/repository/MemberRepository.java index 538a96d..6fbfb89 100644 --- a/src/main/java/efub/eday/edayback/domain/member/repository/MemberRepository.java +++ b/src/main/java/efub/eday/edayback/domain/member/repository/MemberRepository.java @@ -1,9 +1,13 @@ package efub.eday.edayback.domain.member.repository; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; import efub.eday.edayback.domain.member.entity.Member; +@Repository public interface MemberRepository extends JpaRepository { Member findByEmail(String email); + + boolean existsByEmail(String email); } diff --git a/src/main/java/efub/eday/edayback/domain/member/service/JwtProvider.java b/src/main/java/efub/eday/edayback/domain/member/service/JwtProvider.java new file mode 100644 index 0000000..c968025 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/service/JwtProvider.java @@ -0,0 +1,89 @@ +package efub.eday.edayback.domain.member.service; + +import java.time.Duration; +import java.util.Date; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Header; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class JwtProvider { + private static final Long accessTokenValidTime = Duration.ofMinutes(30).toMillis(); // 만료시간 30분 + private static final Long refreshTokenValidTime = Duration.ofDays(14).toMillis(); // 만료시간 2주 + + // 회원 정보 조회 + public static Long getUserId(String token, String secretKey) { + return Jwts.parser() + .setSigningKey(secretKey) + .parseClaimsJws(token) + .getBody() + .get("userId", Long.class); + } + + // 토큰 유효 및 만료 확인 + public static boolean isExpired(String token, String secretKey) { + + // try { + Claims claims = Jwts.parser() + .setSigningKey(secretKey) + .parseClaimsJws(token) + .getBody(); + return false; + } + + // refresh 토큰 확인 + public static boolean isRefreshToken(String token, String secretKey) { + + Header header = Jwts.parser() + .setSigningKey(secretKey) + .parseClaimsJws(token) + .getHeader(); + + if (header.get("type").toString().equals("refresh")) { + return true; + } + return false; + } + + // access 토큰 확인 + public static boolean isAccessToken(String token, String secretKey) { + + Header header = Jwts.parser() + .setSigningKey(secretKey) + .parseClaimsJws(token) + .getHeader(); + + if (header.get("type").toString().equals("access")) { + return true; + } + return false; + } + + // access 토큰 생성 + public static String createAccessToken(Long userId, String secretKey) { + return createJwt(userId, secretKey, "access", accessTokenValidTime); + } + + // refresh 토큰 생성 + public static String createRefreshToken(Long userId, String secretKey) { + return createJwt(userId, secretKey, "refresh", refreshTokenValidTime); + } + + public static String createJwt(Long userId, String secretKey, String type, Long tokenValidTime) { + Claims claims = Jwts.claims(); + claims.put("userId", userId); + + return Jwts.builder() + .setHeaderParam("type", type) + .setClaims(claims) + .setIssuedAt(new Date(System.currentTimeMillis())) + .setExpiration(new Date(System.currentTimeMillis() + tokenValidTime)) + .signWith(SignatureAlgorithm.HS256, secretKey) + .compact() + ; + } + +} From 9bf672a6f42ac3b12f4b6b155b91bdedaf6cdd38 Mon Sep 17 00:00:00 2001 From: choiyounji Date: Wed, 19 Jul 2023 22:05:10 +0900 Subject: [PATCH 027/153] =?UTF-8?q?feat:=20JwtExceptionFilter=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20=EB=B6=80?= =?UTF-8?q?=EB=B6=84=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/config/JwtExceptionFilter.java | 39 ------------------- 1 file changed, 39 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java b/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java index 385266c..324f7e3 100644 --- a/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java +++ b/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java @@ -1,16 +1,11 @@ package efub.eday.edayback.domain.config; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.web.filter.OncePerRequestFilter; import com.fasterxml.jackson.databind.ObjectMapper; -import efub.eday.edayback.domain.global.exception.CustomErrorCode; import efub.eday.edayback.domain.global.exception.CustomException; import io.jsonwebtoken.JwtException; import jakarta.servlet.FilterChain; @@ -34,44 +29,10 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse } catch (JwtException e) { log.error("[-] Invalid Token"); - // 오류 내용 기입 - BaseResponse baseResponse = new BaseResponse(BaseResponseStatus.INVALID_JWT); - - Map errorDetails = setErrorDetails(baseResponse); - - sendErrorMessage(response, errorDetails); } catch (CustomException e) { log.error(e.getMessage()); - // 헤더에 토큰이 비어있거나 잘못된 정보가 기입되었을 경우 - if (e.getErrorCode().equals(CustomErrorCode.INVALID_AUTH)) { - BaseResponse baseResponse = new BaseResponse(BaseResponseStatus.EMPTY_JWT); - - Map errorDetails = setErrorDetails(baseResponse); - - sendErrorMessage(response, errorDetails); - } } } - // Set Error Json - private Map setErrorDetails(BaseResponse baseResponse) { - Map errorDetails = new HashMap<>(); - - errorDetails.put("isSuccess", baseResponse.getIsSuccess()); - errorDetails.put("code", baseResponse.getCode()); - errorDetails.put("message", baseResponse.getMessage()); - - return errorDetails; - } - - // Send Error Message to Client - private void sendErrorMessage(HttpServletResponse response, Map errorDetails) throws IOException { - - response.setStatus(HttpStatus.UNAUTHORIZED.value()); - response.setContentType(MediaType.APPLICATION_JSON_VALUE); - response.setCharacterEncoding("UTF-8"); - - objectMapper.writeValue(response.getWriter(), errorDetails); - } } From 7da8375051dc4e6ce6cf64e84f14582df092d41d Mon Sep 17 00:00:00 2001 From: choiyounji Date: Wed, 19 Jul 2023 22:06:35 +0900 Subject: [PATCH 028/153] =?UTF-8?q?feat:=20JwtExceptionFilter=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20=EB=B6=80?= =?UTF-8?q?=EB=B6=84=20=EC=82=AD=EC=A0=9C2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eday/edayback/domain/config/JwtExceptionFilter.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java b/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java index 324f7e3..3d57629 100644 --- a/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java +++ b/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java @@ -4,8 +4,6 @@ import org.springframework.web.filter.OncePerRequestFilter; -import com.fasterxml.jackson.databind.ObjectMapper; - import efub.eday.edayback.domain.global.exception.CustomException; import io.jsonwebtoken.JwtException; import jakarta.servlet.FilterChain; @@ -18,7 +16,6 @@ @RequiredArgsConstructor @Slf4j public class JwtExceptionFilter extends OncePerRequestFilter { - private final ObjectMapper objectMapper; @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, @@ -28,11 +25,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse filterChain.doFilter(request, response); } catch (JwtException e) { log.error("[-] Invalid Token"); - } catch (CustomException e) { log.error(e.getMessage()); - } } - } From d60d42af3bb1b1f670f92d827201932775e19e76 Mon Sep 17 00:00:00 2001 From: choiyounji Date: Wed, 19 Jul 2023 22:30:16 +0900 Subject: [PATCH 029/153] =?UTF-8?q?chore:=20spring=20=EB=B2=84=EC=A0=84=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 --- build.gradle | 2 +- .../domain/config/JwtExceptionFilter.java | 15 ++++++++--- .../edayback/domain/config/JwtFilter.java | 9 ++++--- .../domain/day/dday/entity/Subject.java | 15 ++++++----- .../edayback/domain/day/info/entity/Info.java | 17 ++++++------ .../domain/day/info/entity/InfoImage.java | 15 ++++++----- .../domain/day/quiz/entity/Options.java | 24 ++++++++--------- .../edayback/domain/day/quiz/entity/Quiz.java | 26 ++++++++++++------- .../domain/day/title/entity/Title.java | 15 ++++++----- .../edayback/domain/member/entity/Member.java | 11 ++++---- .../domain/member/entity/MemberQuiz.java | 15 ++++++----- .../domain/member/entity/MemberTitle.java | 15 ++++++----- .../edayback/domain/query/entity/Query.java | 15 ++++++----- 13 files changed, 109 insertions(+), 85 deletions(-) diff --git a/build.gradle b/build.gradle index 56d917d..7937648 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id 'java' - id 'org.springframework.boot' version '3.1.1' + id 'org.springframework.boot' version '2.7.11' id 'io.spring.dependency-management' version '1.1.0' } diff --git a/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java b/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java index 3d57629..39d39a9 100644 --- a/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java +++ b/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java @@ -2,20 +2,24 @@ import java.io.IOException; +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.springframework.web.filter.OncePerRequestFilter; +import com.fasterxml.jackson.databind.ObjectMapper; + import efub.eday.edayback.domain.global.exception.CustomException; import io.jsonwebtoken.JwtException; -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; @RequiredArgsConstructor @Slf4j public class JwtExceptionFilter extends OncePerRequestFilter { + private final ObjectMapper objectMapper; @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, @@ -25,8 +29,11 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse filterChain.doFilter(request, response); } catch (JwtException e) { log.error("[-] Invalid Token"); + } catch (CustomException e) { log.error(e.getMessage()); + } } + } diff --git a/src/main/java/efub/eday/edayback/domain/config/JwtFilter.java b/src/main/java/efub/eday/edayback/domain/config/JwtFilter.java index 75c9e66..d170f55 100644 --- a/src/main/java/efub/eday/edayback/domain/config/JwtFilter.java +++ b/src/main/java/efub/eday/edayback/domain/config/JwtFilter.java @@ -3,6 +3,11 @@ import java.io.IOException; import java.util.List; +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.springframework.http.HttpHeaders; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.authority.SimpleGrantedAuthority; @@ -14,10 +19,6 @@ import efub.eday.edayback.domain.global.exception.CustomException; import efub.eday.edayback.domain.member.service.JwtProvider; import io.jsonwebtoken.JwtException; -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; diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java index 74b7640..39f19e3 100644 --- a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java +++ b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java @@ -1,12 +1,13 @@ package efub.eday.edayback.domain.day.dday.entity; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java b/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java index ff31988..af4131c 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java @@ -2,15 +2,16 @@ import java.util.List; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; + import efub.eday.edayback.domain.day.dday.entity.Subject; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java b/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java index 535d295..ea0b5c5 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java @@ -1,12 +1,13 @@ package efub.eday.edayback.domain.day.info.entity; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java index ecb0d7e..dc7a9b7 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java @@ -1,13 +1,13 @@ package efub.eday.edayback.domain.day.quiz.entity; -import efub.eday.edayback.domain.day.quiz.dto.QuizResponseDto; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + import lombok.Builder; import lombok.Getter; @@ -31,9 +31,9 @@ public class Options { private Quiz quiz; @Builder - public Options(String content, Boolean isAnswer, Quiz quiz){ - this.content=content; - this.isAnswer=isAnswer; - this.quiz=quiz; + public Options(String content, Boolean isAnswer, Quiz quiz) { + this.content = content; + this.isAnswer = isAnswer; + this.quiz = quiz; } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java index 6f8a39a..62b034f 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java @@ -1,12 +1,20 @@ package efub.eday.edayback.domain.day.quiz.entity; +import java.util.List; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; + import efub.eday.edayback.domain.day.dday.entity.Subject; -import jakarta.persistence.*; import lombok.Builder; import lombok.Getter; -import java.util.List; - @Entity @Getter public class Quiz { @@ -33,11 +41,11 @@ public class Quiz { private List optionsList; @Builder - public Quiz(String content, String description, String imageUrl, Subject subject, List optionsList){ - this.content=content; - this.description=description; - this.imageUrl=imageUrl; - this.subject=subject; - this.optionsList=optionsList; + public Quiz(String content, String description, String imageUrl, Subject subject, List optionsList) { + this.content = content; + this.description = description; + this.imageUrl = imageUrl; + this.subject = subject; + this.optionsList = optionsList; } } diff --git a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java index e5f784c..37380ae 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java @@ -1,13 +1,14 @@ package efub.eday.edayback.domain.day.title.entity; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; + import efub.eday.edayback.domain.day.dday.entity.Subject; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.OneToOne; @Entity public class Title { diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java index 1349aae..c7a5d7e 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java @@ -2,13 +2,14 @@ import java.time.LocalDate; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + import org.hibernate.annotations.CreationTimestamp; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java index 48b3d18..4b84255 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java @@ -1,13 +1,14 @@ package efub.eday.edayback.domain.member.entity; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + import efub.eday.edayback.domain.day.quiz.entity.Quiz; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; @Entity public class MemberQuiz { diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java index bc63414..6d81eff 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java @@ -1,13 +1,14 @@ package efub.eday.edayback.domain.member.entity; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + import efub.eday.edayback.domain.day.title.entity.Title; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; @Entity public class MemberTitle { diff --git a/src/main/java/efub/eday/edayback/domain/query/entity/Query.java b/src/main/java/efub/eday/edayback/domain/query/entity/Query.java index 5a2d393..441929a 100644 --- a/src/main/java/efub/eday/edayback/domain/query/entity/Query.java +++ b/src/main/java/efub/eday/edayback/domain/query/entity/Query.java @@ -1,14 +1,15 @@ package efub.eday.edayback.domain.query.entity; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + import efub.eday.edayback.domain.day.dday.entity.Subject; import efub.eday.edayback.domain.member.entity.Member; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; @Entity public class Query { From f3f59d03f26230f5d7ea871e34c4642c9890ebd5 Mon Sep 17 00:00:00 2001 From: choiyounji Date: Thu, 20 Jul 2023 00:01:37 +0900 Subject: [PATCH 030/153] =?UTF-8?q?feat:=20JWT=20=EC=9E=91=EC=84=B1?= =?UTF-8?q?=EC=A4=91(ing)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/config/AuthenticationConfig.java | 6 ++-- .../member/controller/MemberController.java | 11 ++++--- .../domain/member/dto/LoginResponseDto.java | 21 +++++++++++++ .../domain/member/service/JwtProvider.java | 5 ++++ .../domain/member/service/MemberService.java | 30 +++++++++++++++---- 5 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 src/main/java/efub/eday/edayback/domain/member/dto/LoginResponseDto.java diff --git a/src/main/java/efub/eday/edayback/domain/config/AuthenticationConfig.java b/src/main/java/efub/eday/edayback/domain/config/AuthenticationConfig.java index 9cd35ce..30ab54f 100644 --- a/src/main/java/efub/eday/edayback/domain/config/AuthenticationConfig.java +++ b/src/main/java/efub/eday/edayback/domain/config/AuthenticationConfig.java @@ -3,7 +3,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.http.SessionCreationPolicy; @@ -19,7 +18,7 @@ public class AuthenticationConfig { MemberService memberService; - @Value("${jwt.secret}") + @Value("${spring.jwt.secret}") private String secretKey; private final ObjectMapper objectMapper = new ObjectMapper(); @@ -31,8 +30,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws .csrf().disable() .cors().and() .authorizeRequests() - .antMatchers("카카오 로그인 요청 API").permitAll() - .antMatchers(HttpMethod.GET, "/api/*").authenticated() + .antMatchers("/members/**", "/infos/**", "querys/**", "titles/**", "quiz/**").permitAll() .and() .sessionManagement() .sessionCreationPolicy(SessionCreationPolicy.STATELESS) // jwt 사용하는 경우 사용 diff --git a/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java b/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java index d635440..0ae4666 100644 --- a/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java +++ b/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java @@ -5,7 +5,8 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import efub.eday.edayback.domain.member.dto.MemberResponseDto; +import efub.eday.edayback.domain.member.dto.LoginResponseDto; +import efub.eday.edayback.domain.member.entity.Member; import efub.eday.edayback.domain.member.service.MemberService; import lombok.RequiredArgsConstructor; @@ -16,9 +17,11 @@ public class MemberController { private final MemberService memberService; @GetMapping("/oauth") - public MemberResponseDto kakaoLogin(@RequestParam String code) { - MemberResponseDto member = memberService.getAccessToken(code); - return member; + public LoginResponseDto kakaoLogin(@RequestParam String code) { + System.out.println("HI"); + Member member = memberService.getAccessToken(code); + System.out.println(member); + return memberService.login(member); } } diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/LoginResponseDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/LoginResponseDto.java new file mode 100644 index 0000000..058cbea --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/dto/LoginResponseDto.java @@ -0,0 +1,21 @@ +package efub.eday.edayback.domain.member.dto; + +import efub.eday.edayback.domain.member.entity.Member; +import lombok.Builder; +import lombok.Getter; + +@Getter +public class LoginResponseDto { + private Long memberId; + private String email; + private String nickname; + private String accessToken; + + @Builder + public LoginResponseDto(Member member, String accessToken) { + this.memberId = member.getId(); + this.email = member.getEmail(); + this.nickname = member.getNickname(); + this.accessToken = accessToken; + } +} diff --git a/src/main/java/efub/eday/edayback/domain/member/service/JwtProvider.java b/src/main/java/efub/eday/edayback/domain/member/service/JwtProvider.java index c968025..8fa0989 100644 --- a/src/main/java/efub/eday/edayback/domain/member/service/JwtProvider.java +++ b/src/main/java/efub/eday/edayback/domain/member/service/JwtProvider.java @@ -3,13 +3,18 @@ import java.time.Duration; import java.util.Date; +import org.springframework.stereotype.Service; + import io.jsonwebtoken.Claims; import io.jsonwebtoken.Header; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @Slf4j +@RequiredArgsConstructor +@Service public class JwtProvider { private static final Long accessTokenValidTime = Duration.ofMinutes(30).toMillis(); // 만료시간 30분 private static final Long refreshTokenValidTime = Duration.ofDays(14).toMillis(); // 만료시간 2주 diff --git a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java index 7e6f518..0efdbb1 100644 --- a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java +++ b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java @@ -1,5 +1,6 @@ package efub.eday.edayback.domain.member.service; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -14,20 +15,26 @@ import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; -import efub.eday.edayback.domain.member.dto.MemberResponseDto; +import efub.eday.edayback.domain.member.dto.LoginResponseDto; import efub.eday.edayback.domain.member.entity.Member; import efub.eday.edayback.domain.member.entity.oauth.KakaoProfile; import efub.eday.edayback.domain.member.entity.oauth.OAuthToken; import efub.eday.edayback.domain.member.repository.MemberRepository; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @RequiredArgsConstructor @Service public class MemberService { private final MemberRepository memberRepository; + private final JwtProvider jwtProvider; - public MemberResponseDto getAccessToken(String code) { + @Value("${spring.jwt.secret}") + private String secretKey; + + public Member getAccessToken(String code) { RestTemplate rt = new RestTemplate(); @@ -59,12 +66,13 @@ public MemberResponseDto getAccessToken(String code) { } catch (JsonProcessingException e) { e.printStackTrace(); } + System.out.println(oauthToken); return findProfile(oauthToken); } - private MemberResponseDto findProfile(OAuthToken oauthToken) { + private Member findProfile(OAuthToken oauthToken) { //토큰 이용하여 사용자 정보 조회 RestTemplate rt2 = new RestTemplate(); @@ -90,10 +98,11 @@ private MemberResponseDto findProfile(OAuthToken oauthToken) { } catch (JsonProcessingException e) { e.printStackTrace(); } + System.out.println(kakaoProfile); return saveMember(kakaoProfile); } - public MemberResponseDto saveMember(@RequestBody KakaoProfile kakaoProfile) { + public Member saveMember(@RequestBody KakaoProfile kakaoProfile) { //Member 저장 Member kakaoMember = memberRepository.findByEmail(kakaoProfile.getKakao_account().getEmail()); @@ -108,7 +117,18 @@ public MemberResponseDto saveMember(@RequestBody KakaoProfile kakaoProfile) { .build(); memberRepository.save(kakaoMember); } - return new MemberResponseDto(kakaoMember); + System.out.println(kakaoMember); + return kakaoMember; + } + + public LoginResponseDto login(Member member) { + String authToken = jwtProvider.createAccessToken(member.getId(), secretKey); + LoginResponseDto loginResponseDto = LoginResponseDto.builder() + .member(member) + .accessToken(authToken) + .build(); + System.out.println(loginResponseDto); + return loginResponseDto; } } From 4ab3f7ae6a3a540602096b56247d80581d8697aa Mon Sep 17 00:00:00 2001 From: chhaewxn Date: Thu, 20 Jul 2023 02:29:51 +0900 Subject: [PATCH 031/153] =?UTF-8?q?feat:=20@Builder=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20#7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eday/edayback/domain/day/title/entity/Title.java | 12 ++++++++++++ .../edayback/domain/member/entity/MemberTitle.java | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java index e5f784c..28af8bd 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java @@ -8,8 +8,13 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToOne; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; @Entity +@NoArgsConstructor +@Getter public class Title { @Id @@ -26,4 +31,11 @@ public class Title { @OneToOne @JoinColumn(nullable = false) private Subject subject; + + @Builder + public Title(String name, String imageUrl, Subject subject) { + this.name = name; + this.imageUrl = imageUrl; + this.subject = subject; + } } diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java index bc63414..33ae49d 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java @@ -8,8 +8,13 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; @Entity +@Getter +@NoArgsConstructor public class MemberTitle { @Id @@ -27,4 +32,11 @@ public class MemberTitle { @ManyToOne @JoinColumn(name = "title_id", nullable = false) private Title title; + + @Builder + public MemberTitle(Boolean getTitle, Member member, Title title) { + this.getTitle = getTitle; + this.member = member; + this.title = title; + } } From 23b1b4fcfeea34c7f444e658bf8204d07719fe47 Mon Sep 17 00:00:00 2001 From: chhaewxn Date: Thu, 20 Jul 2023 02:30:52 +0900 Subject: [PATCH 032/153] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=EC=A0=95=EB=B3=B4=20=EB=8B=B4=EB=8A=94=20?= =?UTF-8?q?DTO=20=EC=83=9D=EC=84=B1=20#7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../day/title/dto/MemberProfileDto.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/java/efub/eday/edayback/domain/day/title/dto/MemberProfileDto.java diff --git a/src/main/java/efub/eday/edayback/domain/day/title/dto/MemberProfileDto.java b/src/main/java/efub/eday/edayback/domain/day/title/dto/MemberProfileDto.java new file mode 100644 index 0000000..d6b8b2e --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/title/dto/MemberProfileDto.java @@ -0,0 +1,28 @@ +package efub.eday.edayback.domain.day.title.dto; + +import java.time.LocalDateTime; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class MemberProfileDto { + + private String nickname; + private String email; + private String profileImage; + private int level; + private LocalDateTime createdDate; + private boolean isActive; + + public MemberProfileDto(String nickname, String email, String profileImage, int level, LocalDateTime createdDate, + boolean isActive) { + this.nickname = nickname; + this.email = email; + this.profileImage = profileImage; + this.level = level; + this.createdDate = createdDate; + this.isActive = isActive; + } +} From 3a22ef14b722aa2f88f85b5082a2766a09969992 Mon Sep 17 00:00:00 2001 From: chhaewxn Date: Thu, 20 Jul 2023 02:32:15 +0900 Subject: [PATCH 033/153] =?UTF-8?q?feat:=20=EC=B9=AD=ED=98=B8(Title)=20DTO?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=20#7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/day/title/dto/TitleDto.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/efub/eday/edayback/domain/day/title/dto/TitleDto.java diff --git a/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleDto.java b/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleDto.java new file mode 100644 index 0000000..02bca3a --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleDto.java @@ -0,0 +1,21 @@ +package efub.eday.edayback.domain.day.title.dto; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class TitleDto { + + private int dday; + private String titleName; + private String titleImageUrl; + private boolean getTitle; + + public TitleDto(int dday, String titleName, String titleImageUrl, boolean getTitle) { + this.dday = dday; + this.titleName = titleName; + this.titleImageUrl = titleImageUrl; + this.getTitle = getTitle; + } +} From c240ab3c43d15f744273e47a40c3c5c3abfcf218 Mon Sep 17 00:00:00 2001 From: chhaewxn Date: Thu, 20 Jul 2023 02:33:57 +0900 Subject: [PATCH 034/153] =?UTF-8?q?feat:=20=EC=B9=AD=ED=98=B8(Title)=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20#7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../day/title/controller/TitleController.java | 25 +++++++++ .../day/title/dto/TitleResponseDto.java | 19 +++++++ .../repository/MemberTitleRepository.java | 14 +++++ .../day/title/service/TitleService.java | 56 +++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/title/dto/TitleResponseDto.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/title/repository/MemberTitleRepository.java create mode 100644 src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java diff --git a/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java b/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java new file mode 100644 index 0000000..c054541 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java @@ -0,0 +1,25 @@ +package efub.eday.edayback.domain.day.title.controller; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import efub.eday.edayback.domain.day.title.dto.TitleResponseDto; +import efub.eday.edayback.domain.day.title.service.TitleService; +import lombok.RequiredArgsConstructor; + +@RestController +@RequestMapping("/title") +@RequiredArgsConstructor +public class TitleController { + + private final TitleService titleService; + + @GetMapping("/{member_id}") + public ResponseEntity getTitlePage(@PathVariable("member_id") Long memberId) { + TitleResponseDto titleResponseDto = titleService.getTitlePage(memberId); + return ResponseEntity.ok(titleResponseDto); + } +} diff --git a/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleResponseDto.java new file mode 100644 index 0000000..b2366bb --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleResponseDto.java @@ -0,0 +1,19 @@ +package efub.eday.edayback.domain.day.title.dto; + +import java.util.List; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class TitleResponseDto { + + private MemberProfileDto profile; + private List titleList; + + public TitleResponseDto(MemberProfileDto profile, List titleList) { + this.profile = profile; + this.titleList = titleList; + } +} diff --git a/src/main/java/efub/eday/edayback/domain/day/title/repository/MemberTitleRepository.java b/src/main/java/efub/eday/edayback/domain/day/title/repository/MemberTitleRepository.java new file mode 100644 index 0000000..3ff3e76 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/title/repository/MemberTitleRepository.java @@ -0,0 +1,14 @@ +package efub.eday.edayback.domain.day.title.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import efub.eday.edayback.domain.member.entity.Member; +import efub.eday.edayback.domain.member.entity.MemberTitle; + +@Repository +public interface MemberTitleRepository extends JpaRepository { + List findByMember(Member member); +} diff --git a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java new file mode 100644 index 0000000..5e24d8a --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java @@ -0,0 +1,56 @@ +package efub.eday.edayback.domain.day.title.service; + +import java.util.List; +import java.util.stream.Collectors; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import efub.eday.edayback.domain.day.title.dto.MemberProfileDto; +import efub.eday.edayback.domain.day.title.dto.TitleDto; +import efub.eday.edayback.domain.day.title.dto.TitleResponseDto; +import efub.eday.edayback.domain.day.title.entity.Title; +import efub.eday.edayback.domain.day.title.repository.MemberTitleRepository; +import efub.eday.edayback.domain.member.entity.Member; +import efub.eday.edayback.domain.member.entity.MemberTitle; +import efub.eday.edayback.domain.member.repository.MemberRepository; +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class TitleService { + + private final MemberRepository memberRepository; + private final MemberTitleRepository memberTitleRepository; + + @Transactional(readOnly = true) + public TitleResponseDto getTitlePage(Long memberId) { + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new IllegalArgumentException("해당하는 회원이 없습니다. ID: " + memberId)); + + List memberTitles = memberTitleRepository.findByMember(member); + + MemberProfileDto profile = new MemberProfileDto( + member.getNickname(), + member.getEmail(), + member.getProfileImageUrl(), + member.getLevel(), + member.getCreatedDate().atStartOfDay(), + member.getIsActive() + ); + + List titleList = memberTitles.stream() + .map(memberTitle -> { + Title title = memberTitle.getTitle(); + return new TitleDto( + title.getSubject().getDday(), + title.getName(), + title.getImageUrl(), + memberTitle.getGetTitle() + ); + }) + .collect(Collectors.toList()); + + return new TitleResponseDto(profile, titleList); + } +} From dec92d39198f7115cd92399c46e88a7a0c1ac2c1 Mon Sep 17 00:00:00 2001 From: Kwon Min A Date: Sat, 22 Jul 2023 01:06:40 +0900 Subject: [PATCH 035/153] =?UTF-8?q?chore:=20*plain.jar=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20bui?= =?UTF-8?q?ld.gradle=20=EC=84=A4=EC=A0=95=20=EB=B3=80=EA=B2=BD?= 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 25e97a6..0f30490 100644 --- a/build.gradle +++ b/build.gradle @@ -11,6 +11,10 @@ java { sourceCompatibility = '17' } +jar { + enabled = false +} + configurations { compileOnly { extendsFrom annotationProcessor From 0a9d7fa07d79597a691b40442688c23e2d0b6865 Mon Sep 17 00:00:00 2001 From: Kwon Min A Date: Sat, 22 Jul 2023 01:07:18 +0900 Subject: [PATCH 036/153] =?UTF-8?q?chore:=20.gitignore=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 --- .gitignore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index c054f2a..0846fe9 100644 --- a/.gitignore +++ b/.gitignore @@ -176,9 +176,7 @@ gradle-app.setting *.hprof .idea/ -application.yaml +application.yml .env -docker-compose.yaml -Dockerfile # End of https://www.toptal.com/developers/gitignore/api/java,gradle,intellij,macos,windows From 04fc8703a947a641fe8470880c66b68e88bc92dd Mon Sep 17 00:00:00 2001 From: Kwon Min A Date: Sat, 22 Jul 2023 01:08:41 +0900 Subject: [PATCH 037/153] =?UTF-8?q?chore:=20=EC=95=A0=ED=94=8C=EB=A6=AC?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=85=98=20=EC=8B=A4=ED=96=89=20=EB=B0=8F=20?= =?UTF-8?q?=EC=A2=85=EB=A3=8C=20=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=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 --- scripts/start.sh | 19 +++++++++++++++++++ scripts/stop.sh | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 scripts/start.sh create mode 100644 scripts/stop.sh diff --git a/scripts/start.sh b/scripts/start.sh new file mode 100644 index 0000000..55d2002 --- /dev/null +++ b/scripts/start.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +PROJECT_ROOT="/home/ubuntu/eday" +JAR_FILE="$PROJECT_ROOT/eday-webapp.jar" + +APP_LOG="$PROJECT_ROOT/application.log" +ERROR_LOG="$PROJECT_ROOT/error.log" +DEPLOY_LOG="$PROJECT_ROOT/deploy.log" + +TIME_NOW=$(date +%c) + +echo "$TIME_NOW > $JAR_FILE 파일 복사" >> $DEPLOY_LOG +cp $PROJECT_ROOT/build/libs/*.jar $JAR_FILE + +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 diff --git a/scripts/stop.sh b/scripts/stop.sh new file mode 100644 index 0000000..1d2ef9a --- /dev/null +++ b/scripts/stop.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +PROJECT_ROOT="/home/ubuntu/eday" +JAR_FILE="$PROJECT_ROOT/eday-webapp.jar" + +DEPLOY_LOG="$PROJECT_ROOT/deploy.log" + +TIME_NOW=$(date +%c) + +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 From 2783206dc1a95a5cac6ac15ae1b70f7ee2942fce Mon Sep 17 00:00:00 2001 From: Kwon Min A Date: Sat, 22 Jul 2023 01:09:04 +0900 Subject: [PATCH 038/153] =?UTF-8?q?chore:=20codedeploy=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- appspec.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 appspec.yml diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 0000000..0098ccf --- /dev/null +++ b/appspec.yml @@ -0,0 +1,22 @@ +version: 0.0 +os: Linux + +files: + - source: / + destination: /home/ubuntu/eday + 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 From 33943df8503315db17195b84f0c0d61729f80a99 Mon Sep 17 00:00:00 2001 From: Kwon Min A Date: Sat, 22 Jul 2023 01:10:15 +0900 Subject: [PATCH 039/153] =?UTF-8?q?chore:=20=EB=B0=B0=ED=8F=AC=20=EC=9B=8C?= =?UTF-8?q?=ED=81=AC=ED=94=8C=EB=A1=9C=EC=9A=B0=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 69 ++++++++++++++++++++++++++++++++++++ 1 file changed, 69 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..8e83bcf --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,69 @@ +name: Deploy to Amazon EC2 + +on: + push: + branches: [ "setting" ] + pull_request: + branches: [ "setting" ] + +env: + AWS_REGION: ap-northeast-2 + S3_BUCKET_NAME: eday-s3-bucket + CODE_DEPLOY_APPLICATION_NAME: eday-codedeploy-app + CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: eday-codedeploy-deploy-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: Grant execute permission for gradlew + run: chmod +x gradlew + + - uses: actions/checkout@v3 + - run: mkdir src/main/resources + - run: touch ./src/main/resources/application.yml + - run: echo "${{ env.APPLICATION }}" > ./src/main/resources/application.yml + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + with: + arguments: clean build -x test + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + 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 09c4867c2b142fdee3e7cfcc6b2e3d3ec2f38438 Mon Sep 17 00:00:00 2001 From: Kwon Min A Date: Sat, 22 Jul 2023 01:37:12 +0900 Subject: [PATCH 040/153] =?UTF-8?q?fix:=20os=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20Linux=20->=20linux?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CodeDeploy의 application specification file 설정 오류로 배포 실패 - CodeDeploy가 지원하는 os는 리눅스와 윈도우즈. 각각 linux, windows로 표기해줘야 함 --- appspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appspec.yml b/appspec.yml index 0098ccf..c5ad304 100644 --- a/appspec.yml +++ b/appspec.yml @@ -1,5 +1,5 @@ version: 0.0 -os: Linux +os: linux files: - source: / From 8ade32fd54ee72e114b0014c4f11a6d31b9ebac0 Mon Sep 17 00:00:00 2001 From: hannah0226 Date: Sat, 22 Jul 2023 02:25:45 +0900 Subject: [PATCH 041/153] =?UTF-8?q?feat:=20=ED=80=B4=EC=A6=88=20=EC=A0=95?= =?UTF-8?q?=EB=8B=B5=20=EB=A7=9E=EC=B6=9C=20=EC=8B=9C=20=EC=B9=AD=ED=98=B8?= =?UTF-8?q?=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../day/quiz/controller/QuizController.java | 6 +++- .../edayback/domain/day/quiz/entity/Quiz.java | 2 ++ .../domain/day/quiz/service/QuizService.java | 36 +++++++++++++++---- .../day/title/repository/TitleRepository.java | 12 +++++++ .../domain/member/entity/MemberTitle.java | 12 +++++++ .../repository/MemberTitleRepository.java | 14 ++++++++ 6 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 src/main/java/efub/eday/edayback/domain/day/title/repository/TitleRepository.java create mode 100644 src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java index 69309b3..0df2607 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java @@ -2,6 +2,8 @@ import efub.eday.edayback.domain.day.quiz.dto.QuizAnswerResponseDto; import efub.eday.edayback.domain.day.quiz.dto.QuizRequestDto; +import efub.eday.edayback.domain.member.entity.Member; +import jakarta.servlet.http.HttpSession; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; @@ -15,6 +17,7 @@ @RequiredArgsConstructor public class QuizController { private final QuizService quizService; + private final HttpSession httpSession; //퀴즈 내용 조회 @GetMapping @@ -30,7 +33,8 @@ public QuizAnswerResponseDto checkAnswer( @PathVariable int d_day, @RequestBody QuizRequestDto quizRequestDto ) { - boolean isCorrect = quizService.checkAnswer(d_day, quizRequestDto.getOptionId()); + Long memberId = (Long) httpSession.getAttribute("memberId"); + boolean isCorrect = quizService.checkAnswer(d_day, quizRequestDto.getOptionId(), memberId); String quizDescription = null; if (isCorrect) { quizDescription = quizService.getQuizDescription(d_day); diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java index f82dd7f..9a2fd66 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java @@ -1,6 +1,7 @@ package efub.eday.edayback.domain.day.quiz.entity; import efub.eday.edayback.domain.day.dday.entity.Subject; +import efub.eday.edayback.domain.day.title.entity.Title; import jakarta.persistence.*; import lombok.Builder; import lombok.Getter; @@ -42,4 +43,5 @@ public Quiz(String content, String description, String imageUrl, Subject subject this.subject=subject; this.optionsList=optionsList; } + } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java index 5230b23..553defd 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java @@ -1,9 +1,14 @@ package efub.eday.edayback.domain.day.quiz.service; - +import efub.eday.edayback.domain.day.dday.entity.Subject; import efub.eday.edayback.domain.day.quiz.entity.Options; +import efub.eday.edayback.domain.day.title.entity.Title; +import efub.eday.edayback.domain.day.title.repository.TitleRepository; +import efub.eday.edayback.domain.member.entity.Member; +import efub.eday.edayback.domain.member.entity.MemberTitle; +import efub.eday.edayback.domain.member.repository.MemberRepository; +import efub.eday.edayback.domain.member.repository.MemberTitleRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; - import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.quiz.entity.Quiz; import efub.eday.edayback.domain.day.quiz.repository.QuizRepository; @@ -14,25 +19,44 @@ @RequiredArgsConstructor public class QuizService { private final QuizRepository quizRepository; + private final MemberRepository memberRepository; + private final MemberTitleRepository memberTitleRepository; + private final TitleRepository titleRepository; //퀴즈 내용 조회 @Transactional(readOnly = true) public Quiz findQuiz(int d_day) { Dday dday = Dday.fromRemainingDays(d_day); return quizRepository.findBySubject_Dday(dday) - .orElseThrow(() -> new IllegalArgumentException("퀴즈를 찾을 수 없습니다.")); + .orElseThrow(() -> new IllegalArgumentException("퀴즈를 찾을 수 없습니다.")); } //퀴즈 정답 확인 - public boolean checkAnswer(int d_day, int option_id){ + public boolean checkAnswer(int d_day, int option_id, Long memberId){ Quiz quiz = findQuiz(d_day); + boolean isCorrect = false; for (Options option : quiz.getOptionsList()) { if (option.getOptionNumber() == option_id) { - return option.getIsAnswer(); + isCorrect = option.getIsAnswer(); + break; } } - throw new IllegalArgumentException("올바르지 않은 optionId입니다."); + + if(isCorrect){ + Member member = memberRepository.findById(memberId) + .orElseThrow(()->new IllegalArgumentException("해당 멤버를 찾을 수 없습니다.")); + Long subjectId = quiz.getSubject().getId(); + Title title = titleRepository.findBySubjectId(subjectId) + .orElseThrow(() -> new IllegalArgumentException("해당 subject_id에 대한 타이틀을 찾을 수 없습니다.")); + MemberTitle memberTitle = memberTitleRepository.findByMemberAndTitle(member, title) + .orElseThrow(() -> new IllegalArgumentException("해당 멤버의 타이틀을 찾을 수 없습니다.")); + + //getTitle값 true로 변경 + memberTitle.setGetTitle(true); + memberTitleRepository.save(memberTitle); + } + return isCorrect; } //퀴즈 설명 가져오기 diff --git a/src/main/java/efub/eday/edayback/domain/day/title/repository/TitleRepository.java b/src/main/java/efub/eday/edayback/domain/day/title/repository/TitleRepository.java new file mode 100644 index 0000000..41fd83a --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/title/repository/TitleRepository.java @@ -0,0 +1,12 @@ +package efub.eday.edayback.domain.day.title.repository; + +import efub.eday.edayback.domain.day.title.entity.Title; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface TitleRepository extends JpaRepository { + Optional findBySubjectId(Long subjectId); +} diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java index bc63414..d82122d 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java @@ -8,7 +8,12 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +@Getter +@Setter @Entity public class MemberTitle { @@ -27,4 +32,11 @@ public class MemberTitle { @ManyToOne @JoinColumn(name = "title_id", nullable = false) private Title title; + + @Builder + public MemberTitle(boolean getTitle, Member member, Title title) { + this.getTitle = getTitle; + this.member = member; + this.title = title; + } } diff --git a/src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java b/src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java new file mode 100644 index 0000000..c5e01f3 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java @@ -0,0 +1,14 @@ +package efub.eday.edayback.domain.member.repository; + +import efub.eday.edayback.domain.day.title.entity.Title; +import efub.eday.edayback.domain.member.entity.Member; +import efub.eday.edayback.domain.member.entity.MemberTitle; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface MemberTitleRepository extends JpaRepository<MemberTitle, Long> { + Optional<MemberTitle> findByMemberAndTitle(Member member, Title title); +} From 7607408486fcc48dbadd8cf4b78517df3f041d61 Mon Sep 17 00:00:00 2001 From: hannah0226 <mohan0226@naver.com> Date: Sat, 22 Jul 2023 02:27:10 +0900 Subject: [PATCH 042/153] =?UTF-8?q?feat:=20=ED=80=B4=EC=A6=88=20=EC=A0=95?= =?UTF-8?q?=EB=8B=B5=20=EB=A7=9E=EC=B6=9C=20=EC=8B=9C=20=EC=B9=AD=ED=98=B8?= =?UTF-8?q?=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/day/quiz/controller/QuizController.java | 3 --- .../java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java | 3 --- .../eday/edayback/domain/day/quiz/service/QuizService.java | 1 - 3 files changed, 7 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java index 0df2607..5ff9cde 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java @@ -1,12 +1,9 @@ package efub.eday.edayback.domain.day.quiz.controller; - import efub.eday.edayback.domain.day.quiz.dto.QuizAnswerResponseDto; import efub.eday.edayback.domain.day.quiz.dto.QuizRequestDto; -import efub.eday.edayback.domain.member.entity.Member; import jakarta.servlet.http.HttpSession; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; - import efub.eday.edayback.domain.day.quiz.dto.QuizResponseDto; import efub.eday.edayback.domain.day.quiz.entity.Quiz; import efub.eday.edayback.domain.day.quiz.service.QuizService; diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java index 9a2fd66..7afd549 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java @@ -1,12 +1,9 @@ package efub.eday.edayback.domain.day.quiz.entity; - import efub.eday.edayback.domain.day.dday.entity.Subject; -import efub.eday.edayback.domain.day.title.entity.Title; import jakarta.persistence.*; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; - import java.util.List; @Entity diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java index 553defd..d6ab77b 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java @@ -1,5 +1,4 @@ package efub.eday.edayback.domain.day.quiz.service; -import efub.eday.edayback.domain.day.dday.entity.Subject; import efub.eday.edayback.domain.day.quiz.entity.Options; import efub.eday.edayback.domain.day.title.entity.Title; import efub.eday.edayback.domain.day.title.repository.TitleRepository; From bb9f45b8dfc2f3088b27c4717a6d92b81921ff69 Mon Sep 17 00:00:00 2001 From: hannah0226 <mohan0226@naver.com> Date: Sat, 22 Jul 2023 02:34:03 +0900 Subject: [PATCH 043/153] =?UTF-8?q?feat:=20=ED=80=B4=EC=A6=88=20=EC=A0=95?= =?UTF-8?q?=EB=8B=B5=20=EB=A7=9E=EC=B6=9C=20=EC=8B=9C=20member=20level+1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eday/edayback/domain/day/quiz/service/QuizService.java | 4 ++++ .../java/efub/eday/edayback/domain/member/entity/Member.java | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java index d6ab77b..2796360 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java @@ -51,6 +51,10 @@ public boolean checkAnswer(int d_day, int option_id, Long memberId){ MemberTitle memberTitle = memberTitleRepository.findByMemberAndTitle(member, title) .orElseThrow(() -> new IllegalArgumentException("해당 멤버의 타이틀을 찾을 수 없습니다.")); + //member lever+1 + if(!memberTitle.getGetTitle()){ + member.setLevel(member.getLevel()+1); + } //getTitle값 true로 변경 memberTitle.setGetTitle(true); memberTitleRepository.save(memberTitle); diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java index 1349aae..8d944a5 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java @@ -2,6 +2,7 @@ import java.time.LocalDate; +import lombok.Setter; import org.hibernate.annotations.CreationTimestamp; import jakarta.persistence.Column; @@ -15,6 +16,7 @@ @Entity @Getter +@Setter @NoArgsConstructor public class Member { From 527891f113023f047a8aa9193e68414db4feee0c Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sat, 22 Jul 2023 13:47:41 +0900 Subject: [PATCH 044/153] =?UTF-8?q?style(Quiz):=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20=ED=95=84=EB=93=9C=EB=AA=85=20description=20->=20ex?= =?UTF-8?q?planation=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/day/quiz/entity/Quiz.java | 29 +++++++++++------- .../domain/day/quiz/service/QuizService.java | 30 ++++++++++--------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java index 7afd549..9e7c6a0 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java @@ -1,10 +1,19 @@ package efub.eday.edayback.domain.day.quiz.entity; + +import java.util.List; + import efub.eday.edayback.domain.day.dday.entity.Subject; -import jakarta.persistence.*; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToMany; +import jakarta.persistence.OneToOne; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import java.util.List; @Entity @Getter @@ -20,25 +29,25 @@ public class Quiz { private String content; @Column(nullable = false) - private String description; + private String explanation; @Column(name = "image_url") private String imageUrl; @OneToOne - @JoinColumn(name = "d_day_id", nullable = false) + @JoinColumn(name = "subject_id", nullable = false) private Subject subject; @OneToMany(mappedBy = "quiz") private List<Options> optionsList; @Builder - public Quiz(String content, String description, String imageUrl, Subject subject, List<Options> optionsList){ - this.content=content; - this.description=description; - this.imageUrl=imageUrl; - this.subject=subject; - this.optionsList=optionsList; + public Quiz(String content, String explanation, String imageUrl, Subject subject, List<Options> optionsList) { + this.content = content; + this.explanation = explanation; + this.imageUrl = imageUrl; + this.subject = subject; + this.optionsList = optionsList; } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java index 2796360..bd26501 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java @@ -1,16 +1,18 @@ package efub.eday.edayback.domain.day.quiz.service; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.quiz.entity.Options; +import efub.eday.edayback.domain.day.quiz.entity.Quiz; +import efub.eday.edayback.domain.day.quiz.repository.QuizRepository; import efub.eday.edayback.domain.day.title.entity.Title; import efub.eday.edayback.domain.day.title.repository.TitleRepository; import efub.eday.edayback.domain.member.entity.Member; import efub.eday.edayback.domain.member.entity.MemberTitle; import efub.eday.edayback.domain.member.repository.MemberRepository; import efub.eday.edayback.domain.member.repository.MemberTitleRepository; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import efub.eday.edayback.domain.day.dday.entity.Dday; -import efub.eday.edayback.domain.day.quiz.entity.Quiz; -import efub.eday.edayback.domain.day.quiz.repository.QuizRepository; import lombok.RequiredArgsConstructor; @Service @@ -27,11 +29,11 @@ public class QuizService { public Quiz findQuiz(int d_day) { Dday dday = Dday.fromRemainingDays(d_day); return quizRepository.findBySubject_Dday(dday) - .orElseThrow(() -> new IllegalArgumentException("퀴즈를 찾을 수 없습니다.")); + .orElseThrow(() -> new IllegalArgumentException("퀴즈를 찾을 수 없습니다.")); } //퀴즈 정답 확인 - public boolean checkAnswer(int d_day, int option_id, Long memberId){ + public boolean checkAnswer(int d_day, int option_id, Long memberId) { Quiz quiz = findQuiz(d_day); boolean isCorrect = false; @@ -42,18 +44,18 @@ public boolean checkAnswer(int d_day, int option_id, Long memberId){ } } - if(isCorrect){ + if (isCorrect) { Member member = memberRepository.findById(memberId) - .orElseThrow(()->new IllegalArgumentException("해당 멤버를 찾을 수 없습니다.")); + .orElseThrow(() -> new IllegalArgumentException("해당 멤버를 찾을 수 없습니다.")); Long subjectId = quiz.getSubject().getId(); Title title = titleRepository.findBySubjectId(subjectId) - .orElseThrow(() -> new IllegalArgumentException("해당 subject_id에 대한 타이틀을 찾을 수 없습니다.")); + .orElseThrow(() -> new IllegalArgumentException("해당 subject_id에 대한 타이틀을 찾을 수 없습니다.")); MemberTitle memberTitle = memberTitleRepository.findByMemberAndTitle(member, title) - .orElseThrow(() -> new IllegalArgumentException("해당 멤버의 타이틀을 찾을 수 없습니다.")); + .orElseThrow(() -> new IllegalArgumentException("해당 멤버의 타이틀을 찾을 수 없습니다.")); //member lever+1 - if(!memberTitle.getGetTitle()){ - member.setLevel(member.getLevel()+1); + if (!memberTitle.getGetTitle()) { + member.setLevel(member.getLevel() + 1); } //getTitle값 true로 변경 memberTitle.setGetTitle(true); @@ -65,6 +67,6 @@ public boolean checkAnswer(int d_day, int option_id, Long memberId){ //퀴즈 설명 가져오기 public String getQuizDescription(int d_day) { Quiz quiz = findQuiz(d_day); - return quiz.getDescription(); + return quiz.getExplanation(); } } From d5040bac8ae700eba9b32631977ed9c79334b583 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sat, 22 Jul 2023 13:48:06 +0900 Subject: [PATCH 045/153] =?UTF-8?q?chore:=20gitignore=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - application.yaml / application.yml 둘 다 추가 --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index c054f2a..0938820 100644 --- a/.gitignore +++ b/.gitignore @@ -176,9 +176,8 @@ gradle-app.setting *.hprof .idea/ +application.yml application.yaml .env -docker-compose.yaml -Dockerfile # End of https://www.toptal.com/developers/gitignore/api/java,gradle,intellij,macos,windows From 9a48aa4b19bcd70e80166532db2d2f6cc3c67f91 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sat, 22 Jul 2023 15:11:19 +0900 Subject: [PATCH 046/153] =?UTF-8?q?feat:=20=EC=97=94=ED=8B=B0=ED=8B=B0=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 --- .../domain/day/dday/entity/Subject.java | 6 +-- .../edayback/domain/day/info/entity/Info.java | 4 +- .../domain/day/info/entity/InfoImage.java | 4 +- .../day/quiz/dto/OptionsResponseDto.java | 23 ++++----- .../domain/day/quiz/dto/QuizResponseDto.java | 50 +++++++++---------- .../quiz/entity/{Options.java => Option.java} | 23 ++++++--- .../edayback/domain/day/quiz/entity/Quiz.java | 20 ++++---- .../domain/day/title/entity/Title.java | 6 +-- .../edayback/domain/member/entity/Member.java | 7 ++- .../domain/member/entity/MemberQuiz.java | 2 +- .../domain/member/entity/MemberTitle.java | 7 ++- 11 files changed, 82 insertions(+), 70 deletions(-) rename src/main/java/efub/eday/edayback/domain/day/quiz/entity/{Options.java => Option.java} (57%) diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java index 74b7640..7867c0e 100644 --- a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java +++ b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java @@ -7,18 +7,18 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import lombok.Getter; +import jakarta.persistence.Table; import lombok.NoArgsConstructor; @Entity @NoArgsConstructor -@Getter +@Table(name = "subjects") public class Subject { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "subject_id") - private Long id; + private Integer id; @Enumerated(value = EnumType.ORDINAL) @Column(name = "d_day", nullable = false) diff --git a/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java b/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java index ff31988..5198e13 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/entity/Info.java @@ -23,10 +23,10 @@ public class Info { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "info_id") - private Long id; + private Integer id; @OneToOne - @JoinColumn(name = "subject_id", nullable = false) + @JoinColumn(name = "subject_id", nullable = false, unique = true) private Subject subject; @OneToMany(mappedBy = "info") diff --git a/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java b/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java index 535d295..a89118e 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/entity/InfoImage.java @@ -20,10 +20,10 @@ public class InfoImage { @Column(name = "info_image_id") private Long id; - @Column(name = "image_url") + @Column(name = "image_url", nullable = false) private String url; @ManyToOne - @JoinColumn(name = "info_id") + @JoinColumn(name = "info_id", nullable = false) private Info info; } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java index 1cda2eb..d781d23 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java @@ -1,6 +1,6 @@ package efub.eday.edayback.domain.day.quiz.dto; -import efub.eday.edayback.domain.day.quiz.entity.Options; +import efub.eday.edayback.domain.day.quiz.entity.Option; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -8,18 +8,15 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class OptionsResponseDto { - private Long id; - private String content; + private String content; - private OptionsResponseDto(Long id, String content){ - this.id=id; - this.content=content; - } + private OptionsResponseDto(String content) { + this.content = content; + } - public static OptionsResponseDto from(Options options){ - return new OptionsResponseDto( - options.getId(), - options.getContent() - ); - } + public static OptionsResponseDto from(Option option) { + return new OptionsResponseDto( + option.getContent() + ); + } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java index c3e0f62..49f9611 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java @@ -1,41 +1,41 @@ package efub.eday.edayback.domain.day.quiz.dto; +import java.util.List; +import java.util.stream.Collectors; + import efub.eday.edayback.domain.day.quiz.entity.Quiz; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import java.util.List; -import java.util.stream.Collectors; - @Getter @Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class QuizResponseDto { - private int dday; - private String topic; - private String quizContent; - private List<OptionsResponseDto> optionList; + private int dday; + private String topic; + private String quizContent; + private List<OptionsResponseDto> optionList; - public QuizResponseDto(int dday, String topic, String quizContent, List<OptionsResponseDto> optionList){ - this.dday=dday; - this.topic=topic; - this.quizContent=quizContent; - this.optionList=optionList; - } + public QuizResponseDto(int dday, String topic, String quizContent, List<OptionsResponseDto> optionList) { + this.dday = dday; + this.topic = topic; + this.quizContent = quizContent; + this.optionList = optionList; + } - public static QuizResponseDto from(Quiz quiz){ - List<OptionsResponseDto> optionList = quiz.getOptionsList() - .stream() - .map(OptionsResponseDto::from) - .collect(Collectors.toList()); - return new QuizResponseDto( - quiz.getSubject().getDday(), - quiz.getSubject().getHeadline(), - quiz.getContent(), - optionList - ); - } + public static QuizResponseDto from(Quiz quiz) { + List<OptionsResponseDto> optionList = quiz.getOptionList() + .stream() + .map(OptionsResponseDto::from) + .collect(Collectors.toList()); + return new QuizResponseDto( + quiz.getSubject().getDday(), + quiz.getSubject().getHeadline(), + quiz.getContent(), + optionList + ); + } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Option.java similarity index 57% rename from src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java rename to src/main/java/efub/eday/edayback/domain/day/quiz/entity/Option.java index ecb0d7e..c354db2 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Options.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Option.java @@ -1,6 +1,5 @@ package efub.eday.edayback.domain.day.quiz.entity; -import efub.eday.edayback.domain.day.quiz.dto.QuizResponseDto; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; @@ -8,17 +7,21 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; @Entity @Getter -public class Options { +@NoArgsConstructor +@Table(name = "quiz_option") +public class Option { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "option_id") - private Long id; + private Integer id; @Column(nullable = false) private String content; @@ -26,14 +29,18 @@ public class Options { @Column(nullable = false) private Boolean isAnswer; + @Column(nullable = false) + private Integer optionNumber; + @ManyToOne - @JoinColumn(name = "quiz_id") + @JoinColumn(name = "quiz_id", nullable = false) private Quiz quiz; @Builder - public Options(String content, Boolean isAnswer, Quiz quiz){ - this.content=content; - this.isAnswer=isAnswer; - this.quiz=quiz; + public Option(String content, Boolean isAnswer, Quiz quiz, int optionNumber) { + this.content = content; + this.isAnswer = isAnswer; + this.quiz = quiz; + this.optionNumber = optionNumber; } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java index 6f8a39a..6d2d55d 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java @@ -14,13 +14,13 @@ public class Quiz { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "quiz_id") - private Long id; + private Integer id; @Column(nullable = false) private String content; - @Column(nullable = false) - private String description; + @Column(nullable = false, length = 500) + private String explanation; @Column(name = "image_url") private String imageUrl; @@ -30,14 +30,14 @@ public class Quiz { private Subject subject; @OneToMany(mappedBy = "quiz") - private List<Options> optionsList; + private List<Option> optionList; @Builder - public Quiz(String content, String description, String imageUrl, Subject subject, List<Options> optionsList){ - this.content=content; - this.description=description; - this.imageUrl=imageUrl; - this.subject=subject; - this.optionsList=optionsList; + public Quiz(String content, String explanation, String imageUrl, Subject subject, List<Option> optionList) { + this.content = content; + this.explanation = explanation; + this.imageUrl = imageUrl; + this.subject = subject; + this.optionList = optionList; } } diff --git a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java index e5f784c..641a290 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java @@ -15,15 +15,15 @@ public class Title { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "title_id") - private Long id; + private Integer id; - @Column(nullable = false) + @Column(name = "title_name", nullable = false, length = 127) private String name; @Column(name = "image_url", nullable = false) private String imageUrl; @OneToOne - @JoinColumn(nullable = false) + @JoinColumn(name = "subject_id", nullable = false) private Subject subject; } diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java index 1349aae..366eb62 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java @@ -9,13 +9,16 @@ import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.Table; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; @Entity @Getter @NoArgsConstructor +@Table(name = "members") public class Member { @Id @@ -23,7 +26,7 @@ public class Member { @Column(name = "member_id") private Long id; - @Column(nullable = false) + @Column(nullable = false, length = 30) private String nickname; @Column(nullable = false) @@ -32,7 +35,7 @@ public class Member { @Column(name = "profile_image_url", nullable = false) private String profileImageUrl; - @Column(nullable = false) + @Column(name = "grade", nullable = false) private Integer level; @CreationTimestamp //insert할 때 자동 날짜 적용 diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java index 48b3d18..ca61151 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java @@ -15,7 +15,7 @@ public class MemberQuiz { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "member_quiz_id") - private Long id; + private Integer id; @Column(nullable = false) private Boolean isCorrect; diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java index bc63414..e7f5343 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java @@ -8,14 +8,19 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; @Entity +@NoArgsConstructor public class MemberTitle { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "member_title_id") - private Long id; + private Integer id; @Column(nullable = false) private Boolean getTitle; From 815d350942d5417bf2e084268e7f47587acb7f5b Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sat, 22 Jul 2023 15:45:09 +0900 Subject: [PATCH 047/153] =?UTF-8?q?chore:=20jdk=20=EB=B2=84=EC=A0=84=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=2017=20->=2011?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- .../domain/day/dday/entity/Subject.java | 19 ++++++++++--------- .../domain/day/quiz/entity/Option.java | 17 +++++++++-------- .../edayback/domain/day/quiz/entity/Quiz.java | 2 ++ .../edayback/domain/member/entity/Member.java | 8 +------- .../domain/member/entity/MemberTitle.java | 7 ------- 6 files changed, 23 insertions(+), 32 deletions(-) diff --git a/build.gradle b/build.gradle index 7937648..48400dc 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ group = 'efub.eday' version = '0.0.1-SNAPSHOT' java { - sourceCompatibility = '17' + sourceCompatibility = '11' } configurations { diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java index 7867c0e..1f52964 100644 --- a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java +++ b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java @@ -1,13 +1,14 @@ package efub.eday.edayback.domain.day.dday.entity; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.Table; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + import lombok.NoArgsConstructor; @Entity @@ -20,7 +21,7 @@ public class Subject { @Column(name = "subject_id") private Integer id; - @Enumerated(value = EnumType.ORDINAL) + @Enumerated(value = EnumType.STRING) @Column(name = "d_day", nullable = false) private Dday dday; diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Option.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Option.java index c354db2..2e73a97 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Option.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Option.java @@ -1,13 +1,14 @@ package efub.eday.edayback.domain.day.quiz.entity; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.Table; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java index 5377490..3549209 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java @@ -14,9 +14,11 @@ import efub.eday.edayback.domain.day.dday.entity.Subject; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; @Entity @Getter +@NoArgsConstructor public class Quiz { @Id diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java index 7478eea..c817a5c 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java @@ -7,19 +7,13 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.Table; import org.hibernate.annotations.CreationTimestamp; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.Table; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.Setter; @Entity @Getter diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java index 957c284..abeb95a 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java @@ -9,13 +9,6 @@ import javax.persistence.ManyToOne; import efub.eday.edayback.domain.day.title.entity.Title; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import lombok.NoArgsConstructor; @Entity From d92b4ddbe4b002502468cac62a96e1612a4a57b0 Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Sat, 22 Jul 2023 17:20:56 +0900 Subject: [PATCH 048/153] =?UTF-8?q?feat:=20=EB=AC=B8=EC=9D=98=EC=82=AC?= =?UTF-8?q?=ED=95=AD(Query)=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20=ED=9B=84=EC=97=90=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20#3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../query/controller/QueryController.java | 26 ++++++++++++ .../domain/query/dto/QueryRequestDto.java | 18 +++++++++ .../edayback/domain/query/entity/Query.java | 14 ++++++- .../query/repository/QueryRepository.java | 8 ++++ .../domain/query/service/QueryService.java | 40 +++++++++++++++++++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java create mode 100644 src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java create mode 100644 src/main/java/efub/eday/edayback/domain/query/repository/QueryRepository.java create mode 100644 src/main/java/efub/eday/edayback/domain/query/service/QueryService.java diff --git a/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java b/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java new file mode 100644 index 0000000..0f8d4cf --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java @@ -0,0 +1,26 @@ +package efub.eday.edayback.domain.query.controller; + +import org.springframework.http.HttpStatus; +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.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + +import efub.eday.edayback.domain.query.dto.QueryRequestDto; +import efub.eday.edayback.domain.query.entity.Query; +import efub.eday.edayback.domain.query.service.QueryService; +import lombok.RequiredArgsConstructor; + +@RestController +@RequestMapping("/querys") +@RequiredArgsConstructor +public class QueryController { + private final QueryService queryService; + + @PostMapping + @ResponseStatus(value = HttpStatus.CREATED) + public Query addquery(@RequestBody QueryRequestDto requestDto) { + return queryService.addQuery(requestDto); + } +} diff --git a/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java b/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java new file mode 100644 index 0000000..8f0ad96 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java @@ -0,0 +1,18 @@ +package efub.eday.edayback.domain.query.dto; + +import lombok.Getter; + +/* +{ + "memberId" : 1, + "queryContent" : "공강을 보내기 좋은 장소에 관련하여 문의 드립니다.", + "subjectId" : 1 +} + */ + +@Getter +public class QueryRequestDto { + private int memberId; + private String queryContent; + private int subjectId; +} diff --git a/src/main/java/efub/eday/edayback/domain/query/entity/Query.java b/src/main/java/efub/eday/edayback/domain/query/entity/Query.java index 5a2d393..e5a2b74 100644 --- a/src/main/java/efub/eday/edayback/domain/query/entity/Query.java +++ b/src/main/java/efub/eday/edayback/domain/query/entity/Query.java @@ -9,14 +9,19 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import lombok.Builder; +import lombok.NoArgsConstructor; @Entity +@NoArgsConstructor +@Table(name = "querys") public class Query { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "query_id") - private Long id; + private Integer id; @Column(nullable = false) private String content; @@ -28,4 +33,11 @@ public class Query { @ManyToOne @JoinColumn(nullable = false) private Subject subject; + + @Builder + public Query(String content, Member writer, Subject subject) { + this.content = content; + this.writer = writer; + this.subject = subject; + } } diff --git a/src/main/java/efub/eday/edayback/domain/query/repository/QueryRepository.java b/src/main/java/efub/eday/edayback/domain/query/repository/QueryRepository.java new file mode 100644 index 0000000..84ad292 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/query/repository/QueryRepository.java @@ -0,0 +1,8 @@ +package efub.eday.edayback.domain.query.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import efub.eday.edayback.domain.query.entity.Query; + +public interface QueryRepository extends JpaRepository<Query, Integer> { +} diff --git a/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java b/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java new file mode 100644 index 0000000..8725568 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java @@ -0,0 +1,40 @@ +package efub.eday.edayback.domain.query.service; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import efub.eday.edayback.domain.day.dday.entity.Subject; +import efub.eday.edayback.domain.day.dday.repository.SubjectRepository; +import efub.eday.edayback.domain.member.entity.Member; +import efub.eday.edayback.domain.member.repository.MemberRepository; +import efub.eday.edayback.domain.member.service.MemberService; +import efub.eday.edayback.domain.query.dto.QueryRequestDto; +import efub.eday.edayback.domain.query.entity.Query; +import efub.eday.edayback.domain.query.repository.QueryRepository; +import lombok.RequiredArgsConstructor; + +@Service +@Transactional +@RequiredArgsConstructor +public class QueryService { + private final QueryRepository queryRepository; + private final MemberService memberService; + private final MemberRepository memberRepository; + private final SubjectRepository subjectRepository; + + public Query addQuery(QueryRequestDto requestDto) { + Member writer = memberRepository.findById(requestDto.getMemberId()) + .orElseThrow(() -> new IllegalArgumentException("유효하지 않은 ID")); + + Subject subject = subjectRepository.findById(requestDto.getSubjectId()) + .orElseThrow(() -> new IllegalArgumentException("유효하지 않은 ID")); + + Query query = Query.builder() + .content(requestDto.getQueryContent()) + .writer(writer) + .subject(subject) + .build(); + + return queryRepository.save(query); + } +} From cbf63c3b23dba08bc532b6983c31b177a4c944b8 Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Sat, 22 Jul 2023 17:22:03 +0900 Subject: [PATCH 049/153] =?UTF-8?q?chore:=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=ED=9B=84=20=EC=BD=94=EB=93=9C=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 --- .../domain/day/dday/repository/SubjectRepository.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/efub/eday/edayback/domain/day/dday/repository/SubjectRepository.java diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/repository/SubjectRepository.java b/src/main/java/efub/eday/edayback/domain/day/dday/repository/SubjectRepository.java new file mode 100644 index 0000000..bf0b96c --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/day/dday/repository/SubjectRepository.java @@ -0,0 +1,9 @@ +package efub.eday.edayback.domain.day.dday.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import efub.eday.edayback.domain.day.dday.entity.Subject; + +public interface SubjectRepository extends JpaRepository<Subject, Integer> { + +} From bdd62aa827116eb66aa4a2b7865ceb045ebc2ee0 Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Sat, 22 Jul 2023 17:23:34 +0900 Subject: [PATCH 050/153] =?UTF-8?q?chore:=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=ED=9B=84=20Integer=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/day/title/repository/MemberTitleRepository.java | 2 +- .../edayback/domain/member/repository/MemberRepository.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/title/repository/MemberTitleRepository.java b/src/main/java/efub/eday/edayback/domain/day/title/repository/MemberTitleRepository.java index 3ff3e76..cea3a9c 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/repository/MemberTitleRepository.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/repository/MemberTitleRepository.java @@ -9,6 +9,6 @@ import efub.eday.edayback.domain.member.entity.MemberTitle; @Repository -public interface MemberTitleRepository extends JpaRepository<MemberTitle, Long> { +public interface MemberTitleRepository extends JpaRepository<MemberTitle, Integer> { List<MemberTitle> findByMember(Member member); } diff --git a/src/main/java/efub/eday/edayback/domain/member/repository/MemberRepository.java b/src/main/java/efub/eday/edayback/domain/member/repository/MemberRepository.java index 538a96d..d248118 100644 --- a/src/main/java/efub/eday/edayback/domain/member/repository/MemberRepository.java +++ b/src/main/java/efub/eday/edayback/domain/member/repository/MemberRepository.java @@ -4,6 +4,6 @@ import efub.eday.edayback.domain.member.entity.Member; -public interface MemberRepository extends JpaRepository<Member, Long> { +public interface MemberRepository extends JpaRepository<Member, Integer> { Member findByEmail(String email); } From da95ced23fccf305fd10f47aa446a78a304b2e57 Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Sat, 22 Jul 2023 17:24:58 +0900 Subject: [PATCH 051/153] =?UTF-8?q?chore:=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=ED=9B=84=20Integer=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95=20#7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/day/title/controller/TitleController.java | 2 +- .../efub/eday/edayback/domain/day/title/entity/Title.java | 4 +++- .../eday/edayback/domain/day/title/service/TitleService.java | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java b/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java index c054541..ea909bc 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java @@ -18,7 +18,7 @@ public class TitleController { private final TitleService titleService; @GetMapping("/{member_id}") - public ResponseEntity<TitleResponseDto> getTitlePage(@PathVariable("member_id") Long memberId) { + public ResponseEntity<TitleResponseDto> getTitlePage(@PathVariable("member_id") Integer memberId) { TitleResponseDto titleResponseDto = titleService.getTitlePage(memberId); return ResponseEntity.ok(titleResponseDto); } diff --git a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java index 868a074..b770721 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java @@ -8,13 +8,15 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToOne; +import jakarta.persistence.Table; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Entity -@NoArgsConstructor @Getter +@NoArgsConstructor +@Table(name = "titles") public class Title { @Id diff --git a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java index 5e24d8a..162ba5b 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java @@ -24,7 +24,7 @@ public class TitleService { private final MemberTitleRepository memberTitleRepository; @Transactional(readOnly = true) - public TitleResponseDto getTitlePage(Long memberId) { + public TitleResponseDto getTitlePage(Integer memberId) { Member member = memberRepository.findById(memberId) .orElseThrow(() -> new IllegalArgumentException("해당하는 회원이 없습니다. ID: " + memberId)); From fb941d5251c7fa57364417e986db69979a3605fe Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Sat, 22 Jul 2023 17:51:29 +0900 Subject: [PATCH 052/153] =?UTF-8?q?chore:=20=EC=97=94=ED=8B=B0=ED=8B=B0=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=ED=9B=84=20Integer=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95=20#6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/day/info/repository/InfoRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java b/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java index 68770e6..0c1d6e3 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/repository/InfoRepository.java @@ -7,6 +7,6 @@ import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.info.entity.Info; -public interface InfoRepository extends JpaRepository<Info, Long> { +public interface InfoRepository extends JpaRepository<Info, Integer> { Optional<Info> findInfoBySubject_Dday(Dday dday); } From 5cf86b5a85af20bad3a89b89b1a84673fd178ce4 Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Sun, 23 Jul 2023 01:43:08 +0900 Subject: [PATCH 053/153] =?UTF-8?q?refactor:=20=EB=AC=B8=EC=9D=98=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20dto=20=EC=BD=94=EB=93=9C=20dday=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20#3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eday/edayback/domain/day/dday/entity/Subject.java | 7 +++++++ .../domain/day/dday/repository/SubjectRepository.java | 5 ++++- .../eday/edayback/domain/query/dto/QueryRequestDto.java | 6 +++--- .../eday/edayback/domain/query/service/QueryService.java | 9 ++++++--- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java index 7867c0e..11ddf4c 100644 --- a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java +++ b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java @@ -8,6 +8,7 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Table; +import lombok.Builder; import lombok.NoArgsConstructor; @Entity @@ -34,4 +35,10 @@ public int getDday() { public String getHeadline() { return headline; } + + @Builder + public Subject(Dday dday, String headline) { + this.dday = dday; + this.headline = headline; + } } diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/repository/SubjectRepository.java b/src/main/java/efub/eday/edayback/domain/day/dday/repository/SubjectRepository.java index bf0b96c..957b683 100644 --- a/src/main/java/efub/eday/edayback/domain/day/dday/repository/SubjectRepository.java +++ b/src/main/java/efub/eday/edayback/domain/day/dday/repository/SubjectRepository.java @@ -1,9 +1,12 @@ package efub.eday.edayback.domain.day.dday.repository; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; +import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.dday.entity.Subject; public interface SubjectRepository extends JpaRepository<Subject, Integer> { - + Optional<Subject> findByDday(Dday dday); } diff --git a/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java b/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java index 8f0ad96..51d6e0b 100644 --- a/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java +++ b/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java @@ -5,8 +5,8 @@ /* { "memberId" : 1, - "queryContent" : "공강을 보내기 좋은 장소에 관련하여 문의 드립니다.", - "subjectId" : 1 + "queryContent" : "D-3 내용 문의드립니다!", + "dday" : 3 } */ @@ -14,5 +14,5 @@ public class QueryRequestDto { private int memberId; private String queryContent; - private int subjectId; + private int dday; } diff --git a/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java b/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java index 8725568..4a86ee0 100644 --- a/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java +++ b/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java @@ -3,6 +3,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.dday.entity.Subject; import efub.eday.edayback.domain.day.dday.repository.SubjectRepository; import efub.eday.edayback.domain.member.entity.Member; @@ -24,10 +25,12 @@ public class QueryService { public Query addQuery(QueryRequestDto requestDto) { Member writer = memberRepository.findById(requestDto.getMemberId()) - .orElseThrow(() -> new IllegalArgumentException("유효하지 않은 ID")); + .orElseThrow(() -> new IllegalArgumentException("유효하지 않은 ID입니다.")); - Subject subject = subjectRepository.findById(requestDto.getSubjectId()) - .orElseThrow(() -> new IllegalArgumentException("유효하지 않은 ID")); + Dday dday = Dday.fromRemainingDays(requestDto.getDday()); + + Subject subject = subjectRepository.findByDday(dday) + .orElseThrow(() -> new IllegalArgumentException("해당하는 Subject가 없습니다. dday: " + dday.getRemainingDays())); Query query = Query.builder() .content(requestDto.getQueryContent()) From a6a5ebae55f74f5ef87661c5b624a15d4a68ac77 Mon Sep 17 00:00:00 2001 From: hannah0226 <mohan0226@naver.com> Date: Sun, 23 Jul 2023 02:50:54 +0900 Subject: [PATCH 054/153] =?UTF-8?q?fix:=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EC=82=AC=ED=95=AD=20=EC=88=98=EC=9A=A9=20=EB=B0=8F?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/day/dday/entity/Subject.java | 2 ++ .../day/quiz/controller/QuizController.java | 5 +++-- .../domain/day/quiz/dto/OptionsResponseDto.java | 7 +++++-- .../domain/day/quiz/dto/QuizRequestDto.java | 2 +- .../edayback/domain/day/quiz/entity/Quiz.java | 10 ++++++++++ .../domain/day/quiz/service/QuizService.java | 16 ++++------------ .../day/title/repository/TitleRepository.java | 4 ++-- 7 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java index 7867c0e..27e2219 100644 --- a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java +++ b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java @@ -8,8 +8,10 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Table; +import lombok.Getter; import lombok.NoArgsConstructor; +@Getter @Entity @NoArgsConstructor @Table(name = "subjects") diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java index 5ff9cde..ef453b7 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java @@ -30,8 +30,9 @@ public QuizAnswerResponseDto checkAnswer( @PathVariable int d_day, @RequestBody QuizRequestDto quizRequestDto ) { - Long memberId = (Long) httpSession.getAttribute("memberId"); - boolean isCorrect = quizService.checkAnswer(d_day, quizRequestDto.getOptionId(), memberId); + Long memberId = (Long) httpSession.getAttribute("memberId"); //JwtProvider로 변경 예정 + + boolean isCorrect = quizService.checkAnswer(d_day, quizRequestDto.getOptionNumber(), memberId); String quizDescription = null; if (isCorrect) { quizDescription = quizService.getQuizDescription(d_day); diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java index d781d23..ab9b1e3 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java @@ -8,15 +8,18 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class OptionsResponseDto { + private Integer optionNumber; private String content; - private OptionsResponseDto(String content) { + private OptionsResponseDto(Integer optionNumber, String content) { + this.optionNumber = optionNumber; this.content = content; } public static OptionsResponseDto from(Option option) { return new OptionsResponseDto( - option.getContent() + option.getOptionNumber(), + option.getContent() ); } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizRequestDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizRequestDto.java index f8e4961..f2cd385 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizRequestDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizRequestDto.java @@ -4,5 +4,5 @@ @Getter public class QuizRequestDto { - private int optionId; + private int optionNumber; } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java index 7ac92a1..f3c764e 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java @@ -41,6 +41,16 @@ public class Quiz { @OneToMany(mappedBy = "quiz") private List<Option> optionList; + //퀴즈 정답 확인 로직 + public boolean isAnswerOption(int optionNumber){ + for(Option option : optionList){ + if(option.getOptionNumber() == optionNumber){ + return option.getIsAnswer(); + } + } + return false; + } + @Builder public Quiz(String content, String explanation, String imageUrl, Subject subject, List<Option> optionList) { this.content = content; diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java index bd26501..7683a2a 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java @@ -2,9 +2,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; - import efub.eday.edayback.domain.day.dday.entity.Dday; -import efub.eday.edayback.domain.day.quiz.entity.Options; import efub.eday.edayback.domain.day.quiz.entity.Quiz; import efub.eday.edayback.domain.day.quiz.repository.QuizRepository; import efub.eday.edayback.domain.day.title.entity.Title; @@ -33,21 +31,16 @@ public Quiz findQuiz(int d_day) { } //퀴즈 정답 확인 - public boolean checkAnswer(int d_day, int option_id, Long memberId) { + public boolean checkAnswer(int d_day, int optionNumber, Long memberId) { Quiz quiz = findQuiz(d_day); - boolean isCorrect = false; - for (Options option : quiz.getOptionsList()) { - if (option.getOptionNumber() == option_id) { - isCorrect = option.getIsAnswer(); - break; - } - } + boolean isCorrect = quiz.isAnswerOption(optionNumber); + //member title 찾는 로직 if (isCorrect) { Member member = memberRepository.findById(memberId) .orElseThrow(() -> new IllegalArgumentException("해당 멤버를 찾을 수 없습니다.")); - Long subjectId = quiz.getSubject().getId(); + Integer subjectId = quiz.getSubject().getId(); Title title = titleRepository.findBySubjectId(subjectId) .orElseThrow(() -> new IllegalArgumentException("해당 subject_id에 대한 타이틀을 찾을 수 없습니다.")); MemberTitle memberTitle = memberTitleRepository.findByMemberAndTitle(member, title) @@ -59,7 +52,6 @@ public boolean checkAnswer(int d_day, int option_id, Long memberId) { } //getTitle값 true로 변경 memberTitle.setGetTitle(true); - memberTitleRepository.save(memberTitle); } return isCorrect; } diff --git a/src/main/java/efub/eday/edayback/domain/day/title/repository/TitleRepository.java b/src/main/java/efub/eday/edayback/domain/day/title/repository/TitleRepository.java index 41fd83a..ca82959 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/repository/TitleRepository.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/repository/TitleRepository.java @@ -7,6 +7,6 @@ import java.util.Optional; @Repository -public interface TitleRepository extends JpaRepository<Title, Long> { - Optional<Title> findBySubjectId(Long subjectId); +public interface TitleRepository extends JpaRepository<Title, Integer> { + Optional<Title> findBySubjectId(Integer subjectId); } From 547e065be0d74e736e789be57da91abddd101b11 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:18:43 +0900 Subject: [PATCH 055/153] =?UTF-8?q?chore:=20OpenFeign=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/build.gradle b/build.gradle index 48400dc..3f1d861 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,16 @@ repositories { mavenCentral() } +ext { + set('springCloudVersion', "2021.0.8") +} + +dependencyManagement { + imports { + mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}" + } +} + dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-validation' @@ -29,6 +39,8 @@ dependencies { implementation 'io.jsonwebtoken:jjwt:0.9.1' implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.cloud:spring-cloud-starter-openfeign' + compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' From cf17e6e4ccfc7d0ac0c892fc6872f413356d8ac8 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:19:47 +0900 Subject: [PATCH 056/153] =?UTF-8?q?feat(FeignConfig):=20OpenFeign=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 로그 레벨 설정 - 모든 OpenFeign client에 Content-type 헤더 설정 --- .../eday/edayback/config/FeignConfig.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/efub/eday/edayback/config/FeignConfig.java diff --git a/src/main/java/efub/eday/edayback/config/FeignConfig.java b/src/main/java/efub/eday/edayback/config/FeignConfig.java new file mode 100644 index 0000000..f2aa3d2 --- /dev/null +++ b/src/main/java/efub/eday/edayback/config/FeignConfig.java @@ -0,0 +1,24 @@ +package efub.eday.edayback.config; + +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import feign.Logger; +import feign.RequestInterceptor; + +@Configuration +@EnableFeignClients("efub.eday.edayback.domain.member.auth.service.feign") +public class FeignConfig { + + @Bean + Logger.Level feignLoggerLevel() { + return Logger.Level.FULL; + } + + @Bean + public RequestInterceptor requestInterceptor() { + return requestTemplate -> requestTemplate.header("Content-type", + "application/x-www-form-urlencoded;charset=utf-8"); + } +} From 1ddf8b10112be14d5e51f40df1a3b079fa6f6a55 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:20:51 +0900 Subject: [PATCH 057/153] =?UTF-8?q?feat(KakaoAuthFeign):=20=EC=B9=B4?= =?UTF-8?q?=EC=B9=B4=EC=98=A4=20=ED=86=A0=ED=81=B0=20=EB=B0=9C=EA=B8=89?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=9C=20Feign=20Client=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 --- .../member/auth/service/feign/KakaoAuthFeign.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/efub/eday/edayback/domain/member/auth/service/feign/KakaoAuthFeign.java diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/feign/KakaoAuthFeign.java b/src/main/java/efub/eday/edayback/domain/member/auth/service/feign/KakaoAuthFeign.java new file mode 100644 index 0000000..9e156ac --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/auth/service/feign/KakaoAuthFeign.java @@ -0,0 +1,14 @@ +package efub.eday.edayback.domain.member.auth.service.feign; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.PostMapping; + +import efub.eday.edayback.domain.member.auth.dto.KakaoTokenRequestDto; +import efub.eday.edayback.domain.member.auth.dto.KakaoTokenResponseDto; + +@FeignClient(name = "KakaoAuthFeign", url = "https://kauth.kakao.com/oauth/token") +public interface KakaoAuthFeign { + + @PostMapping(consumes = "application/x-www-form-urlencoded") + KakaoTokenResponseDto getKakaoToken(KakaoTokenRequestDto requestDto); +} From 431030dbaefc519d2b73f2a19dd6cac0d4381390 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:21:58 +0900 Subject: [PATCH 058/153] =?UTF-8?q?feat(KakaoApiFeign):=20=EC=B9=B4?= =?UTF-8?q?=EC=B9=B4=EC=98=A4=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=EB=A5=BC=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?Feign=20Client=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/auth/service/feign/KakaoApiFeign.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/efub/eday/edayback/domain/member/auth/service/feign/KakaoApiFeign.java diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/feign/KakaoApiFeign.java b/src/main/java/efub/eday/edayback/domain/member/auth/service/feign/KakaoApiFeign.java new file mode 100644 index 0000000..fda5fed --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/auth/service/feign/KakaoApiFeign.java @@ -0,0 +1,15 @@ +package efub.eday.edayback.domain.member.auth.service.feign; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.http.HttpHeaders; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; + +import efub.eday.edayback.domain.member.auth.dto.KakaoProfileResponseDto; + +@FeignClient(name = "KakaoApiFeign", url = "https://kapi.kakao.com/v2/user/me") +public interface KakaoApiFeign { + + @GetMapping + KakaoProfileResponseDto getKakaoProfile(@RequestHeader HttpHeaders headers); +} From ccf0654c475105f32b2cdfd43252faad30e24df8 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:24:54 +0900 Subject: [PATCH 059/153] =?UTF-8?q?feat(Member):=20Member=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - email 필드 삭제 & loginId 필드 추가 - 빌더 수정 - 사용자 정보 업데이트 메소드(updateProfile) 추가 --- .../edayback/domain/member/entity/Member.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java index c817a5c..94f1d8f 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java @@ -1,6 +1,6 @@ package efub.eday.edayback.domain.member.entity; -import java.time.LocalDate; +import java.time.LocalDateTime; import javax.persistence.Column; import javax.persistence.Entity; @@ -30,7 +30,7 @@ public class Member { private String nickname; @Column(nullable = false) - private String email; + private Long loginId; @Column(name = "profile_image_url", nullable = false) private String profileImageUrl; @@ -46,11 +46,16 @@ public class Member { private Boolean isActive; @Builder - public Member(String nickname, String email, String profileImageUrl, Integer level, Boolean isActive) { + public Member(String nickname, Long loginId, String profileImageUrl) { + this.nickname = nickname; + this.loginId = loginId; + this.profileImageUrl = profileImageUrl; + this.level = 1; + this.isActive = true; + } + + public void updateProfile(String nickname, String profileImageUrl) { this.nickname = nickname; - this.email = email; this.profileImageUrl = profileImageUrl; - this.level = level; - this.isActive = isActive; } } From 8ba600cb2c2c6b568fc1d9404798eaa9882be837 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:25:54 +0900 Subject: [PATCH 060/153] =?UTF-8?q?feat(JwtProvider):=20JWT=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=B0=8F=20=EA=B4=80=EB=A6=AC=20=EB=A9=94=EC=86=8C?= =?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 --- .../member/auth/service/jwt/JwtProvider.java | 111 ++++++++++++++++++ .../domain/member/service/JwtProvider.java | 94 --------------- 2 files changed, 111 insertions(+), 94 deletions(-) create mode 100644 src/main/java/efub/eday/edayback/domain/member/auth/service/jwt/JwtProvider.java delete mode 100644 src/main/java/efub/eday/edayback/domain/member/service/JwtProvider.java diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/jwt/JwtProvider.java b/src/main/java/efub/eday/edayback/domain/member/auth/service/jwt/JwtProvider.java new file mode 100644 index 0000000..3c773e4 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/auth/service/jwt/JwtProvider.java @@ -0,0 +1,111 @@ +package efub.eday.edayback.domain.member.auth.service.jwt; + +import java.time.Duration; +import java.util.Base64; +import java.util.Date; + +import javax.annotation.PostConstruct; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jws; +import io.jsonwebtoken.Jwts; +import io.jsonwebtoken.SignatureAlgorithm; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RequiredArgsConstructor +@Service +public class JwtProvider { + private static final Long ACCESS_TOKEN_VALID_TIME = Duration.ofMinutes(30).toMillis(); // 만료시간 30분 + private static final Long REFRESH_TOKEN_VALID_TIME = Duration.ofDays(14).toMillis(); // 만료시간 2주 + private static final String MEMBER_ID = "memberId"; + private static final String TOKEN_TYPE = "type"; + + @Value("${jwt.secret}") + private String secretKey; + + @PostConstruct + private void initSecretKey() { + secretKey = Base64.getEncoder().encodeToString(secretKey.getBytes()); + } + + // JWT 생성 + private String createJwt(Long memberId, String type, Long tokenValidTime) { + Claims claims = Jwts.claims(); + claims.put(MEMBER_ID, memberId); + + return Jwts.builder() + .setHeaderParam("type", type) + .setClaims(claims) + .setIssuedAt(new Date(System.currentTimeMillis())) + .setExpiration(new Date(System.currentTimeMillis() + tokenValidTime)) + .signWith(SignatureAlgorithm.HS256, secretKey) + .compact(); + } + + // access 토큰 생성 + public String createAccessToken(Long memberId) { + return createJwt(memberId, TokenType.REFRESH.type, ACCESS_TOKEN_VALID_TIME); + } + + // refresh 토큰 생성 + public String createRefreshToken(Long memberId) { + return createJwt(memberId, TokenType.REFRESH.type, REFRESH_TOKEN_VALID_TIME); + } + + // 회원 정보 조회 + public Long getMemberId(String token) { + return Jwts.parser() + .setSigningKey(secretKey) + .parseClaimsJws(token) + .getBody() + .get(MEMBER_ID, Long.class); + } + + // 토큰 유효 및 만료 확인 + public boolean isExpired(String token) { + try { + Jws<Claims> claimsJws = Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token); + return claimsJws.getBody().getExpiration().before(new Date()); + } catch (Exception e) { + log.error(e.getMessage()); + return false; + } + } + + // refresh 토큰 확인 + public boolean isRefreshToken(String token) { + String tokenType = Jwts.parser() + .setSigningKey(secretKey) + .parseClaimsJws(token) + .getHeader() + .get(TOKEN_TYPE).toString(); + return tokenType.equals(TokenType.REFRESH.type); + } + + // access 토큰 확인 + public boolean isAccessToken(String token) { + String tokenType = Jwts.parser() + .setSigningKey(secretKey) + .parseClaimsJws(token) + .getHeader() + .get(TOKEN_TYPE).toString(); + return tokenType.equals(TokenType.ACCESS.type); + } + + private enum TokenType { + ACCESS("access"), + REFRESH("refresh"); + + private final String type; + + TokenType(String type) { + this.type = type; + } + } + +} diff --git a/src/main/java/efub/eday/edayback/domain/member/service/JwtProvider.java b/src/main/java/efub/eday/edayback/domain/member/service/JwtProvider.java deleted file mode 100644 index 8fa0989..0000000 --- a/src/main/java/efub/eday/edayback/domain/member/service/JwtProvider.java +++ /dev/null @@ -1,94 +0,0 @@ -package efub.eday.edayback.domain.member.service; - -import java.time.Duration; -import java.util.Date; - -import org.springframework.stereotype.Service; - -import io.jsonwebtoken.Claims; -import io.jsonwebtoken.Header; -import io.jsonwebtoken.Jwts; -import io.jsonwebtoken.SignatureAlgorithm; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -@RequiredArgsConstructor -@Service -public class JwtProvider { - private static final Long accessTokenValidTime = Duration.ofMinutes(30).toMillis(); // 만료시간 30분 - private static final Long refreshTokenValidTime = Duration.ofDays(14).toMillis(); // 만료시간 2주 - - // 회원 정보 조회 - public static Long getUserId(String token, String secretKey) { - return Jwts.parser() - .setSigningKey(secretKey) - .parseClaimsJws(token) - .getBody() - .get("userId", Long.class); - } - - // 토큰 유효 및 만료 확인 - public static boolean isExpired(String token, String secretKey) { - - // try { - Claims claims = Jwts.parser() - .setSigningKey(secretKey) - .parseClaimsJws(token) - .getBody(); - return false; - } - - // refresh 토큰 확인 - public static boolean isRefreshToken(String token, String secretKey) { - - Header header = Jwts.parser() - .setSigningKey(secretKey) - .parseClaimsJws(token) - .getHeader(); - - if (header.get("type").toString().equals("refresh")) { - return true; - } - return false; - } - - // access 토큰 확인 - public static boolean isAccessToken(String token, String secretKey) { - - Header header = Jwts.parser() - .setSigningKey(secretKey) - .parseClaimsJws(token) - .getHeader(); - - if (header.get("type").toString().equals("access")) { - return true; - } - return false; - } - - // access 토큰 생성 - public static String createAccessToken(Long userId, String secretKey) { - return createJwt(userId, secretKey, "access", accessTokenValidTime); - } - - // refresh 토큰 생성 - public static String createRefreshToken(Long userId, String secretKey) { - return createJwt(userId, secretKey, "refresh", refreshTokenValidTime); - } - - public static String createJwt(Long userId, String secretKey, String type, Long tokenValidTime) { - Claims claims = Jwts.claims(); - claims.put("userId", userId); - - return Jwts.builder() - .setHeaderParam("type", type) - .setClaims(claims) - .setIssuedAt(new Date(System.currentTimeMillis())) - .setExpiration(new Date(System.currentTimeMillis() + tokenValidTime)) - .signWith(SignatureAlgorithm.HS256, secretKey) - .compact() - ; - } - -} From c685f6a16ef92b23d39f9c6f6a7affa2617ca7ab Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:26:52 +0900 Subject: [PATCH 061/153] =?UTF-8?q?feat(MemberRepository):=20email=20?= =?UTF-8?q?=EA=B8=B0=EC=A4=80=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=20=EB=B0=8F=20loginId=20=EA=B8=B0=EC=A4=80?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/member/repository/MemberRepository.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/repository/MemberRepository.java b/src/main/java/efub/eday/edayback/domain/member/repository/MemberRepository.java index 6fbfb89..444cd41 100644 --- a/src/main/java/efub/eday/edayback/domain/member/repository/MemberRepository.java +++ b/src/main/java/efub/eday/edayback/domain/member/repository/MemberRepository.java @@ -1,5 +1,7 @@ package efub.eday.edayback.domain.member.repository; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -7,7 +9,6 @@ @Repository public interface MemberRepository extends JpaRepository<Member, Long> { - Member findByEmail(String email); - boolean existsByEmail(String email); + Optional<Member> findByLoginId(Long loginId); } From f74d6f8e829d062cbe15d587adb94e43f0f1e827 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:28:17 +0900 Subject: [PATCH 062/153] =?UTF-8?q?feat:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=EC=9A=94=EC=B2=AD=20=EB=B0=8F=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20DTO=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/auth/dto/KakaoTokenRequestDto.java | 16 ++++++++++++++++ .../member/auth/dto/KakaoTokenResponseDto.java | 18 ++++++++++++++++++ .../domain/member/entity/oauth/OAuthToken.java | 13 ------------- 3 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoTokenRequestDto.java create mode 100644 src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoTokenResponseDto.java delete mode 100644 src/main/java/efub/eday/edayback/domain/member/entity/oauth/OAuthToken.java diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoTokenRequestDto.java b/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoTokenRequestDto.java new file mode 100644 index 0000000..06efa50 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoTokenRequestDto.java @@ -0,0 +1,16 @@ +package efub.eday.edayback.domain.member.auth.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +@AllArgsConstructor +public class KakaoTokenRequestDto { + + private String grant_type; + private String client_id; + private String redirect_uri; + private String code; +} diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoTokenResponseDto.java b/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoTokenResponseDto.java new file mode 100644 index 0000000..ab8d77f --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoTokenResponseDto.java @@ -0,0 +1,18 @@ +package efub.eday.edayback.domain.member.auth.dto; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class KakaoTokenResponseDto { + + private String token_type; + private String access_token; + private int expires_in; + private String refresh_token; + private int refresh_token_expires_in; + private String scope; +} diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/oauth/OAuthToken.java b/src/main/java/efub/eday/edayback/domain/member/entity/oauth/OAuthToken.java deleted file mode 100644 index f2ee8a9..0000000 --- a/src/main/java/efub/eday/edayback/domain/member/entity/oauth/OAuthToken.java +++ /dev/null @@ -1,13 +0,0 @@ -package efub.eday.edayback.domain.member.entity.oauth; - -import lombok.Data; - -@Data -public class OAuthToken { - private String access_token; - private String token_type; - private String refresh_token; - private int expires_in; - private String scope; - private int refresh_token_expires_in; -} From 69554152ff8396c90d541ad2cdae2d40230d7fa7 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:29:10 +0900 Subject: [PATCH 063/153] =?UTF-8?q?feat(KakaoProfileResponseDto):=20?= =?UTF-8?q?=EC=B9=B4=EC=B9=B4=EC=98=A4=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20DTO=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/dto/KakaoProfileResponseDto.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoProfileResponseDto.java diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoProfileResponseDto.java b/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoProfileResponseDto.java new file mode 100644 index 0000000..14d7d23 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoProfileResponseDto.java @@ -0,0 +1,39 @@ +package efub.eday.edayback.domain.member.auth.dto; + +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Setter +@NoArgsConstructor +public class KakaoProfileResponseDto { + + private Long id; + private KakaoAccount kakao_account; + + @Setter + @NoArgsConstructor + public class KakaoAccount { + + private Profile profile; + + @Setter + @NoArgsConstructor + public class Profile { + private String nickname; + private String profile_image_url; + private Boolean is_default_image; + } + } + + public Long getId() { + return id; + } + + public String getNickname() { + return kakao_account.profile.nickname; + } + + public String getProfileImageUrl() { + return kakao_account.profile.profile_image_url; + } +} From eede9893850af896419e4f5f270e2b1636f4ae87 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:30:15 +0900 Subject: [PATCH 064/153] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EC=9A=94=EC=B2=AD=20=EB=B0=8F=20=EC=9D=91=EB=8B=B5?= =?UTF-8?q?=20DTO=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/auth/dto/AuthRequestDto.java | 12 +++++++++ .../member/auth/dto/AuthResponseDto.java | 26 +++++++++++++++++++ .../domain/member/dto/LoginResponseDto.java | 21 --------------- 3 files changed, 38 insertions(+), 21 deletions(-) create mode 100644 src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthRequestDto.java create mode 100644 src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthResponseDto.java delete mode 100644 src/main/java/efub/eday/edayback/domain/member/dto/LoginResponseDto.java diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthRequestDto.java b/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthRequestDto.java new file mode 100644 index 0000000..6c69190 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthRequestDto.java @@ -0,0 +1,12 @@ +package efub.eday.edayback.domain.member.auth.dto; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class AuthRequestDto { + + private String code; +} diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthResponseDto.java b/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthResponseDto.java new file mode 100644 index 0000000..4151692 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthResponseDto.java @@ -0,0 +1,26 @@ +package efub.eday.edayback.domain.member.auth.dto; + +import efub.eday.edayback.domain.member.entity.Member; +import lombok.Builder; +import lombok.Getter; + +@Getter +public class AuthResponseDto { + + private Long memberId; + private String nickname; + private String profileImage; + private Integer level; + private String accessToken; + private String refreshToken; + + @Builder + public AuthResponseDto(Member member, String accessToken, String refreshToken) { + this.memberId = member.getId(); + this.nickname = member.getNickname(); + this.profileImage = member.getProfileImageUrl(); + this.level = member.getLevel(); + this.accessToken = accessToken; + this.refreshToken = refreshToken; + } +} diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/LoginResponseDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/LoginResponseDto.java deleted file mode 100644 index 058cbea..0000000 --- a/src/main/java/efub/eday/edayback/domain/member/dto/LoginResponseDto.java +++ /dev/null @@ -1,21 +0,0 @@ -package efub.eday.edayback.domain.member.dto; - -import efub.eday.edayback.domain.member.entity.Member; -import lombok.Builder; -import lombok.Getter; - -@Getter -public class LoginResponseDto { - private Long memberId; - private String email; - private String nickname; - private String accessToken; - - @Builder - public LoginResponseDto(Member member, String accessToken) { - this.memberId = member.getId(); - this.email = member.getEmail(); - this.nickname = member.getNickname(); - this.accessToken = accessToken; - } -} From 8f7aef59cfe16d3bf5c3b3a02f7df2f96026b56e Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:31:22 +0900 Subject: [PATCH 065/153] =?UTF-8?q?feat(AuthService):=20=EC=B9=B4=EC=B9=B4?= =?UTF-8?q?=EC=98=A4=20OAuth=20=EB=B0=8F=20=EC=9D=B4=EB=8D=B0=EC=9D=B4=20?= =?UTF-8?q?=ED=9A=8C=EC=9B=90=EA=B0=80=EC=9E=85=EA=B3=BC=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/auth/service/AuthService.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java new file mode 100644 index 0000000..2b93c88 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java @@ -0,0 +1,95 @@ +package efub.eday.edayback.domain.member.auth.service; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import org.springframework.stereotype.Service; + +import efub.eday.edayback.domain.member.auth.dto.AuthResponseDto; +import efub.eday.edayback.domain.member.auth.dto.KakaoProfileResponseDto; +import efub.eday.edayback.domain.member.auth.dto.KakaoTokenRequestDto; +import efub.eday.edayback.domain.member.auth.dto.KakaoTokenResponseDto; +import efub.eday.edayback.domain.member.auth.service.feign.KakaoApiFeign; +import efub.eday.edayback.domain.member.auth.service.feign.KakaoAuthFeign; +import efub.eday.edayback.domain.member.auth.service.jwt.JwtProvider; +import efub.eday.edayback.domain.member.entity.Member; +import efub.eday.edayback.domain.member.repository.MemberRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +@RequiredArgsConstructor +public class AuthService { + + private static final String GRANT_TYPE_VALUE = "authorization_code"; + private static final String BEARER = "Bearer "; + + private final KakaoAuthFeign kakaoAuthFeign; + private final KakaoApiFeign kakaoApiFeign; + private final MemberRepository memberRepository; + private final JwtProvider jwtProvider; + + @Value("${kakao.client-id}") + private String clientId; + + @Value("${kakao.redirect-uri}") + private String redirectUri; + + public AuthResponseDto signIn(String code) { + String kakaoToken = getKakaoToken(code); + log.debug("kakaoToken: {}", kakaoToken); + Member member = getKakaoProfile(kakaoToken); + log.debug("member login: {} {}", member.getId(), member.getNickname()); + String accessToken = jwtProvider.createAccessToken(member.getId()); + String refreshToken = jwtProvider.createRefreshToken(member.getId()); + AuthResponseDto authResponseDto = AuthResponseDto.builder() + .member(member) + .accessToken(accessToken) + .refreshToken(refreshToken) + .build(); + log.debug("nickname: {} / access: {} / refresh: {}", authResponseDto.getNickname(), + authResponseDto.getAccessToken(), authResponseDto.getRefreshToken()); + return authResponseDto; + } + + private String getKakaoToken(String code) { + KakaoTokenResponseDto tokenResponseDto = kakaoAuthFeign.getKakaoToken( + KakaoTokenRequestDto.builder() + .grant_type(GRANT_TYPE_VALUE) + .client_id(clientId) + .redirect_uri(redirectUri) + .code(code) + .build() + ); + return tokenResponseDto.getAccess_token(); + } + + private Member getKakaoProfile(String kakaoToken) { + HttpHeaders httpHeaders = new HttpHeaders(); + httpHeaders.add(HttpHeaders.AUTHORIZATION, BEARER + kakaoToken); + KakaoProfileResponseDto kakaoProfile = kakaoApiFeign.getKakaoProfile(httpHeaders); + + log.debug("카카오 프로필: {}", kakaoProfile.getNickname()); + + Long loginId = kakaoProfile.getId(); + String nickname = kakaoProfile.getNickname(); + String profileImageUrl = kakaoProfile.getProfileImageUrl(); + + Member member = memberRepository.findByLoginId(loginId).orElse(null); + if (member != null) { + member.updateProfile(nickname, profileImageUrl); + return member; + } + member = Member.builder() + .loginId(loginId) + .nickname(nickname) + .profileImageUrl(profileImageUrl) + .build(); + signUp(member); + return member; + } + + private void signUp(Member member) { + memberRepository.save(member); + } +} From ca505e49085bc18a3dc151a9c61858dadcff13de Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:33:17 +0900 Subject: [PATCH 066/153] =?UTF-8?q?feat(AuthController):=20=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=EA=B0=80=EC=9E=85=20=EB=B0=8F=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=B2=98=EB=A6=AC=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/controller/AuthController.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/efub/eday/edayback/domain/member/auth/controller/AuthController.java diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/controller/AuthController.java b/src/main/java/efub/eday/edayback/domain/member/auth/controller/AuthController.java new file mode 100644 index 0000000..c5cb027 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/auth/controller/AuthController.java @@ -0,0 +1,27 @@ +package efub.eday.edayback.domain.member.auth.controller; + +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 efub.eday.edayback.domain.member.auth.dto.AuthRequestDto; +import efub.eday.edayback.domain.member.auth.dto.AuthResponseDto; +import efub.eday.edayback.domain.member.auth.service.AuthService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@RestController +@RequiredArgsConstructor +@RequestMapping("/member/auth") +public class AuthController { + + private final AuthService authService; + + @PostMapping + public AuthResponseDto login(@RequestBody AuthRequestDto authRequestDto) { + return authService.signIn(authRequestDto.getCode()); + } + +} From 87fd2d8c67cbde20f74187ca0007e95821dff0e8 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:38:06 +0900 Subject: [PATCH 067/153] =?UTF-8?q?feat:=20JWT=20=ED=95=84=ED=84=B0=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 - jwt secret key 위치 이동 (JwtFilter -> JwtProvider) - 패키지 위치 변경 --- .../config/JwtExceptionFilter.java | 11 +-- .../{domain => }/config/JwtFilter.java | 71 +++++++++---------- 2 files changed, 38 insertions(+), 44 deletions(-) rename src/main/java/efub/eday/edayback/{domain => }/config/JwtExceptionFilter.java (80%) rename src/main/java/efub/eday/edayback/{domain => }/config/JwtFilter.java (58%) diff --git a/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java b/src/main/java/efub/eday/edayback/config/JwtExceptionFilter.java similarity index 80% rename from src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java rename to src/main/java/efub/eday/edayback/config/JwtExceptionFilter.java index 39d39a9..c03daa3 100644 --- a/src/main/java/efub/eday/edayback/domain/config/JwtExceptionFilter.java +++ b/src/main/java/efub/eday/edayback/config/JwtExceptionFilter.java @@ -1,4 +1,4 @@ -package efub.eday.edayback.domain.config; +package efub.eday.edayback.config; import java.io.IOException; @@ -9,17 +9,14 @@ import org.springframework.web.filter.OncePerRequestFilter; -import com.fasterxml.jackson.databind.ObjectMapper; - import efub.eday.edayback.domain.global.exception.CustomException; import io.jsonwebtoken.JwtException; -import lombok.RequiredArgsConstructor; +import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; -@RequiredArgsConstructor +@NoArgsConstructor @Slf4j public class JwtExceptionFilter extends OncePerRequestFilter { - private final ObjectMapper objectMapper; @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, @@ -29,10 +26,8 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse filterChain.doFilter(request, response); } catch (JwtException e) { log.error("[-] Invalid Token"); - } catch (CustomException e) { log.error(e.getMessage()); - } } diff --git a/src/main/java/efub/eday/edayback/domain/config/JwtFilter.java b/src/main/java/efub/eday/edayback/config/JwtFilter.java similarity index 58% rename from src/main/java/efub/eday/edayback/domain/config/JwtFilter.java rename to src/main/java/efub/eday/edayback/config/JwtFilter.java index d170f55..706ef49 100644 --- a/src/main/java/efub/eday/edayback/domain/config/JwtFilter.java +++ b/src/main/java/efub/eday/edayback/config/JwtFilter.java @@ -1,4 +1,4 @@ -package efub.eday.edayback.domain.config; +package efub.eday.edayback.config; import java.io.IOException; import java.util.List; @@ -15,74 +15,73 @@ import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; import org.springframework.web.filter.OncePerRequestFilter; -import efub.eday.edayback.domain.global.exception.CustomErrorCode; -import efub.eday.edayback.domain.global.exception.CustomException; -import efub.eday.edayback.domain.member.service.JwtProvider; -import io.jsonwebtoken.JwtException; +import efub.eday.edayback.jwt.JwtProvider; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @RequiredArgsConstructor @Slf4j public class JwtFilter extends OncePerRequestFilter { - private final String secretKey; + + private static final String BEARER = "Bearer"; + private static final String BLANK = " "; + private static final String USER_ROLE = "USER"; + + private final JwtProvider jwtProvider; @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { - String path = request.getServletPath(); + final String authorization = request.getHeader(HttpHeaders.AUTHORIZATION); + log.debug("authorization : {}", authorization); + log.debug(request.getServletPath()); - // 로그인일 경우 건너뛰기 - if ( - path.startsWith("로그인 요청 API") - ) { + if (authorization == null || !authorization.startsWith(BEARER)) { + SecurityContextHolder.getContext().setAuthentication(null); filterChain.doFilter(request, response); return; } - final String authorization = request.getHeader(HttpHeaders.AUTHORIZATION); - log.info("authorization : {}", authorization); - - if (authorization == null || !authorization.startsWith("Bearer ")) { - throw new CustomException(CustomErrorCode.INVALID_AUTH); - } - // Token 꺼내기 - String token = authorization.split(" ")[1]; + String token = authorization.split(BLANK)[1]; // Token Expired 되었는지 여부 - if (JwtProvider.isExpired(token, secretKey)) { + if (jwtProvider.isExpired(token)) { filterChain.doFilter(request, response); return; } - // UserId Token에서 꺼내기 - Long userId = JwtProvider.getUserId(token, secretKey); - log.info("userName: {}", userId); + // memberId Token에서 꺼내기 + Long memberId = jwtProvider.getMemberId(token); + log.debug("memberId: {}", memberId); + log.debug("isAccess: {} / token: {}", jwtProvider.isAccessToken(token), token); // 토큰 재발급일 경우 리프레쉬 토큰 확인 // 위에서 만료됐는지 확인했기 때문에 따로 만료확인 필요 없음 // 리프레쉬 토큰이 유효한지와 path 정보를 통해 확인이 끝났기 때문에 컨트롤러에서는 바로 토큰 재발행해주고 보내주면 됨 - if ( - !( - (path.startsWith("토큰 재발행 API") && JwtProvider.isRefreshToken(token, secretKey)) - || JwtProvider.isAccessToken(token, secretKey) - ) - ) { - // 재발행 요청 api인데, access token을 전달했을 경우 - // 아니면 access token을 넣어줘야하는데, 다른 토큰을 넣었을 경우 - throw new JwtException(""); - } + // if ( + // !( + // (path.startsWith("토큰 재발행 API") && jwtProvider.isRefreshToken(token)) + // || jwtProvider.isAccessToken(token) + // ) + // ) { + // // 재발행 요청 api인데, access token을 전달했을 경우 + // // 아니면 access token을 넣어줘야하는데, 다른 토큰을 넣었을 경우 + // throw new JwtException(""); + // } // 권한 부여 - UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(userId, null, - List.of(new SimpleGrantedAuthority("USER"))); + UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken( + memberId, + null, + List.of(new SimpleGrantedAuthority(USER_ROLE))); // Detail을 넣어줌 authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); SecurityContextHolder.getContext().setAuthentication(authenticationToken); - log.info("[+] Token in SecurityContextHolder"); + log.debug("[+] Token in SecurityContextHolder"); + filterChain.doFilter(request, response); } } From fed44b48f8d35b2c86d64eb920dfe578a10d3c6b Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:40:18 +0900 Subject: [PATCH 068/153] =?UTF-8?q?feat(AuthenticationConfig):=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=EC=9D=B4=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C=20?= =?UTF-8?q?=EA=B2=BD=EB=A1=9C=20=EC=84=A4=EC=A0=95=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 회원가입 및 로그인 경로(/member/auth)만 인증이 불필요하도록 변경 --- .../config/AuthenticationConfig.java | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) rename src/main/java/efub/eday/edayback/{domain => }/config/AuthenticationConfig.java (50%) diff --git a/src/main/java/efub/eday/edayback/domain/config/AuthenticationConfig.java b/src/main/java/efub/eday/edayback/config/AuthenticationConfig.java similarity index 50% rename from src/main/java/efub/eday/edayback/domain/config/AuthenticationConfig.java rename to src/main/java/efub/eday/edayback/config/AuthenticationConfig.java index 30ab54f..42bf98c 100644 --- a/src/main/java/efub/eday/edayback/domain/config/AuthenticationConfig.java +++ b/src/main/java/efub/eday/edayback/config/AuthenticationConfig.java @@ -1,6 +1,5 @@ -package efub.eday.edayback.domain.config; +package efub.eday.edayback.config; -import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; @@ -9,35 +8,33 @@ import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; -import com.fasterxml.jackson.databind.ObjectMapper; - -import efub.eday.edayback.domain.member.service.MemberService; +import efub.eday.edayback.jwt.JwtProvider; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @Configuration +@RequiredArgsConstructor @EnableWebSecurity public class AuthenticationConfig { - MemberService memberService; - - @Value("${spring.jwt.secret}") - private String secretKey; - private final ObjectMapper objectMapper = new ObjectMapper(); + private final JwtProvider jwtProvider; @Bean public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception { return httpSecurity .httpBasic().disable() .csrf().disable() - .cors().and() - .authorizeRequests() - .antMatchers("/members/**", "/infos/**", "querys/**", "titles/**", "quiz/**").permitAll() + .cors() .and() - .sessionManagement() - .sessionCreationPolicy(SessionCreationPolicy.STATELESS) // jwt 사용하는 경우 사용 + .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) // 세션 대신 jwt 사용하는 경우 사용 + .and() + .authorizeRequests() + .antMatchers("/member/auth").permitAll() + .anyRequest().authenticated() .and() - .addFilterBefore(new JwtFilter(secretKey), UsernamePasswordAuthenticationFilter.class) - .addFilterBefore(new JwtExceptionFilter(objectMapper), JwtFilter.class) - .build() - ; + .addFilterBefore(new JwtFilter(jwtProvider), UsernamePasswordAuthenticationFilter.class) + .addFilterBefore(new JwtExceptionFilter(), JwtFilter.class) + .build(); } } From 71560e8200dd6472b6a3db9dbf4dd141f9a5fc22 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:41:25 +0900 Subject: [PATCH 069/153] =?UTF-8?q?fix(Member):=20createDate=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=ED=83=80=EC=9E=85=20LocalDate=20->=20LocalDateTime?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - @CreationTimestamp로 생성하는데 LocalDate 타입이어서 오류 발생 --- .../java/efub/eday/edayback/domain/member/entity/Member.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java index 94f1d8f..8a1471f 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java @@ -40,7 +40,7 @@ public class Member { @CreationTimestamp //insert할 때 자동 날짜 적용 @Column(nullable = false) - private LocalDate createdDate; + private LocalDateTime createdDate; @Column(nullable = false) private Boolean isActive; From 0c3f3e7dee9794172827be317c830dd49a3759c0 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:42:01 +0900 Subject: [PATCH 070/153] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EB=B0=8F=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 18 +-- .../member/entity/oauth/KakaoProfile.java | 38 ------ .../domain/member/service/MemberService.java | 121 ------------------ 3 files changed, 3 insertions(+), 174 deletions(-) delete mode 100644 src/main/java/efub/eday/edayback/domain/member/entity/oauth/KakaoProfile.java diff --git a/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java b/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java index 0ae4666..d8f4b07 100644 --- a/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java +++ b/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java @@ -1,27 +1,15 @@ package efub.eday.edayback.domain.member.controller; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import efub.eday.edayback.domain.member.dto.LoginResponseDto; -import efub.eday.edayback.domain.member.entity.Member; -import efub.eday.edayback.domain.member.service.MemberService; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @RestController @RequiredArgsConstructor -@RequestMapping("/members") +@RequestMapping("/member") public class MemberController { - private final MemberService memberService; - - @GetMapping("/oauth") - public LoginResponseDto kakaoLogin(@RequestParam String code) { - System.out.println("HI"); - Member member = memberService.getAccessToken(code); - System.out.println(member); - return memberService.login(member); - } } diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/oauth/KakaoProfile.java b/src/main/java/efub/eday/edayback/domain/member/entity/oauth/KakaoProfile.java deleted file mode 100644 index 4750e1c..0000000 --- a/src/main/java/efub/eday/edayback/domain/member/entity/oauth/KakaoProfile.java +++ /dev/null @@ -1,38 +0,0 @@ -package efub.eday.edayback.domain.member.entity.oauth; - -import lombok.Data; - -@Data -public class KakaoProfile { - public Long id = null; - public String connected_at; - public Properties properties; - public KakaoAccount kakao_account; - - @Data - public class Properties { - public String nickname; - public String profile_image; - public String thumbnail_image; - } - - @Data - public class KakaoAccount { - public Boolean profile_nickname_needs_agreement; - public Boolean profile_image_needs_agreement; - public Profile profile; - public Boolean has_email; - public Boolean email_needs_agreement; - public Boolean is_email_valid; - public Boolean is_email_verified; - public String email; - - @Data - public class Profile { - public String nickname; - public String thumbnail_image_url; - public String profile_image_url; - public Boolean is_default_image; - } - } -} diff --git a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java index 0efdbb1..d3568a1 100644 --- a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java +++ b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java @@ -1,25 +1,7 @@ package efub.eday.edayback.domain.member.service; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.client.RestTemplate; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -import efub.eday.edayback.domain.member.dto.LoginResponseDto; -import efub.eday.edayback.domain.member.entity.Member; -import efub.eday.edayback.domain.member.entity.oauth.KakaoProfile; -import efub.eday.edayback.domain.member.entity.oauth.OAuthToken; -import efub.eday.edayback.domain.member.repository.MemberRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -28,107 +10,4 @@ @Service public class MemberService { - private final MemberRepository memberRepository; - private final JwtProvider jwtProvider; - - @Value("${spring.jwt.secret}") - private String secretKey; - - public Member getAccessToken(String code) { - - RestTemplate rt = new RestTemplate(); - - HttpHeaders headers = new HttpHeaders(); - headers.add("Content-type", "application/x-www-form-urlencoded;charset=utf-8"); - - MultiValueMap<String, String> params = new LinkedMultiValueMap<>(); - params.add("grant_type", "authorization_code"); - params.add("client_id", "24964b4a10d417e6a957b25423a635a5"); - params.add("redirect_uri", "http://localhost:8080/members/oauth"); - params.add("code", code); - - //아래 exchange 함수에 하나의 object로 넣기 위해 합치기 - HttpEntity<MultiValueMap<String, String>> kakaoTokenRequest = new HttpEntity<>(params, headers); - - ResponseEntity<String> response = rt.exchange( - "https://kauth.kakao.com/oauth/token", - HttpMethod.POST, - kakaoTokenRequest, - String.class - ); - - ObjectMapper objectMapper = new ObjectMapper(); - OAuthToken oauthToken = null; - try { - oauthToken = objectMapper.readValue(response.getBody(), OAuthToken.class); - } catch (JsonMappingException e) { - e.printStackTrace(); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - System.out.println(oauthToken); - - return findProfile(oauthToken); - - } - - private Member findProfile(OAuthToken oauthToken) { - //토큰 이용하여 사용자 정보 조회 - RestTemplate rt2 = new RestTemplate(); - - HttpHeaders headers2 = new HttpHeaders(); - headers2.add("Authorization", "Bearer " + oauthToken.getAccess_token()); - headers2.add("Content-type", "application/x-www-form-urlencoded;charset=utf-8"); - - HttpEntity<MultiValueMap<String, String>> kakaoProfileRequest2 = new HttpEntity<>(headers2); - - ResponseEntity<String> response2 = rt2.exchange( - "https://kapi.kakao.com/v2/user/me", - HttpMethod.POST, - kakaoProfileRequest2, - String.class - ); - - ObjectMapper objectMapper2 = new ObjectMapper(); - KakaoProfile kakaoProfile = null; - try { - kakaoProfile = objectMapper2.readValue(response2.getBody(), KakaoProfile.class); - } catch (JsonMappingException e) { - e.printStackTrace(); - } catch (JsonProcessingException e) { - e.printStackTrace(); - } - System.out.println(kakaoProfile); - return saveMember(kakaoProfile); - } - - public Member saveMember(@RequestBody KakaoProfile kakaoProfile) { - //Member 저장 - Member kakaoMember = memberRepository.findByEmail(kakaoProfile.getKakao_account().getEmail()); - - if (kakaoMember == null) { - //기존 회원이 아닐경우 자동으로 회원가입 - kakaoMember = Member.builder() - .nickname(kakaoProfile.getKakao_account().profile.nickname) - .email(kakaoProfile.getKakao_account().getEmail()) - .profileImageUrl(kakaoProfile.getKakao_account().profile.profile_image_url) - .level(0) //level은 0에서부터 시작 - .isActive(true) //처음 회원가입하면 활성 상태로 시작 - .build(); - memberRepository.save(kakaoMember); - } - System.out.println(kakaoMember); - return kakaoMember; - } - - public LoginResponseDto login(Member member) { - String authToken = jwtProvider.createAccessToken(member.getId(), secretKey); - LoginResponseDto loginResponseDto = LoginResponseDto.builder() - .member(member) - .accessToken(authToken) - .build(); - System.out.println(loginResponseDto); - return loginResponseDto; - } - } From 18d1f2b2f0a2e77c07ec6ee4193008f98c371f8f Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 03:43:27 +0900 Subject: [PATCH 071/153] =?UTF-8?q?refactor:=20=ED=94=84=EB=A1=9C=EC=A0=9D?= =?UTF-8?q?=ED=8A=B8=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - config / domain / feign / jwt 로 구조화 --- .../efub/eday/edayback/config/AuthenticationConfig.java | 2 ++ src/main/java/efub/eday/edayback/config/FeignConfig.java | 2 +- .../edayback/domain/member/auth/service/AuthService.java | 6 +++--- .../member/auth/service => }/feign/KakaoApiFeign.java | 2 +- .../member/auth/service => }/feign/KakaoAuthFeign.java | 2 +- .../eday/edayback/{config => jwt}/JwtExceptionFilter.java | 2 +- .../java/efub/eday/edayback/{config => jwt}/JwtFilter.java | 3 +-- .../{domain/member/auth/service => }/jwt/JwtProvider.java | 2 +- 8 files changed, 11 insertions(+), 10 deletions(-) rename src/main/java/efub/eday/edayback/{domain/member/auth/service => }/feign/KakaoApiFeign.java (89%) rename src/main/java/efub/eday/edayback/{domain/member/auth/service => }/feign/KakaoAuthFeign.java (89%) rename src/main/java/efub/eday/edayback/{config => jwt}/JwtExceptionFilter.java (96%) rename src/main/java/efub/eday/edayback/{config => jwt}/JwtFilter.java (97%) rename src/main/java/efub/eday/edayback/{domain/member/auth/service => }/jwt/JwtProvider.java (98%) diff --git a/src/main/java/efub/eday/edayback/config/AuthenticationConfig.java b/src/main/java/efub/eday/edayback/config/AuthenticationConfig.java index 42bf98c..2cfdf2d 100644 --- a/src/main/java/efub/eday/edayback/config/AuthenticationConfig.java +++ b/src/main/java/efub/eday/edayback/config/AuthenticationConfig.java @@ -8,6 +8,8 @@ import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; +import efub.eday.edayback.jwt.JwtExceptionFilter; +import efub.eday.edayback.jwt.JwtFilter; import efub.eday.edayback.jwt.JwtProvider; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/efub/eday/edayback/config/FeignConfig.java b/src/main/java/efub/eday/edayback/config/FeignConfig.java index f2aa3d2..4a87bf4 100644 --- a/src/main/java/efub/eday/edayback/config/FeignConfig.java +++ b/src/main/java/efub/eday/edayback/config/FeignConfig.java @@ -8,7 +8,7 @@ import feign.RequestInterceptor; @Configuration -@EnableFeignClients("efub.eday.edayback.domain.member.auth.service.feign") +@EnableFeignClients("efub.eday.edayback.feign") public class FeignConfig { @Bean diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java index 2b93c88..0e21533 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java @@ -8,11 +8,11 @@ import efub.eday.edayback.domain.member.auth.dto.KakaoProfileResponseDto; import efub.eday.edayback.domain.member.auth.dto.KakaoTokenRequestDto; import efub.eday.edayback.domain.member.auth.dto.KakaoTokenResponseDto; -import efub.eday.edayback.domain.member.auth.service.feign.KakaoApiFeign; -import efub.eday.edayback.domain.member.auth.service.feign.KakaoAuthFeign; -import efub.eday.edayback.domain.member.auth.service.jwt.JwtProvider; import efub.eday.edayback.domain.member.entity.Member; import efub.eday.edayback.domain.member.repository.MemberRepository; +import efub.eday.edayback.feign.KakaoApiFeign; +import efub.eday.edayback.feign.KakaoAuthFeign; +import efub.eday.edayback.jwt.JwtProvider; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/feign/KakaoApiFeign.java b/src/main/java/efub/eday/edayback/feign/KakaoApiFeign.java similarity index 89% rename from src/main/java/efub/eday/edayback/domain/member/auth/service/feign/KakaoApiFeign.java rename to src/main/java/efub/eday/edayback/feign/KakaoApiFeign.java index fda5fed..7e6c8ad 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/service/feign/KakaoApiFeign.java +++ b/src/main/java/efub/eday/edayback/feign/KakaoApiFeign.java @@ -1,4 +1,4 @@ -package efub.eday.edayback.domain.member.auth.service.feign; +package efub.eday.edayback.feign; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.http.HttpHeaders; diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/feign/KakaoAuthFeign.java b/src/main/java/efub/eday/edayback/feign/KakaoAuthFeign.java similarity index 89% rename from src/main/java/efub/eday/edayback/domain/member/auth/service/feign/KakaoAuthFeign.java rename to src/main/java/efub/eday/edayback/feign/KakaoAuthFeign.java index 9e156ac..5df9027 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/service/feign/KakaoAuthFeign.java +++ b/src/main/java/efub/eday/edayback/feign/KakaoAuthFeign.java @@ -1,4 +1,4 @@ -package efub.eday.edayback.domain.member.auth.service.feign; +package efub.eday.edayback.feign; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; diff --git a/src/main/java/efub/eday/edayback/config/JwtExceptionFilter.java b/src/main/java/efub/eday/edayback/jwt/JwtExceptionFilter.java similarity index 96% rename from src/main/java/efub/eday/edayback/config/JwtExceptionFilter.java rename to src/main/java/efub/eday/edayback/jwt/JwtExceptionFilter.java index c03daa3..140d9d7 100644 --- a/src/main/java/efub/eday/edayback/config/JwtExceptionFilter.java +++ b/src/main/java/efub/eday/edayback/jwt/JwtExceptionFilter.java @@ -1,4 +1,4 @@ -package efub.eday.edayback.config; +package efub.eday.edayback.jwt; import java.io.IOException; diff --git a/src/main/java/efub/eday/edayback/config/JwtFilter.java b/src/main/java/efub/eday/edayback/jwt/JwtFilter.java similarity index 97% rename from src/main/java/efub/eday/edayback/config/JwtFilter.java rename to src/main/java/efub/eday/edayback/jwt/JwtFilter.java index 706ef49..250be2c 100644 --- a/src/main/java/efub/eday/edayback/config/JwtFilter.java +++ b/src/main/java/efub/eday/edayback/jwt/JwtFilter.java @@ -1,4 +1,4 @@ -package efub.eday.edayback.config; +package efub.eday.edayback.jwt; import java.io.IOException; import java.util.List; @@ -15,7 +15,6 @@ import org.springframework.security.web.authentication.WebAuthenticationDetailsSource; import org.springframework.web.filter.OncePerRequestFilter; -import efub.eday.edayback.jwt.JwtProvider; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/jwt/JwtProvider.java b/src/main/java/efub/eday/edayback/jwt/JwtProvider.java similarity index 98% rename from src/main/java/efub/eday/edayback/domain/member/auth/service/jwt/JwtProvider.java rename to src/main/java/efub/eday/edayback/jwt/JwtProvider.java index 3c773e4..c24ae55 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/service/jwt/JwtProvider.java +++ b/src/main/java/efub/eday/edayback/jwt/JwtProvider.java @@ -1,4 +1,4 @@ -package efub.eday.edayback.domain.member.auth.service.jwt; +package efub.eday.edayback.jwt; import java.time.Duration; import java.util.Base64; From 301ed0412b0fed3c510bf3febf898095ef3f791e Mon Sep 17 00:00:00 2001 From: hannah0226 <mohan0226@naver.com> Date: Sun, 23 Jul 2023 04:12:46 +0900 Subject: [PATCH 072/153] =?UTF-8?q?feat:=20=EC=A0=95=EB=8B=B5=20=EB=A7=9E?= =?UTF-8?q?=EC=B6=9C=20=EC=8B=9C=20MemberQuiz=20isCorrect=20true=EB=A1=9C?= =?UTF-8?q?=20=EB=B0=94=EA=BE=B8=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/day/quiz/service/QuizService.java | 16 ++++++++++++---- .../domain/member/entity/MemberQuiz.java | 10 ++++++++++ .../member/repository/MemberQuizRepository.java | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 src/main/java/efub/eday/edayback/domain/member/repository/MemberQuizRepository.java diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java index 7683a2a..cb511dc 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java @@ -1,5 +1,7 @@ package efub.eday.edayback.domain.day.quiz.service; +import efub.eday.edayback.domain.member.entity.MemberQuiz; +import efub.eday.edayback.domain.member.repository.MemberQuizRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import efub.eday.edayback.domain.day.dday.entity.Dday; @@ -21,6 +23,7 @@ public class QuizService { private final MemberRepository memberRepository; private final MemberTitleRepository memberTitleRepository; private final TitleRepository titleRepository; + private final MemberQuizRepository memberQuizRepository; //퀴즈 내용 조회 @Transactional(readOnly = true) @@ -36,7 +39,6 @@ public boolean checkAnswer(int d_day, int optionNumber, Long memberId) { boolean isCorrect = quiz.isAnswerOption(optionNumber); - //member title 찾는 로직 if (isCorrect) { Member member = memberRepository.findById(memberId) .orElseThrow(() -> new IllegalArgumentException("해당 멤버를 찾을 수 없습니다.")); @@ -44,14 +46,20 @@ public boolean checkAnswer(int d_day, int optionNumber, Long memberId) { Title title = titleRepository.findBySubjectId(subjectId) .orElseThrow(() -> new IllegalArgumentException("해당 subject_id에 대한 타이틀을 찾을 수 없습니다.")); MemberTitle memberTitle = memberTitleRepository.findByMemberAndTitle(member, title) - .orElseThrow(() -> new IllegalArgumentException("해당 멤버의 타이틀을 찾을 수 없습니다.")); + .orElseThrow(() -> new IllegalArgumentException("해당 멤버 타이틀을 찾을 수 없습니다.")); + MemberQuiz memberQuiz = memberQuizRepository.findByMemberAndQuiz(member, quiz) + .orElseThrow(() -> new IllegalArgumentException("해당 멤버 퀴즈를 찾을 수 없습니다.")); - //member lever+1 + //member level+1 if (!memberTitle.getGetTitle()) { member.setLevel(member.getLevel() + 1); } - //getTitle값 true로 변경 + //MemberTitle의 getTitle값 true로 변경 memberTitle.setGetTitle(true); + + //MemberQuiz의 isCorrect 값 true로 변경 + memberQuiz.setIsCorrect(true); + } return isCorrect; } diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java index ca61151..5bfa842 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java @@ -8,7 +8,10 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import lombok.Builder; +import lombok.Setter; +@Setter @Entity public class MemberQuiz { @@ -27,4 +30,11 @@ public class MemberQuiz { @ManyToOne @JoinColumn(name = "quiz_id", nullable = false) private Quiz quiz; + + @Builder + public MemberQuiz(boolean isCorrect, Member member, Quiz quiz){ + this.isCorrect = isCorrect; + this.member = member; + this.quiz = quiz; + } } diff --git a/src/main/java/efub/eday/edayback/domain/member/repository/MemberQuizRepository.java b/src/main/java/efub/eday/edayback/domain/member/repository/MemberQuizRepository.java new file mode 100644 index 0000000..014f1a3 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/repository/MemberQuizRepository.java @@ -0,0 +1,14 @@ +package efub.eday.edayback.domain.member.repository; + +import efub.eday.edayback.domain.day.quiz.entity.Quiz; +import efub.eday.edayback.domain.member.entity.Member; +import efub.eday.edayback.domain.member.entity.MemberQuiz; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public interface MemberQuizRepository extends JpaRepository <MemberQuiz, Long> { + Optional<MemberQuiz> findByMemberAndQuiz(Member member, Quiz quiz); +} From 7e10e8e25599dd8d1999ff942c104574b0be5baa Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 13:40:43 +0900 Subject: [PATCH 073/153] =?UTF-8?q?chore:=20=EC=9E=90=EB=B0=94=20=EB=B2=84?= =?UTF-8?q?=EC=A0=84=20=EB=B3=80=EA=B2=BD=2017=20->=2011?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/day/dday/entity/Subject.java | 17 +++++++++-------- .../edayback/domain/day/quiz/entity/Quiz.java | 7 +++---- .../edayback/domain/day/title/entity/Title.java | 1 - .../edayback/domain/member/entity/Member.java | 6 +++--- .../domain/member/entity/MemberQuiz.java | 7 ++++--- .../domain/member/entity/MemberTitle.java | 6 ++++-- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java index 8d32222..314f957 100644 --- a/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java +++ b/src/main/java/efub/eday/edayback/domain/day/dday/entity/Subject.java @@ -1,13 +1,14 @@ package efub.eday.edayback.domain.day.dday.entity; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.EnumType; -import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.Table; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java index d355791..b753dab 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/entity/Quiz.java @@ -12,7 +12,6 @@ import javax.persistence.OneToOne; import efub.eday.edayback.domain.day.dday.entity.Subject; - import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -44,9 +43,9 @@ public class Quiz { private List<Option> optionList; //퀴즈 정답 확인 로직 - public boolean isAnswerOption(int optionNumber){ - for(Option option : optionList){ - if(option.getOptionNumber() == optionNumber){ + public boolean isAnswerOption(int optionNumber) { + for (Option option : optionList) { + if (option.getOptionNumber() == optionNumber) { return option.getIsAnswer(); } } diff --git a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java index e84ef8f..09f131e 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java @@ -9,7 +9,6 @@ import javax.persistence.OneToOne; import efub.eday.edayback.domain.day.dday.entity.Subject; - import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java index 2b6ae1e..3abc334 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java @@ -9,17 +9,17 @@ import javax.persistence.Id; import javax.persistence.Table; -import lombok.Setter; import org.hibernate.annotations.CreationTimestamp; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; -@Entity @Getter @Setter @NoArgsConstructor +@Entity @Table(name = "members") public class Member { @@ -48,7 +48,7 @@ public class Member { private Boolean isActive; @Builder - public Member(String nickname, Long loginId, String profileImageUrl) { + public Member(Long loginId, String nickname, String profileImageUrl) { this.nickname = nickname; this.loginId = loginId; this.profileImageUrl = profileImageUrl; diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java index 7993f52..a6ffb7b 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java @@ -9,12 +9,13 @@ import javax.persistence.ManyToOne; import efub.eday.edayback.domain.day.quiz.entity.Quiz; - import lombok.Builder; +import lombok.NoArgsConstructor; import lombok.Setter; -@Setter @Entity +@Setter +@NoArgsConstructor public class MemberQuiz { @Id @@ -34,7 +35,7 @@ public class MemberQuiz { private Quiz quiz; @Builder - public MemberQuiz(boolean isCorrect, Member member, Quiz quiz){ + public MemberQuiz(Boolean isCorrect, Member member, Quiz quiz) { this.isCorrect = isCorrect; this.member = member; this.quiz = quiz; diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java index 42c6962..96f0657 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java @@ -9,12 +9,14 @@ import javax.persistence.ManyToOne; import efub.eday.edayback.domain.day.title.entity.Title; +import lombok.Builder; +import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; -@Getter @Setter -@Entity @Getter +@Entity @NoArgsConstructor public class MemberTitle { From 2c9330ad492702b65b68fc2743fdc0233e95cf99 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 13:53:21 +0900 Subject: [PATCH 074/153] =?UTF-8?q?feat:=20Member=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20email=20=ED=95=84=EB=93=9C=20=EC=A0=9C=EA=B1=B0=20?= =?UTF-8?q?=EB=B0=8F=20memberId=20Long=20=ED=83=80=EC=9E=85=EC=9C=BC?= =?UTF-8?q?=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 --- .../eday/edayback/domain/day/title/dto/MemberProfileDto.java | 4 +--- .../eday/edayback/domain/day/title/service/TitleService.java | 5 ++--- .../efub/eday/edayback/domain/query/dto/QueryRequestDto.java | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/title/dto/MemberProfileDto.java b/src/main/java/efub/eday/edayback/domain/day/title/dto/MemberProfileDto.java index d6b8b2e..4c61a22 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/dto/MemberProfileDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/dto/MemberProfileDto.java @@ -10,16 +10,14 @@ public class MemberProfileDto { private String nickname; - private String email; private String profileImage; private int level; private LocalDateTime createdDate; private boolean isActive; - public MemberProfileDto(String nickname, String email, String profileImage, int level, LocalDateTime createdDate, + public MemberProfileDto(String nickname, String profileImage, int level, LocalDateTime createdDate, boolean isActive) { this.nickname = nickname; - this.email = email; this.profileImage = profileImage; this.level = level; this.createdDate = createdDate; diff --git a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java index 162ba5b..9ce9646 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java @@ -24,7 +24,7 @@ public class TitleService { private final MemberTitleRepository memberTitleRepository; @Transactional(readOnly = true) - public TitleResponseDto getTitlePage(Integer memberId) { + public TitleResponseDto getTitlePage(Long memberId) { Member member = memberRepository.findById(memberId) .orElseThrow(() -> new IllegalArgumentException("해당하는 회원이 없습니다. ID: " + memberId)); @@ -32,10 +32,9 @@ public TitleResponseDto getTitlePage(Integer memberId) { MemberProfileDto profile = new MemberProfileDto( member.getNickname(), - member.getEmail(), member.getProfileImageUrl(), member.getLevel(), - member.getCreatedDate().atStartOfDay(), + member.getCreatedDate(), member.getIsActive() ); diff --git a/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java b/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java index 51d6e0b..fae0510 100644 --- a/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java +++ b/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java @@ -12,7 +12,7 @@ @Getter public class QueryRequestDto { - private int memberId; + private Long memberId; private String queryContent; private int dday; } From a620aa491f75cee0aa19d333694511f788f19c6d Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 14:23:11 +0900 Subject: [PATCH 075/153] =?UTF-8?q?feat:=20MemberQuiz,=20MemberTitle=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=20=EA=B8=B0=EB=B3=B8=EA=B0=92=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../efub/eday/edayback/domain/member/entity/MemberQuiz.java | 4 ++-- .../efub/eday/edayback/domain/member/entity/MemberTitle.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java index a6ffb7b..a15bc7f 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java @@ -35,8 +35,8 @@ public class MemberQuiz { private Quiz quiz; @Builder - public MemberQuiz(Boolean isCorrect, Member member, Quiz quiz) { - this.isCorrect = isCorrect; + public MemberQuiz(Member member, Quiz quiz) { + this.isCorrect = false; this.member = member; this.quiz = quiz; } diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java index 96f0657..d38fee4 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberTitle.java @@ -37,8 +37,8 @@ public class MemberTitle { private Title title; @Builder - public MemberTitle(Boolean getTitle, Member member, Title title) { - this.getTitle = getTitle; + public MemberTitle(Member member, Title title) { + this.getTitle = false; this.member = member; this.title = title; } From cce4f9adcc182e0a8034d606130d5a81a6a0c00f Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 14:23:33 +0900 Subject: [PATCH 076/153] =?UTF-8?q?feat(Query):=20content=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EA=B8=B8=EC=9D=B4=20=EC=A0=9C=ED=95=9C=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 --- src/main/java/efub/eday/edayback/domain/query/entity/Query.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/domain/query/entity/Query.java b/src/main/java/efub/eday/edayback/domain/query/entity/Query.java index 5c24f97..02ecec3 100644 --- a/src/main/java/efub/eday/edayback/domain/query/entity/Query.java +++ b/src/main/java/efub/eday/edayback/domain/query/entity/Query.java @@ -24,7 +24,7 @@ public class Query { @Column(name = "query_id") private Integer id; - @Column(nullable = false) + @Column(nullable = false, length = 500) private String content; @ManyToOne From 1fc709c3bf03441bf744f17a3ca5c6bc0f3d9e1a Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 15:05:17 +0900 Subject: [PATCH 077/153] =?UTF-8?q?feat:=20=ED=98=84=EC=9E=AC=20=EC=9D=B8?= =?UTF-8?q?=EC=A6=9D=EB=90=9C=20=EC=9C=A0=EC=A0=80=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=EB=A5=BC=20=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/member/auth/service/AuthService.java | 9 +++++++++ src/main/java/efub/eday/edayback/jwt/JwtProvider.java | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java index 0e21533..81d88e4 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java @@ -2,6 +2,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import efub.eday.edayback.domain.member.auth.dto.AuthResponseDto; @@ -92,4 +94,11 @@ private Member getKakaoProfile(String kakaoToken) { private void signUp(Member member) { memberRepository.save(member); } + + public Member getCurrentMember() { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + String principalName = authentication.getName(); + Long memberId = Long.parseLong(principalName); + return memberRepository.findById(memberId).orElseThrow(IllegalArgumentException::new); + } } diff --git a/src/main/java/efub/eday/edayback/jwt/JwtProvider.java b/src/main/java/efub/eday/edayback/jwt/JwtProvider.java index c24ae55..300d776 100644 --- a/src/main/java/efub/eday/edayback/jwt/JwtProvider.java +++ b/src/main/java/efub/eday/edayback/jwt/JwtProvider.java @@ -20,7 +20,7 @@ @RequiredArgsConstructor @Service public class JwtProvider { - private static final Long ACCESS_TOKEN_VALID_TIME = Duration.ofMinutes(30).toMillis(); // 만료시간 30분 + private static final Long ACCESS_TOKEN_VALID_TIME = Duration.ofDays(14).toMillis(); // 만료시간 30분 private static final Long REFRESH_TOKEN_VALID_TIME = Duration.ofDays(14).toMillis(); // 만료시간 2주 private static final String MEMBER_ID = "memberId"; private static final String TOKEN_TYPE = "type"; @@ -49,7 +49,7 @@ private String createJwt(Long memberId, String type, Long tokenValidTime) { // access 토큰 생성 public String createAccessToken(Long memberId) { - return createJwt(memberId, TokenType.REFRESH.type, ACCESS_TOKEN_VALID_TIME); + return createJwt(memberId, TokenType.ACCESS.type, ACCESS_TOKEN_VALID_TIME); } // refresh 토큰 생성 From ed01a348a506d988e6cb1faf733a64084e1e59c1 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 15:12:19 +0900 Subject: [PATCH 078/153] =?UTF-8?q?feat:=20=ED=80=B4=EC=A6=88=20=EB=B0=8F?= =?UTF-8?q?=20=EC=B9=AD=ED=98=B8=20=EC=84=9C=EB=B9=84=EC=8A=A4=EC=97=90=20?= =?UTF-8?q?=EC=9D=B8=EC=A6=9D=EB=90=9C=20=EC=9C=A0=EC=A0=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../day/quiz/controller/QuizController.java | 35 +++++++++++-------- .../domain/day/quiz/service/QuizService.java | 16 ++++----- .../day/title/controller/TitleController.java | 7 ++-- .../day/title/service/TitleService.java | 9 +++-- 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java index ef453b7..0d3f3ba 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java @@ -1,43 +1,48 @@ package efub.eday.edayback.domain.day.quiz.controller; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +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.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; + import efub.eday.edayback.domain.day.quiz.dto.QuizAnswerResponseDto; import efub.eday.edayback.domain.day.quiz.dto.QuizRequestDto; -import jakarta.servlet.http.HttpSession; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; import efub.eday.edayback.domain.day.quiz.dto.QuizResponseDto; import efub.eday.edayback.domain.day.quiz.entity.Quiz; import efub.eday.edayback.domain.day.quiz.service.QuizService; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +@Slf4j @RestController -@RequestMapping("/quiz/{d_day}") +@RequestMapping("/quiz/{dDay}") @RequiredArgsConstructor public class QuizController { private final QuizService quizService; - private final HttpSession httpSession; //퀴즈 내용 조회 @GetMapping @ResponseStatus(value = HttpStatus.OK) - public QuizResponseDto findQuiz(@PathVariable int d_day) { - Quiz quiz = quizService.findQuiz(d_day); + public QuizResponseDto findQuiz(@PathVariable int dDay) { + Quiz quiz = quizService.findQuiz(dDay); return QuizResponseDto.from(quiz); } //퀴즈 정답 확인 @PostMapping public QuizAnswerResponseDto checkAnswer( - @PathVariable int d_day, - @RequestBody QuizRequestDto quizRequestDto + @PathVariable int dDay, + @RequestBody QuizRequestDto quizRequestDto ) { - Long memberId = (Long) httpSession.getAttribute("memberId"); //JwtProvider로 변경 예정 - - boolean isCorrect = quizService.checkAnswer(d_day, quizRequestDto.getOptionNumber(), memberId); + boolean isCorrect = quizService.checkAnswer(dDay, quizRequestDto.getOptionNumber()); String quizDescription = null; if (isCorrect) { - quizDescription = quizService.getQuizDescription(d_day); + quizDescription = quizService.getQuizDescription(dDay); } - QuizAnswerResponseDto responseDto = new QuizAnswerResponseDto(isCorrect, quizDescription); - return responseDto; + return new QuizAnswerResponseDto(isCorrect, quizDescription); } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java index cb511dc..0fe9f58 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java @@ -1,18 +1,19 @@ package efub.eday.edayback.domain.day.quiz.service; -import efub.eday.edayback.domain.member.entity.MemberQuiz; -import efub.eday.edayback.domain.member.repository.MemberQuizRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; + import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.quiz.entity.Quiz; import efub.eday.edayback.domain.day.quiz.repository.QuizRepository; import efub.eday.edayback.domain.day.title.entity.Title; +import efub.eday.edayback.domain.day.title.repository.MemberTitleRepository; import efub.eday.edayback.domain.day.title.repository.TitleRepository; +import efub.eday.edayback.domain.member.auth.service.AuthService; import efub.eday.edayback.domain.member.entity.Member; +import efub.eday.edayback.domain.member.entity.MemberQuiz; import efub.eday.edayback.domain.member.entity.MemberTitle; -import efub.eday.edayback.domain.member.repository.MemberRepository; -import efub.eday.edayback.domain.member.repository.MemberTitleRepository; +import efub.eday.edayback.domain.member.repository.MemberQuizRepository; import lombok.RequiredArgsConstructor; @Service @@ -20,10 +21,10 @@ @RequiredArgsConstructor public class QuizService { private final QuizRepository quizRepository; - private final MemberRepository memberRepository; private final MemberTitleRepository memberTitleRepository; private final TitleRepository titleRepository; private final MemberQuizRepository memberQuizRepository; + private final AuthService authService; //퀴즈 내용 조회 @Transactional(readOnly = true) @@ -34,14 +35,13 @@ public Quiz findQuiz(int d_day) { } //퀴즈 정답 확인 - public boolean checkAnswer(int d_day, int optionNumber, Long memberId) { + public boolean checkAnswer(int d_day, int optionNumber) { Quiz quiz = findQuiz(d_day); boolean isCorrect = quiz.isAnswerOption(optionNumber); if (isCorrect) { - Member member = memberRepository.findById(memberId) - .orElseThrow(() -> new IllegalArgumentException("해당 멤버를 찾을 수 없습니다.")); + Member member = authService.getCurrentMember(); Integer subjectId = quiz.getSubject().getId(); Title title = titleRepository.findBySubjectId(subjectId) .orElseThrow(() -> new IllegalArgumentException("해당 subject_id에 대한 타이틀을 찾을 수 없습니다.")); diff --git a/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java b/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java index ea909bc..ff52500 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java @@ -2,7 +2,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -17,9 +16,9 @@ public class TitleController { private final TitleService titleService; - @GetMapping("/{member_id}") - public ResponseEntity<TitleResponseDto> getTitlePage(@PathVariable("member_id") Integer memberId) { - TitleResponseDto titleResponseDto = titleService.getTitlePage(memberId); + @GetMapping() + public ResponseEntity<TitleResponseDto> getTitlePage() { + TitleResponseDto titleResponseDto = titleService.getTitlePage(); return ResponseEntity.ok(titleResponseDto); } } diff --git a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java index 9ce9646..c4b9b0a 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java @@ -11,22 +11,21 @@ import efub.eday.edayback.domain.day.title.dto.TitleResponseDto; import efub.eday.edayback.domain.day.title.entity.Title; import efub.eday.edayback.domain.day.title.repository.MemberTitleRepository; +import efub.eday.edayback.domain.member.auth.service.AuthService; import efub.eday.edayback.domain.member.entity.Member; import efub.eday.edayback.domain.member.entity.MemberTitle; -import efub.eday.edayback.domain.member.repository.MemberRepository; import lombok.RequiredArgsConstructor; @Service @RequiredArgsConstructor public class TitleService { - private final MemberRepository memberRepository; private final MemberTitleRepository memberTitleRepository; + private final AuthService authService; @Transactional(readOnly = true) - public TitleResponseDto getTitlePage(Long memberId) { - Member member = memberRepository.findById(memberId) - .orElseThrow(() -> new IllegalArgumentException("해당하는 회원이 없습니다. ID: " + memberId)); + public TitleResponseDto getTitlePage() { + Member member = authService.getCurrentMember(); List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); From 5cbf8a95ad4309313b349eda1ce5ec7e89e4070f Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 15:13:05 +0900 Subject: [PATCH 079/153] =?UTF-8?q?chore:=20=EC=A4=91=EB=B3=B5=EB=90=9C=20?= =?UTF-8?q?MemberTitleRepository=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../title/repository/MemberTitleRepository.java | 4 ++++ .../member/repository/MemberTitleRepository.java | 14 -------------- 2 files changed, 4 insertions(+), 14 deletions(-) delete mode 100644 src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java diff --git a/src/main/java/efub/eday/edayback/domain/day/title/repository/MemberTitleRepository.java b/src/main/java/efub/eday/edayback/domain/day/title/repository/MemberTitleRepository.java index cea3a9c..dc9744a 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/repository/MemberTitleRepository.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/repository/MemberTitleRepository.java @@ -1,14 +1,18 @@ package efub.eday.edayback.domain.day.title.repository; import java.util.List; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import efub.eday.edayback.domain.day.title.entity.Title; import efub.eday.edayback.domain.member.entity.Member; import efub.eday.edayback.domain.member.entity.MemberTitle; @Repository public interface MemberTitleRepository extends JpaRepository<MemberTitle, Integer> { List<MemberTitle> findByMember(Member member); + + Optional<MemberTitle> findByMemberAndTitle(Member member, Title title); } diff --git a/src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java b/src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java deleted file mode 100644 index c5e01f3..0000000 --- a/src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java +++ /dev/null @@ -1,14 +0,0 @@ -package efub.eday.edayback.domain.member.repository; - -import efub.eday.edayback.domain.day.title.entity.Title; -import efub.eday.edayback.domain.member.entity.Member; -import efub.eday.edayback.domain.member.entity.MemberTitle; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.Optional; - -@Repository -public interface MemberTitleRepository extends JpaRepository<MemberTitle, Long> { - Optional<MemberTitle> findByMemberAndTitle(Member member, Title title); -} From 25d47a8a9e3d16b2c05538fb7d2e6fae8529bcb9 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 15:26:40 +0900 Subject: [PATCH 080/153] =?UTF-8?q?chore:=20MemberTitleRepository=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EC=9C=84=EC=B9=98=20title=20->?= =?UTF-8?q?=20member=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../efub/eday/edayback/domain/day/quiz/service/QuizService.java | 2 +- .../eday/edayback/domain/day/title/service/TitleService.java | 2 +- .../{day/title => member}/repository/MemberTitleRepository.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/main/java/efub/eday/edayback/domain/{day/title => member}/repository/MemberTitleRepository.java (90%) diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java index 0fe9f58..90ddb18 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java @@ -7,13 +7,13 @@ import efub.eday.edayback.domain.day.quiz.entity.Quiz; import efub.eday.edayback.domain.day.quiz.repository.QuizRepository; import efub.eday.edayback.domain.day.title.entity.Title; -import efub.eday.edayback.domain.day.title.repository.MemberTitleRepository; import efub.eday.edayback.domain.day.title.repository.TitleRepository; import efub.eday.edayback.domain.member.auth.service.AuthService; import efub.eday.edayback.domain.member.entity.Member; import efub.eday.edayback.domain.member.entity.MemberQuiz; import efub.eday.edayback.domain.member.entity.MemberTitle; import efub.eday.edayback.domain.member.repository.MemberQuizRepository; +import efub.eday.edayback.domain.member.repository.MemberTitleRepository; import lombok.RequiredArgsConstructor; @Service diff --git a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java index c4b9b0a..0167e39 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java @@ -10,10 +10,10 @@ import efub.eday.edayback.domain.day.title.dto.TitleDto; import efub.eday.edayback.domain.day.title.dto.TitleResponseDto; import efub.eday.edayback.domain.day.title.entity.Title; -import efub.eday.edayback.domain.day.title.repository.MemberTitleRepository; import efub.eday.edayback.domain.member.auth.service.AuthService; import efub.eday.edayback.domain.member.entity.Member; import efub.eday.edayback.domain.member.entity.MemberTitle; +import efub.eday.edayback.domain.member.repository.MemberTitleRepository; import lombok.RequiredArgsConstructor; @Service diff --git a/src/main/java/efub/eday/edayback/domain/day/title/repository/MemberTitleRepository.java b/src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java similarity index 90% rename from src/main/java/efub/eday/edayback/domain/day/title/repository/MemberTitleRepository.java rename to src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java index dc9744a..eca3269 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/repository/MemberTitleRepository.java +++ b/src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java @@ -1,4 +1,4 @@ -package efub.eday.edayback.domain.day.title.repository; +package efub.eday.edayback.domain.member.repository; import java.util.List; import java.util.Optional; From 9c70a600f93fbedb08df2449d1e175ee0ca7d2ec Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Sun, 23 Jul 2023 20:26:57 +0900 Subject: [PATCH 081/153] =?UTF-8?q?feat=20:=20Info(=EC=B6=94=EA=B0=80?= =?UTF-8?q?=EC=A0=95=EB=B3=B4)=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80=20#24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/day/info/controller/InfoController.java | 9 +++++++-- .../edayback/domain/day/info/service/InfoService.java | 4 +++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java b/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java index d461520..55d09d2 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java @@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.server.ResponseStatusException; import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.info.dto.InfoDto; @@ -23,7 +24,11 @@ public class InfoController { @ResponseStatus(value = HttpStatus.OK) public InfoDto getInfoByDday(@PathVariable("d_day") int dday) { Dday ddayEnum = Dday.fromRemainingDays(dday); - Info info = infoService.getInfoByDday(ddayEnum); - return InfoDto.from(info); + try { + Info info = infoService.getInfoByDday(ddayEnum); + return InfoDto.from(info); + } catch (ResponseStatusException message) { + throw message; + } } } diff --git a/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java b/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java index 990ef12..a4a0e70 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/service/InfoService.java @@ -1,7 +1,9 @@ package efub.eday.edayback.domain.day.info.service; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.server.ResponseStatusException; import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.info.entity.Info; @@ -17,6 +19,6 @@ public class InfoService { @Transactional(readOnly = true) public Info getInfoByDday(Dday dday) { return infoRepository.findInfoBySubject_Dday(dday) - .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 추가정보입니다.")); + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, dday + "는 존재하지 않는 디데이입니다.")); } } From 11e0f59453891bce088af66b53f72f8464eb9020 Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Sun, 23 Jul 2023 20:49:42 +0900 Subject: [PATCH 082/153] =?UTF-8?q?feat:=20Query(=EB=AC=B8=EC=9D=98?= =?UTF-8?q?=EC=82=AC=ED=95=AD)=EC=97=90=20=EC=9D=B8=EC=A6=9D=EB=90=9C=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=A0=95=EB=B3=B4=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/query/controller/QueryController.java | 5 +++++ .../efub/eday/edayback/domain/query/dto/QueryRequestDto.java | 2 ++ .../eday/edayback/domain/query/service/QueryService.java | 2 -- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java b/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java index 0f8d4cf..ca8f24c 100644 --- a/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java +++ b/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java @@ -7,6 +7,8 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import efub.eday.edayback.domain.member.auth.service.AuthService; +import efub.eday.edayback.domain.member.entity.Member; import efub.eday.edayback.domain.query.dto.QueryRequestDto; import efub.eday.edayback.domain.query.entity.Query; import efub.eday.edayback.domain.query.service.QueryService; @@ -17,10 +19,13 @@ @RequiredArgsConstructor public class QueryController { private final QueryService queryService; + private final AuthService authService; @PostMapping @ResponseStatus(value = HttpStatus.CREATED) public Query addquery(@RequestBody QueryRequestDto requestDto) { + Member writer = authService.getCurrentMember(); // 로그인된 유저 정보 가져오기 + requestDto.setMemberId(writer.getId()); // 가져온 유저 정보의 ID를 QueryRequestDto에 설정 return queryService.addQuery(requestDto); } } diff --git a/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java b/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java index fae0510..e969cbf 100644 --- a/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java +++ b/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java @@ -1,6 +1,7 @@ package efub.eday.edayback.domain.query.dto; import lombok.Getter; +import lombok.Setter; /* { @@ -11,6 +12,7 @@ */ @Getter +@Setter public class QueryRequestDto { private Long memberId; private String queryContent; diff --git a/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java b/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java index 4a86ee0..e58053f 100644 --- a/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java +++ b/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java @@ -8,7 +8,6 @@ import efub.eday.edayback.domain.day.dday.repository.SubjectRepository; import efub.eday.edayback.domain.member.entity.Member; import efub.eday.edayback.domain.member.repository.MemberRepository; -import efub.eday.edayback.domain.member.service.MemberService; import efub.eday.edayback.domain.query.dto.QueryRequestDto; import efub.eday.edayback.domain.query.entity.Query; import efub.eday.edayback.domain.query.repository.QueryRepository; @@ -19,7 +18,6 @@ @RequiredArgsConstructor public class QueryService { private final QueryRepository queryRepository; - private final MemberService memberService; private final MemberRepository memberRepository; private final SubjectRepository subjectRepository; From c89bdfec134b4e45dfa1c68d4ee16745313f11bd Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 21:13:29 +0900 Subject: [PATCH 083/153] =?UTF-8?q?chore:=20springdoc=20=EB=9D=BC=EC=9D=B4?= =?UTF-8?q?=EB=B8=8C=EB=9F=AC=EB=A6=AC=20=EC=9D=98=EC=A1=B4=EC=84=B1=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 --- build.gradle | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 3f1d861..86536a2 100644 --- a/build.gradle +++ b/build.gradle @@ -32,14 +32,19 @@ dependencyManagement { } dependencies { - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation 'org.springframework.boot:spring-boot-starter-validation' + // Spring web implementation 'org.springframework.boot:spring-boot-starter-web' - - implementation 'io.jsonwebtoken:jjwt:0.9.1' + // Spring Data JPA + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + // Spring Security implementation 'org.springframework.boot:spring-boot-starter-security' - + // JWT + implementation 'io.jsonwebtoken:jjwt:0.9.1' + // OpenFeign implementation 'org.springframework.cloud:spring-cloud-starter-openfeign' + // Swagger + implementation 'org.springdoc:springdoc-openapi-ui:1.7.0' + implementation 'org.springdoc:springdoc-openapi-security:1.7.0' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' From 2be8756effa7ae928c25422bd790b2d7af445c9b Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 23 Jul 2023 21:14:23 +0900 Subject: [PATCH 084/153] =?UTF-8?q?refactor:=20=ED=8C=A8=ED=82=A4=EC=A7=80?= =?UTF-8?q?=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - domain - global ㄴ config ㄴ feign ㄴ jwt --- .../domain/member/auth/service/AuthService.java | 6 +++--- .../{ => global}/config/AuthenticationConfig.java | 10 +++++----- .../eday/edayback/{ => global}/config/FeignConfig.java | 2 +- .../edayback/{ => global}/feign/KakaoApiFeign.java | 2 +- .../edayback/{ => global}/feign/KakaoAuthFeign.java | 2 +- .../edayback/{ => global}/jwt/JwtExceptionFilter.java | 2 +- .../efub/eday/edayback/{ => global}/jwt/JwtFilter.java | 2 +- .../eday/edayback/{ => global}/jwt/JwtProvider.java | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) rename src/main/java/efub/eday/edayback/{ => global}/config/AuthenticationConfig.java (82%) rename src/main/java/efub/eday/edayback/{ => global}/config/FeignConfig.java (93%) rename src/main/java/efub/eday/edayback/{ => global}/feign/KakaoApiFeign.java (92%) rename src/main/java/efub/eday/edayback/{ => global}/feign/KakaoAuthFeign.java (92%) rename src/main/java/efub/eday/edayback/{ => global}/jwt/JwtExceptionFilter.java (95%) rename src/main/java/efub/eday/edayback/{ => global}/jwt/JwtFilter.java (98%) rename src/main/java/efub/eday/edayback/{ => global}/jwt/JwtProvider.java (98%) diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java index 81d88e4..3233b74 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java @@ -12,9 +12,9 @@ import efub.eday.edayback.domain.member.auth.dto.KakaoTokenResponseDto; import efub.eday.edayback.domain.member.entity.Member; import efub.eday.edayback.domain.member.repository.MemberRepository; -import efub.eday.edayback.feign.KakaoApiFeign; -import efub.eday.edayback.feign.KakaoAuthFeign; -import efub.eday.edayback.jwt.JwtProvider; +import efub.eday.edayback.global.feign.KakaoApiFeign; +import efub.eday.edayback.global.feign.KakaoAuthFeign; +import efub.eday.edayback.global.jwt.JwtProvider; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/efub/eday/edayback/config/AuthenticationConfig.java b/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java similarity index 82% rename from src/main/java/efub/eday/edayback/config/AuthenticationConfig.java rename to src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java index 2cfdf2d..af1663f 100644 --- a/src/main/java/efub/eday/edayback/config/AuthenticationConfig.java +++ b/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java @@ -1,4 +1,4 @@ -package efub.eday.edayback.config; +package efub.eday.edayback.global.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -8,9 +8,9 @@ import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; -import efub.eday.edayback.jwt.JwtExceptionFilter; -import efub.eday.edayback.jwt.JwtFilter; -import efub.eday.edayback.jwt.JwtProvider; +import efub.eday.edayback.global.jwt.JwtExceptionFilter; +import efub.eday.edayback.global.jwt.JwtFilter; +import efub.eday.edayback.global.jwt.JwtProvider; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -32,7 +32,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) // 세션 대신 jwt 사용하는 경우 사용 .and() .authorizeRequests() - .antMatchers("/member/auth").permitAll() + .antMatchers("/member/auth", "/docs", "/swagger-ui/**").permitAll() .anyRequest().authenticated() .and() .addFilterBefore(new JwtFilter(jwtProvider), UsernamePasswordAuthenticationFilter.class) diff --git a/src/main/java/efub/eday/edayback/config/FeignConfig.java b/src/main/java/efub/eday/edayback/global/config/FeignConfig.java similarity index 93% rename from src/main/java/efub/eday/edayback/config/FeignConfig.java rename to src/main/java/efub/eday/edayback/global/config/FeignConfig.java index 4a87bf4..6d71f9f 100644 --- a/src/main/java/efub/eday/edayback/config/FeignConfig.java +++ b/src/main/java/efub/eday/edayback/global/config/FeignConfig.java @@ -1,4 +1,4 @@ -package efub.eday.edayback.config; +package efub.eday.edayback.global.config; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.Bean; diff --git a/src/main/java/efub/eday/edayback/feign/KakaoApiFeign.java b/src/main/java/efub/eday/edayback/global/feign/KakaoApiFeign.java similarity index 92% rename from src/main/java/efub/eday/edayback/feign/KakaoApiFeign.java rename to src/main/java/efub/eday/edayback/global/feign/KakaoApiFeign.java index 7e6c8ad..231040b 100644 --- a/src/main/java/efub/eday/edayback/feign/KakaoApiFeign.java +++ b/src/main/java/efub/eday/edayback/global/feign/KakaoApiFeign.java @@ -1,4 +1,4 @@ -package efub.eday.edayback.feign; +package efub.eday.edayback.global.feign; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.http.HttpHeaders; diff --git a/src/main/java/efub/eday/edayback/feign/KakaoAuthFeign.java b/src/main/java/efub/eday/edayback/global/feign/KakaoAuthFeign.java similarity index 92% rename from src/main/java/efub/eday/edayback/feign/KakaoAuthFeign.java rename to src/main/java/efub/eday/edayback/global/feign/KakaoAuthFeign.java index 5df9027..1c3adac 100644 --- a/src/main/java/efub/eday/edayback/feign/KakaoAuthFeign.java +++ b/src/main/java/efub/eday/edayback/global/feign/KakaoAuthFeign.java @@ -1,4 +1,4 @@ -package efub.eday.edayback.feign; +package efub.eday.edayback.global.feign; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PostMapping; diff --git a/src/main/java/efub/eday/edayback/jwt/JwtExceptionFilter.java b/src/main/java/efub/eday/edayback/global/jwt/JwtExceptionFilter.java similarity index 95% rename from src/main/java/efub/eday/edayback/jwt/JwtExceptionFilter.java rename to src/main/java/efub/eday/edayback/global/jwt/JwtExceptionFilter.java index 140d9d7..2c5164a 100644 --- a/src/main/java/efub/eday/edayback/jwt/JwtExceptionFilter.java +++ b/src/main/java/efub/eday/edayback/global/jwt/JwtExceptionFilter.java @@ -1,4 +1,4 @@ -package efub.eday.edayback.jwt; +package efub.eday.edayback.global.jwt; import java.io.IOException; diff --git a/src/main/java/efub/eday/edayback/jwt/JwtFilter.java b/src/main/java/efub/eday/edayback/global/jwt/JwtFilter.java similarity index 98% rename from src/main/java/efub/eday/edayback/jwt/JwtFilter.java rename to src/main/java/efub/eday/edayback/global/jwt/JwtFilter.java index 250be2c..40748ed 100644 --- a/src/main/java/efub/eday/edayback/jwt/JwtFilter.java +++ b/src/main/java/efub/eday/edayback/global/jwt/JwtFilter.java @@ -1,4 +1,4 @@ -package efub.eday.edayback.jwt; +package efub.eday.edayback.global.jwt; import java.io.IOException; import java.util.List; diff --git a/src/main/java/efub/eday/edayback/jwt/JwtProvider.java b/src/main/java/efub/eday/edayback/global/jwt/JwtProvider.java similarity index 98% rename from src/main/java/efub/eday/edayback/jwt/JwtProvider.java rename to src/main/java/efub/eday/edayback/global/jwt/JwtProvider.java index 300d776..841da8f 100644 --- a/src/main/java/efub/eday/edayback/jwt/JwtProvider.java +++ b/src/main/java/efub/eday/edayback/global/jwt/JwtProvider.java @@ -1,4 +1,4 @@ -package efub.eday.edayback.jwt; +package efub.eday.edayback.global.jwt; import java.time.Duration; import java.util.Base64; From 72c4c8cead0f416cf1ce4f074305f445c08526a8 Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Sun, 23 Jul 2023 21:26:50 +0900 Subject: [PATCH 085/153] =?UTF-8?q?feat=20:=20Query(=EB=AC=B8=EC=9D=98?= =?UTF-8?q?=EC=82=AC=ED=95=AD)=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80=20#24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/query/controller/QueryController.java | 11 ++++++++--- .../edayback/domain/query/service/QueryService.java | 7 +++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java b/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java index ca8f24c..1c9f20b 100644 --- a/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java +++ b/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java @@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.server.ResponseStatusException; import efub.eday.edayback.domain.member.auth.service.AuthService; import efub.eday.edayback.domain.member.entity.Member; @@ -24,8 +25,12 @@ public class QueryController { @PostMapping @ResponseStatus(value = HttpStatus.CREATED) public Query addquery(@RequestBody QueryRequestDto requestDto) { - Member writer = authService.getCurrentMember(); // 로그인된 유저 정보 가져오기 - requestDto.setMemberId(writer.getId()); // 가져온 유저 정보의 ID를 QueryRequestDto에 설정 - return queryService.addQuery(requestDto); + try { + Member writer = authService.getCurrentMember(); // 로그인된 유저 정보 가져오기 + requestDto.setMemberId(writer.getId()); // 가져온 유저 정보의 ID를 QueryRequestDto에 설정 + return queryService.addQuery(requestDto); + } catch (ResponseStatusException message) { + throw message; + } } } diff --git a/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java b/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java index e58053f..75f42f5 100644 --- a/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java +++ b/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java @@ -1,7 +1,9 @@ package efub.eday.edayback.domain.query.service; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.server.ResponseStatusException; import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.dday.entity.Subject; @@ -23,12 +25,13 @@ public class QueryService { public Query addQuery(QueryRequestDto requestDto) { Member writer = memberRepository.findById(requestDto.getMemberId()) - .orElseThrow(() -> new IllegalArgumentException("유효하지 않은 ID입니다.")); + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "유효하지 않은 ID입니다.")); Dday dday = Dday.fromRemainingDays(requestDto.getDday()); Subject subject = subjectRepository.findByDday(dday) - .orElseThrow(() -> new IllegalArgumentException("해당하는 Subject가 없습니다. dday: " + dday.getRemainingDays())); + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, + "해당하는 Subject가 없습니다. dday: " + dday.getRemainingDays())); Query query = Query.builder() .content(requestDto.getQueryContent()) From a2cb3cdea3bc8febe9a691ad284659f60b911e15 Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Sun, 23 Jul 2023 21:52:53 +0900 Subject: [PATCH 086/153] =?UTF-8?q?feat=20:=20Title(=EC=B9=AD=ED=98=B8)=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20#24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../day/title/controller/TitleController.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java b/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java index ff52500..5e26b9d 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java @@ -1,9 +1,11 @@ package efub.eday.edayback.domain.day.title.controller; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.server.ResponseStatusException; import efub.eday.edayback.domain.day.title.dto.TitleResponseDto; import efub.eday.edayback.domain.day.title.service.TitleService; @@ -18,7 +20,14 @@ public class TitleController { @GetMapping() public ResponseEntity<TitleResponseDto> getTitlePage() { - TitleResponseDto titleResponseDto = titleService.getTitlePage(); - return ResponseEntity.ok(titleResponseDto); + try { + TitleResponseDto titleResponseDto = titleService.getTitlePage(); + return ResponseEntity.ok(titleResponseDto); + } catch (IllegalArgumentException e) { + // 해당하는 Subject가 없는 경우 404 상태 코드와 에러 메시지를 반환 + throw new ResponseStatusException(HttpStatus.NOT_FOUND, "해당하는 Subject가 없습니다."); + } catch (Exception e) { + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "서버에서 오류가 발생했습니다."); + } } } From aad5d64762d5c357780b34c3a2485eea4dd59cc0 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Mon, 24 Jul 2023 01:11:11 +0900 Subject: [PATCH 087/153] =?UTF-8?q?feat:=20Swagger=20=EC=84=A4=EC=A0=95=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 - AuthenticationConfig: swagger api 문서 경로는 인증 없이도 접근 가능하도록 수정 - OpenApiConfig: swagger api 문서에 api 정보와 인증 추가 --- .../global/config/AuthenticationConfig.java | 2 +- .../edayback/global/config/OpenApiConfig.java | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/main/java/efub/eday/edayback/global/config/OpenApiConfig.java diff --git a/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java b/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java index af1663f..b2af603 100644 --- a/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java +++ b/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java @@ -32,7 +32,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) // 세션 대신 jwt 사용하는 경우 사용 .and() .authorizeRequests() - .antMatchers("/member/auth", "/docs", "/swagger-ui/**").permitAll() + .antMatchers("/member/auth", "/docs", "/swagger-ui/*", "/v3/**").permitAll() .anyRequest().authenticated() .and() .addFilterBefore(new JwtFilter(jwtProvider), UsernamePasswordAuthenticationFilter.class) diff --git a/src/main/java/efub/eday/edayback/global/config/OpenApiConfig.java b/src/main/java/efub/eday/edayback/global/config/OpenApiConfig.java new file mode 100644 index 0000000..3137713 --- /dev/null +++ b/src/main/java/efub/eday/edayback/global/config/OpenApiConfig.java @@ -0,0 +1,43 @@ +package efub.eday.edayback.global.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; + +@Configuration +public class OpenApiConfig { + + private static final String JWT_SCHEME = "JWT Auth"; + + @Bean + public OpenAPI openApi() { + SecurityRequirement securityRequirement = new SecurityRequirement().addList(JWT_SCHEME); + Components components = new Components() + .addSecuritySchemes(JWT_SCHEME, apiSecurityScheme()); + return new OpenAPI() + .info(apiInfo()) + .addSecurityItem(securityRequirement) + .components(components); + } + + private SecurityScheme apiSecurityScheme() { + return new SecurityScheme() + .type(SecurityScheme.Type.HTTP) + .in(SecurityScheme.In.HEADER) + .name(JWT_SCHEME) + .scheme("Bearer") + .bearerFormat("JWT"); + } + + private Info apiInfo() { + return new Info() + .version("v1.0.0") + .title("E-DAY API Documentation") + .description("EFUB 3rd SWS : E-DAY API 공식 문서입니다."); + } +} From 76b0a6b609ccf87e1c44a1e8d22c3c8e867de121 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Mon, 24 Jul 2023 01:13:33 +0900 Subject: [PATCH 088/153] =?UTF-8?q?fix(FeignConfig):=20FeignClient=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=8C=80=EC=83=81=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EA=B2=BD=EB=A1=9C=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/efub/eday/edayback/global/config/FeignConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/global/config/FeignConfig.java b/src/main/java/efub/eday/edayback/global/config/FeignConfig.java index 6d71f9f..704b751 100644 --- a/src/main/java/efub/eday/edayback/global/config/FeignConfig.java +++ b/src/main/java/efub/eday/edayback/global/config/FeignConfig.java @@ -8,7 +8,7 @@ import feign.RequestInterceptor; @Configuration -@EnableFeignClients("efub.eday.edayback.feign") +@EnableFeignClients("efub.eday.edayback.global.feign") public class FeignConfig { @Bean From 0fe9c470b5690277c55d42ed2c6b587c7ec2d4a5 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Mon, 24 Jul 2023 01:20:14 +0900 Subject: [PATCH 089/153] =?UTF-8?q?chore:=20JDK=20=EB=B2=84=EC=A0=84=2017?= =?UTF-8?q?=20->=2011=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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 8e83bcf..b173916 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,9 +2,9 @@ name: Deploy to Amazon EC2 on: push: - branches: [ "setting" ] + branches: [ "main", "develop" ] pull_request: - branches: [ "setting" ] + branches: [ "main", "develop" ] env: AWS_REGION: ap-northeast-2 @@ -26,11 +26,11 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - name: Set up JDK 17 + - name: Set up JDK 11 uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: '17' + java-version: '11' - name: Grant execute permission for gradlew run: chmod +x gradlew From 1ada7e8b6af6b848c36ec56daf5b4958302fbbea Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Mon, 24 Jul 2023 01:23:25 +0900 Subject: [PATCH 090/153] =?UTF-8?q?chore:=20=EB=B0=B0=ED=8F=AC=20=EB=8C=80?= =?UTF-8?q?=EC=83=81=20=EB=B8=8C=EB=9E=9C=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 - develop 브랜치 제거 --- .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 b173916..d1198ee 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,7 +4,7 @@ on: push: branches: [ "main", "develop" ] pull_request: - branches: [ "main", "develop" ] + branches: [ "main" ] env: AWS_REGION: ap-northeast-2 From 8391c672b3dfdaa0e28b54851bc8beb73eb7eca6 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Mon, 24 Jul 2023 01:46:31 +0900 Subject: [PATCH 091/153] =?UTF-8?q?chore:=20.gitignore=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 --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0938820..498f61c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,8 +12,6 @@ .idea/**/dictionaries .idea/**/shelf - - # AWS User-specific .idea/**/aws.xml From e01e4854d491c0de3afba6783270abe094785646 Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Mon, 24 Jul 2023 02:22:03 +0900 Subject: [PATCH 092/153] =?UTF-8?q?chore:=20=EC=9C=A0=EC=A0=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20dto=EC=97=90=EC=84=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../efub/eday/edayback/domain/query/dto/QueryRequestDto.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java b/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java index e969cbf..0f268fc 100644 --- a/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java +++ b/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java @@ -5,7 +5,6 @@ /* { - "memberId" : 1, "queryContent" : "D-3 내용 문의드립니다!", "dday" : 3 } @@ -14,7 +13,6 @@ @Getter @Setter public class QueryRequestDto { - private Long memberId; private String queryContent; private int dday; } From 82397a0d90eef2a994f294c52878be07767127b8 Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Mon, 24 Jul 2023 02:23:08 +0900 Subject: [PATCH 093/153] =?UTF-8?q?chore:=20authService=EC=97=90=EC=84=9C?= =?UTF-8?q?=20getCurrentMember=20=ED=98=B8=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/query/controller/QueryController.java | 5 ----- .../eday/edayback/domain/query/service/QueryService.java | 7 +++---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java b/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java index 1c9f20b..9a9a36c 100644 --- a/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java +++ b/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java @@ -8,8 +8,6 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.server.ResponseStatusException; -import efub.eday.edayback.domain.member.auth.service.AuthService; -import efub.eday.edayback.domain.member.entity.Member; import efub.eday.edayback.domain.query.dto.QueryRequestDto; import efub.eday.edayback.domain.query.entity.Query; import efub.eday.edayback.domain.query.service.QueryService; @@ -20,14 +18,11 @@ @RequiredArgsConstructor public class QueryController { private final QueryService queryService; - private final AuthService authService; @PostMapping @ResponseStatus(value = HttpStatus.CREATED) public Query addquery(@RequestBody QueryRequestDto requestDto) { try { - Member writer = authService.getCurrentMember(); // 로그인된 유저 정보 가져오기 - requestDto.setMemberId(writer.getId()); // 가져온 유저 정보의 ID를 QueryRequestDto에 설정 return queryService.addQuery(requestDto); } catch (ResponseStatusException message) { throw message; diff --git a/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java b/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java index 75f42f5..abeecb4 100644 --- a/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java +++ b/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java @@ -8,8 +8,8 @@ import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.dday.entity.Subject; import efub.eday.edayback.domain.day.dday.repository.SubjectRepository; +import efub.eday.edayback.domain.member.auth.service.AuthService; import efub.eday.edayback.domain.member.entity.Member; -import efub.eday.edayback.domain.member.repository.MemberRepository; import efub.eday.edayback.domain.query.dto.QueryRequestDto; import efub.eday.edayback.domain.query.entity.Query; import efub.eday.edayback.domain.query.repository.QueryRepository; @@ -20,12 +20,11 @@ @RequiredArgsConstructor public class QueryService { private final QueryRepository queryRepository; - private final MemberRepository memberRepository; private final SubjectRepository subjectRepository; + private final AuthService authService; public Query addQuery(QueryRequestDto requestDto) { - Member writer = memberRepository.findById(requestDto.getMemberId()) - .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "유효하지 않은 ID입니다.")); + Member writer = authService.getCurrentMember(); // 로그인된 유저 정보 가져오기 Dday dday = Dday.fromRemainingDays(requestDto.getDday()); From 73e48a511452aee7f217e55c154a444f4fea9b84 Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Mon, 24 Jul 2023 02:30:35 +0900 Subject: [PATCH 094/153] =?UTF-8?q?chore:=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20403=20Forbidden=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eday/edayback/domain/query/service/QueryService.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java b/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java index abeecb4..4cb73ad 100644 --- a/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java +++ b/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java @@ -24,7 +24,12 @@ public class QueryService { private final AuthService authService; public Query addQuery(QueryRequestDto requestDto) { - Member writer = authService.getCurrentMember(); // 로그인된 유저 정보 가져오기 + Member writer; + try { + writer = authService.getCurrentMember(); // 로그인된 유저 정보 가져오기 + } catch (ResponseStatusException ex) { + throw new ResponseStatusException(HttpStatus.FORBIDDEN, "인증된 사용자 정보가 없습니다.", ex); + } Dday dday = Dday.fromRemainingDays(requestDto.getDday()); From cd17137cbb27bdb1c73dc88eac80ca237c2d8c6f Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Mon, 24 Jul 2023 02:38:23 +0900 Subject: [PATCH 095/153] =?UTF-8?q?chore:=20Title(=EC=B9=AD=ED=98=B8)=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../day/title/controller/TitleController.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java b/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java index 5e26b9d..ff52500 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java @@ -1,11 +1,9 @@ package efub.eday.edayback.domain.day.title.controller; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.server.ResponseStatusException; import efub.eday.edayback.domain.day.title.dto.TitleResponseDto; import efub.eday.edayback.domain.day.title.service.TitleService; @@ -20,14 +18,7 @@ public class TitleController { @GetMapping() public ResponseEntity<TitleResponseDto> getTitlePage() { - try { - TitleResponseDto titleResponseDto = titleService.getTitlePage(); - return ResponseEntity.ok(titleResponseDto); - } catch (IllegalArgumentException e) { - // 해당하는 Subject가 없는 경우 404 상태 코드와 에러 메시지를 반환 - throw new ResponseStatusException(HttpStatus.NOT_FOUND, "해당하는 Subject가 없습니다."); - } catch (Exception e) { - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "서버에서 오류가 발생했습니다."); - } + TitleResponseDto titleResponseDto = titleService.getTitlePage(); + return ResponseEntity.ok(titleResponseDto); } } From 0932a4dfee223286cad443e8127a27c1d2d1509c Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Mon, 24 Jul 2023 02:41:31 +0900 Subject: [PATCH 096/153] =?UTF-8?q?chore:=20try-catch=20=EB=B8=94=EB=A1=9D?= =?UTF-8?q?=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/day/info/controller/InfoController.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java b/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java index 55d09d2..d461520 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java @@ -6,7 +6,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.server.ResponseStatusException; import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.info.dto.InfoDto; @@ -24,11 +23,7 @@ public class InfoController { @ResponseStatus(value = HttpStatus.OK) public InfoDto getInfoByDday(@PathVariable("d_day") int dday) { Dday ddayEnum = Dday.fromRemainingDays(dday); - try { - Info info = infoService.getInfoByDday(ddayEnum); - return InfoDto.from(info); - } catch (ResponseStatusException message) { - throw message; - } + Info info = infoService.getInfoByDday(ddayEnum); + return InfoDto.from(info); } } From 77fab3d77162edfafdaf550ed879c51601d1f4cd Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Mon, 24 Jul 2023 07:35:10 +0900 Subject: [PATCH 097/153] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=A1=B0=ED=9A=8Capi=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/controller/MemberController.java | 13 ++++ .../domain/member/dto/MemberResponseDto.java | 1 + .../domain/member/dto/ProfileDto.java | 26 ++++++++ .../domain/member/dto/ProfileResDto.java | 17 +++++ .../edayback/domain/member/dto/QuizDto.java | 16 +++++ .../domain/member/dto/QuizListDto.java | 15 +++++ .../domain/member/service/MemberService.java | 63 +++++++++++++++++++ 7 files changed, 151 insertions(+) create mode 100644 src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java create mode 100644 src/main/java/efub/eday/edayback/domain/member/dto/ProfileResDto.java create mode 100644 src/main/java/efub/eday/edayback/domain/member/dto/QuizDto.java create mode 100644 src/main/java/efub/eday/edayback/domain/member/dto/QuizListDto.java diff --git a/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java b/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java index d8f4b07..4aae5f7 100644 --- a/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java +++ b/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java @@ -1,8 +1,13 @@ package efub.eday.edayback.domain.member.controller; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import efub.eday.edayback.domain.member.dto.ProfileResDto; +import efub.eday.edayback.domain.member.service.MemberService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -12,4 +17,12 @@ @RequestMapping("/member") public class MemberController { + private final MemberService memberService; + + @GetMapping + @ResponseStatus(value = HttpStatus.OK) + public ProfileResDto getMember() { + return memberService.getMember(); + } + } diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/MemberResponseDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/MemberResponseDto.java index 5f9abb1..04f8fba 100644 --- a/src/main/java/efub/eday/edayback/domain/member/dto/MemberResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/dto/MemberResponseDto.java @@ -5,6 +5,7 @@ @Getter public class MemberResponseDto { + private String nickname; private String profileImageUrl; private Integer level; diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java new file mode 100644 index 0000000..2a6b9b7 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java @@ -0,0 +1,26 @@ +package efub.eday.edayback.domain.member.dto; + +import efub.eday.edayback.domain.member.entity.Member; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class ProfileDto { + private String nickname; + private String profileImageUrl; + private int level; + private int dDay; + private String titleName; + + @Builder + public ProfileDto(Member member) { + this.nickname = member.getNickname(); + this.profileImageUrl = member.getProfileImageUrl(); + this.level = member.getLevel(); + this.dDay = 7 - member.getLevel(); + } +} diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileResDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileResDto.java new file mode 100644 index 0000000..ab83749 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileResDto.java @@ -0,0 +1,17 @@ +package efub.eday.edayback.domain.member.dto; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class ProfileResDto { + private ProfileDto profile; + private QuizListDto quiz; + + public ProfileResDto(ProfileDto profile, QuizListDto quiz) { + this.profile = profile; + this.quiz = quiz; + } +} + diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/QuizDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/QuizDto.java new file mode 100644 index 0000000..30daf90 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/dto/QuizDto.java @@ -0,0 +1,16 @@ +package efub.eday.edayback.domain.member.dto; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class QuizDto { + private int dday; + + public QuizDto(int dday) { + this.dday = dday; + } +} diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/QuizListDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/QuizListDto.java new file mode 100644 index 0000000..028a301 --- /dev/null +++ b/src/main/java/efub/eday/edayback/domain/member/dto/QuizListDto.java @@ -0,0 +1,15 @@ +package efub.eday.edayback.domain.member.dto; + +import java.util.List; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class QuizListDto { + private List<QuizDto> openList; + private List<QuizDto> doneList; + private List<QuizDto> closeList; + +} diff --git a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java index d3568a1..d94c5a3 100644 --- a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java +++ b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java @@ -1,7 +1,23 @@ package efub.eday.edayback.domain.member.service; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.List; + import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import efub.eday.edayback.domain.day.title.entity.Title; +import efub.eday.edayback.domain.day.title.repository.TitleRepository; +import efub.eday.edayback.domain.member.auth.service.AuthService; +import efub.eday.edayback.domain.member.dto.ProfileDto; +import efub.eday.edayback.domain.member.dto.ProfileResDto; +import efub.eday.edayback.domain.member.dto.QuizDto; +import efub.eday.edayback.domain.member.dto.QuizListDto; +import efub.eday.edayback.domain.member.entity.Member; +import efub.eday.edayback.domain.member.entity.MemberTitle; +import efub.eday.edayback.domain.member.repository.MemberTitleRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -10,4 +26,51 @@ @Service public class MemberService { + private final AuthService authService; + private final MemberTitleRepository memberTitleRepository; + private final TitleRepository titleRepository; + + @Transactional(readOnly = true) + public ProfileResDto getMember() { + Member member = authService.getCurrentMember(); + + ProfileDto profile = new ProfileDto(member); + Title title = titleRepository.findBySubjectId(profile.getDDay()).orElseThrow(IllegalArgumentException::new); + profile.setTitleName(title.getName()); + + // 현재 날짜와 데이터베이스에 저장된 날짜 사이의 차이 계산 + LocalDateTime currentDate = LocalDateTime.now(); + int differenceInDays = Math.toIntExact(ChronoUnit.DAYS.between(member.getCreatedDate(), currentDate)); + if (differenceInDays >= 7) { + differenceInDays = 7; + } + + //날짜가 같아 그러면 difference=0, openList는 dDay=7 하나 + List<QuizDto> openList = new ArrayList<>(); + for (int dDay = 7; dDay >= 7 - differenceInDays; dDay--) { + openList.add(new QuizDto(dDay)); + } + + List<QuizDto> doneList = new ArrayList<>(); + List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); + for (MemberTitle memberTitle : memberTitles) { + if (memberTitle.getGetTitle()) { + int dDay = memberTitle.getTitle().getSubject().getDday(); + doneList.add(new QuizDto(dDay)); + } + } + + List<QuizDto> closeList = new ArrayList<>(); + for (int dDay = 6 - differenceInDays; dDay >= 1; dDay--) { + closeList.add(new QuizDto(dDay)); + } + + QuizListDto quizListDto = new QuizListDto(); + quizListDto.setOpenList(openList); + quizListDto.setDoneList(doneList); + quizListDto.setCloseList(closeList); + + return new ProfileResDto(profile, quizListDto); + } + } From 75be31d91da3741d32e1f8dc2927dab13d9253bc Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Mon, 24 Jul 2023 14:09:26 +0900 Subject: [PATCH 098/153] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20api=20=EC=9E=91=EC=84=B1?= =?UTF-8?q?=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/dto/ProfileDto.java | 12 +++---- .../domain/member/dto/ProfileResDto.java | 6 ++++ .../domain/member/entity/MemberQuiz.java | 4 ++- .../domain/member/service/MemberService.java | 33 +++++++++++-------- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java index 2a6b9b7..303fe44 100644 --- a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java @@ -1,6 +1,5 @@ package efub.eday.edayback.domain.member.dto; -import efub.eday.edayback.domain.member.entity.Member; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -17,10 +16,11 @@ public class ProfileDto { private String titleName; @Builder - public ProfileDto(Member member) { - this.nickname = member.getNickname(); - this.profileImageUrl = member.getProfileImageUrl(); - this.level = member.getLevel(); - this.dDay = 7 - member.getLevel(); + public ProfileDto(String nickname, String profileImageUrl, int level, String titleName) { + this.nickname = nickname; + this.profileImageUrl = profileImageUrl; + this.level = level; + this.dDay = 7 - level; + this.titleName = titleName; } } diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileResDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileResDto.java index ab83749..6fe6524 100644 --- a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileResDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileResDto.java @@ -7,11 +7,17 @@ @NoArgsConstructor public class ProfileResDto { private ProfileDto profile; + + /* private QuizListDto quiz; public ProfileResDto(ProfileDto profile, QuizListDto quiz) { this.profile = profile; this.quiz = quiz; } + */ + public ProfileResDto(ProfileDto profile) { + this.profile = profile; + } } diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java b/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java index a15bc7f..3713e39 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/MemberQuiz.java @@ -16,7 +16,9 @@ @Entity @Setter @NoArgsConstructor -public class MemberQuiz { +public class + +MemberQuiz { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java index d94c5a3..44a51a3 100644 --- a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java +++ b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java @@ -1,10 +1,5 @@ package efub.eday.edayback.domain.member.service; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.ArrayList; -import java.util.List; - import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -13,10 +8,7 @@ import efub.eday.edayback.domain.member.auth.service.AuthService; import efub.eday.edayback.domain.member.dto.ProfileDto; import efub.eday.edayback.domain.member.dto.ProfileResDto; -import efub.eday.edayback.domain.member.dto.QuizDto; -import efub.eday.edayback.domain.member.dto.QuizListDto; import efub.eday.edayback.domain.member.entity.Member; -import efub.eday.edayback.domain.member.entity.MemberTitle; import efub.eday.edayback.domain.member.repository.MemberTitleRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -34,9 +26,20 @@ public class MemberService { public ProfileResDto getMember() { Member member = authService.getCurrentMember(); - ProfileDto profile = new ProfileDto(member); - Title title = titleRepository.findBySubjectId(profile.getDDay()).orElseThrow(IllegalArgumentException::new); - profile.setTitleName(title.getName()); + //return new ProfileDto(member); + Integer subjectId = Integer.valueOf(7 - member.getLevel()); + + Title title = titleRepository.findBySubjectId(subjectId) + .orElseThrow(() -> new IllegalArgumentException("해당 subject_id에 대한 타이틀을 찾을 수 없습니다.")); + + ProfileDto profile = new ProfileDto( + member.getNickname(), + member.getProfileImageUrl(), + member.getLevel(), + title.getName() + ); + + /* // 현재 날짜와 데이터베이스에 저장된 날짜 사이의 차이 계산 LocalDateTime currentDate = LocalDateTime.now(); @@ -55,8 +58,8 @@ public ProfileResDto getMember() { List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); for (MemberTitle memberTitle : memberTitles) { if (memberTitle.getGetTitle()) { - int dDay = memberTitle.getTitle().getSubject().getDday(); - doneList.add(new QuizDto(dDay)); + int subject = memberTitle.getTitle().getSubject().getDday(); + doneList.add(new QuizDto(subject)); } } @@ -69,8 +72,10 @@ public ProfileResDto getMember() { quizListDto.setOpenList(openList); quizListDto.setDoneList(doneList); quizListDto.setCloseList(closeList); + */ - return new ProfileResDto(profile, quizListDto); + //return new ProfileResDto(profile, quizListDto); + return new ProfileResDto(profile); } } From 9b59789719f0bf8799d0b3226bb30b8122916079 Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Mon, 24 Jul 2023 18:17:07 +0900 Subject: [PATCH 099/153] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20api=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../day/title/repository/TitleRepository.java | 10 ++++-- .../domain/member/dto/ProfileResDto.java | 6 +--- .../domain/member/service/MemberService.java | 33 ++++++++++--------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/title/repository/TitleRepository.java b/src/main/java/efub/eday/edayback/domain/day/title/repository/TitleRepository.java index ca82959..74fb458 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/repository/TitleRepository.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/repository/TitleRepository.java @@ -1,12 +1,16 @@ package efub.eday.edayback.domain.day.title.repository; -import efub.eday.edayback.domain.day.title.entity.Title; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import java.util.Optional; +import efub.eday.edayback.domain.day.dday.entity.Dday; +import efub.eday.edayback.domain.day.title.entity.Title; @Repository public interface TitleRepository extends JpaRepository<Title, Integer> { - Optional<Title> findBySubjectId(Integer subjectId); + Optional<Title> findBySubjectId(Integer subjectId); + + Optional<Title> findBySubject_Dday(Dday dday); } diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileResDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileResDto.java index 6fe6524..bdba7c2 100644 --- a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileResDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileResDto.java @@ -8,16 +8,12 @@ public class ProfileResDto { private ProfileDto profile; - /* private QuizListDto quiz; public ProfileResDto(ProfileDto profile, QuizListDto quiz) { this.profile = profile; this.quiz = quiz; } - */ - public ProfileResDto(ProfileDto profile) { - this.profile = profile; - } + } diff --git a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java index 44a51a3..b014401 100644 --- a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java +++ b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java @@ -1,14 +1,19 @@ package efub.eday.edayback.domain.member.service; +import java.util.ArrayList; +import java.util.List; + import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import efub.eday.edayback.domain.day.title.entity.Title; import efub.eday.edayback.domain.day.title.repository.TitleRepository; import efub.eday.edayback.domain.member.auth.service.AuthService; import efub.eday.edayback.domain.member.dto.ProfileDto; import efub.eday.edayback.domain.member.dto.ProfileResDto; +import efub.eday.edayback.domain.member.dto.QuizDto; +import efub.eday.edayback.domain.member.dto.QuizListDto; import efub.eday.edayback.domain.member.entity.Member; +import efub.eday.edayback.domain.member.entity.MemberTitle; import efub.eday.edayback.domain.member.repository.MemberTitleRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -19,34 +24,34 @@ public class MemberService { private final AuthService authService; - private final MemberTitleRepository memberTitleRepository; private final TitleRepository titleRepository; + private final MemberTitleRepository memberTitleRepository; - @Transactional(readOnly = true) + //@Transactional(readOnly = true) public ProfileResDto getMember() { + //현재 로그인 중인 사용자 정보 불러오기 Member member = authService.getCurrentMember(); - //return new ProfileDto(member); - Integer subjectId = Integer.valueOf(7 - member.getLevel()); + int level = member.getLevel(); - Title title = titleRepository.findBySubjectId(subjectId) - .orElseThrow(() -> new IllegalArgumentException("해당 subject_id에 대한 타이틀을 찾을 수 없습니다.")); + //칭호는 dDay가 아닌 level을 기준으로 정해짐 + Title title = titleRepository.findBySubjectId(level).orElseThrow(); - ProfileDto profile = new ProfileDto( - member.getNickname(), + //profile부분에 들어갈 속성들 + ProfileDto profile = new ProfileDto(member.getNickname(), member.getProfileImageUrl(), member.getLevel(), - title.getName() - ); + title.getName()); /* - // 현재 날짜와 데이터베이스에 저장된 날짜 사이의 차이 계산 LocalDateTime currentDate = LocalDateTime.now(); int differenceInDays = Math.toIntExact(ChronoUnit.DAYS.between(member.getCreatedDate(), currentDate)); if (differenceInDays >= 7) { differenceInDays = 7; } + */ + int differenceInDays = 2; //날짜가 같아 그러면 difference=0, openList는 dDay=7 하나 List<QuizDto> openList = new ArrayList<>(); @@ -72,10 +77,8 @@ public ProfileResDto getMember() { quizListDto.setOpenList(openList); quizListDto.setDoneList(doneList); quizListDto.setCloseList(closeList); - */ - //return new ProfileResDto(profile, quizListDto); - return new ProfileResDto(profile); + return new ProfileResDto(profile, quizListDto); } } From f4f00ae36a72f94215260d99622450ce3210c235 Mon Sep 17 00:00:00 2001 From: hannah0226 <mohan0226@naver.com> Date: Mon, 24 Jul 2023 19:03:30 +0900 Subject: [PATCH 100/153] =?UTF-8?q?feat:=20Quiz(=ED=80=B4=EC=A6=88)=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EC=BD=94=EB=93=9C=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 --- .../day/quiz/controller/QuizController.java | 17 ++++++++++++----- .../domain/day/quiz/service/QuizService.java | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java index 0d3f3ba..f2b2fb2 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java @@ -1,6 +1,7 @@ package efub.eday.edayback.domain.day.quiz.controller; import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -34,15 +35,21 @@ public QuizResponseDto findQuiz(@PathVariable int dDay) { //퀴즈 정답 확인 @PostMapping - public QuizAnswerResponseDto checkAnswer( + public ResponseEntity<QuizAnswerResponseDto> checkAnswer( @PathVariable int dDay, @RequestBody QuizRequestDto quizRequestDto ) { - boolean isCorrect = quizService.checkAnswer(dDay, quizRequestDto.getOptionNumber()); + boolean isCorrect; String quizDescription = null; - if (isCorrect) { - quizDescription = quizService.getQuizDescription(dDay); + try { + isCorrect = quizService.checkAnswer(dDay, quizRequestDto.getOptionNumber()); + if (isCorrect) { + quizDescription = quizService.getQuizDescription(dDay); + } + } catch (IllegalArgumentException e) { + String errorMessage = e.getMessage(); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new QuizAnswerResponseDto(false, errorMessage)); } - return new QuizAnswerResponseDto(isCorrect, quizDescription); + return ResponseEntity.ok(new QuizAnswerResponseDto(isCorrect, quizDescription)); } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java index 90ddb18..a5a857a 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java @@ -31,7 +31,7 @@ public class QuizService { public Quiz findQuiz(int d_day) { Dday dday = Dday.fromRemainingDays(d_day); return quizRepository.findBySubject_Dday(dday) - .orElseThrow(() -> new IllegalArgumentException("퀴즈를 찾을 수 없습니다.")); + .orElseThrow(() -> new IllegalArgumentException("해당 날짜의 퀴즈를 찾을 수 없습니다.")); } //퀴즈 정답 확인 From b995742e055ee68543963cfd6310699ee0778d0a Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Mon, 24 Jul 2023 19:47:31 +0900 Subject: [PATCH 101/153] =?UTF-8?q?chore:=20=EB=82=A0=EC=A7=9C=20=EC=B0=A8?= =?UTF-8?q?=EC=9D=B4=20=EB=B6=80=EB=B6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/service/MemberService.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java index b014401..26349ca 100644 --- a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java +++ b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java @@ -1,9 +1,12 @@ package efub.eday.edayback.domain.member.service; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import efub.eday.edayback.domain.day.title.entity.Title; import efub.eday.edayback.domain.day.title.repository.TitleRepository; @@ -27,7 +30,7 @@ public class MemberService { private final TitleRepository titleRepository; private final MemberTitleRepository memberTitleRepository; - //@Transactional(readOnly = true) + @Transactional(readOnly = true) public ProfileResDto getMember() { //현재 로그인 중인 사용자 정보 불러오기 Member member = authService.getCurrentMember(); @@ -43,20 +46,19 @@ public ProfileResDto getMember() { member.getLevel(), title.getName()); - /* // 현재 날짜와 데이터베이스에 저장된 날짜 사이의 차이 계산 LocalDateTime currentDate = LocalDateTime.now(); int differenceInDays = Math.toIntExact(ChronoUnit.DAYS.between(member.getCreatedDate(), currentDate)); if (differenceInDays >= 7) { differenceInDays = 7; } - */ - int differenceInDays = 2; //날짜가 같아 그러면 difference=0, openList는 dDay=7 하나 List<QuizDto> openList = new ArrayList<>(); for (int dDay = 7; dDay >= 7 - differenceInDays; dDay--) { - openList.add(new QuizDto(dDay)); + if (dDay != 0) { + openList.add(new QuizDto(dDay)); + } } List<QuizDto> doneList = new ArrayList<>(); From fc94ff53e22dbdad843b05c0062866f5bfd65772 Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Mon, 24 Jul 2023 19:55:09 +0900 Subject: [PATCH 102/153] =?UTF-8?q?chore:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20Dto=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/dto/MemberResponseDto.java | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 src/main/java/efub/eday/edayback/domain/member/dto/MemberResponseDto.java diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/MemberResponseDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/MemberResponseDto.java deleted file mode 100644 index 04f8fba..0000000 --- a/src/main/java/efub/eday/edayback/domain/member/dto/MemberResponseDto.java +++ /dev/null @@ -1,19 +0,0 @@ -package efub.eday.edayback.domain.member.dto; - -import efub.eday.edayback.domain.member.entity.Member; -import lombok.Getter; - -@Getter -public class MemberResponseDto { - - private String nickname; - private String profileImageUrl; - private Integer level; - - public MemberResponseDto(Member member) { - this.nickname = member.getNickname(); - this.profileImageUrl = member.getProfileImageUrl(); - this.level = member.getLevel(); - } - -} From 09852482d3b893ced25342ae8d24d2ce51ac2cb0 Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Mon, 24 Jul 2023 20:30:55 +0900 Subject: [PATCH 103/153] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=EC=8B=9C=20=EB=AA=A8=EB=93=A0=20=EB=94=94=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=EC=97=90=20=EB=8C=80=ED=95=9C=20MemberQuiz=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 --- .../member/auth/service/AuthService.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java index 86ddc33..f746424 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java @@ -1,5 +1,7 @@ package efub.eday.edayback.domain.member.auth.service; +import java.util.List; + import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -8,12 +10,18 @@ import org.springframework.stereotype.Service; import org.springframework.web.server.ResponseStatusException; +import efub.eday.edayback.domain.day.quiz.entity.Quiz; +import efub.eday.edayback.domain.day.quiz.repository.QuizRepository; +import efub.eday.edayback.domain.day.title.repository.TitleRepository; import efub.eday.edayback.domain.member.auth.dto.AuthResponseDto; import efub.eday.edayback.domain.member.auth.dto.KakaoProfileResponseDto; import efub.eday.edayback.domain.member.auth.dto.KakaoTokenRequestDto; import efub.eday.edayback.domain.member.auth.dto.KakaoTokenResponseDto; import efub.eday.edayback.domain.member.entity.Member; +import efub.eday.edayback.domain.member.entity.MemberQuiz; +import efub.eday.edayback.domain.member.repository.MemberQuizRepository; import efub.eday.edayback.domain.member.repository.MemberRepository; +import efub.eday.edayback.domain.member.repository.MemberTitleRepository; import efub.eday.edayback.global.feign.KakaoApiFeign; import efub.eday.edayback.global.feign.KakaoAuthFeign; import efub.eday.edayback.global.jwt.JwtProvider; @@ -31,6 +39,10 @@ public class AuthService { private final KakaoAuthFeign kakaoAuthFeign; private final KakaoApiFeign kakaoApiFeign; private final MemberRepository memberRepository; + private final QuizRepository quizRepository; + private final MemberQuizRepository memberQuizRepository; + private final TitleRepository titleRepository; + private final MemberTitleRepository memberTitleRepository; private final JwtProvider jwtProvider; @Value("${kakao.client-id}") @@ -94,7 +106,15 @@ private Member getKakaoProfile(String kakaoToken) { } private void signUp(Member member) { + memberRepository.save(member); + + List<Quiz> quizs = quizRepository.findAll(); + for (Quiz quiz : quizs) { + MemberQuiz mQuiz = new MemberQuiz(member, quiz); + memberQuizRepository.save(mQuiz); + } + } public Member getCurrentMember() { From 2c2ad09f3a6c8ba63ad93c57af81f337be05e7fd Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Mon, 24 Jul 2023 20:32:38 +0900 Subject: [PATCH 104/153] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=EC=8B=9C=20=EB=AA=A8=EB=93=A0=20=EB=94=94=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=EC=97=90=20=EB=8C=80=ED=95=9C=20MemberTitle=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 --- .../edayback/domain/member/auth/service/AuthService.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java index f746424..6e08dca 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java @@ -12,6 +12,7 @@ import efub.eday.edayback.domain.day.quiz.entity.Quiz; import efub.eday.edayback.domain.day.quiz.repository.QuizRepository; +import efub.eday.edayback.domain.day.title.entity.Title; import efub.eday.edayback.domain.day.title.repository.TitleRepository; import efub.eday.edayback.domain.member.auth.dto.AuthResponseDto; import efub.eday.edayback.domain.member.auth.dto.KakaoProfileResponseDto; @@ -19,6 +20,7 @@ import efub.eday.edayback.domain.member.auth.dto.KakaoTokenResponseDto; import efub.eday.edayback.domain.member.entity.Member; import efub.eday.edayback.domain.member.entity.MemberQuiz; +import efub.eday.edayback.domain.member.entity.MemberTitle; import efub.eday.edayback.domain.member.repository.MemberQuizRepository; import efub.eday.edayback.domain.member.repository.MemberRepository; import efub.eday.edayback.domain.member.repository.MemberTitleRepository; @@ -115,6 +117,12 @@ private void signUp(Member member) { memberQuizRepository.save(mQuiz); } + List<Title> titles = titleRepository.findAll(); + for (Title title : titles) { + MemberTitle mTitle = new MemberTitle(member, title); + memberTitleRepository.save(mTitle); + } + } public Member getCurrentMember() { From c5dabb5a655c236d95e26296473a3673df5d793b Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Mon, 24 Jul 2023 22:21:19 +0900 Subject: [PATCH 105/153] =?UTF-8?q?feat:=20=EC=9D=B8=EC=A6=9D=EB=90=9C=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EC=A0=95=EB=B3=B4=EA=B0=80=20=EC=97=86?= =?UTF-8?q?=EC=9C=BC=EB=A9=B4=20ResponseStatusException=EC=9D=84=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D=EC=8B=9C=ED=82=A4=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/member/auth/service/AuthService.java | 5 ++++- .../edayback/domain/query/controller/QueryController.java | 7 +------ .../eday/edayback/domain/query/service/QueryService.java | 7 +------ 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java index 81d88e4..dd7335a 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java @@ -2,9 +2,11 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; +import org.springframework.web.server.ResponseStatusException; import efub.eday.edayback.domain.member.auth.dto.AuthResponseDto; import efub.eday.edayback.domain.member.auth.dto.KakaoProfileResponseDto; @@ -99,6 +101,7 @@ public Member getCurrentMember() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String principalName = authentication.getName(); Long memberId = Long.parseLong(principalName); - return memberRepository.findById(memberId).orElseThrow(IllegalArgumentException::new); + return memberRepository.findById(memberId).orElseThrow(() -> + new ResponseStatusException(HttpStatus.FORBIDDEN, "인증된 사용자 정보가 없습니다.")); } } diff --git a/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java b/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java index 9a9a36c..0f8d4cf 100644 --- a/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java +++ b/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java @@ -6,7 +6,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.server.ResponseStatusException; import efub.eday.edayback.domain.query.dto.QueryRequestDto; import efub.eday.edayback.domain.query.entity.Query; @@ -22,10 +21,6 @@ public class QueryController { @PostMapping @ResponseStatus(value = HttpStatus.CREATED) public Query addquery(@RequestBody QueryRequestDto requestDto) { - try { - return queryService.addQuery(requestDto); - } catch (ResponseStatusException message) { - throw message; - } + return queryService.addQuery(requestDto); } } diff --git a/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java b/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java index 4cb73ad..331dd74 100644 --- a/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java +++ b/src/main/java/efub/eday/edayback/domain/query/service/QueryService.java @@ -24,12 +24,7 @@ public class QueryService { private final AuthService authService; public Query addQuery(QueryRequestDto requestDto) { - Member writer; - try { - writer = authService.getCurrentMember(); // 로그인된 유저 정보 가져오기 - } catch (ResponseStatusException ex) { - throw new ResponseStatusException(HttpStatus.FORBIDDEN, "인증된 사용자 정보가 없습니다.", ex); - } + Member writer = authService.getCurrentMember(); Dday dday = Dday.fromRemainingDays(requestDto.getDday()); From a08d6b79ddf37a56c6e9e1fa179a74fe219e369c Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Tue, 25 Jul 2023 01:49:20 +0900 Subject: [PATCH 106/153] =?UTF-8?q?feat:=20CORS=20=EC=84=A4=EC=A0=95=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 --- .../global/config/AuthenticationConfig.java | 2 -- .../eday/edayback/global/config/CorsConfig.java | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 src/main/java/efub/eday/edayback/global/config/CorsConfig.java diff --git a/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java b/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java index b2af603..3d664f9 100644 --- a/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java +++ b/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java @@ -27,8 +27,6 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws return httpSecurity .httpBasic().disable() .csrf().disable() - .cors() - .and() .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) // 세션 대신 jwt 사용하는 경우 사용 .and() .authorizeRequests() diff --git a/src/main/java/efub/eday/edayback/global/config/CorsConfig.java b/src/main/java/efub/eday/edayback/global/config/CorsConfig.java new file mode 100644 index 0000000..ebcffb2 --- /dev/null +++ b/src/main/java/efub/eday/edayback/global/config/CorsConfig.java @@ -0,0 +1,16 @@ +package efub.eday.edayback.global.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class CorsConfig implements WebMvcConfigurer { + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedMethods(HttpMethod.GET.name(), HttpMethod.POST.name()); + } +} From 96f7eb69b217ff5b12322bd3b32b081beec87714 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Tue, 25 Jul 2023 01:57:09 +0900 Subject: [PATCH 107/153] =?UTF-8?q?feat:=20OpenApi=20=EC=84=9C=EB=B2=84=20?= =?UTF-8?q?=EC=A3=BC=EC=86=8C=20=EB=B3=80=EA=B2=BD=20(https=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/efub/eday/edayback/global/config/OpenApiConfig.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/efub/eday/edayback/global/config/OpenApiConfig.java b/src/main/java/efub/eday/edayback/global/config/OpenApiConfig.java index 3137713..cba5886 100644 --- a/src/main/java/efub/eday/edayback/global/config/OpenApiConfig.java +++ b/src/main/java/efub/eday/edayback/global/config/OpenApiConfig.java @@ -3,6 +3,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.servers.Server; import io.swagger.v3.oas.models.Components; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Info; @@ -10,6 +12,7 @@ import io.swagger.v3.oas.models.security.SecurityScheme; @Configuration +@OpenAPIDefinition(servers = {@Server(url = "https://api.ewha-day.com", description = "Default Server URL")}) public class OpenApiConfig { private static final String JWT_SCHEME = "JWT Auth"; From f784e1d4dc7d6243f01d58d76b4e3898c4d1ebb2 Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Tue, 25 Jul 2023 19:43:55 +0900 Subject: [PATCH 108/153] =?UTF-8?q?chore:=20Subject=20Column=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/efub/eday/edayback/domain/query/entity/Query.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/domain/query/entity/Query.java b/src/main/java/efub/eday/edayback/domain/query/entity/Query.java index 02ecec3..43243f4 100644 --- a/src/main/java/efub/eday/edayback/domain/query/entity/Query.java +++ b/src/main/java/efub/eday/edayback/domain/query/entity/Query.java @@ -32,7 +32,7 @@ public class Query { private Member writer; @ManyToOne - @JoinColumn(nullable = false) + @JoinColumn(name = "subject_id", nullable = false) private Subject subject; @Builder From d423a1f813aaef67a5cbb39f4b14949ed6902908 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Thu, 27 Jul 2023 10:10:51 +0900 Subject: [PATCH 109/153] =?UTF-8?q?feat:=20CORS=20=EC=84=A4=EC=A0=95=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 --- .../eday/edayback/global/config/AuthenticationConfig.java | 3 +++ .../java/efub/eday/edayback/global/config/CorsConfig.java | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java b/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java index 3d664f9..fd82287 100644 --- a/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java +++ b/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java @@ -26,7 +26,10 @@ public class AuthenticationConfig { public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception { return httpSecurity .httpBasic().disable() + .cors() + .and() .csrf().disable() + .formLogin().disable() .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) // 세션 대신 jwt 사용하는 경우 사용 .and() .authorizeRequests() diff --git a/src/main/java/efub/eday/edayback/global/config/CorsConfig.java b/src/main/java/efub/eday/edayback/global/config/CorsConfig.java index ebcffb2..7ee0259 100644 --- a/src/main/java/efub/eday/edayback/global/config/CorsConfig.java +++ b/src/main/java/efub/eday/edayback/global/config/CorsConfig.java @@ -11,6 +11,11 @@ public class CorsConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") - .allowedMethods(HttpMethod.GET.name(), HttpMethod.POST.name()); + .allowCredentials(true) + .exposedHeaders("Authorization") + .allowedOrigins("http://localhost:3000") + .allowedOrigins("https://ewha-day.com") + .allowedMethods(HttpMethod.GET.name(), HttpMethod.POST.name()) + .maxAge(3600); } } From 71d51398fa7555ae859db353a9cd42bc6bc2e1da Mon Sep 17 00:00:00 2001 From: hannah0226 <mohan0226@naver.com> Date: Fri, 28 Jul 2023 21:15:39 +0900 Subject: [PATCH 110/153] =?UTF-8?q?feat:=20Quiz=20API=20=EB=AA=85=EC=84=B8?= =?UTF-8?q?=EC=84=9C=20=EC=9E=91=EC=84=B1=20(Swagger)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../day/quiz/controller/QuizController.java | 61 +++++++++++++------ .../day/quiz/dto/OptionsResponseDto.java | 3 + .../day/quiz/dto/QuizAnswerResponseDto.java | 3 + .../domain/day/quiz/dto/QuizRequestDto.java | 2 + .../domain/day/quiz/dto/QuizResponseDto.java | 5 ++ 5 files changed, 56 insertions(+), 18 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java index f2b2fb2..2034e57 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java @@ -1,23 +1,30 @@ package efub.eday.edayback.domain.day.quiz.controller; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -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.ResponseStatus; -import org.springframework.web.bind.annotation.RestController; + import io.swagger.v3.oas.annotations.Operation; + import io.swagger.v3.oas.annotations.media.Content; + import io.swagger.v3.oas.annotations.media.Schema; + import io.swagger.v3.oas.annotations.responses.ApiResponse; + import io.swagger.v3.oas.annotations.responses.ApiResponses; + import io.swagger.v3.oas.annotations.tags.Tag; + import org.springframework.http.HttpStatus; + import org.springframework.http.ResponseEntity; + import org.springframework.web.bind.annotation.GetMapping; + import org.springframework.web.bind.annotation.PathVariable; + 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.ResponseStatus; + import org.springframework.web.bind.annotation.RestController; -import efub.eday.edayback.domain.day.quiz.dto.QuizAnswerResponseDto; -import efub.eday.edayback.domain.day.quiz.dto.QuizRequestDto; -import efub.eday.edayback.domain.day.quiz.dto.QuizResponseDto; -import efub.eday.edayback.domain.day.quiz.entity.Quiz; -import efub.eday.edayback.domain.day.quiz.service.QuizService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; + import efub.eday.edayback.domain.day.quiz.dto.QuizAnswerResponseDto; + import efub.eday.edayback.domain.day.quiz.dto.QuizRequestDto; + import efub.eday.edayback.domain.day.quiz.dto.QuizResponseDto; + import efub.eday.edayback.domain.day.quiz.entity.Quiz; + import efub.eday.edayback.domain.day.quiz.service.QuizService; + import lombok.RequiredArgsConstructor; + import lombok.extern.slf4j.Slf4j; +@Tag(name="퀴즈", description = "퀴즈 관련 api입니다.") @Slf4j @RestController @RequestMapping("/quiz/{dDay}") @@ -26,6 +33,15 @@ public class QuizController { private final QuizService quizService; //퀴즈 내용 조회 + @Operation(summary = "퀴즈 내용 조회 메서드", description = "해당 디데이의 퀴즈를 조회하는 메서드입니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "퀴즈 내용 조회 성공", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = QuizResponseDto.class))), + @ApiResponse(responseCode = "404", description = "퀴즈 내용 조회 실패", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = QuizResponseDto.class))) + }) @GetMapping @ResponseStatus(value = HttpStatus.OK) public QuizResponseDto findQuiz(@PathVariable int dDay) { @@ -34,10 +50,19 @@ public QuizResponseDto findQuiz(@PathVariable int dDay) { } //퀴즈 정답 확인 + @Operation(summary = "퀴즈 정답 확인 메서드", description = "퀴즈 선지 중 하나를 보내면 정답 여부를 판별해 주는 메서드입니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "퀴즈 정답 확인 성공", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = QuizAnswerResponseDto.class))), + @ApiResponse(responseCode = "404", description = "퀴즈 정답 확인 실패", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = QuizAnswerResponseDto.class))) + }) @PostMapping public ResponseEntity<QuizAnswerResponseDto> checkAnswer( - @PathVariable int dDay, - @RequestBody QuizRequestDto quizRequestDto + @PathVariable int dDay, + @RequestBody QuizRequestDto quizRequestDto ) { boolean isCorrect; String quizDescription = null; diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java index ab9b1e3..129448a 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/OptionsResponseDto.java @@ -1,6 +1,7 @@ package efub.eday.edayback.domain.day.quiz.dto; import efub.eday.edayback.domain.day.quiz.entity.Option; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -8,7 +9,9 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class OptionsResponseDto { + @Schema(description = "선지 번호") private Integer optionNumber; + @Schema(description = "선지 내용") private String content; private OptionsResponseDto(Integer optionNumber, String content) { diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java index 12b6a79..b7c94ad 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java @@ -1,5 +1,6 @@ package efub.eday.edayback.domain.day.quiz.dto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -8,7 +9,9 @@ @Setter @NoArgsConstructor public class QuizAnswerResponseDto { + @Schema(description = "정답 여부") private boolean isAnswer; + @Schema(description = "해당 퀴즈에 대한 설명") private String quizDescription; public QuizAnswerResponseDto(boolean isAnswer, String quizDescription) { diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizRequestDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizRequestDto.java index f2cd385..59df8be 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizRequestDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizRequestDto.java @@ -1,8 +1,10 @@ package efub.eday.edayback.domain.day.quiz.dto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; @Getter public class QuizRequestDto { + @Schema(description = "선지 번호", example = "1") private int optionNumber; } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java index 49f9611..287fcf2 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizResponseDto.java @@ -4,6 +4,7 @@ import java.util.stream.Collectors; import efub.eday.edayback.domain.day.quiz.entity.Quiz; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -13,9 +14,13 @@ @Setter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class QuizResponseDto { + @Schema(description = "디데이") private int dday; + @Schema(description = "각 구역의 주제") private String topic; + @Schema(description = "퀴즈 질문") private String quizContent; + @Schema(description = "정답 선택지 리스트") private List<OptionsResponseDto> optionList; public QuizResponseDto(int dday, String topic, String quizContent, List<OptionsResponseDto> optionList) { From 64866ecde944d206ec796c1cf36d8aacfed2b6bb Mon Sep 17 00:00:00 2001 From: hannah0226 <mohan0226@naver.com> Date: Fri, 28 Jul 2023 21:54:17 +0900 Subject: [PATCH 111/153] =?UTF-8?q?feat:=20Query=20API=20=EB=AA=85?= =?UTF-8?q?=EC=84=B8=EC=84=9C=20=EC=9E=91=EC=84=B1=20(Swagger)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/query/controller/QueryController.java | 10 ++++++++++ .../edayback/domain/query/dto/QueryRequestDto.java | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java b/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java index 0f8d4cf..27681d8 100644 --- a/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java +++ b/src/main/java/efub/eday/edayback/domain/query/controller/QueryController.java @@ -1,5 +1,10 @@ package efub.eday.edayback.domain.query.controller; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -15,9 +20,14 @@ @RestController @RequestMapping("/querys") @RequiredArgsConstructor +@Tag(name = "문의", description = "문의사항 관련 api입니다") public class QueryController { private final QueryService queryService; + @Operation(summary = "문의사항 추가 메서드", description = "새로운 문의사항을 추가하는 메서드 입니다") + @ApiResponse(responseCode = "201", description = "문의사항 추가 성공", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = Query.class))) @PostMapping @ResponseStatus(value = HttpStatus.CREATED) public Query addquery(@RequestBody QueryRequestDto requestDto) { diff --git a/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java b/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java index 0f268fc..eea60aa 100644 --- a/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java +++ b/src/main/java/efub/eday/edayback/domain/query/dto/QueryRequestDto.java @@ -1,5 +1,6 @@ package efub.eday.edayback.domain.query.dto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.Setter; @@ -13,6 +14,8 @@ @Getter @Setter public class QueryRequestDto { + @Schema(description = "문의사항 내용", example = "D-3 내용 문의 드립니다!") private String queryContent; + @Schema(description = "디데이", example = "3") private int dday; } From b2e602ebe2f3dc73e29688404ae0e62f3563b92e Mon Sep 17 00:00:00 2001 From: hannah0226 <mohan0226@naver.com> Date: Fri, 28 Jul 2023 22:09:22 +0900 Subject: [PATCH 112/153] =?UTF-8?q?feat:=20Title=20API=20=EB=AA=85?= =?UTF-8?q?=EC=84=B8=EC=84=9C=20=EC=9E=91=EC=84=B1=20(Swagger)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/day/title/controller/TitleController.java | 10 ++++++++++ .../domain/day/title/dto/MemberProfileDto.java | 6 ++++++ .../eday/edayback/domain/day/title/dto/TitleDto.java | 6 +++++- .../domain/day/title/dto/TitleResponseDto.java | 4 +++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java b/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java index ff52500..596b7c8 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java @@ -1,5 +1,10 @@ package efub.eday.edayback.domain.day.title.controller; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -12,10 +17,15 @@ @RestController @RequestMapping("/title") @RequiredArgsConstructor +@Tag(name = "칭호 페이지", description = "칭호 페이지 관련 api입니다.") public class TitleController { private final TitleService titleService; + @Operation(summary = "칭호 페이지 조회", description = "칭호 페이지를 조회하는 메서드입니다.") + @ApiResponse(responseCode = "200", description = "칭호 페이지 조회 성공", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = TitleResponseDto.class))) @GetMapping() public ResponseEntity<TitleResponseDto> getTitlePage() { TitleResponseDto titleResponseDto = titleService.getTitlePage(); diff --git a/src/main/java/efub/eday/edayback/domain/day/title/dto/MemberProfileDto.java b/src/main/java/efub/eday/edayback/domain/day/title/dto/MemberProfileDto.java index 4c61a22..0f3afc9 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/dto/MemberProfileDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/dto/MemberProfileDto.java @@ -2,6 +2,7 @@ import java.time.LocalDateTime; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.NoArgsConstructor; @@ -9,10 +10,15 @@ @NoArgsConstructor public class MemberProfileDto { + @Schema(description = "사용자 닉네임") private String nickname; + @Schema(description = "프로필 이미지 URL") private String profileImage; + @Schema(description = "레벨") private int level; + @Schema(description = "계정 생성일") private LocalDateTime createdDate; + @Schema(description = "활성 상태 여부") private boolean isActive; public MemberProfileDto(String nickname, String profileImage, int level, LocalDateTime createdDate, diff --git a/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleDto.java b/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleDto.java index 02bca3a..52ae459 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleDto.java @@ -1,15 +1,19 @@ package efub.eday.edayback.domain.day.title.dto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.NoArgsConstructor; @Getter @NoArgsConstructor public class TitleDto { - + @Schema(description = "디데이") private int dday; + @Schema(description = "칭호명") private String titleName; + @Schema(description = "칭호 이미지 URL") private String titleImageUrl; + @Schema(description = "칭호 획득 여부") private boolean getTitle; public TitleDto(int dday, String titleName, String titleImageUrl, boolean getTitle) { diff --git a/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleResponseDto.java index b2366bb..fa0c328 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleResponseDto.java @@ -2,14 +2,16 @@ import java.util.List; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.NoArgsConstructor; @Getter @NoArgsConstructor public class TitleResponseDto { - + @Schema(description = "사용자 프로필 정보") private MemberProfileDto profile; + @Schema(description = "칭호 목록") private List<TitleDto> titleList; public TitleResponseDto(MemberProfileDto profile, List<TitleDto> titleList) { From b290b5c72398f8d2afa32baf30c8c69f4c2fb95c Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Sat, 29 Jul 2023 04:04:21 +0900 Subject: [PATCH 113/153] =?UTF-8?q?feat=20:=20info=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?swagger=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../day/info/controller/InfoController.java | 16 ++++++++++++++++ .../edayback/domain/day/info/dto/ImageDto.java | 3 +++ .../edayback/domain/day/info/dto/InfoDto.java | 4 ++++ 3 files changed, 23 insertions(+) diff --git a/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java b/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java index d461520..75d606b 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/controller/InfoController.java @@ -11,14 +11,30 @@ import efub.eday.edayback.domain.day.info.dto.InfoDto; import efub.eday.edayback.domain.day.info.entity.Info; import efub.eday.edayback.domain.day.info.service.InfoService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +@Tag(name = "추가정보", description = "추가정보 관련 api입니다.") @RestController @RequestMapping("/infos") @RequiredArgsConstructor public class InfoController { private final InfoService infoService; + @Operation(summary = "추가정보 확인 메소드", description = "디데이 일수와 주제, 그리고 사진정보를 제공하는 메소드입니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "추가정보 확인 성공", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = InfoDto.class))), + @ApiResponse(responseCode = "404", description = "추가정보 확인 실패(존재하지 않는 디데이)", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = InfoDto.class))) + }) @GetMapping("/{d_day}") @ResponseStatus(value = HttpStatus.OK) public InfoDto getInfoByDday(@PathVariable("d_day") int dday) { diff --git a/src/main/java/efub/eday/edayback/domain/day/info/dto/ImageDto.java b/src/main/java/efub/eday/edayback/domain/day/info/dto/ImageDto.java index fd87620..07764ac 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/dto/ImageDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/dto/ImageDto.java @@ -1,11 +1,14 @@ package efub.eday.edayback.domain.day.info.dto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.Setter; @Getter @Setter public class ImageDto { + @Schema(description = "이미지 pk") private Long imageId; + @Schema(description = "이미지 url") private String imageUrl; } diff --git a/src/main/java/efub/eday/edayback/domain/day/info/dto/InfoDto.java b/src/main/java/efub/eday/edayback/domain/day/info/dto/InfoDto.java index bfd4916..95154ce 100644 --- a/src/main/java/efub/eday/edayback/domain/day/info/dto/InfoDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/info/dto/InfoDto.java @@ -5,6 +5,7 @@ import efub.eday.edayback.domain.day.info.entity.Info; import efub.eday.edayback.domain.day.info.entity.InfoImage; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -16,8 +17,11 @@ public class InfoDto { // private Long infoId; // private Long infoImageId; + @Schema(description = "디데이 일수") private int dday; + @Schema(description = "추가정보 주제") private String headline; + @Schema(description = "사진 url 리스트") private List<ImageDto> imageList; public static InfoDto from(Info info) { From 3154670b16132edf185b52b1af3477d44666120e Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Sat, 29 Jul 2023 04:11:21 +0900 Subject: [PATCH 114/153] =?UTF-8?q?feat:=20member=20=EB=B6=80=EB=B6=84=20s?= =?UTF-8?q?wagger=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/controller/MemberController.java | 13 +++++++++++++ .../eday/edayback/domain/member/dto/ProfileDto.java | 6 ++++++ .../edayback/domain/member/dto/ProfileResDto.java | 4 +++- .../eday/edayback/domain/member/dto/QuizDto.java | 2 ++ .../edayback/domain/member/dto/QuizListDto.java | 4 ++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java b/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java index 4aae5f7..bcc44a9 100644 --- a/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java +++ b/src/main/java/efub/eday/edayback/domain/member/controller/MemberController.java @@ -8,9 +8,16 @@ import efub.eday.edayback.domain.member.dto.ProfileResDto; import efub.eday.edayback.domain.member.service.MemberService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +@Tag(name = "회원", description = "회원정보 관련 api입니다.") @Slf4j @RestController @RequiredArgsConstructor @@ -19,6 +26,12 @@ public class MemberController { private final MemberService memberService; + @Operation(summary = "회원정보 조회 메소드", description = "현재 로그인 중인 회원정보를 제공하는 메소드입니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "회원정보 조회 성공", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = ProfileResDto.class))) + }) @GetMapping @ResponseStatus(value = HttpStatus.OK) public ProfileResDto getMember() { diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java index 303fe44..3ab8c43 100644 --- a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java @@ -1,5 +1,6 @@ package efub.eday.edayback.domain.member.dto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -9,10 +10,15 @@ @Setter @NoArgsConstructor public class ProfileDto { + @Schema(description = "닉네임") private String nickname; + @Schema(description = "프로필 사진 url") private String profileImageUrl; + @Schema(description = "레벨") private int level; + @Schema(description = "디데이 일수") private int dDay; + @Schema(description = "칭호") private String titleName; @Builder diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileResDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileResDto.java index bdba7c2..4b38cd6 100644 --- a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileResDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileResDto.java @@ -1,13 +1,15 @@ package efub.eday.edayback.domain.member.dto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.NoArgsConstructor; @Getter @NoArgsConstructor public class ProfileResDto { + @Schema(description = "회원정보") private ProfileDto profile; - + @Schema(description = "풀 수 있는, 푼, 아직 풀 수 없는 퀴즈 리스트") private QuizListDto quiz; public ProfileResDto(ProfileDto profile, QuizListDto quiz) { diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/QuizDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/QuizDto.java index 30daf90..09a79bc 100644 --- a/src/main/java/efub/eday/edayback/domain/member/dto/QuizDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/dto/QuizDto.java @@ -1,5 +1,6 @@ package efub.eday.edayback.domain.member.dto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -8,6 +9,7 @@ @Setter @NoArgsConstructor public class QuizDto { + @Schema(description = "디데이 일수") private int dday; public QuizDto(int dday) { diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/QuizListDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/QuizListDto.java index 028a301..c4ac854 100644 --- a/src/main/java/efub/eday/edayback/domain/member/dto/QuizListDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/dto/QuizListDto.java @@ -2,14 +2,18 @@ import java.util.List; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.Setter; @Getter @Setter public class QuizListDto { + @Schema(description = "풀 수 있도록 열려있는 퀴즈 리스트") private List<QuizDto> openList; + @Schema(description = "회원이 푼 퀴즈 리스트") private List<QuizDto> doneList; + @Schema(description = "아직 날짜가 되지 않아 풀 수 없는 퀴즈 리스트") private List<QuizDto> closeList; } From 67d69a22f981eb88f07daaa1bb5e6d565a89ca2e Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Sat, 29 Jul 2023 04:27:02 +0900 Subject: [PATCH 115/153] =?UTF-8?q?feat:=20auth=20=EB=B6=80=EB=B6=84=20swa?= =?UTF-8?q?gger=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/auth/controller/AuthController.java | 16 ++++++++++++++++ .../domain/member/auth/dto/AuthRequestDto.java | 3 ++- .../domain/member/auth/dto/AuthResponseDto.java | 7 +++++++ .../member/auth/dto/KakaoProfileResponseDto.java | 2 ++ .../member/auth/dto/KakaoTokenRequestDto.java | 5 +++++ .../member/auth/dto/KakaoTokenResponseDto.java | 8 +++++++- 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/controller/AuthController.java b/src/main/java/efub/eday/edayback/domain/member/auth/controller/AuthController.java index c5cb027..e635a3b 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/controller/AuthController.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/controller/AuthController.java @@ -8,9 +8,16 @@ import efub.eday.edayback.domain.member.auth.dto.AuthRequestDto; import efub.eday.edayback.domain.member.auth.dto.AuthResponseDto; import efub.eday.edayback.domain.member.auth.service.AuthService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +@Tag(name = "로그인", description = "로그인 관련 api입니다.") @Slf4j @RestController @RequiredArgsConstructor @@ -19,6 +26,15 @@ public class AuthController { private final AuthService authService; + @Operation(summary = "kakao에게 정보 요청 메소드", description = "로그인 정보를 바탕으로 kakao에 정보를 요청하는 메소드입니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "로그인 성공", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AuthResponseDto.class))), + @ApiResponse(responseCode = "404", description = "로그인 실패(인증되지 않은 사용자)", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AuthResponseDto.class))) + }) @PostMapping public AuthResponseDto login(@RequestBody AuthRequestDto authRequestDto) { return authService.signIn(authRequestDto.getCode()); diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthRequestDto.java b/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthRequestDto.java index 6c69190..941f5f0 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthRequestDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthRequestDto.java @@ -1,5 +1,6 @@ package efub.eday.edayback.domain.member.auth.dto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -7,6 +8,6 @@ @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) public class AuthRequestDto { - + @Schema(description = "인가 코드") private String code; } diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthResponseDto.java b/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthResponseDto.java index 4151692..63381c8 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthResponseDto.java @@ -1,17 +1,24 @@ package efub.eday.edayback.domain.member.auth.dto; import efub.eday.edayback.domain.member.entity.Member; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Builder; import lombok.Getter; @Getter public class AuthResponseDto { + @Schema(description = "회원 아이디 pk") private Long memberId; + @Schema(description = "닉네임") private String nickname; + @Schema(description = "프로필 사진 url") private String profileImage; + @Schema(description = "레벨") private Integer level; + @Schema(description = "accessToken") private String accessToken; + @Schema(description = "refreshToken") private String refreshToken; @Builder diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoProfileResponseDto.java b/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoProfileResponseDto.java index 14d7d23..11f6de3 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoProfileResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoProfileResponseDto.java @@ -1,5 +1,6 @@ package efub.eday.edayback.domain.member.auth.dto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.NoArgsConstructor; import lombok.Setter; @@ -14,6 +15,7 @@ public class KakaoProfileResponseDto { @NoArgsConstructor public class KakaoAccount { + @Schema(description = "프로필 정보 from kakao") private Profile profile; @Setter diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoTokenRequestDto.java b/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoTokenRequestDto.java index 06efa50..b70c482 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoTokenRequestDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoTokenRequestDto.java @@ -1,5 +1,6 @@ package efub.eday.edayback.domain.member.auth.dto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -9,8 +10,12 @@ @AllArgsConstructor public class KakaoTokenRequestDto { + @Schema(description = "authoriztion_code로 고정된 타입") private String grant_type; + @Schema(description = "클라이언트 아이디(rest api 키)") private String client_id; + @Schema(description = "리다이렉트 uri") private String redirect_uri; + @Schema(description = "인가 코드") private String code; } diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoTokenResponseDto.java b/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoTokenResponseDto.java index ab8d77f..01cc396 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoTokenResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/dto/KakaoTokenResponseDto.java @@ -1,5 +1,6 @@ package efub.eday.edayback.domain.member.auth.dto; +import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -8,11 +9,16 @@ @Setter @NoArgsConstructor public class KakaoTokenResponseDto { - + @Schema(description = "토큰 타입") private String token_type; + @Schema(description = "accessToken") private String access_token; + @Schema(description = "accessToken 만료 기한") private int expires_in; + @Schema(description = "refreshToken") private String refresh_token; + @Schema(description = "refreshToken 만료 기한") private int refresh_token_expires_in; + @Schema(description = "인가 코드") private String scope; } From cabd785f51a7193d1cdc86a1e7c9c76defbcf935 Mon Sep 17 00:00:00 2001 From: Chaewon Song <chaewon1019@ewhain.net> Date: Sun, 30 Jul 2023 23:08:17 +0900 Subject: [PATCH 116/153] =?UTF-8?q?docs:=20EDay=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=EC=A0=9D=ED=8A=B8=20=EC=83=81=EC=84=B8=EC=84=A4=EB=AA=85=20REA?= =?UTF-8?q?DME.md=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 140 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 92bf588..83237cf 100644 --- a/README.md +++ b/README.md @@ -1 +1,139 @@ -# EDAY-BACK +# 🌱 Ewha-Day, E-Day +> EFUB 3rd SWS(Summer Web Surf) 2팀 E-Day Project + +![](https://velog.velcdn.com/images/chhaewxn/post/b7a59ccb-3ef9-474e-9cea-616ace518712/image.png) + +<br> + +## 🪴 프로젝트 설명 +### 🕊️ 예비 이화인을 위한 퀴즈 서비스 +> 예비 벗들이 개강 D-7부터 하루하루 열리는 퀴즈를 맞추며 이화여대에 대해 알아가는 퀴즈+정보 사이트입니다. 이화인으로서 알아두면 쓸모 있는, 알아두면 좋을 지식과 꿀팁들을 받아갈 수 있는 유용한 사이트가 될 것입니다. D-7부터 퀴즈를 하나씩 맞출 때마다 메인 화면에 있는 학교 지도에 색이 입혀지면서, 개강 날에는 색이 모두 칠해진 학교 지도를 얻을 수 있습니다. + +### 📆 개발 기간 +- 프로젝트 세팅: 2023.07.04. - 2023.07.09. +- API 개발: 2023.07.10. - 2023.07.24. +- 배포 및 API 연결: 2023.07.25 - 2023.08. + +<br> + +## 👩‍💻 팀원 소개 +|권민아|최윤지|송채원|이한나| +|:-:|:-:|:-:|:-:| +|<img src="https://avatars.githubusercontent.com/u/71026706?v=4"/>|<img src="https://avatars.githubusercontent.com/u/100260416?v=4"/>|<img src="https://avatars.githubusercontent.com/u/96541582?v=4"/>|<img src="https://avatars.githubusercontent.com/u/89291223?v=4"/> +|[@mingulmangul](https://github.com/mingulmangul)|[@choiyounji](https://github.com/choiyounji)|[@chhaewxn](https://github.com/chhaewxn)|[@hannah0226](https://github.com/hannah0226)| +|프로젝트 세팅<br>엔티티 생성<br>CI/CD 환경 구축<br>RDS 환경 구축<br>프로젝트 배포<br>S3 Bucket 생성<br>DB 설계 및 삽입 SQL문 작성|OAuth JWT API 개발<br>카카오 회원가입 및 로그인 API 개발<br>카카오 로그인 서버 연결<br>API 명세서 작성<br>유저 정보 저장 DB 설계<br>Swagger API Docs 세팅|API 명세서 작성<br>추가정보 API 개발<br>문의사항 API 개발<br>칭호 API 개발<br>데이터 삽입 SQL문 작성<br>S3 Bucket 파일 업로드|API 명세서 작성<br>퀴즈 내용 보기 API 개발<br>퀴즈 정답 확인 API 개발<br>Swagger API Docs 세팅 + +<br> + +### 📚 APIs +| View | Method | Detail | Developer | +|:-----------------:|:--------:|:--------:|:-----------:| +| 사용자 API | POST | 사용자 로그인 | 윤지 | +| | GET | 사용자 정보 가져오기 | 윤지 | +| 퀴즈 API | GET | 퀴즈 내용 보기 | 한나 | +| | POST | 퀴즈 정답 선택 | 한나 | +| 문의 API | POST | 문의사항 작성하기 | 채원 | +| 추가정보 API | GET | 추가정보 페이지 보기 | 채원 | +| 칭호 API | GET | 칭호 페이지 보기 | 채원 | + +<br> + +## 📌 Commit Convention + +### [TAG] 메시지 + +| 태그 이름 | 설명 | +| :--------: | :---------------------------------------------------------------: | +| feat | 새로운 기능 추가 | +| fix | 버그, 오류 수정 | +| style | 코드 포맷팅, 오타 수정, 주석 수정 및 삭제 등 | +| docs | 문서 수정 | +| chore | 빌드 및 패키지 수정 및 삭제 | +| refactor | 코드 리팩토링 | +| setting | 환경설정 | + +### 🪵 Branch Strategy + +1. issue 생성 +2. local - feature/~ 에서 각자 기능 작업 +3. remote - feature/~ 에 Push +4. remote - develop 으로 Pull Request +5. 코드 리뷰 후 remote - develop Merge +6. remote - develop 에 Merge 될 때 local - develop pull 받아 최신 상태 유지 + +<br> + + +## ⚙️ 기술 아키텍쳐 +### 사용 스택 +| 통합 개발 환경 | IntelliJ | +| --- | --- | +| Spring 버전 | 2.7.11 | +| 데이터베이스 | AWS RDS(MySQL) | +| 배포 | AWS EC2(Ubuntu), S3, CodeDepoly | +| Project 빌드 관리 도구 | Gradle | +| CI/CD 툴 | Github Actions | +| ERD 다이어그램 툴 | MySQLWorkbench | +| Java version | Java 11 | + +<br> + +### 아키텍쳐 구조 +![](https://velog.velcdn.com/images/chhaewxn/post/b8fcf36c-6f4c-44b8-8a15-67d880553b15/image.png) + +<br> + +## ☁️ ERD +![](https://velog.velcdn.com/images/chhaewxn/post/6976bd24-ca03-405f-9083-02c320313816/image.png) + +<br> + +## 📁 프로젝트 폴더 구조 +``` +📂 src/main/java/efub/eday + └── edayback + ├── domain + │   ├── day + │   │ ├── dday + | | | ├── entity + │ │ │ └── repository + │   │ ├── info + | | | ├── controller + │ │ │ ├── dto + │ │ │ ├── entity + │ │ │ ├── repository + │ │ │ └── service + │   │ ├── quiz + | | | ├── controller + │ │ │ ├── dto + │ │ │ ├── entity + │ │ │ ├── repository + │ │ │ └── service + │   │ └── title + | | ├── controller + │ │ ├── dto + │ │ ├── entity + │ │ ├── repository + │ │ └── service + │   ├── global + │   │ └── exception + │   ├── member + | | ├── auth + │ │ ├── controller + │ │ ├── dto + │ │ ├── entity + │ │ ├── repository + │ │ └── service + │   └── query + | ├── controller + │ ├── dto + │ ├── entity + │ ├── repository + │ └── service + └── global + ├── config + ├── feign + └── jwt +``` + + From 4c8792dadd8fe6bc33b0ec529ca482a1c054d73c Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Mon, 31 Jul 2023 01:11:47 +0900 Subject: [PATCH 117/153] =?UTF-8?q?feat:=20CORS=20=EC=84=A4=EC=A0=95=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 --- .../edayback/global/config/AuthenticationConfig.java | 9 +++++---- .../efub/eday/edayback/global/config/CorsConfig.java | 11 ++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java b/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java index fd82287..4a7413e 100644 --- a/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java +++ b/src/main/java/efub/eday/edayback/global/config/AuthenticationConfig.java @@ -2,6 +2,7 @@ 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.http.SessionCreationPolicy; @@ -25,14 +26,13 @@ public class AuthenticationConfig { @Bean public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception { return httpSecurity - .httpBasic().disable() - .cors() - .and() + .httpBasic().and() + .cors().and() .csrf().disable() - .formLogin().disable() .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) // 세션 대신 jwt 사용하는 경우 사용 .and() .authorizeRequests() + .antMatchers(HttpMethod.OPTIONS, "/**").permitAll() .antMatchers("/member/auth", "/docs", "/swagger-ui/*", "/v3/**").permitAll() .anyRequest().authenticated() .and() @@ -40,4 +40,5 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws .addFilterBefore(new JwtExceptionFilter(), JwtFilter.class) .build(); } + } diff --git a/src/main/java/efub/eday/edayback/global/config/CorsConfig.java b/src/main/java/efub/eday/edayback/global/config/CorsConfig.java index 7ee0259..289af1d 100644 --- a/src/main/java/efub/eday/edayback/global/config/CorsConfig.java +++ b/src/main/java/efub/eday/edayback/global/config/CorsConfig.java @@ -1,21 +1,22 @@ package efub.eday.edayback.global.config; import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpMethod; import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration +@EnableWebMvc public class CorsConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") - .allowCredentials(true) + .allowCredentials(false) + .allowedHeaders("Authorization") .exposedHeaders("Authorization") - .allowedOrigins("http://localhost:3000") - .allowedOrigins("https://ewha-day.com") - .allowedMethods(HttpMethod.GET.name(), HttpMethod.POST.name()) + .allowedMethods("*") + .allowedOrigins("*") .maxAge(3600); } } From a4a28023851fb1ce85b0aa3b132e4578be7f12db Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Mon, 31 Jul 2023 02:29:09 +0900 Subject: [PATCH 118/153] =?UTF-8?q?docs:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=8B=A4=ED=8C=A8=20=EC=8B=9C=20=EC=83=81=ED=83=9C=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20404=20->=20403=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/member/auth/controller/AuthController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/controller/AuthController.java b/src/main/java/efub/eday/edayback/domain/member/auth/controller/AuthController.java index e635a3b..76c7efb 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/controller/AuthController.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/controller/AuthController.java @@ -31,7 +31,7 @@ public class AuthController { @ApiResponse(responseCode = "200", description = "로그인 성공", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AuthResponseDto.class))), - @ApiResponse(responseCode = "404", description = "로그인 실패(인증되지 않은 사용자)", + @ApiResponse(responseCode = "403", description = "로그인 실패(인증되지 않은 사용자)", content = @Content(mediaType = "application/json", schema = @Schema(implementation = AuthResponseDto.class))) }) From 34c18948b41d1fb58f6de32481fb66b467b17c46 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Mon, 31 Jul 2023 02:41:54 +0900 Subject: [PATCH 119/153] =?UTF-8?q?feat:=20CORS=20=EC=84=A4=EC=A0=95=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 --- .../java/efub/eday/edayback/global/config/CorsConfig.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/efub/eday/edayback/global/config/CorsConfig.java b/src/main/java/efub/eday/edayback/global/config/CorsConfig.java index 289af1d..297626c 100644 --- a/src/main/java/efub/eday/edayback/global/config/CorsConfig.java +++ b/src/main/java/efub/eday/edayback/global/config/CorsConfig.java @@ -12,11 +12,11 @@ public class CorsConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") - .allowCredentials(false) - .allowedHeaders("Authorization") + .allowedOrigins("http://localhost:3000") + .allowCredentials(true) + .allowedHeaders("Authorization", "Content-Type") .exposedHeaders("Authorization") .allowedMethods("*") - .allowedOrigins("*") .maxAge(3600); } } From fa4f8ee0ac7a4655f2f46394c6ced1d8be1129a2 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Tue, 1 Aug 2023 10:15:12 +0900 Subject: [PATCH 120/153] =?UTF-8?q?feat:=20CORS=20=EC=84=A4=EC=A0=95=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 --- .../java/efub/eday/edayback/global/config/CorsConfig.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/global/config/CorsConfig.java b/src/main/java/efub/eday/edayback/global/config/CorsConfig.java index 297626c..6be13db 100644 --- a/src/main/java/efub/eday/edayback/global/config/CorsConfig.java +++ b/src/main/java/efub/eday/edayback/global/config/CorsConfig.java @@ -12,7 +12,9 @@ public class CorsConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") - .allowedOrigins("http://localhost:3000") + .allowedOrigins("http://localhost:[3000,8080]") + .allowedOrigins("https://ewha-day.com") + .allowedOrigins("https://api.ewha-day.com") .allowCredentials(true) .allowedHeaders("Authorization", "Content-Type") .exposedHeaders("Authorization") From 136e5bb4176061d973158e2a7ce58c86febd9cd8 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Tue, 1 Aug 2023 20:11:02 +0900 Subject: [PATCH 121/153] =?UTF-8?q?fix:=20CORS=20=EC=97=90=EB=9F=AC=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/efub/eday/edayback/global/config/CorsConfig.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/efub/eday/edayback/global/config/CorsConfig.java b/src/main/java/efub/eday/edayback/global/config/CorsConfig.java index 6be13db..9fafeb5 100644 --- a/src/main/java/efub/eday/edayback/global/config/CorsConfig.java +++ b/src/main/java/efub/eday/edayback/global/config/CorsConfig.java @@ -12,9 +12,7 @@ public class CorsConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") - .allowedOrigins("http://localhost:[3000,8080]") - .allowedOrigins("https://ewha-day.com") - .allowedOrigins("https://api.ewha-day.com") + .allowedOrigins("http://localhost:3000", "https://api.ewha-day.com") .allowCredentials(true) .allowedHeaders("Authorization", "Content-Type") .exposedHeaders("Authorization") From 341a24fe225fce29551c451a1b075cc67848fc70 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Tue, 1 Aug 2023 20:55:24 +0900 Subject: [PATCH 122/153] =?UTF-8?q?feat(AuthService):=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=ED=95=9C=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EC=9D=98=20=EA=B2=BD=EC=9A=B0=20=EC=9D=B8=EA=B0=80=EB=A5=BC=20?= =?UTF-8?q?=EA=B1=B0=EC=B9=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=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 --- .../domain/member/auth/service/AuthService.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java index 6e08dca..a1a024a 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java @@ -54,10 +54,19 @@ public class AuthService { private String redirectUri; public AuthResponseDto signIn(String code) { - String kakaoToken = getKakaoToken(code); - log.debug("kakaoToken: {}", kakaoToken); - Member member = getKakaoProfile(kakaoToken); - log.debug("member login: {} {}", member.getId(), member.getNickname()); + try { + Member currentMember = getCurrentMember(); + return createAuthResponse(currentMember); + } catch (ResponseStatusException err) { + String kakaoToken = getKakaoToken(code); + log.debug("kakaoToken: {}", kakaoToken); + Member member = getKakaoProfile(kakaoToken); + log.debug("member login: {} {}", member.getId(), member.getNickname()); + return createAuthResponse(member); + } + } + + private AuthResponseDto createAuthResponse(Member member) { String accessToken = jwtProvider.createAccessToken(member.getId()); String refreshToken = jwtProvider.createRefreshToken(member.getId()); AuthResponseDto authResponseDto = AuthResponseDto.builder() From 6d52b4c245584793ffdf24e3e8a315c480f19daf Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Tue, 1 Aug 2023 13:57:57 +0900 Subject: [PATCH 123/153] =?UTF-8?q?chore:=20dday=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/efub/eday/edayback/domain/member/dto/ProfileDto.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java index 3ab8c43..ecbb564 100644 --- a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java @@ -26,7 +26,8 @@ public ProfileDto(String nickname, String profileImageUrl, int level, String tit this.nickname = nickname; this.profileImageUrl = profileImageUrl; this.level = level; - this.dDay = 7 - level; + //level이 1부터 시작하므로 dday는 8에서 빼는 것으로 수정 + this.dDay = 8 - level; this.titleName = titleName; } } From 697770d23486bd444bea70c910d4a1d3ffbafbae Mon Sep 17 00:00:00 2001 From: Chaewon Song <chaewon1019@ewhain.net> Date: Tue, 1 Aug 2023 15:52:09 +0900 Subject: [PATCH 124/153] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 83237cf..dd5b6e7 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ |:-:|:-:|:-:|:-:| |<img src="https://avatars.githubusercontent.com/u/71026706?v=4"/>|<img src="https://avatars.githubusercontent.com/u/100260416?v=4"/>|<img src="https://avatars.githubusercontent.com/u/96541582?v=4"/>|<img src="https://avatars.githubusercontent.com/u/89291223?v=4"/> |[@mingulmangul](https://github.com/mingulmangul)|[@choiyounji](https://github.com/choiyounji)|[@chhaewxn](https://github.com/chhaewxn)|[@hannah0226](https://github.com/hannah0226)| -|프로젝트 세팅<br>엔티티 생성<br>CI/CD 환경 구축<br>RDS 환경 구축<br>프로젝트 배포<br>S3 Bucket 생성<br>DB 설계 및 삽입 SQL문 작성|OAuth JWT API 개발<br>카카오 회원가입 및 로그인 API 개발<br>카카오 로그인 서버 연결<br>API 명세서 작성<br>유저 정보 저장 DB 설계<br>Swagger API Docs 세팅|API 명세서 작성<br>추가정보 API 개발<br>문의사항 API 개발<br>칭호 API 개발<br>데이터 삽입 SQL문 작성<br>S3 Bucket 파일 업로드|API 명세서 작성<br>퀴즈 내용 보기 API 개발<br>퀴즈 정답 확인 API 개발<br>Swagger API Docs 세팅 +|프로젝트 세팅<br>엔티티 생성<br>CI/CD 및 RDS 환경 구축<br>OAuth JWT API 개발<br>카카오 로그인 서버 연결<br>프로젝트 배포<br>S3 Bucket 생성<br>DB 설계 및 삽입 SQL문 작성|OAuth JWT API 개발<br>회원가입 및 로그인 API 개발<br>회원정보 API 개발<br>카카오 로그인 서버 연결<br>API 명세서 작성<br>유저 정보 저장 DB 설계<br>Swagger API Docs 세팅|API 명세서 작성<br>추가정보 API 개발<br>문의사항 API 개발<br>칭호 API 개발<br>데이터 삽입 SQL문 작성<br>S3 Bucket 파일 업로드|API 명세서 작성<br>퀴즈 내용 보기 API 개발<br>퀴즈 정답 확인 API 개발<br>Swagger API Docs 세팅 <br> From e107081a7871431c931fc6d79a1dac42c7a3e90e Mon Sep 17 00:00:00 2001 From: Chaewon Song <chaewon1019@ewhain.net> Date: Tue, 1 Aug 2023 15:52:43 +0900 Subject: [PATCH 125/153] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd5b6e7..fdcfbef 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ ### 📚 APIs | View | Method | Detail | Developer | |:-----------------:|:--------:|:--------:|:-----------:| -| 사용자 API | POST | 사용자 로그인 | 윤지 | +| 사용자 API | POST | 사용자 로그인 | 윤지/민아 | | | GET | 사용자 정보 가져오기 | 윤지 | | 퀴즈 API | GET | 퀴즈 내용 보기 | 한나 | | | POST | 퀴즈 정답 선택 | 한나 | From 8a5d612ce5571f70794fca7caf8d4d61ecd9ce2d Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Tue, 1 Aug 2023 21:24:53 +0900 Subject: [PATCH 126/153] =?UTF-8?q?fix:=20CORS=20=EC=97=90=EB=9F=AC=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/efub/eday/edayback/global/config/CorsConfig.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/efub/eday/edayback/global/config/CorsConfig.java b/src/main/java/efub/eday/edayback/global/config/CorsConfig.java index 6be13db..5864595 100644 --- a/src/main/java/efub/eday/edayback/global/config/CorsConfig.java +++ b/src/main/java/efub/eday/edayback/global/config/CorsConfig.java @@ -12,9 +12,8 @@ public class CorsConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") - .allowedOrigins("http://localhost:[3000,8080]") - .allowedOrigins("https://ewha-day.com") - .allowedOrigins("https://api.ewha-day.com") + .allowedOrigins("http://localhost:3000", "https://api.ewha-day.com", "https://eday-front.vercel.app", + "https://eday-day.com") .allowCredentials(true) .allowedHeaders("Authorization", "Content-Type") .exposedHeaders("Authorization") From 86b8084773246de83bbea92accb8030b597e3a82 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Tue, 1 Aug 2023 22:09:29 +0900 Subject: [PATCH 127/153] =?UTF-8?q?fix:=20URL=20=EC=98=A4=ED=83=80=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 --- src/main/java/efub/eday/edayback/global/config/CorsConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/global/config/CorsConfig.java b/src/main/java/efub/eday/edayback/global/config/CorsConfig.java index 5864595..1241d91 100644 --- a/src/main/java/efub/eday/edayback/global/config/CorsConfig.java +++ b/src/main/java/efub/eday/edayback/global/config/CorsConfig.java @@ -13,7 +13,7 @@ public class CorsConfig implements WebMvcConfigurer { public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOrigins("http://localhost:3000", "https://api.ewha-day.com", "https://eday-front.vercel.app", - "https://eday-day.com") + "https://ewha-day.com") .allowCredentials(true) .allowedHeaders("Authorization", "Content-Type") .exposedHeaders("Authorization") From 02b4a40ec636ef8881c75151b36f274fdb33710b Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Tue, 1 Aug 2023 13:57:57 +0900 Subject: [PATCH 128/153] =?UTF-8?q?chore:=20dday=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/efub/eday/edayback/domain/member/dto/ProfileDto.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java index 3ab8c43..ecbb564 100644 --- a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java @@ -26,7 +26,8 @@ public ProfileDto(String nickname, String profileImageUrl, int level, String tit this.nickname = nickname; this.profileImageUrl = profileImageUrl; this.level = level; - this.dDay = 7 - level; + //level이 1부터 시작하므로 dday는 8에서 빼는 것으로 수정 + this.dDay = 8 - level; this.titleName = titleName; } } From 48562820a682c3f85e680b61ae232f274d966961 Mon Sep 17 00:00:00 2001 From: Kwon Min A <71026706+mingulmangul@users.noreply.github.com> Date: Tue, 1 Aug 2023 22:51:32 +0900 Subject: [PATCH 129/153] =?UTF-8?q?docs(README):=20=EB=A6=AC=EB=93=9C?= =?UTF-8?q?=EB=AF=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fdcfbef..ff7f2dc 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ |:-:|:-:|:-:|:-:| |<img src="https://avatars.githubusercontent.com/u/71026706?v=4"/>|<img src="https://avatars.githubusercontent.com/u/100260416?v=4"/>|<img src="https://avatars.githubusercontent.com/u/96541582?v=4"/>|<img src="https://avatars.githubusercontent.com/u/89291223?v=4"/> |[@mingulmangul](https://github.com/mingulmangul)|[@choiyounji](https://github.com/choiyounji)|[@chhaewxn](https://github.com/chhaewxn)|[@hannah0226](https://github.com/hannah0226)| -|프로젝트 세팅<br>엔티티 생성<br>CI/CD 및 RDS 환경 구축<br>OAuth JWT API 개발<br>카카오 로그인 서버 연결<br>프로젝트 배포<br>S3 Bucket 생성<br>DB 설계 및 삽입 SQL문 작성|OAuth JWT API 개발<br>회원가입 및 로그인 API 개발<br>회원정보 API 개발<br>카카오 로그인 서버 연결<br>API 명세서 작성<br>유저 정보 저장 DB 설계<br>Swagger API Docs 세팅|API 명세서 작성<br>추가정보 API 개발<br>문의사항 API 개발<br>칭호 API 개발<br>데이터 삽입 SQL문 작성<br>S3 Bucket 파일 업로드|API 명세서 작성<br>퀴즈 내용 보기 API 개발<br>퀴즈 정답 확인 API 개발<br>Swagger API Docs 세팅 +|프로젝트 세팅 및 엔티티 생성<br>CI/CD 환경 구축<br>카카오 OAuth 로그인 개발<br>DB 설계 및 데이터 삽입 SQL문 작성<br>Swagger API Docs 세팅|카카오 OAuth 로그인 개발<br>사용자 API 개발<br>API 명세서 작성<br>유저 정보 저장 DB 설계|추가정보 API 개발<br>문의사항 API 개발<br>사용자 칭호 API 개발<br>데이터 삽입 SQL문 작성<br>API 명세서 작성|퀴즈 내용 보기 API 개발<br>퀴즈 정답 확인 API 개발<br>API 명세서 작성 <br> @@ -73,13 +73,13 @@ | 배포 | AWS EC2(Ubuntu), S3, CodeDepoly | | Project 빌드 관리 도구 | Gradle | | CI/CD 툴 | Github Actions | -| ERD 다이어그램 툴 | MySQLWorkbench | +| ERD 다이어그램 툴 | ERD Cloud | | Java version | Java 11 | <br> ### 아키텍쳐 구조 -![](https://velog.velcdn.com/images/chhaewxn/post/b8fcf36c-6f4c-44b8-8a15-67d880553b15/image.png) +<img width="1029" alt="image" src="https://github.com/EFUB-EDAY/EDAY-BACK/assets/71026706/357a011f-3628-453a-9f40-9c73a5545adc"> <br> From a98c67e73f2872dbf365c1889b0bd460b8867f71 Mon Sep 17 00:00:00 2001 From: hannah0226 <mohan0226@naver.com> Date: Thu, 3 Aug 2023 19:16:50 +0900 Subject: [PATCH 130/153] =?UTF-8?q?feat:=20=ED=80=B4=EC=A6=88=20=EC=A0=95?= =?UTF-8?q?=EB=8B=B5=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edayback/domain/day/quiz/controller/QuizController.java | 6 ++++-- .../edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java | 5 ++++- .../eday/edayback/domain/day/quiz/service/QuizService.java | 6 ++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java index 2034e57..e369e08 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java @@ -66,15 +66,17 @@ public ResponseEntity<QuizAnswerResponseDto> checkAnswer( ) { boolean isCorrect; String quizDescription = null; + String imageUrl = null; try { isCorrect = quizService.checkAnswer(dDay, quizRequestDto.getOptionNumber()); if (isCorrect) { quizDescription = quizService.getQuizDescription(dDay); + imageUrl = quizService.getDescriptionImg(dDay); } } catch (IllegalArgumentException e) { String errorMessage = e.getMessage(); - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new QuizAnswerResponseDto(false, errorMessage)); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new QuizAnswerResponseDto(false, errorMessage, null)); } - return ResponseEntity.ok(new QuizAnswerResponseDto(isCorrect, quizDescription)); + return ResponseEntity.ok(new QuizAnswerResponseDto(isCorrect, quizDescription, imageUrl)); } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java index b7c94ad..8f5a589 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java @@ -13,9 +13,12 @@ public class QuizAnswerResponseDto { private boolean isAnswer; @Schema(description = "해당 퀴즈에 대한 설명") private String quizDescription; + @Schema(description = "퀴즈 정답 해설 이미지") + private String imageUrl; - public QuizAnswerResponseDto(boolean isAnswer, String quizDescription) { + public QuizAnswerResponseDto(boolean isAnswer, String quizDescription, String imageUrl) { this.isAnswer = isAnswer; this.quizDescription = quizDescription; + this.imageUrl = imageUrl; } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java index a5a857a..e857746 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java @@ -69,4 +69,10 @@ public String getQuizDescription(int d_day) { Quiz quiz = findQuiz(d_day); return quiz.getExplanation(); } + + //퀴즈 설명 이미지 가져오기 + public String getDescriptionImg(int d_day){ + Quiz quiz = findQuiz(d_day); + return quiz.getImageUrl(); + } } From 1e93aac1c8fa11aeca6a2f695b7aa7cd3c1ce461 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Fri, 4 Aug 2023 01:21:38 +0900 Subject: [PATCH 131/153] =?UTF-8?q?feat:=20=ED=80=B4=EC=A6=88=20=EC=A0=95?= =?UTF-8?q?=EB=8B=B5=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EC=B9=AD=ED=98=B8?= =?UTF-8?q?=20=EC=9D=B4=EB=AF=B8=EC=A7=80=EB=8F=84=20=EC=9D=91=EB=8B=B5?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=A0=84=EC=86=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../day/quiz/controller/QuizController.java | 138 +++++++++--------- .../day/quiz/dto/QuizAnswerResponseDto.java | 9 +- .../domain/day/quiz/service/QuizService.java | 105 ++++++------- 3 files changed, 129 insertions(+), 123 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java index e369e08..3f28ad2 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/controller/QuizController.java @@ -1,82 +1,78 @@ package efub.eday.edayback.domain.day.quiz.controller; - import io.swagger.v3.oas.annotations.Operation; - import io.swagger.v3.oas.annotations.media.Content; - import io.swagger.v3.oas.annotations.media.Schema; - import io.swagger.v3.oas.annotations.responses.ApiResponse; - import io.swagger.v3.oas.annotations.responses.ApiResponses; - import io.swagger.v3.oas.annotations.tags.Tag; - import org.springframework.http.HttpStatus; - import org.springframework.http.ResponseEntity; - import org.springframework.web.bind.annotation.GetMapping; - import org.springframework.web.bind.annotation.PathVariable; - 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.ResponseStatus; - import org.springframework.web.bind.annotation.RestController; +import efub.eday.edayback.domain.day.quiz.dto.QuizAnswerResponseDto; +import efub.eday.edayback.domain.day.quiz.dto.QuizRequestDto; +import efub.eday.edayback.domain.day.quiz.dto.QuizResponseDto; +import efub.eday.edayback.domain.day.quiz.entity.Quiz; +import efub.eday.edayback.domain.day.quiz.service.QuizService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; - import efub.eday.edayback.domain.day.quiz.dto.QuizAnswerResponseDto; - import efub.eday.edayback.domain.day.quiz.dto.QuizRequestDto; - import efub.eday.edayback.domain.day.quiz.dto.QuizResponseDto; - import efub.eday.edayback.domain.day.quiz.entity.Quiz; - import efub.eday.edayback.domain.day.quiz.service.QuizService; - import lombok.RequiredArgsConstructor; - import lombok.extern.slf4j.Slf4j; - -@Tag(name="퀴즈", description = "퀴즈 관련 api입니다.") +@Tag(name = "퀴즈", description = "퀴즈 관련 api입니다.") @Slf4j @RestController @RequestMapping("/quiz/{dDay}") @RequiredArgsConstructor public class QuizController { - private final QuizService quizService; + private final QuizService quizService; - //퀴즈 내용 조회 - @Operation(summary = "퀴즈 내용 조회 메서드", description = "해당 디데이의 퀴즈를 조회하는 메서드입니다.") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "퀴즈 내용 조회 성공", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = QuizResponseDto.class))), - @ApiResponse(responseCode = "404", description = "퀴즈 내용 조회 실패", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = QuizResponseDto.class))) - }) - @GetMapping - @ResponseStatus(value = HttpStatus.OK) - public QuizResponseDto findQuiz(@PathVariable int dDay) { - Quiz quiz = quizService.findQuiz(dDay); - return QuizResponseDto.from(quiz); - } + //퀴즈 내용 조회 + @Operation(summary = "퀴즈 내용 조회 메서드", description = "해당 디데이의 퀴즈를 조회하는 메서드입니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "퀴즈 내용 조회 성공", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = QuizResponseDto.class))), + @ApiResponse(responseCode = "404", description = "퀴즈 내용 조회 실패", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = QuizResponseDto.class))) + }) + @GetMapping + @ResponseStatus(value = HttpStatus.OK) + public QuizResponseDto findQuiz(@PathVariable int dDay) { + Quiz quiz = quizService.findQuiz(dDay); + return QuizResponseDto.from(quiz); + } - //퀴즈 정답 확인 - @Operation(summary = "퀴즈 정답 확인 메서드", description = "퀴즈 선지 중 하나를 보내면 정답 여부를 판별해 주는 메서드입니다.") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "퀴즈 정답 확인 성공", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = QuizAnswerResponseDto.class))), - @ApiResponse(responseCode = "404", description = "퀴즈 정답 확인 실패", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = QuizAnswerResponseDto.class))) - }) - @PostMapping - public ResponseEntity<QuizAnswerResponseDto> checkAnswer( - @PathVariable int dDay, - @RequestBody QuizRequestDto quizRequestDto - ) { - boolean isCorrect; - String quizDescription = null; - String imageUrl = null; - try { - isCorrect = quizService.checkAnswer(dDay, quizRequestDto.getOptionNumber()); - if (isCorrect) { - quizDescription = quizService.getQuizDescription(dDay); - imageUrl = quizService.getDescriptionImg(dDay); - } - } catch (IllegalArgumentException e) { - String errorMessage = e.getMessage(); - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new QuizAnswerResponseDto(false, errorMessage, null)); - } - return ResponseEntity.ok(new QuizAnswerResponseDto(isCorrect, quizDescription, imageUrl)); - } + //퀴즈 정답 확인 + @Operation(summary = "퀴즈 정답 확인 메서드", description = "퀴즈 선지 중 하나를 보내면 정답 여부를 판별해 주는 메서드입니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "퀴즈 정답 확인 성공", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = QuizAnswerResponseDto.class))), + @ApiResponse(responseCode = "404", description = "퀴즈 정답 확인 실패", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = QuizAnswerResponseDto.class))) + }) + @PostMapping + public ResponseEntity<QuizAnswerResponseDto> checkAnswer( + @PathVariable int dDay, + @RequestBody QuizRequestDto quizRequestDto + ) { + boolean isCorrect; + String quizDescription = null; + String descriptionImageUrl = null; + String titleImageUrl = null; + try { + isCorrect = quizService.checkAnswer(dDay, quizRequestDto.getOptionNumber()); + if (isCorrect) { + quizDescription = quizService.getQuizDescription(dDay); + descriptionImageUrl = quizService.getDescriptionImg(dDay); + titleImageUrl = quizService.getTitleImage(dDay); + } + } catch (IllegalArgumentException e) { + String errorMessage = e.getMessage(); + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body(new QuizAnswerResponseDto(false, errorMessage, null, null)); + } + return ResponseEntity.ok(new QuizAnswerResponseDto(isCorrect, quizDescription, descriptionImageUrl, titleImageUrl)); + } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java index 8f5a589..abf1d74 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/dto/QuizAnswerResponseDto.java @@ -14,11 +14,14 @@ public class QuizAnswerResponseDto { @Schema(description = "해당 퀴즈에 대한 설명") private String quizDescription; @Schema(description = "퀴즈 정답 해설 이미지") - private String imageUrl; + private String quizDescriptionImage; + @Schema(description = "칭호 이미지") + private String titleImage; - public QuizAnswerResponseDto(boolean isAnswer, String quizDescription, String imageUrl) { + public QuizAnswerResponseDto(boolean isAnswer, String quizDescription, String quizDescriptionImage, String titleImage) { this.isAnswer = isAnswer; this.quizDescription = quizDescription; - this.imageUrl = imageUrl; + this.quizDescriptionImage = quizDescriptionImage; + this.titleImage = titleImage; } } diff --git a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java index e857746..f976575 100644 --- a/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java +++ b/src/main/java/efub/eday/edayback/domain/day/quiz/service/QuizService.java @@ -1,8 +1,5 @@ package efub.eday.edayback.domain.day.quiz.service; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.quiz.entity.Quiz; import efub.eday.edayback.domain.day.quiz.repository.QuizRepository; @@ -15,64 +12,74 @@ import efub.eday.edayback.domain.member.repository.MemberQuizRepository; import efub.eday.edayback.domain.member.repository.MemberTitleRepository; import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @Transactional @RequiredArgsConstructor public class QuizService { - private final QuizRepository quizRepository; - private final MemberTitleRepository memberTitleRepository; - private final TitleRepository titleRepository; - private final MemberQuizRepository memberQuizRepository; - private final AuthService authService; + private final QuizRepository quizRepository; + private final MemberTitleRepository memberTitleRepository; + private final TitleRepository titleRepository; + private final MemberQuizRepository memberQuizRepository; + private final AuthService authService; + + //퀴즈 내용 조회 + @Transactional(readOnly = true) + public Quiz findQuiz(int d_day) { + Dday dday = Dday.fromRemainingDays(d_day); + return quizRepository.findBySubject_Dday(dday) + .orElseThrow(() -> new IllegalArgumentException("해당 날짜의 퀴즈를 찾을 수 없습니다.")); + } - //퀴즈 내용 조회 - @Transactional(readOnly = true) - public Quiz findQuiz(int d_day) { - Dday dday = Dday.fromRemainingDays(d_day); - return quizRepository.findBySubject_Dday(dday) - .orElseThrow(() -> new IllegalArgumentException("해당 날짜의 퀴즈를 찾을 수 없습니다.")); - } + //퀴즈 정답 확인 + public boolean checkAnswer(int d_day, int optionNumber) { + Quiz quiz = findQuiz(d_day); - //퀴즈 정답 확인 - public boolean checkAnswer(int d_day, int optionNumber) { - Quiz quiz = findQuiz(d_day); + boolean isCorrect = quiz.isAnswerOption(optionNumber); - boolean isCorrect = quiz.isAnswerOption(optionNumber); + if (isCorrect) { + Member member = authService.getCurrentMember(); + Integer subjectId = quiz.getSubject().getId(); + Title title = titleRepository.findBySubjectId(subjectId) + .orElseThrow(() -> new IllegalArgumentException("해당 subject_id에 대한 타이틀을 찾을 수 없습니다.")); + MemberTitle memberTitle = memberTitleRepository.findByMemberAndTitle(member, title) + .orElseThrow(() -> new IllegalArgumentException("해당 멤버 타이틀을 찾을 수 없습니다.")); + MemberQuiz memberQuiz = memberQuizRepository.findByMemberAndQuiz(member, quiz) + .orElseThrow(() -> new IllegalArgumentException("해당 멤버 퀴즈를 찾을 수 없습니다.")); - if (isCorrect) { - Member member = authService.getCurrentMember(); - Integer subjectId = quiz.getSubject().getId(); - Title title = titleRepository.findBySubjectId(subjectId) - .orElseThrow(() -> new IllegalArgumentException("해당 subject_id에 대한 타이틀을 찾을 수 없습니다.")); - MemberTitle memberTitle = memberTitleRepository.findByMemberAndTitle(member, title) - .orElseThrow(() -> new IllegalArgumentException("해당 멤버 타이틀을 찾을 수 없습니다.")); - MemberQuiz memberQuiz = memberQuizRepository.findByMemberAndQuiz(member, quiz) - .orElseThrow(() -> new IllegalArgumentException("해당 멤버 퀴즈를 찾을 수 없습니다.")); + //member level+1 + if (!memberTitle.getGetTitle()) { + member.setLevel(member.getLevel() + 1); + } + //MemberTitle의 getTitle값 true로 변경 + memberTitle.setGetTitle(true); - //member level+1 - if (!memberTitle.getGetTitle()) { - member.setLevel(member.getLevel() + 1); - } - //MemberTitle의 getTitle값 true로 변경 - memberTitle.setGetTitle(true); + //MemberQuiz의 isCorrect 값 true로 변경 + memberQuiz.setIsCorrect(true); - //MemberQuiz의 isCorrect 값 true로 변경 - memberQuiz.setIsCorrect(true); + } + return isCorrect; + } - } - return isCorrect; - } + //퀴즈 설명 가져오기 + public String getQuizDescription(int dDay) { + Quiz quiz = findQuiz(dDay); + return quiz.getExplanation(); + } - //퀴즈 설명 가져오기 - public String getQuizDescription(int d_day) { - Quiz quiz = findQuiz(d_day); - return quiz.getExplanation(); - } + //퀴즈 설명 이미지 가져오기 + public String getDescriptionImg(int dDay) { + Quiz quiz = findQuiz(dDay); + return quiz.getImageUrl(); + } - //퀴즈 설명 이미지 가져오기 - public String getDescriptionImg(int d_day){ - Quiz quiz = findQuiz(d_day); - return quiz.getImageUrl(); - } + public String getTitleImage(int dDay) { + Quiz quiz = findQuiz(dDay); + Integer subjectId = quiz.getSubject().getId(); + Title title = titleRepository.findBySubjectId(subjectId) + .orElseThrow(() -> new IllegalArgumentException("해당 subject_id에 대한 타이틀을 찾을 수 없습니다.")); + return title.getImageUrl(); + } } From dfb0175ca7dc16261091ee9a9d3dd775dcf81c3e Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Fri, 4 Aug 2023 01:26:23 +0900 Subject: [PATCH 132/153] =?UTF-8?q?feat:=20Title=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=EC=97=90=20=ED=85=8D=EC=8A=A4=ED=8A=B8=20=EC=97=86?= =?UTF-8?q?=EB=8A=94=20=EC=9D=B4=EB=AF=B8=EC=A7=80=EB=A5=BC=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=ED=95=98=EB=8A=94=20=EC=BB=AC=EB=9F=BC=20=EB=A7=A4?= =?UTF-8?q?=ED=95=91=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/day/title/entity/Title.java | 42 +++++++------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java index 86947ec..8a37690 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java @@ -1,42 +1,32 @@ package efub.eday.edayback.domain.day.title.entity; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.OneToOne; - import efub.eday.edayback.domain.day.dday.entity.Subject; -import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import javax.persistence.*; + @Entity @Getter @NoArgsConstructor public class Title { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "title_id") - private Integer id; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "title_id") + private Integer id; + + @Column(name = "title_name", nullable = false, length = 127) + private String name; - @Column(name = "title_name", nullable = false, length = 127) - private String name; + @Column(name = "image_url", nullable = false) + private String imageUrl; - @Column(name = "image_url", nullable = false) - private String imageUrl; + @Column(name = "image_with_not_text_url", nullable = false) + private String imageWithNotTextUrl; - @OneToOne - @JoinColumn(name = "subject_id", nullable = false) - private Subject subject; + @OneToOne + @JoinColumn(name = "subject_id", nullable = false) + private Subject subject; - @Builder - public Title(String name, String imageUrl, Subject subject) { - this.name = name; - this.imageUrl = imageUrl; - this.subject = subject; - } } From 1b19fae879592c3c897d4166b7dd1d25caccf75b Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Fri, 4 Aug 2023 01:28:58 +0900 Subject: [PATCH 133/153] =?UTF-8?q?feat:=20=EC=B9=AD=ED=98=B8=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=EC=97=90=EC=84=9C=20=ED=85=8D=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=97=86=EB=8A=94=20=EC=9D=B4=EB=AF=B8=EC=A7=80?= =?UTF-8?q?=EB=A5=BC=20=EC=9D=91=EB=8B=B5=ED=95=98=EB=8F=84=EB=A1=9D=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 --- .../day/title/service/TitleService.java | 73 +++++++++---------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java index 0167e39..8a337f7 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java @@ -1,11 +1,5 @@ package efub.eday.edayback.domain.day.title.service; -import java.util.List; -import java.util.stream.Collectors; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - import efub.eday.edayback.domain.day.title.dto.MemberProfileDto; import efub.eday.edayback.domain.day.title.dto.TitleDto; import efub.eday.edayback.domain.day.title.dto.TitleResponseDto; @@ -15,40 +9,45 @@ import efub.eday.edayback.domain.member.entity.MemberTitle; import efub.eday.edayback.domain.member.repository.MemberTitleRepository; import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor public class TitleService { - private final MemberTitleRepository memberTitleRepository; - private final AuthService authService; - - @Transactional(readOnly = true) - public TitleResponseDto getTitlePage() { - Member member = authService.getCurrentMember(); - - List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); - - MemberProfileDto profile = new MemberProfileDto( - member.getNickname(), - member.getProfileImageUrl(), - member.getLevel(), - member.getCreatedDate(), - member.getIsActive() - ); - - List<TitleDto> titleList = memberTitles.stream() - .map(memberTitle -> { - Title title = memberTitle.getTitle(); - return new TitleDto( - title.getSubject().getDday(), - title.getName(), - title.getImageUrl(), - memberTitle.getGetTitle() - ); - }) - .collect(Collectors.toList()); - - return new TitleResponseDto(profile, titleList); - } + private final MemberTitleRepository memberTitleRepository; + private final AuthService authService; + + @Transactional(readOnly = true) + public TitleResponseDto getTitlePage() { + Member member = authService.getCurrentMember(); + + List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); + + MemberProfileDto profile = new MemberProfileDto( + member.getNickname(), + member.getProfileImageUrl(), + member.getLevel(), + member.getCreatedDate(), + member.getIsActive() + ); + + List<TitleDto> titleList = memberTitles.stream() + .map(memberTitle -> { + Title title = memberTitle.getTitle(); + return new TitleDto( + title.getSubject().getDday(), + title.getName(), + title.getImageWithNotTextUrl(), + memberTitle.getGetTitle() + ); + }) + .collect(Collectors.toList()); + + return new TitleResponseDto(profile, titleList); + } } From ff07e93d273bbf139d1d028b77cbe02446c4b849 Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Fri, 4 Aug 2023 02:04:17 +0900 Subject: [PATCH 134/153] =?UTF-8?q?fix:=20openList=EC=97=90=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=EC=95=88=EB=90=98=EB=8F=84=EB=A1=9D=20=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EB=AC=B8=EC=A0=9C=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 --- .../domain/member/service/MemberService.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java index 907b75b..8982200 100644 --- a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java +++ b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java @@ -53,19 +53,8 @@ public ProfileResDto getMember() { differenceInDays = 7; } - //날짜가 같아 그러면 difference=0, openList는 dDay=7 하나 - List<QuizDto> openList = new ArrayList<>(); - List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); - for (int dDay = 7; dDay >= 7 - differenceInDays; dDay--) { - for (MemberTitle memberTitle : memberTitles) { - if (!memberTitle.getGetTitle() && dDay != 0) { - openList.add(new QuizDto(dDay)); - } - } - } - List<QuizDto> doneList = new ArrayList<>(); - //List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); + List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); for (MemberTitle memberTitle : memberTitles) { if (memberTitle.getGetTitle()) { int subject = memberTitle.getTitle().getSubject().getDday(); @@ -73,6 +62,21 @@ public ProfileResDto getMember() { } } + //날짜가 같아 그러면 difference=0, openList는 dDay=7 하나 + List<QuizDto> openList = new ArrayList<>(); + for (int dDay = 7; dDay >= 7 - differenceInDays; dDay--) { + boolean isInDoneList = false; + for (QuizDto quiz : doneList) { + if (quiz.getDday() == dDay) { + isInDoneList = true; + break; + } + } + if (!isInDoneList && dDay != 0) { + openList.add(new QuizDto(dDay)); + } + } + List<QuizDto> closeList = new ArrayList<>(); for (int dDay = 6 - differenceInDays; dDay >= 1; dDay--) { closeList.add(new QuizDto(dDay)); From 6a34056c38e8a4371e24b90dc2d1a966bdfb9248 Mon Sep 17 00:00:00 2001 From: choiyounji <100260416+choiyounji@users.noreply.github.com> Date: Fri, 4 Aug 2023 08:29:52 +0900 Subject: [PATCH 135/153] =?UTF-8?q?fix=20:=20AuthService.java=20=EA=BC=AC?= =?UTF-8?q?=EC=9D=B8=EA=B1=B0=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/auth/service/AuthService.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java index a1a024a..6e08dca 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java @@ -54,19 +54,10 @@ public class AuthService { private String redirectUri; public AuthResponseDto signIn(String code) { - try { - Member currentMember = getCurrentMember(); - return createAuthResponse(currentMember); - } catch (ResponseStatusException err) { - String kakaoToken = getKakaoToken(code); - log.debug("kakaoToken: {}", kakaoToken); - Member member = getKakaoProfile(kakaoToken); - log.debug("member login: {} {}", member.getId(), member.getNickname()); - return createAuthResponse(member); - } - } - - private AuthResponseDto createAuthResponse(Member member) { + String kakaoToken = getKakaoToken(code); + log.debug("kakaoToken: {}", kakaoToken); + Member member = getKakaoProfile(kakaoToken); + log.debug("member login: {} {}", member.getId(), member.getNickname()); String accessToken = jwtProvider.createAccessToken(member.getId()); String refreshToken = jwtProvider.createRefreshToken(member.getId()); AuthResponseDto authResponseDto = AuthResponseDto.builder() From 06543f4cdbc025c299517d8eab8da6c97ec7fc39 Mon Sep 17 00:00:00 2001 From: choiyounji <100260416+choiyounji@users.noreply.github.com> Date: Fri, 4 Aug 2023 08:30:55 +0900 Subject: [PATCH 136/153] =?UTF-8?q?fix=20:=20ProfileDto.java=20=EA=BC=AC?= =?UTF-8?q?=EC=9D=B8=EA=B1=B0=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From a4d98d96db8b5ef1eb957c337ef70465f83d88ed Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Fri, 4 Aug 2023 17:40:29 +0900 Subject: [PATCH 137/153] =?UTF-8?q?feat:=20=ED=8A=B9=EC=A0=95=20=EB=94=94?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=20=EC=B9=AD=ED=98=B8=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20api=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../day/title/controller/TitleController.java | 26 ++++-- .../day/title/service/TitleService.java | 90 +++++++++++-------- .../repository/MemberTitleRepository.java | 2 + 3 files changed, 75 insertions(+), 43 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java b/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java index 596b7c8..4b16103 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java @@ -1,17 +1,19 @@ package efub.eday.edayback.domain.day.title.controller; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import efub.eday.edayback.domain.day.title.dto.TitleDto; import efub.eday.edayback.domain.day.title.dto.TitleResponseDto; import efub.eday.edayback.domain.day.title.service.TitleService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @RestController @@ -24,11 +26,21 @@ public class TitleController { @Operation(summary = "칭호 페이지 조회", description = "칭호 페이지를 조회하는 메서드입니다.") @ApiResponse(responseCode = "200", description = "칭호 페이지 조회 성공", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = TitleResponseDto.class))) + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = TitleResponseDto.class))) @GetMapping() public ResponseEntity<TitleResponseDto> getTitlePage() { TitleResponseDto titleResponseDto = titleService.getTitlePage(); return ResponseEntity.ok(titleResponseDto); } + + @Operation(summary = "특정 디데이에 해당하는 칭호 정보 조회", description = "특정 디데이(d_day)에 해당하는 칭호 정보를 조회하는 메서드입니다.") + @ApiResponse(responseCode = "200", description = "칭호 정보 조회 성공", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = TitleDto.class))) + @GetMapping("/{d_day}") + public ResponseEntity<TitleDto> getTitleByDday(@PathVariable("d_day") int dday) { + TitleDto titleDto = titleService.getTitleByDday(dday); + return ResponseEntity.ok(titleDto); + } } diff --git a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java index 8a337f7..e8fc184 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java @@ -1,5 +1,13 @@ package efub.eday.edayback.domain.day.title.service; +import java.util.List; +import java.util.stream.Collectors; + +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.server.ResponseStatusException; + import efub.eday.edayback.domain.day.title.dto.MemberProfileDto; import efub.eday.edayback.domain.day.title.dto.TitleDto; import efub.eday.edayback.domain.day.title.dto.TitleResponseDto; @@ -9,45 +17,55 @@ import efub.eday.edayback.domain.member.entity.MemberTitle; import efub.eday.edayback.domain.member.repository.MemberTitleRepository; import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; -import java.util.stream.Collectors; @Service @RequiredArgsConstructor public class TitleService { - private final MemberTitleRepository memberTitleRepository; - private final AuthService authService; - - @Transactional(readOnly = true) - public TitleResponseDto getTitlePage() { - Member member = authService.getCurrentMember(); - - List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); - - MemberProfileDto profile = new MemberProfileDto( - member.getNickname(), - member.getProfileImageUrl(), - member.getLevel(), - member.getCreatedDate(), - member.getIsActive() - ); - - List<TitleDto> titleList = memberTitles.stream() - .map(memberTitle -> { - Title title = memberTitle.getTitle(); - return new TitleDto( - title.getSubject().getDday(), - title.getName(), - title.getImageWithNotTextUrl(), - memberTitle.getGetTitle() - ); - }) - .collect(Collectors.toList()); - - return new TitleResponseDto(profile, titleList); - } + private final MemberTitleRepository memberTitleRepository; + private final AuthService authService; + + @Transactional(readOnly = true) + public TitleResponseDto getTitlePage() { + Member member = authService.getCurrentMember(); + + List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); + + MemberProfileDto profile = new MemberProfileDto( + member.getNickname(), + member.getProfileImageUrl(), + member.getLevel(), + member.getCreatedDate(), + member.getIsActive() + ); + + List<TitleDto> titleList = memberTitles.stream() + .map(memberTitle -> { + Title title = memberTitle.getTitle(); + return new TitleDto( + title.getSubject().getDday(), + title.getName(), + title.getImageWithNotTextUrl(), + memberTitle.getGetTitle() + ); + }) + .collect(Collectors.toList()); + + return new TitleResponseDto(profile, titleList); + } + + @Transactional(readOnly = true) + public TitleDto getTitleByDday(int dday) { + Member member = authService.getCurrentMember(); + MemberTitle memberTitle = memberTitleRepository.findByMemberAndTitleSubjectDday(member, dday) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "해당 디데이의 칭호를 찾을 수 없습니다.")); + + Title title = memberTitle.getTitle(); + return new TitleDto( + dday, + title.getName(), + title.getImageUrl(), + memberTitle.getGetTitle() + ); + } } diff --git a/src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java b/src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java index eca3269..5844f4f 100644 --- a/src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java +++ b/src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java @@ -15,4 +15,6 @@ public interface MemberTitleRepository extends JpaRepository<MemberTitle, Intege List<MemberTitle> findByMember(Member member); Optional<MemberTitle> findByMemberAndTitle(Member member, Title title); + + Optional<MemberTitle> findByMemberAndTitleSubjectDday(Member member, int dday); } From a2f601dd2b62932c56480f5abe287d994c7ea8f7 Mon Sep 17 00:00:00 2001 From: chhaewxn <chaewon1019@ewhain.net> Date: Fri, 4 Aug 2023 19:34:10 +0900 Subject: [PATCH 138/153] =?UTF-8?q?fix:=20Dday=20=EC=97=B4=EA=B1=B0?= =?UTF-8?q?=EC=B2=B4=EB=A1=9C=20=ED=83=80=EC=9E=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/day/title/controller/TitleController.java | 4 +++- .../edayback/domain/day/title/service/TitleService.java | 7 ++++--- .../domain/member/repository/MemberTitleRepository.java | 3 ++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java b/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java index 4b16103..0225c6c 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/controller/TitleController.java @@ -6,6 +6,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.title.dto.TitleDto; import efub.eday.edayback.domain.day.title.dto.TitleResponseDto; import efub.eday.edayback.domain.day.title.service.TitleService; @@ -40,7 +41,8 @@ public ResponseEntity<TitleResponseDto> getTitlePage() { schema = @Schema(implementation = TitleDto.class))) @GetMapping("/{d_day}") public ResponseEntity<TitleDto> getTitleByDday(@PathVariable("d_day") int dday) { - TitleDto titleDto = titleService.getTitleByDday(dday); + Dday ddayEnum = Dday.fromRemainingDays(dday); + TitleDto titleDto = titleService.getTitleByDday(ddayEnum); return ResponseEntity.ok(titleDto); } } diff --git a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java index e8fc184..bb41746 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java @@ -8,6 +8,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.server.ResponseStatusException; +import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.title.dto.MemberProfileDto; import efub.eday.edayback.domain.day.title.dto.TitleDto; import efub.eday.edayback.domain.day.title.dto.TitleResponseDto; @@ -55,14 +56,14 @@ public TitleResponseDto getTitlePage() { } @Transactional(readOnly = true) - public TitleDto getTitleByDday(int dday) { + public TitleDto getTitleByDday(Dday dday) { Member member = authService.getCurrentMember(); MemberTitle memberTitle = memberTitleRepository.findByMemberAndTitleSubjectDday(member, dday) - .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "해당 디데이의 칭호를 찾을 수 없습니다.")); + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, dday + ": 해당 디데이의 칭호를 찾을 수 없습니다.")); Title title = memberTitle.getTitle(); return new TitleDto( - dday, + title.getSubject().getDday(), title.getName(), title.getImageUrl(), memberTitle.getGetTitle() diff --git a/src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java b/src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java index 5844f4f..01fcf58 100644 --- a/src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java +++ b/src/main/java/efub/eday/edayback/domain/member/repository/MemberTitleRepository.java @@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.title.entity.Title; import efub.eday.edayback.domain.member.entity.Member; import efub.eday.edayback.domain.member.entity.MemberTitle; @@ -16,5 +17,5 @@ public interface MemberTitleRepository extends JpaRepository<MemberTitle, Intege Optional<MemberTitle> findByMemberAndTitle(Member member, Title title); - Optional<MemberTitle> findByMemberAndTitleSubjectDday(Member member, int dday); + Optional<MemberTitle> findByMemberAndTitleSubjectDday(Member member, Dday dday); } From a0bcae0ccd4c860dfc2dff7fe7fea4da6c08878a Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sat, 5 Aug 2023 23:53:15 +0900 Subject: [PATCH 139/153] =?UTF-8?q?feat:=20=EC=B9=AD=ED=98=B8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=EC=97=90=20=EC=8D=B8=EB=84=A4=EC=9D=BC=20?= =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/day/title/dto/TitleDto.java | 31 +++--- .../domain/day/title/entity/Title.java | 2 +- .../day/title/service/TitleService.java | 95 ++++++++++--------- 3 files changed, 66 insertions(+), 62 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleDto.java b/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleDto.java index 52ae459..64efb6a 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/dto/TitleDto.java @@ -7,19 +7,22 @@ @Getter @NoArgsConstructor public class TitleDto { - @Schema(description = "디데이") - private int dday; - @Schema(description = "칭호명") - private String titleName; - @Schema(description = "칭호 이미지 URL") - private String titleImageUrl; - @Schema(description = "칭호 획득 여부") - private boolean getTitle; + @Schema(description = "디데이") + private int dday; + @Schema(description = "칭호명") + private String titleName; + @Schema(description = "칭호 이미지 썸네일 URL") + private String titleThumbnailUrl; + @Schema(description = "칭호 이미지 URL") + private String titleImageUrl; + @Schema(description = "칭호 획득 여부") + private boolean getTitle; - public TitleDto(int dday, String titleName, String titleImageUrl, boolean getTitle) { - this.dday = dday; - this.titleName = titleName; - this.titleImageUrl = titleImageUrl; - this.getTitle = getTitle; - } + public TitleDto(int dday, String titleName, String titleThumbnailUrl, String titleImageUrl, boolean getTitle) { + this.dday = dday; + this.titleName = titleName; + this.titleThumbnailUrl = titleThumbnailUrl; + this.titleImageUrl = titleImageUrl; + this.getTitle = getTitle; + } } diff --git a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java index 8a37690..7854127 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/entity/Title.java @@ -23,7 +23,7 @@ public class Title { private String imageUrl; @Column(name = "image_with_not_text_url", nullable = false) - private String imageWithNotTextUrl; + private String thumbnailImageUrl; @OneToOne @JoinColumn(name = "subject_id", nullable = false) diff --git a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java index bb41746..76ff4be 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/service/TitleService.java @@ -1,13 +1,5 @@ package efub.eday.edayback.domain.day.title.service; -import java.util.List; -import java.util.stream.Collectors; - -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.server.ResponseStatusException; - import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.title.dto.MemberProfileDto; import efub.eday.edayback.domain.day.title.dto.TitleDto; @@ -18,55 +10,64 @@ import efub.eday.edayback.domain.member.entity.MemberTitle; import efub.eday.edayback.domain.member.repository.MemberTitleRepository; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.server.ResponseStatusException; + +import java.util.List; +import java.util.stream.Collectors; @Service @RequiredArgsConstructor public class TitleService { - private final MemberTitleRepository memberTitleRepository; - private final AuthService authService; + private final MemberTitleRepository memberTitleRepository; + private final AuthService authService; - @Transactional(readOnly = true) - public TitleResponseDto getTitlePage() { - Member member = authService.getCurrentMember(); + @Transactional(readOnly = true) + public TitleResponseDto getTitlePage() { + Member member = authService.getCurrentMember(); - List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); + List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); - MemberProfileDto profile = new MemberProfileDto( - member.getNickname(), - member.getProfileImageUrl(), - member.getLevel(), - member.getCreatedDate(), - member.getIsActive() - ); + MemberProfileDto profile = new MemberProfileDto( + member.getNickname(), + member.getProfileImageUrl(), + member.getLevel(), + member.getCreatedDate(), + member.getIsActive() + ); - List<TitleDto> titleList = memberTitles.stream() - .map(memberTitle -> { - Title title = memberTitle.getTitle(); - return new TitleDto( - title.getSubject().getDday(), - title.getName(), - title.getImageWithNotTextUrl(), - memberTitle.getGetTitle() - ); - }) - .collect(Collectors.toList()); + List<TitleDto> titleList = memberTitles.stream() + .map(memberTitle -> { + Title title = memberTitle.getTitle(); + return new TitleDto( + title.getSubject().getDday(), + title.getName(), + title.getThumbnailImageUrl(), + title.getImageUrl(), + memberTitle.getGetTitle() + ); + }) + .collect(Collectors.toList()); - return new TitleResponseDto(profile, titleList); - } + return new TitleResponseDto(profile, titleList); + } - @Transactional(readOnly = true) - public TitleDto getTitleByDday(Dday dday) { - Member member = authService.getCurrentMember(); - MemberTitle memberTitle = memberTitleRepository.findByMemberAndTitleSubjectDday(member, dday) - .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, dday + ": 해당 디데이의 칭호를 찾을 수 없습니다.")); + @Transactional(readOnly = true) + public TitleDto getTitleByDday(Dday dday) { + Member member = authService.getCurrentMember(); + MemberTitle memberTitle = memberTitleRepository.findByMemberAndTitleSubjectDday(member, dday) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, dday + ": 해당 디데이의 칭호를 찾을 수 없습니다.")); - Title title = memberTitle.getTitle(); - return new TitleDto( - title.getSubject().getDday(), - title.getName(), - title.getImageUrl(), - memberTitle.getGetTitle() - ); - } + Title title = memberTitle.getTitle(); + return new TitleDto( + title.getSubject().getDday(), + title.getName(), + title.getThumbnailImageUrl(), + title.getImageUrl(), + memberTitle.getGetTitle() + ); + } } From b009c82dae594d493acd0babfa12303a2e518c61 Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Sun, 6 Aug 2023 16:50:09 +0900 Subject: [PATCH 140/153] =?UTF-8?q?feat:=20openList=EC=9D=80=20=EB=82=A0?= =?UTF-8?q?=EC=A7=9C=EC=97=90=EB=A7=8C=20=EC=98=81=ED=96=A5=EB=B0=9B?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=8B=A4=EC=8B=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/service/MemberService.java | 140 +++++++++--------- 1 file changed, 67 insertions(+), 73 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java index 54640b5..aaa0cff 100644 --- a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java +++ b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java @@ -1,5 +1,13 @@ package efub.eday.edayback.domain.member.service; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.List; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + import efub.eday.edayback.domain.day.title.entity.Title; import efub.eday.edayback.domain.day.title.repository.TitleRepository; import efub.eday.edayback.domain.member.auth.service.AuthService; @@ -12,84 +20,70 @@ import efub.eday.edayback.domain.member.repository.MemberTitleRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.ArrayList; -import java.util.List; @Slf4j @RequiredArgsConstructor @Service public class MemberService { - private final AuthService authService; - private final TitleRepository titleRepository; - private final MemberTitleRepository memberTitleRepository; - - @Transactional(readOnly = true) - public ProfileResDto getMember() { - //현재 로그인 중인 사용자 정보 불러오기 - Member member = authService.getCurrentMember(); - - int level = member.getLevel(); - if (level > 7) { - level = 7; - } - - //칭호는 dDay가 아닌 level을 기준으로 정해짐 - Title title = titleRepository.findBySubjectId(level).orElseThrow(); - - //profile부분에 들어갈 속성들 - ProfileDto profile = new ProfileDto(member.getNickname(), - member.getProfileImageUrl(), - member.getLevel(), - title.getName()); - - // 현재 날짜와 데이터베이스에 저장된 날짜 사이의 차이 계산 - LocalDateTime currentDate = LocalDateTime.now(); - int differenceInDays = Math.toIntExact(ChronoUnit.DAYS.between(member.getCreatedDate(), currentDate)); - if (differenceInDays >= 7) { - differenceInDays = 7; - } - - List<QuizDto> doneList = new ArrayList<>(); - List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); - for (MemberTitle memberTitle : memberTitles) { - if (memberTitle.getGetTitle()) { - int subject = memberTitle.getTitle().getSubject().getDday(); - doneList.add(new QuizDto(subject)); - } - } - - //날짜가 같아 그러면 difference=0, openList는 dDay=7 하나 - List<QuizDto> openList = new ArrayList<>(); - for (int dDay = 7; dDay >= 7 - differenceInDays; dDay--) { - boolean isInDoneList = false; - for (QuizDto quiz : doneList) { - if (quiz.getDday() == dDay) { - isInDoneList = true; - break; - } - } - if (!isInDoneList && dDay != 0) { - openList.add(new QuizDto(dDay)); - } - } - - List<QuizDto> closeList = new ArrayList<>(); - for (int dDay = 6 - differenceInDays; dDay >= 1; dDay--) { - closeList.add(new QuizDto(dDay)); - } - - QuizListDto quizListDto = new QuizListDto(); - quizListDto.setOpenList(openList); - quizListDto.setDoneList(doneList); - quizListDto.setCloseList(closeList); - - return new ProfileResDto(profile, quizListDto); - } + private final AuthService authService; + private final TitleRepository titleRepository; + private final MemberTitleRepository memberTitleRepository; + + @Transactional(readOnly = true) + public ProfileResDto getMember() { + //현재 로그인 중인 사용자 정보 불러오기 + Member member = authService.getCurrentMember(); + + int level = member.getLevel(); + if (level > 7) { + level = 7; + } + + //칭호는 dDay가 아닌 level을 기준으로 정해짐 + Title title = titleRepository.findBySubjectId(level).orElseThrow(); + + //profile부분에 들어갈 속성들 + ProfileDto profile = new ProfileDto(member.getNickname(), + member.getProfileImageUrl(), + member.getLevel(), + title.getName()); + + // 현재 날짜와 데이터베이스에 저장된 날짜 사이의 차이 계산 + LocalDateTime currentDate = LocalDateTime.now(); + int differenceInDays = Math.toIntExact(ChronoUnit.DAYS.between(member.getCreatedDate(), currentDate)); + if (differenceInDays >= 7) { + differenceInDays = 7; + } + + //날짜가 같아 그러면 difference=0, openList는 dDay=7 하나 + List<QuizDto> openList = new ArrayList<>(); + for (int dDay = 7; dDay >= 7 - differenceInDays; dDay--) { + if (dDay != 0) { + openList.add(new QuizDto(dDay)); + } + } + + List<QuizDto> doneList = new ArrayList<>(); + List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); + for (MemberTitle memberTitle : memberTitles) { + if (memberTitle.getGetTitle()) { + int subject = memberTitle.getTitle().getSubject().getDday(); + doneList.add(new QuizDto(subject)); + } + } + + List<QuizDto> closeList = new ArrayList<>(); + for (int dDay = 6 - differenceInDays; dDay >= 1; dDay--) { + closeList.add(new QuizDto(dDay)); + } + + QuizListDto quizListDto = new QuizListDto(); + quizListDto.setOpenList(openList); + quizListDto.setDoneList(doneList); + quizListDto.setCloseList(closeList); + + return new ProfileResDto(profile, quizListDto); + } } From 4a46555a15468d25d21f8c5654b13136b74458e6 Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Sun, 6 Aug 2023 17:02:50 +0900 Subject: [PATCH 141/153] =?UTF-8?q?fix:=20MemberService=20differenceInDays?= =?UTF-8?q?=206=EC=9D=B4=20=EC=B5=9C=EB=8C=80=EC=9D=B4=EB=8F=84=EB=A1=9D?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/service/MemberService.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java index aaa0cff..331bf79 100644 --- a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java +++ b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java @@ -49,21 +49,21 @@ public ProfileResDto getMember() { member.getLevel(), title.getName()); - // 현재 날짜와 데이터베이스에 저장된 날짜 사이의 차이 계산 + // 현재 날짜와 데이터베이스에 저장된 날짜 사이의 차이 계산. 날짜 차이는 6일이 최대(날짜 차이가 6이면 D-1임) LocalDateTime currentDate = LocalDateTime.now(); int differenceInDays = Math.toIntExact(ChronoUnit.DAYS.between(member.getCreatedDate(), currentDate)); - if (differenceInDays >= 7) { - differenceInDays = 7; + if (differenceInDays > 6) { + differenceInDays = 6; } + int dDay = 7 - differenceInDays; //날짜가 같아 그러면 difference=0, openList는 dDay=7 하나 List<QuizDto> openList = new ArrayList<>(); - for (int dDay = 7; dDay >= 7 - differenceInDays; dDay--) { - if (dDay != 0) { - openList.add(new QuizDto(dDay)); - } + for (int day = 7; day >= 7 - differenceInDays; day--) { + openList.add(new QuizDto(day)); } + //doneList는 memberTitle테이블에 1로 된(푼 처리된) 애들 리스트를 불러옴 List<QuizDto> doneList = new ArrayList<>(); List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); for (MemberTitle memberTitle : memberTitles) { @@ -74,8 +74,8 @@ public ProfileResDto getMember() { } List<QuizDto> closeList = new ArrayList<>(); - for (int dDay = 6 - differenceInDays; dDay >= 1; dDay--) { - closeList.add(new QuizDto(dDay)); + for (int day = 6 - differenceInDays; day >= 1; day--) { + closeList.add(new QuizDto(day)); } QuizListDto quizListDto = new QuizListDto(); From 5ee18ab023605483798a1ec1fb65c67db8569fc8 Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Sun, 6 Aug 2023 17:04:13 +0900 Subject: [PATCH 142/153] =?UTF-8?q?chore:=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=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../efub/eday/edayback/domain/member/service/MemberService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java index 331bf79..000ee1e 100644 --- a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java +++ b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java @@ -55,7 +55,6 @@ public ProfileResDto getMember() { if (differenceInDays > 6) { differenceInDays = 6; } - int dDay = 7 - differenceInDays; //날짜가 같아 그러면 difference=0, openList는 dDay=7 하나 List<QuizDto> openList = new ArrayList<>(); From b35c0f2ee4ea014c9d8979d7d72e419618ed2423 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 6 Aug 2023 18:24:18 +0900 Subject: [PATCH 143/153] =?UTF-8?q?fix:=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EB=A0=88=EB=B2=A8=EC=9D=B4=208=20=EC=9D=B4=EC=83=81=EC=9D=B4?= =?UTF-8?q?=20=EB=90=98=EB=8A=94=20=EC=83=81=ED=99=A9=20=EB=B0=A9=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/service/MemberService.java | 144 +++++++++--------- 1 file changed, 73 insertions(+), 71 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java index 8982200..54640b5 100644 --- a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java +++ b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java @@ -1,13 +1,5 @@ package efub.eday.edayback.domain.member.service; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; -import java.util.ArrayList; -import java.util.List; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - import efub.eday.edayback.domain.day.title.entity.Title; import efub.eday.edayback.domain.day.title.repository.TitleRepository; import efub.eday.edayback.domain.member.auth.service.AuthService; @@ -20,74 +12,84 @@ import efub.eday.edayback.domain.member.repository.MemberTitleRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.List; @Slf4j @RequiredArgsConstructor @Service public class MemberService { - private final AuthService authService; - private final TitleRepository titleRepository; - private final MemberTitleRepository memberTitleRepository; - - @Transactional(readOnly = true) - public ProfileResDto getMember() { - //현재 로그인 중인 사용자 정보 불러오기 - Member member = authService.getCurrentMember(); - - int level = member.getLevel(); - - //칭호는 dDay가 아닌 level을 기준으로 정해짐 - Title title = titleRepository.findBySubjectId(level).orElseThrow(); - - //profile부분에 들어갈 속성들 - ProfileDto profile = new ProfileDto(member.getNickname(), - member.getProfileImageUrl(), - member.getLevel(), - title.getName()); - - // 현재 날짜와 데이터베이스에 저장된 날짜 사이의 차이 계산 - LocalDateTime currentDate = LocalDateTime.now(); - int differenceInDays = Math.toIntExact(ChronoUnit.DAYS.between(member.getCreatedDate(), currentDate)); - if (differenceInDays >= 7) { - differenceInDays = 7; - } - - List<QuizDto> doneList = new ArrayList<>(); - List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); - for (MemberTitle memberTitle : memberTitles) { - if (memberTitle.getGetTitle()) { - int subject = memberTitle.getTitle().getSubject().getDday(); - doneList.add(new QuizDto(subject)); - } - } - - //날짜가 같아 그러면 difference=0, openList는 dDay=7 하나 - List<QuizDto> openList = new ArrayList<>(); - for (int dDay = 7; dDay >= 7 - differenceInDays; dDay--) { - boolean isInDoneList = false; - for (QuizDto quiz : doneList) { - if (quiz.getDday() == dDay) { - isInDoneList = true; - break; - } - } - if (!isInDoneList && dDay != 0) { - openList.add(new QuizDto(dDay)); - } - } - - List<QuizDto> closeList = new ArrayList<>(); - for (int dDay = 6 - differenceInDays; dDay >= 1; dDay--) { - closeList.add(new QuizDto(dDay)); - } - - QuizListDto quizListDto = new QuizListDto(); - quizListDto.setOpenList(openList); - quizListDto.setDoneList(doneList); - quizListDto.setCloseList(closeList); - - return new ProfileResDto(profile, quizListDto); - } + private final AuthService authService; + private final TitleRepository titleRepository; + private final MemberTitleRepository memberTitleRepository; + + @Transactional(readOnly = true) + public ProfileResDto getMember() { + //현재 로그인 중인 사용자 정보 불러오기 + Member member = authService.getCurrentMember(); + + int level = member.getLevel(); + if (level > 7) { + level = 7; + } + + //칭호는 dDay가 아닌 level을 기준으로 정해짐 + Title title = titleRepository.findBySubjectId(level).orElseThrow(); + + //profile부분에 들어갈 속성들 + ProfileDto profile = new ProfileDto(member.getNickname(), + member.getProfileImageUrl(), + member.getLevel(), + title.getName()); + + // 현재 날짜와 데이터베이스에 저장된 날짜 사이의 차이 계산 + LocalDateTime currentDate = LocalDateTime.now(); + int differenceInDays = Math.toIntExact(ChronoUnit.DAYS.between(member.getCreatedDate(), currentDate)); + if (differenceInDays >= 7) { + differenceInDays = 7; + } + + List<QuizDto> doneList = new ArrayList<>(); + List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); + for (MemberTitle memberTitle : memberTitles) { + if (memberTitle.getGetTitle()) { + int subject = memberTitle.getTitle().getSubject().getDday(); + doneList.add(new QuizDto(subject)); + } + } + + //날짜가 같아 그러면 difference=0, openList는 dDay=7 하나 + List<QuizDto> openList = new ArrayList<>(); + for (int dDay = 7; dDay >= 7 - differenceInDays; dDay--) { + boolean isInDoneList = false; + for (QuizDto quiz : doneList) { + if (quiz.getDday() == dDay) { + isInDoneList = true; + break; + } + } + if (!isInDoneList && dDay != 0) { + openList.add(new QuizDto(dDay)); + } + } + + List<QuizDto> closeList = new ArrayList<>(); + for (int dDay = 6 - differenceInDays; dDay >= 1; dDay--) { + closeList.add(new QuizDto(dDay)); + } + + QuizListDto quizListDto = new QuizListDto(); + quizListDto.setOpenList(openList); + quizListDto.setDoneList(doneList); + quizListDto.setCloseList(closeList); + + return new ProfileResDto(profile, quizListDto); + } } From ad684b0e670436941ad6e97c5403af9bb3346755 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 6 Aug 2023 18:59:00 +0900 Subject: [PATCH 144/153] =?UTF-8?q?feat:=20=EC=B9=B4=EC=B9=B4=EC=98=A4=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=8B=9C=20=EB=A6=AC=EB=8B=A4?= =?UTF-8?q?=EC=9D=B4=EB=A0=89=ED=8A=B8=20URI=EB=A5=BC=20=ED=81=B4=EB=9D=BC?= =?UTF-8?q?=EC=9D=B4=EC=96=B8=ED=8A=B8=EC=97=90=EA=B2=8C=20=EB=B0=9B?= =?UTF-8?q?=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 --- .../auth/controller/AuthController.java | 37 ++-- .../member/auth/dto/AuthRequestDto.java | 6 +- .../member/auth/service/AuthService.java | 205 +++++++++--------- 3 files changed, 120 insertions(+), 128 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/controller/AuthController.java b/src/main/java/efub/eday/edayback/domain/member/auth/controller/AuthController.java index 76c7efb..4f278db 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/controller/AuthController.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/controller/AuthController.java @@ -1,10 +1,5 @@ package efub.eday.edayback.domain.member.auth.controller; -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 efub.eday.edayback.domain.member.auth.dto.AuthRequestDto; import efub.eday.edayback.domain.member.auth.dto.AuthResponseDto; import efub.eday.edayback.domain.member.auth.service.AuthService; @@ -16,6 +11,10 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +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; @Tag(name = "로그인", description = "로그인 관련 api입니다.") @Slf4j @@ -24,20 +23,20 @@ @RequestMapping("/member/auth") public class AuthController { - private final AuthService authService; + private final AuthService authService; - @Operation(summary = "kakao에게 정보 요청 메소드", description = "로그인 정보를 바탕으로 kakao에 정보를 요청하는 메소드입니다.") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "로그인 성공", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = AuthResponseDto.class))), - @ApiResponse(responseCode = "403", description = "로그인 실패(인증되지 않은 사용자)", - content = @Content(mediaType = "application/json", - schema = @Schema(implementation = AuthResponseDto.class))) - }) - @PostMapping - public AuthResponseDto login(@RequestBody AuthRequestDto authRequestDto) { - return authService.signIn(authRequestDto.getCode()); - } + @Operation(summary = "kakao에게 정보 요청 메소드", description = "로그인 정보를 바탕으로 kakao에 정보를 요청하는 메소드입니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "로그인 성공", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AuthResponseDto.class))), + @ApiResponse(responseCode = "403", description = "로그인 실패(인증되지 않은 사용자)", + content = @Content(mediaType = "application/json", + schema = @Schema(implementation = AuthResponseDto.class))) + }) + @PostMapping + public AuthResponseDto login(@RequestBody AuthRequestDto authRequestDto) { + return authService.signIn(authRequestDto.getCode(), authRequestDto.getRedirectUri()); + } } diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthRequestDto.java b/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthRequestDto.java index 941f5f0..1664f80 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthRequestDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/dto/AuthRequestDto.java @@ -8,6 +8,8 @@ @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) public class AuthRequestDto { - @Schema(description = "인가 코드") - private String code; + @Schema(description = "인가 코드") + private String code; + @Schema(description = "리다이렉트 URI") + private String redirectUri; } diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java index 6e08dca..33c081e 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java @@ -1,15 +1,5 @@ package efub.eday.edayback.domain.member.auth.service; -import java.util.List; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Service; -import org.springframework.web.server.ResponseStatusException; - import efub.eday.edayback.domain.day.quiz.entity.Quiz; import efub.eday.edayback.domain.day.quiz.repository.QuizRepository; import efub.eday.edayback.domain.day.title.entity.Title; @@ -29,107 +19,108 @@ import efub.eday.edayback.global.jwt.JwtProvider; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Service; +import org.springframework.web.server.ResponseStatusException; + +import java.util.List; @Slf4j @Service @RequiredArgsConstructor public class AuthService { - private static final String GRANT_TYPE_VALUE = "authorization_code"; - private static final String BEARER = "Bearer "; - - private final KakaoAuthFeign kakaoAuthFeign; - private final KakaoApiFeign kakaoApiFeign; - private final MemberRepository memberRepository; - private final QuizRepository quizRepository; - private final MemberQuizRepository memberQuizRepository; - private final TitleRepository titleRepository; - private final MemberTitleRepository memberTitleRepository; - private final JwtProvider jwtProvider; - - @Value("${kakao.client-id}") - private String clientId; - - @Value("${kakao.redirect-uri}") - private String redirectUri; - - public AuthResponseDto signIn(String code) { - String kakaoToken = getKakaoToken(code); - log.debug("kakaoToken: {}", kakaoToken); - Member member = getKakaoProfile(kakaoToken); - log.debug("member login: {} {}", member.getId(), member.getNickname()); - String accessToken = jwtProvider.createAccessToken(member.getId()); - String refreshToken = jwtProvider.createRefreshToken(member.getId()); - AuthResponseDto authResponseDto = AuthResponseDto.builder() - .member(member) - .accessToken(accessToken) - .refreshToken(refreshToken) - .build(); - log.debug("nickname: {} / access: {} / refresh: {}", authResponseDto.getNickname(), - authResponseDto.getAccessToken(), authResponseDto.getRefreshToken()); - return authResponseDto; - } - - private String getKakaoToken(String code) { - KakaoTokenResponseDto tokenResponseDto = kakaoAuthFeign.getKakaoToken( - KakaoTokenRequestDto.builder() - .grant_type(GRANT_TYPE_VALUE) - .client_id(clientId) - .redirect_uri(redirectUri) - .code(code) - .build() - ); - return tokenResponseDto.getAccess_token(); - } - - private Member getKakaoProfile(String kakaoToken) { - HttpHeaders httpHeaders = new HttpHeaders(); - httpHeaders.add(HttpHeaders.AUTHORIZATION, BEARER + kakaoToken); - KakaoProfileResponseDto kakaoProfile = kakaoApiFeign.getKakaoProfile(httpHeaders); - - log.debug("카카오 프로필: {}", kakaoProfile.getNickname()); - - Long loginId = kakaoProfile.getId(); - String nickname = kakaoProfile.getNickname(); - String profileImageUrl = kakaoProfile.getProfileImageUrl(); - - Member member = memberRepository.findByLoginId(loginId).orElse(null); - if (member != null) { - member.updateProfile(nickname, profileImageUrl); - return member; - } - member = Member.builder() - .loginId(loginId) - .nickname(nickname) - .profileImageUrl(profileImageUrl) - .build(); - signUp(member); - return member; - } - - private void signUp(Member member) { - - memberRepository.save(member); - - List<Quiz> quizs = quizRepository.findAll(); - for (Quiz quiz : quizs) { - MemberQuiz mQuiz = new MemberQuiz(member, quiz); - memberQuizRepository.save(mQuiz); - } - - List<Title> titles = titleRepository.findAll(); - for (Title title : titles) { - MemberTitle mTitle = new MemberTitle(member, title); - memberTitleRepository.save(mTitle); - } - - } - - public Member getCurrentMember() { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - String principalName = authentication.getName(); - Long memberId = Long.parseLong(principalName); - return memberRepository.findById(memberId).orElseThrow(() -> - new ResponseStatusException(HttpStatus.FORBIDDEN, "인증된 사용자 정보가 없습니다.")); - } + private static final String GRANT_TYPE_VALUE = "authorization_code"; + private static final String BEARER = "Bearer "; + + private final KakaoAuthFeign kakaoAuthFeign; + private final KakaoApiFeign kakaoApiFeign; + private final MemberRepository memberRepository; + private final QuizRepository quizRepository; + private final MemberQuizRepository memberQuizRepository; + private final TitleRepository titleRepository; + private final MemberTitleRepository memberTitleRepository; + private final JwtProvider jwtProvider; + + @Value("${kakao.client-id}") + private String clientId; + + public AuthResponseDto signIn(String code, String redirectUri) { + String kakaoToken = getKakaoToken(code, redirectUri); + Member member = getKakaoProfile(kakaoToken); + String accessToken = jwtProvider.createAccessToken(member.getId()); + String refreshToken = jwtProvider.createRefreshToken(member.getId()); + return AuthResponseDto.builder() + .member(member) + .accessToken(accessToken) + .refreshToken(refreshToken) + .build(); + } + + private String getKakaoToken(String code, String redirectUri) { + KakaoTokenResponseDto tokenResponseDto = kakaoAuthFeign.getKakaoToken( + KakaoTokenRequestDto.builder() + .grant_type(GRANT_TYPE_VALUE) + .client_id(clientId) + .redirect_uri(redirectUri) + .code(code) + .build() + ); + return tokenResponseDto.getAccess_token(); + } + + private Member getKakaoProfile(String kakaoToken) { + HttpHeaders httpHeaders = new HttpHeaders(); + httpHeaders.add(HttpHeaders.AUTHORIZATION, BEARER + kakaoToken); + KakaoProfileResponseDto kakaoProfile = kakaoApiFeign.getKakaoProfile(httpHeaders); + + log.debug("카카오 프로필: {}", kakaoProfile.getNickname()); + + Long loginId = kakaoProfile.getId(); + String nickname = kakaoProfile.getNickname(); + String profileImageUrl = kakaoProfile.getProfileImageUrl(); + + Member member = memberRepository.findByLoginId(loginId).orElse(null); + if (member != null) { + member.updateProfile(nickname, profileImageUrl); + return member; + } + member = Member.builder() + .loginId(loginId) + .nickname(nickname) + .profileImageUrl(profileImageUrl) + .build(); + signUp(member); + return member; + } + + private void signUp(Member member) { + + memberRepository.save(member); + + List<Quiz> quizs = quizRepository.findAll(); + for (Quiz quiz : quizs) { + MemberQuiz mQuiz = new MemberQuiz(member, quiz); + memberQuizRepository.save(mQuiz); + } + + List<Title> titles = titleRepository.findAll(); + for (Title title : titles) { + MemberTitle mTitle = new MemberTitle(member, title); + memberTitleRepository.save(mTitle); + } + + } + + public Member getCurrentMember() { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + String principalName = authentication.getName(); + Long memberId = Long.parseLong(principalName); + return memberRepository.findById(memberId).orElseThrow(() -> + new ResponseStatusException(HttpStatus.FORBIDDEN, "인증된 사용자 정보가 없습니다.")); + } } From fff8d5497f6c5188cccaac2f2709c0efedbeaab4 Mon Sep 17 00:00:00 2001 From: choiyounji <yunji71@naver.com> Date: Mon, 7 Aug 2023 07:59:49 +0900 Subject: [PATCH 145/153] =?UTF-8?q?fix:=20=EB=82=A0=EC=A7=9C=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../eday/edayback/domain/member/service/MemberService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java index 000ee1e..9814951 100644 --- a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java +++ b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java @@ -51,7 +51,8 @@ public ProfileResDto getMember() { // 현재 날짜와 데이터베이스에 저장된 날짜 사이의 차이 계산. 날짜 차이는 6일이 최대(날짜 차이가 6이면 D-1임) LocalDateTime currentDate = LocalDateTime.now(); - int differenceInDays = Math.toIntExact(ChronoUnit.DAYS.between(member.getCreatedDate(), currentDate)); + int differenceInDays = Math.toIntExact( + ChronoUnit.DAYS.between(member.getCreatedDate().toLocalDate(), currentDate.toLocalDate())); if (differenceInDays > 6) { differenceInDays = 6; } From c5a17ff39955f17dec559dd3bfce0ac916eb4d0c Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 13 Aug 2023 15:55:48 +0900 Subject: [PATCH 146/153] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=EC=B2=AB?= =?UTF-8?q?=20=EA=B0=80=EC=9E=85=20=EC=8B=9C=20=EB=A0=88=EB=B2=A8=200?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/efub/eday/edayback/domain/member/entity/Member.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java index 3abc334..19785f5 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java @@ -52,7 +52,7 @@ public Member(Long loginId, String nickname, String profileImageUrl) { this.nickname = nickname; this.loginId = loginId; this.profileImageUrl = profileImageUrl; - this.level = 1; + this.level = 0; this.isActive = true; } From 6c14c634340af60795761271db45b5830f250f36 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 13 Aug 2023 15:59:19 +0900 Subject: [PATCH 147/153] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=EC=9D=98=20?= =?UTF-8?q?=EA=B0=80=EC=9E=85=EB=82=A0=EC=A7=9C=20=ED=83=80=EC=9E=85=20Loc?= =?UTF-8?q?alDateTime=20->=20LocalDate=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/efub/eday/edayback/domain/member/entity/Member.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java index 19785f5..244b751 100644 --- a/src/main/java/efub/eday/edayback/domain/member/entity/Member.java +++ b/src/main/java/efub/eday/edayback/domain/member/entity/Member.java @@ -1,6 +1,6 @@ package efub.eday.edayback.domain.member.entity; -import java.time.LocalDateTime; +import java.time.LocalDate; import javax.persistence.Column; import javax.persistence.Entity; @@ -42,7 +42,7 @@ public class Member { @CreationTimestamp //insert할 때 자동 날짜 적용 @Column(nullable = false) - private LocalDateTime createdDate; + private LocalDate createdDate; @Column(nullable = false) private Boolean isActive; From f6bb23e7bc219642e06b45d9eb0f44dd600792a2 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 13 Aug 2023 16:48:11 +0900 Subject: [PATCH 148/153] =?UTF-8?q?fix:=20=EB=82=A0=EC=A7=9C=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=EC=8B=9C=20=EB=AC=B8=EC=9E=90=EC=97=B4=20=ED=98=95?= =?UTF-8?q?=ED=83=9C=EB=A1=9C=20=EC=B6=9C=EB=A0=A5=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 --- .../edayback/domain/day/title/dto/MemberProfileDto.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/day/title/dto/MemberProfileDto.java b/src/main/java/efub/eday/edayback/domain/day/title/dto/MemberProfileDto.java index 0f3afc9..08e221c 100644 --- a/src/main/java/efub/eday/edayback/domain/day/title/dto/MemberProfileDto.java +++ b/src/main/java/efub/eday/edayback/domain/day/title/dto/MemberProfileDto.java @@ -1,6 +1,6 @@ package efub.eday.edayback.domain.day.title.dto; -import java.time.LocalDateTime; +import java.time.LocalDate; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Getter; @@ -17,16 +17,16 @@ public class MemberProfileDto { @Schema(description = "레벨") private int level; @Schema(description = "계정 생성일") - private LocalDateTime createdDate; + private String createdDate; @Schema(description = "활성 상태 여부") private boolean isActive; - public MemberProfileDto(String nickname, String profileImage, int level, LocalDateTime createdDate, + public MemberProfileDto(String nickname, String profileImage, int level, LocalDate createdDate, boolean isActive) { this.nickname = nickname; this.profileImage = profileImage; this.level = level; - this.createdDate = createdDate; + this.createdDate = createdDate.toString(); this.isActive = isActive; } } From 2ab3573edd03d8c331a1c356897ae15b8c4bf653 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 13 Aug 2023 16:48:27 +0900 Subject: [PATCH 149/153] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=EC=8A=A4?= =?UTF-8?q?=ED=83=80=EC=9D=BC=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/auth/service/AuthService.java | 197 +++++++++--------- 1 file changed, 99 insertions(+), 98 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java index 33c081e..1b8380c 100644 --- a/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java +++ b/src/main/java/efub/eday/edayback/domain/member/auth/service/AuthService.java @@ -1,5 +1,15 @@ package efub.eday.edayback.domain.member.auth.service; +import java.util.List; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Service; +import org.springframework.web.server.ResponseStatusException; + import efub.eday.edayback.domain.day.quiz.entity.Quiz; import efub.eday.edayback.domain.day.quiz.repository.QuizRepository; import efub.eday.edayback.domain.day.title.entity.Title; @@ -19,108 +29,99 @@ import efub.eday.edayback.global.jwt.JwtProvider; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Service; -import org.springframework.web.server.ResponseStatusException; - -import java.util.List; @Slf4j @Service @RequiredArgsConstructor public class AuthService { - private static final String GRANT_TYPE_VALUE = "authorization_code"; - private static final String BEARER = "Bearer "; - - private final KakaoAuthFeign kakaoAuthFeign; - private final KakaoApiFeign kakaoApiFeign; - private final MemberRepository memberRepository; - private final QuizRepository quizRepository; - private final MemberQuizRepository memberQuizRepository; - private final TitleRepository titleRepository; - private final MemberTitleRepository memberTitleRepository; - private final JwtProvider jwtProvider; - - @Value("${kakao.client-id}") - private String clientId; - - public AuthResponseDto signIn(String code, String redirectUri) { - String kakaoToken = getKakaoToken(code, redirectUri); - Member member = getKakaoProfile(kakaoToken); - String accessToken = jwtProvider.createAccessToken(member.getId()); - String refreshToken = jwtProvider.createRefreshToken(member.getId()); - return AuthResponseDto.builder() - .member(member) - .accessToken(accessToken) - .refreshToken(refreshToken) - .build(); - } - - private String getKakaoToken(String code, String redirectUri) { - KakaoTokenResponseDto tokenResponseDto = kakaoAuthFeign.getKakaoToken( - KakaoTokenRequestDto.builder() - .grant_type(GRANT_TYPE_VALUE) - .client_id(clientId) - .redirect_uri(redirectUri) - .code(code) - .build() - ); - return tokenResponseDto.getAccess_token(); - } - - private Member getKakaoProfile(String kakaoToken) { - HttpHeaders httpHeaders = new HttpHeaders(); - httpHeaders.add(HttpHeaders.AUTHORIZATION, BEARER + kakaoToken); - KakaoProfileResponseDto kakaoProfile = kakaoApiFeign.getKakaoProfile(httpHeaders); - - log.debug("카카오 프로필: {}", kakaoProfile.getNickname()); - - Long loginId = kakaoProfile.getId(); - String nickname = kakaoProfile.getNickname(); - String profileImageUrl = kakaoProfile.getProfileImageUrl(); - - Member member = memberRepository.findByLoginId(loginId).orElse(null); - if (member != null) { - member.updateProfile(nickname, profileImageUrl); - return member; - } - member = Member.builder() - .loginId(loginId) - .nickname(nickname) - .profileImageUrl(profileImageUrl) - .build(); - signUp(member); - return member; - } - - private void signUp(Member member) { - - memberRepository.save(member); - - List<Quiz> quizs = quizRepository.findAll(); - for (Quiz quiz : quizs) { - MemberQuiz mQuiz = new MemberQuiz(member, quiz); - memberQuizRepository.save(mQuiz); - } - - List<Title> titles = titleRepository.findAll(); - for (Title title : titles) { - MemberTitle mTitle = new MemberTitle(member, title); - memberTitleRepository.save(mTitle); - } - - } - - public Member getCurrentMember() { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - String principalName = authentication.getName(); - Long memberId = Long.parseLong(principalName); - return memberRepository.findById(memberId).orElseThrow(() -> - new ResponseStatusException(HttpStatus.FORBIDDEN, "인증된 사용자 정보가 없습니다.")); - } + private static final String GRANT_TYPE_VALUE = "authorization_code"; + private static final String BEARER = "Bearer "; + + private final KakaoAuthFeign kakaoAuthFeign; + private final KakaoApiFeign kakaoApiFeign; + private final MemberRepository memberRepository; + private final QuizRepository quizRepository; + private final MemberQuizRepository memberQuizRepository; + private final TitleRepository titleRepository; + private final MemberTitleRepository memberTitleRepository; + private final JwtProvider jwtProvider; + + @Value("${kakao.client-id}") + private String clientId; + + public AuthResponseDto signIn(String code, String redirectUri) { + String kakaoToken = getKakaoToken(code, redirectUri); + Member member = getKakaoProfile(kakaoToken); + String accessToken = jwtProvider.createAccessToken(member.getId()); + String refreshToken = jwtProvider.createRefreshToken(member.getId()); + return AuthResponseDto.builder() + .member(member) + .accessToken(accessToken) + .refreshToken(refreshToken) + .build(); + } + + private String getKakaoToken(String code, String redirectUri) { + KakaoTokenResponseDto tokenResponseDto = kakaoAuthFeign.getKakaoToken( + KakaoTokenRequestDto.builder() + .grant_type(GRANT_TYPE_VALUE) + .client_id(clientId) + .redirect_uri(redirectUri) + .code(code) + .build() + ); + return tokenResponseDto.getAccess_token(); + } + + private Member getKakaoProfile(String kakaoToken) { + HttpHeaders httpHeaders = new HttpHeaders(); + httpHeaders.add(HttpHeaders.AUTHORIZATION, BEARER + kakaoToken); + KakaoProfileResponseDto kakaoProfile = kakaoApiFeign.getKakaoProfile(httpHeaders); + + log.debug("카카오 프로필: {}", kakaoProfile.getNickname()); + + Long loginId = kakaoProfile.getId(); + String nickname = kakaoProfile.getNickname(); + String profileImageUrl = kakaoProfile.getProfileImageUrl(); + + Member member = memberRepository.findByLoginId(loginId).orElse(null); + if (member != null) { + member.updateProfile(nickname, profileImageUrl); + return member; + } + member = Member.builder() + .loginId(loginId) + .nickname(nickname) + .profileImageUrl(profileImageUrl) + .build(); + signUp(member); + return member; + } + + private void signUp(Member member) { + + memberRepository.save(member); + + List<Quiz> quizs = quizRepository.findAll(); + for (Quiz quiz : quizs) { + MemberQuiz mQuiz = new MemberQuiz(member, quiz); + memberQuizRepository.save(mQuiz); + } + + List<Title> titles = titleRepository.findAll(); + for (Title title : titles) { + MemberTitle mTitle = new MemberTitle(member, title); + memberTitleRepository.save(mTitle); + } + + } + + public Member getCurrentMember() { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + String principalName = authentication.getName(); + Long memberId = Long.parseLong(principalName); + return memberRepository.findById(memberId).orElseThrow(() -> + new ResponseStatusException(HttpStatus.FORBIDDEN, "인증된 사용자 정보가 없습니다.")); + } } From 943050b00392e6d4421bd52966615bb1952c6499 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 13 Aug 2023 16:53:10 +0900 Subject: [PATCH 150/153] =?UTF-8?q?fix:=20=ED=80=B4=EC=A6=88=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EA=B0=80=20=EC=8B=A4=EC=A0=9C=20=EB=94=94?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=EC=99=80=20=EB=8B=A4=EB=A5=B4=EA=B2=8C=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=EB=90=98=EB=8A=94=20=EC=98=A4=EB=A5=98=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 --- .../domain/member/service/MemberService.java | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java index 9814951..c5f5126 100644 --- a/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java +++ b/src/main/java/efub/eday/edayback/domain/member/service/MemberService.java @@ -1,14 +1,16 @@ package efub.eday.edayback.domain.member.service; -import java.time.LocalDateTime; +import java.time.LocalDate; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.server.ResponseStatusException; -import efub.eday.edayback.domain.day.title.entity.Title; +import efub.eday.edayback.domain.day.dday.entity.Dday; import efub.eday.edayback.domain.day.title.repository.TitleRepository; import efub.eday.edayback.domain.member.auth.service.AuthService; import efub.eday.edayback.domain.member.dto.ProfileDto; @@ -16,8 +18,6 @@ import efub.eday.edayback.domain.member.dto.QuizDto; import efub.eday.edayback.domain.member.dto.QuizListDto; import efub.eday.edayback.domain.member.entity.Member; -import efub.eday.edayback.domain.member.entity.MemberTitle; -import efub.eday.edayback.domain.member.repository.MemberTitleRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -28,55 +28,55 @@ public class MemberService { private final AuthService authService; private final TitleRepository titleRepository; - private final MemberTitleRepository memberTitleRepository; @Transactional(readOnly = true) public ProfileResDto getMember() { //현재 로그인 중인 사용자 정보 불러오기 Member member = authService.getCurrentMember(); + // 열린 퀴즈 리스트 + LocalDate currentDate = LocalDate.now(); + long diff = ChronoUnit.DAYS.between(member.getCreatedDate(), currentDate); + if (diff >= 7) { + diff = 7; + } + int dayIndex = 7; + List<QuizDto> openList = new ArrayList<>(); + for (; dayIndex >= 8 - diff; dayIndex--) { + openList.add(new QuizDto(dayIndex)); + } + + // 완료된 퀴즈 리스트 int level = member.getLevel(); if (level > 7) { level = 7; } - - //칭호는 dDay가 아닌 level을 기준으로 정해짐 - Title title = titleRepository.findBySubjectId(level).orElseThrow(); - - //profile부분에 들어갈 속성들 - ProfileDto profile = new ProfileDto(member.getNickname(), - member.getProfileImageUrl(), - member.getLevel(), - title.getName()); - - // 현재 날짜와 데이터베이스에 저장된 날짜 사이의 차이 계산. 날짜 차이는 6일이 최대(날짜 차이가 6이면 D-1임) - LocalDateTime currentDate = LocalDateTime.now(); - int differenceInDays = Math.toIntExact( - ChronoUnit.DAYS.between(member.getCreatedDate().toLocalDate(), currentDate.toLocalDate())); - if (differenceInDays > 6) { - differenceInDays = 6; + List<QuizDto> doneList = new ArrayList<>(); + int titleIndex = 7; + for (; titleIndex >= 8 - level; titleIndex--) { + doneList.add(new QuizDto(titleIndex)); } - //날짜가 같아 그러면 difference=0, openList는 dDay=7 하나 - List<QuizDto> openList = new ArrayList<>(); - for (int day = 7; day >= 7 - differenceInDays; day--) { - openList.add(new QuizDto(day)); + // 잠긴 퀴즈 리스트 + List<QuizDto> closeList = new ArrayList<>(); + for (; dayIndex > 0; dayIndex--) { + closeList.add(new QuizDto(dayIndex)); } - //doneList는 memberTitle테이블에 1로 된(푼 처리된) 애들 리스트를 불러옴 - List<QuizDto> doneList = new ArrayList<>(); - List<MemberTitle> memberTitles = memberTitleRepository.findByMember(member); - for (MemberTitle memberTitle : memberTitles) { - if (memberTitle.getGetTitle()) { - int subject = memberTitle.getTitle().getSubject().getDday(); - doneList.add(new QuizDto(subject)); - } + // 칭호 + String title = ""; + if (level > 0) { + title = titleRepository.findBySubject_Dday(Dday.fromRemainingDays(titleIndex + 1)) + .orElseThrow(() -> + new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR)) + .getName(); } - List<QuizDto> closeList = new ArrayList<>(); - for (int day = 6 - differenceInDays; day >= 1; day--) { - closeList.add(new QuizDto(day)); - } + //profile부분에 들어갈 속성들 + ProfileDto profile = new ProfileDto(member.getNickname(), + member.getProfileImageUrl(), + member.getLevel(), + title); QuizListDto quizListDto = new QuizListDto(); quizListDto.setOpenList(openList); From 59f6f513723ed0852bd0e4893cad662c489c72dd Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 13 Aug 2023 16:53:40 +0900 Subject: [PATCH 151/153] =?UTF-8?q?feat:=20=EB=A0=88=EB=B2=A8=200=EC=9D=BC?= =?UTF-8?q?=20=EB=95=8C=EC=9D=98=20=EC=9D=91=EB=8B=B5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/efub/eday/edayback/domain/member/dto/ProfileDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java index ecbb564..c55cced 100644 --- a/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java +++ b/src/main/java/efub/eday/edayback/domain/member/dto/ProfileDto.java @@ -27,7 +27,7 @@ public ProfileDto(String nickname, String profileImageUrl, int level, String tit this.profileImageUrl = profileImageUrl; this.level = level; //level이 1부터 시작하므로 dday는 8에서 빼는 것으로 수정 - this.dDay = 8 - level; + this.dDay = 7 - level; this.titleName = titleName; } } From 37dc5bd57614f0794f06494d73205f647602f398 Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 13 Aug 2023 16:58:24 +0900 Subject: [PATCH 152/153] =?UTF-8?q?feat:=20=EB=B0=B0=ED=8F=AC=20=EC=9B=8C?= =?UTF-8?q?=ED=81=AC=ED=94=8C=EB=A1=9C=20=ED=8A=B8=EB=A6=AC=EA=B1=B0=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 main에 푸시하는 경우 워크플로가 실행되도록 변경 --- .github/workflows/deploy.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d1198ee..5d47a96 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,8 +2,6 @@ name: Deploy to Amazon EC2 on: push: - branches: [ "main", "develop" ] - pull_request: branches: [ "main" ] env: From bb2d7e127828bcd0c43d063d7f31952139e22d9f Mon Sep 17 00:00:00 2001 From: Kwon Min A <min2010011@gmail.com> Date: Sun, 13 Aug 2023 17:21:03 +0900 Subject: [PATCH 153/153] =?UTF-8?q?docs:=20README=20=EC=88=98=EC=A0=95=20-?= =?UTF-8?q?=20=EC=9D=B4=EB=8D=B0=EC=9D=B4=20=EC=8A=A4=ED=81=AC=EB=A6=B0?= =?UTF-8?q?=EC=83=B7=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 102 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index ff7f2dc..2beadbb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # 🌱 Ewha-Day, E-Day + > EFUB 3rd SWS(Summer Web Surf) 2팀 E-Day Project ![](https://velog.velcdn.com/images/chhaewxn/post/b7a59ccb-3ef9-474e-9cea-616ace518712/image.png) @@ -6,10 +7,31 @@ <br> ## 🪴 프로젝트 설명 -### 🕊️ 예비 이화인을 위한 퀴즈 서비스 -> 예비 벗들이 개강 D-7부터 하루하루 열리는 퀴즈를 맞추며 이화여대에 대해 알아가는 퀴즈+정보 사이트입니다. 이화인으로서 알아두면 쓸모 있는, 알아두면 좋을 지식과 꿀팁들을 받아갈 수 있는 유용한 사이트가 될 것입니다. D-7부터 퀴즈를 하나씩 맞출 때마다 메인 화면에 있는 학교 지도에 색이 입혀지면서, 개강 날에는 색이 모두 칠해진 학교 지도를 얻을 수 있습니다. + +<img src="https://github.com/EFUB-EDAY/EDAY-BACK/assets/71026706/db9ee448-cd51-495c-ae32-254d4f867c0f" width=300 /> + +<details> +<summary>스크린샷</summary> +<img src="https://github.com/EFUB-EDAY/EDAY-BACK/assets/71026706/cf71d72d-c4fc-4e1f-8a02-8fdfa17f7c3e" width="300"> + +<img src="https://github.com/EFUB-EDAY/EDAY-BACK/assets/71026706/2de6a9c2-4ca8-4513-8c72-8f299fcfc02a" width="300"> +<img src="https://github.com/EFUB-EDAY/EDAY-BACK/assets/71026706/a15b39b1-ddb5-47a2-8061-dd10cd51982f" width="300"> + +<img src="https://github.com/EFUB-EDAY/EDAY-BACK/assets/71026706/a02b81f3-4442-45c5-af89-2b51731c820d" width="300" /> +<img src="https://github.com/EFUB-EDAY/EDAY-BACK/assets/71026706/f8fc7d2c-f908-41e8-ac94-2e6fc7e60a77" width="300" /> + +<img src="https://github.com/EFUB-EDAY/EDAY-BACK/assets/71026706/f7ca2fd4-ec8b-4fbf-8b4d-66e383b21229" width="300" /> +<img src="https://github.com/EFUB-EDAY/EDAY-BACK/assets/71026706/a1d77b0e-b4cd-42c1-98b4-b29eeb5b7195" width="300" /> +<img src="https://github.com/EFUB-EDAY/EDAY-BACK/assets/71026706/ca8b677f-cfe2-44c8-9583-f769fb28b562" width="300" /> +</details> + +### 🕊️ 예비 이화인을 위한 퀴즈 서비스 + +> 예비 벗들이 개강 D-7부터 하루하루 열리는 퀴즈를 맞추며 이화여대에 대해 알아가는 퀴즈+정보 사이트입니다. 이화인으로서 알아두면 쓸모 있는, 알아두면 좋을 지식과 꿀팁들을 받아갈 수 있는 유용한 사이트가 될 +> 것입니다. D-7부터 퀴즈를 하나씩 맞출 때마다 메인 화면에 있는 학교 지도에 색이 입혀지면서, 개강 날에는 색이 모두 칠해진 학교 지도를 얻을 수 있습니다. ### 📆 개발 기간 + - 프로젝트 세팅: 2023.07.04. - 2023.07.09. - API 개발: 2023.07.10. - 2023.07.24. - 배포 및 API 연결: 2023.07.25 - 2023.08. @@ -17,24 +39,26 @@ <br> ## 👩‍💻 팀원 소개 -|권민아|최윤지|송채원|이한나| -|:-:|:-:|:-:|:-:| -|<img src="https://avatars.githubusercontent.com/u/71026706?v=4"/>|<img src="https://avatars.githubusercontent.com/u/100260416?v=4"/>|<img src="https://avatars.githubusercontent.com/u/96541582?v=4"/>|<img src="https://avatars.githubusercontent.com/u/89291223?v=4"/> -|[@mingulmangul](https://github.com/mingulmangul)|[@choiyounji](https://github.com/choiyounji)|[@chhaewxn](https://github.com/chhaewxn)|[@hannah0226](https://github.com/hannah0226)| -|프로젝트 세팅 및 엔티티 생성<br>CI/CD 환경 구축<br>카카오 OAuth 로그인 개발<br>DB 설계 및 데이터 삽입 SQL문 작성<br>Swagger API Docs 세팅|카카오 OAuth 로그인 개발<br>사용자 API 개발<br>API 명세서 작성<br>유저 정보 저장 DB 설계|추가정보 API 개발<br>문의사항 API 개발<br>사용자 칭호 API 개발<br>데이터 삽입 SQL문 작성<br>API 명세서 작성|퀴즈 내용 보기 API 개발<br>퀴즈 정답 확인 API 개발<br>API 명세서 작성 + +| 권민아 | 최윤지 | 송채원 | 이한나 | +|:-----------------------------------------------------------------------------------------:|:------------------------------------------------------------------:|:---------------------------------------------------------------------------:|:-----------------------------------------------------------------:| +| <img src="https://avatars.githubusercontent.com/u/71026706?v=4"/> | <img src="https://avatars.githubusercontent.com/u/100260416?v=4"/> | <img src="https://avatars.githubusercontent.com/u/96541582?v=4"/> | <img src="https://avatars.githubusercontent.com/u/89291223?v=4"/> +| [@mingulmangul](https://github.com/mingulmangul) | [@choiyounji](https://github.com/choiyounji) | [@chhaewxn](https://github.com/chhaewxn) | [@hannah0226](https://github.com/hannah0226) | +| 프로젝트 세팅 및 엔티티 생성<br>CI/CD 환경 구축<br>카카오 OAuth 로그인 개발<br>사용자 정보 조회 API 개발<br>DB 설계 및 데이터 구축 | 카카오 OAuth 로그인 개발<br>사용자 API 개발<br>API 명세서 작성<br>유저 정보 저장 DB 설계 | 추가정보 API 개발<br>문의사항 API 개발<br>사용자 칭호 API 개발<br>데이터 삽입 SQL문 작성<br>API 명세서 작성 | 퀴즈 내용 보기 API 개발<br>퀴즈 정답 확인 API 개발<br>API 명세서 작성 <br> ### 📚 APIs -| View | Method | Detail | Developer | -|:-----------------:|:--------:|:--------:|:-----------:| -| 사용자 API | POST | 사용자 로그인 | 윤지/민아 | -| | GET | 사용자 정보 가져오기 | 윤지 | -| 퀴즈 API | GET | 퀴즈 내용 보기 | 한나 | -| | POST | 퀴즈 정답 선택 | 한나 | -| 문의 API | POST | 문의사항 작성하기 | 채원 | -| 추가정보 API | GET | 추가정보 페이지 보기 | 채원 | -| 칭호 API | GET | 칭호 페이지 보기 | 채원 | + +| View | Method | Detail | Developer | +|:--------:|:------:|:-----------:|:---------:| +| 사용자 API | POST | 사용자 로그인 | 윤지/민아 | +| | GET | 사용자 정보 보기 | 윤지/민아 | +| 퀴즈 API | GET | 퀴즈 내용 보기 | 한나 | +| | POST | 퀴즈 정답 선택 | 한나 | +| 문의 API | POST | 문의사항 작성하기 | 채원 | +| 추가정보 API | GET | 추가정보 페이지 보기 | 채원 | +| 칭호 API | GET | 칭호 페이지 보기 | 채원 | <br> @@ -42,53 +66,57 @@ ### [TAG] 메시지 -| 태그 이름 | 설명 | -| :--------: | :---------------------------------------------------------------: | -| feat | 새로운 기능 추가 | -| fix | 버그, 오류 수정 | -| style | 코드 포맷팅, 오타 수정, 주석 수정 및 삭제 등 | -| docs | 문서 수정 | -| chore | 빌드 및 패키지 수정 및 삭제 | -| refactor | 코드 리팩토링 | -| setting | 환경설정 | +| 태그 이름 | 설명 | +|:--------:|:---------------------------:| +| feat | 새로운 기능 추가 | +| fix | 버그, 오류 수정 | +| style | 코드 포맷팅, 오타 수정, 주석 수정 및 삭제 등 | +| docs | 문서 수정 | +| chore | 빌드 및 패키지 수정 및 삭제 | +| refactor | 코드 리팩토링 | +| setting | 환경설정 | ### 🪵 Branch Strategy 1. issue 생성 2. local - feature/~ 에서 각자 기능 작업 3. remote - feature/~ 에 Push -4. remote - develop 으로 Pull Request +4. remote - develop 으로 Pull Request 5. 코드 리뷰 후 remote - develop Merge 6. remote - develop 에 Merge 될 때 local - develop pull 받아 최신 상태 유지 <br> +## ⚙️ 기술 아키텍쳐 -## ⚙️ 기술 아키텍쳐 ### 사용 스택 -| 통합 개발 환경 | IntelliJ | -| --- | --- | -| Spring 버전 | 2.7.11 | -| 데이터베이스 | AWS RDS(MySQL) | -| 배포 | AWS EC2(Ubuntu), S3, CodeDepoly | -| Project 빌드 관리 도구 | Gradle | -| CI/CD 툴 | Github Actions | -| ERD 다이어그램 툴 | ERD Cloud | -| Java version | Java 11 | + +| 통합 개발 환경 | IntelliJ | +|------------------|---------------------------------| +| Spring 버전 | 2.7.11 | +| 데이터베이스 | AWS RDS(MySQL) | +| 배포 | AWS EC2(Ubuntu), S3, CodeDepoly | +| Project 빌드 관리 도구 | Gradle | +| CI/CD 툴 | Github Actions | +| ERD 다이어그램 툴 | ERD Cloud | +| Java version | Java 11 | <br> ### 아키텍쳐 구조 + <img width="1029" alt="image" src="https://github.com/EFUB-EDAY/EDAY-BACK/assets/71026706/357a011f-3628-453a-9f40-9c73a5545adc"> <br> -## ☁️ ERD +## ☁️ ERD + ![](https://velog.velcdn.com/images/chhaewxn/post/6976bd24-ca03-405f-9083-02c320313816/image.png) <br> ## 📁 프로젝트 폴더 구조 + ``` 📂 src/main/java/efub/eday └── edayback