From 94bd1f162fecbe11fb9c23be4281300522a7944e Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:26:59 +0900 Subject: [PATCH 01/10] =?UTF-8?q?update=20::=20book=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mindway/server/v2/domain/{Book => book}/entity/Book.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) rename src/main/java/com/mindway/server/v2/domain/{Book => book}/entity/Book.java (84%) diff --git a/src/main/java/com/mindway/server/v2/domain/Book/entity/Book.java b/src/main/java/com/mindway/server/v2/domain/book/entity/Book.java similarity index 84% rename from src/main/java/com/mindway/server/v2/domain/Book/entity/Book.java rename to src/main/java/com/mindway/server/v2/domain/book/entity/Book.java index 278d52b..4d0386b 100644 --- a/src/main/java/com/mindway/server/v2/domain/Book/entity/Book.java +++ b/src/main/java/com/mindway/server/v2/domain/book/entity/Book.java @@ -1,6 +1,5 @@ -package com.mindway.server.v2.domain.Book.entity; +package com.mindway.server.v2.domain.book.entity; -import com.mindway.server.v2.domain.goal.entity.Goal; import com.mindway.server.v2.domain.user.entity.User; import jakarta.persistence.*; import lombok.AllArgsConstructor; From 3f79dfe8f1b40c66c3d64d4bfe0e67f50cd45cef Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:27:15 +0900 Subject: [PATCH 02/10] =?UTF-8?q?add=20::=20NotExistGoalException=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 --- .../domain/goal/exception/NotExistGoalException.java | 10 ++++++++++ .../mindway/server/v2/global/exception/ErrorCode.java | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/mindway/server/v2/domain/goal/exception/NotExistGoalException.java diff --git a/src/main/java/com/mindway/server/v2/domain/goal/exception/NotExistGoalException.java b/src/main/java/com/mindway/server/v2/domain/goal/exception/NotExistGoalException.java new file mode 100644 index 0000000..ac746ab --- /dev/null +++ b/src/main/java/com/mindway/server/v2/domain/goal/exception/NotExistGoalException.java @@ -0,0 +1,10 @@ +package com.mindway.server.v2.domain.goal.exception; + +import com.mindway.server.v2.global.exception.ErrorCode; +import com.mindway.server.v2.global.exception.MindWayException; + +public class NotExistGoalException extends MindWayException { + public NotExistGoalException() { + super(ErrorCode.EXIST_ALREADY_GOAL); + } +} diff --git a/src/main/java/com/mindway/server/v2/global/exception/ErrorCode.java b/src/main/java/com/mindway/server/v2/global/exception/ErrorCode.java index 6e36fcf..2fb7ede 100644 --- a/src/main/java/com/mindway/server/v2/global/exception/ErrorCode.java +++ b/src/main/java/com/mindway/server/v2/global/exception/ErrorCode.java @@ -24,7 +24,8 @@ public enum ErrorCode { NOT_ACCESS_STUDENT(403,"접근 권한이 없습니다."), /* goal */ - EXIST_ALREADY_GOAL(400, "이미 목표 설정이 되어있습니다."); + EXIST_ALREADY_GOAL(400, "이미 목표 설정이 되어있습니다."), + NOT_EXIST_GOAL(404, "유저가 설정한 목표가 존재하지 않습니다"); private final int status; private final String message; From 095103e38dbe266d02bc368b5d50c30b61dbee34 Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:27:33 +0900 Subject: [PATCH 03/10] =?UTF-8?q?add=20::=20getGoal=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/goal/presentation/GoalController.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/mindway/server/v2/domain/goal/presentation/GoalController.java b/src/main/java/com/mindway/server/v2/domain/goal/presentation/GoalController.java index 929548f..1b1534d 100644 --- a/src/main/java/com/mindway/server/v2/domain/goal/presentation/GoalController.java +++ b/src/main/java/com/mindway/server/v2/domain/goal/presentation/GoalController.java @@ -1,15 +1,14 @@ package com.mindway.server.v2.domain.goal.presentation; import com.mindway.server.v2.domain.goal.presentation.dto.request.GoalAddRequestDto; +import com.mindway.server.v2.domain.goal.presentation.dto.response.GoalGetResponse; import com.mindway.server.v2.domain.goal.service.GoalAddService; +import com.mindway.server.v2.domain.goal.service.GoalGetService; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor @@ -17,6 +16,7 @@ public class GoalController { private final GoalAddService goalAddService; + private final GoalGetService goalGetService; @PostMapping public ResponseEntity addGoal(@Valid @RequestBody GoalAddRequestDto goalAddRequestDto) { @@ -24,5 +24,11 @@ public ResponseEntity addGoal(@Valid @RequestBody GoalAddRequestDto goalAd return ResponseEntity.status(HttpStatus.CREATED).build(); } + @GetMapping + public ResponseEntity getGoal() { + GoalGetResponse response = goalGetService.execute(); + return ResponseEntity.ok(response); + } + } From 583a700735a3cce39242c62723bc7597ad76b145 Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:27:44 +0900 Subject: [PATCH 04/10] =?UTF-8?q?add=20::=20toDto=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/v2/domain/goal/util/GoalConverter.java | 3 +++ .../domain/goal/util/impl/GoalConverterImpl.java | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/com/mindway/server/v2/domain/goal/util/GoalConverter.java b/src/main/java/com/mindway/server/v2/domain/goal/util/GoalConverter.java index 6546ba1..100e9f9 100644 --- a/src/main/java/com/mindway/server/v2/domain/goal/util/GoalConverter.java +++ b/src/main/java/com/mindway/server/v2/domain/goal/util/GoalConverter.java @@ -1,10 +1,13 @@ package com.mindway.server.v2.domain.goal.util; import com.mindway.server.v2.domain.goal.entity.Goal; +import com.mindway.server.v2.domain.goal.entity.Week; +import com.mindway.server.v2.domain.goal.presentation.dto.response.GoalGetResponse; import com.mindway.server.v2.domain.user.entity.User; import java.time.LocalDate; public interface GoalConverter { Goal toEntity(User user, String created_at, String ended_at, Integer goal_count); + GoalGetResponse toDto(Week week, Integer goal_value, Integer now_count); } diff --git a/src/main/java/com/mindway/server/v2/domain/goal/util/impl/GoalConverterImpl.java b/src/main/java/com/mindway/server/v2/domain/goal/util/impl/GoalConverterImpl.java index 38c80a7..f7a4149 100644 --- a/src/main/java/com/mindway/server/v2/domain/goal/util/impl/GoalConverterImpl.java +++ b/src/main/java/com/mindway/server/v2/domain/goal/util/impl/GoalConverterImpl.java @@ -2,6 +2,7 @@ import com.mindway.server.v2.domain.goal.entity.Goal; import com.mindway.server.v2.domain.goal.entity.Week; +import com.mindway.server.v2.domain.goal.presentation.dto.response.GoalGetResponse; import com.mindway.server.v2.domain.goal.util.GoalConverter; import com.mindway.server.v2.domain.user.entity.User; import org.springframework.stereotype.Component; @@ -21,5 +22,19 @@ public Goal toEntity(User user, String created_at, String ended_at, Integer goal .user(user) .build(); } + + public GoalGetResponse toDto(Week week, Integer goal_value, Integer now_count) { + return GoalGetResponse.builder() + .mon(week.getMon()) + .tue(week.getTue()) + .wed(week.getWed()) + .thu(week.getThu()) + .fri(week.getFri()) + .sat(week.getSat()) + .sun(week.getSun()) + .goal_value(goal_value) + .now_count(now_count) + .build(); + } } From bb9903c67f9e4a47ec9a63b681cf0a2a8839c5cf Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:28:05 +0900 Subject: [PATCH 05/10] =?UTF-8?q?add=20::=20GoalGetService=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 --- .../server/v2/domain/goal/service/GoalGetService.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/com/mindway/server/v2/domain/goal/service/GoalGetService.java diff --git a/src/main/java/com/mindway/server/v2/domain/goal/service/GoalGetService.java b/src/main/java/com/mindway/server/v2/domain/goal/service/GoalGetService.java new file mode 100644 index 0000000..38ad442 --- /dev/null +++ b/src/main/java/com/mindway/server/v2/domain/goal/service/GoalGetService.java @@ -0,0 +1,7 @@ +package com.mindway.server.v2.domain.goal.service; + +import com.mindway.server.v2.domain.goal.presentation.dto.response.GoalGetResponse; + +public interface GoalGetService { + GoalGetResponse execute(); +} From 6ad779d3b97bf10f1299c1d92bacc994d6d64c05 Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:28:11 +0900 Subject: [PATCH 06/10] =?UTF-8?q?add=20::=20GoalGetServiceImpl=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 --- .../goal/service/impl/GoalGetServiceImpl.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/com/mindway/server/v2/domain/goal/service/impl/GoalGetServiceImpl.java diff --git a/src/main/java/com/mindway/server/v2/domain/goal/service/impl/GoalGetServiceImpl.java b/src/main/java/com/mindway/server/v2/domain/goal/service/impl/GoalGetServiceImpl.java new file mode 100644 index 0000000..f88cba5 --- /dev/null +++ b/src/main/java/com/mindway/server/v2/domain/goal/service/impl/GoalGetServiceImpl.java @@ -0,0 +1,32 @@ +package com.mindway.server.v2.domain.goal.service.impl; + +import com.mindway.server.v2.domain.goal.entity.Goal; +import com.mindway.server.v2.domain.goal.exception.NotExistGoalException; +import com.mindway.server.v2.domain.goal.presentation.dto.response.GoalGetResponse; +import com.mindway.server.v2.domain.goal.repository.GoalRepository; +import com.mindway.server.v2.domain.goal.service.GoalGetService; +import com.mindway.server.v2.domain.goal.util.GoalConverter; +import com.mindway.server.v2.domain.user.entity.User; +import com.mindway.server.v2.domain.user.util.UserUtil; +import com.mindway.server.v2.global.annotation.ServiceWithReadOnlyTransaction; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@ServiceWithReadOnlyTransaction +@RequiredArgsConstructor +@Slf4j +public class GoalGetServiceImpl implements GoalGetService { + + private final GoalRepository goalRepository; + private final UserUtil userUtil; + private final GoalConverter goalConverter; + + public GoalGetResponse execute() { + User user = userUtil.getCurrentUser(); + + Goal goal = goalRepository.findByUser(user) + .orElseThrow(NotExistGoalException::new); + + return goalConverter.toDto(goal.getWeek(), goal.getGoal_value(), goal.getNow_count()); + } +} From 4d1f8cfbdc5678b477ec0e19eda848173fc2b725 Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:28:23 +0900 Subject: [PATCH 07/10] =?UTF-8?q?add=20::=20GoalGetResponse=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 --- .../dto/response/GoalGetResponse.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/com/mindway/server/v2/domain/goal/presentation/dto/response/GoalGetResponse.java diff --git a/src/main/java/com/mindway/server/v2/domain/goal/presentation/dto/response/GoalGetResponse.java b/src/main/java/com/mindway/server/v2/domain/goal/presentation/dto/response/GoalGetResponse.java new file mode 100644 index 0000000..b75cebf --- /dev/null +++ b/src/main/java/com/mindway/server/v2/domain/goal/presentation/dto/response/GoalGetResponse.java @@ -0,0 +1,31 @@ +package com.mindway.server.v2.domain.goal.presentation.dto.response; + +import com.mindway.server.v2.domain.goal.entity.Week; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Builder +@Setter +public class GoalGetResponse { + + private Integer mon; + + private Integer tue; + + private Integer wed; + + private Integer thu; + + private Integer fri; + + private Integer sat; + + private Integer sun; + + private Integer now_count; + + private Integer goal_value; + +} From 04f9198ea9577c3455aa3d0e4b8c9b2df61c5e10 Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:28:38 +0900 Subject: [PATCH 08/10] =?UTF-8?q?add=20::=20findByUser=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 --- .../server/v2/domain/goal/repository/GoalRepository.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/mindway/server/v2/domain/goal/repository/GoalRepository.java b/src/main/java/com/mindway/server/v2/domain/goal/repository/GoalRepository.java index 0406216..a0b42ee 100644 --- a/src/main/java/com/mindway/server/v2/domain/goal/repository/GoalRepository.java +++ b/src/main/java/com/mindway/server/v2/domain/goal/repository/GoalRepository.java @@ -4,6 +4,9 @@ import com.mindway.server.v2.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface GoalRepository extends JpaRepository { Boolean existsByUser(User user); + Optional findByUser(User user); } From 812d55fc73d3b09f7fff628478ae9b9c85887116 Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:28:50 +0900 Subject: [PATCH 09/10] =?UTF-8?q?add=20::=20url=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mindway/server/v2/global/security/config/SecurityConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/mindway/server/v2/global/security/config/SecurityConfig.java b/src/main/java/com/mindway/server/v2/global/security/config/SecurityConfig.java index dffdf83..3b6f123 100644 --- a/src/main/java/com/mindway/server/v2/global/security/config/SecurityConfig.java +++ b/src/main/java/com/mindway/server/v2/global/security/config/SecurityConfig.java @@ -61,6 +61,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { // goal .requestMatchers(HttpMethod.POST, "/api/v2/goal").authenticated() + .requestMatchers(HttpMethod.GET, "/api/v2/goal").authenticated() .anyRequest().authenticated() ) From 535e743eb979d634e570f08997a3c91d15fe8466 Mon Sep 17 00:00:00 2001 From: Umjiseung <127853946+Umjiseung@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:29:02 +0900 Subject: [PATCH 10/10] =?UTF-8?q?add=20::=20getter=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/mindway/server/v2/domain/goal/entity/Week.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/mindway/server/v2/domain/goal/entity/Week.java b/src/main/java/com/mindway/server/v2/domain/goal/entity/Week.java index 1a33f3a..772a021 100644 --- a/src/main/java/com/mindway/server/v2/domain/goal/entity/Week.java +++ b/src/main/java/com/mindway/server/v2/domain/goal/entity/Week.java @@ -4,12 +4,14 @@ import jakarta.persistence.Embeddable; import jakarta.persistence.MappedSuperclass; import lombok.AllArgsConstructor; +import lombok.Getter; import lombok.NoArgsConstructor; @Embeddable @MappedSuperclass @NoArgsConstructor @AllArgsConstructor +@Getter public class Week { @Column(length = 3)