-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from Team-MindWay/70-goal-get-api-create
🔀 :: 현재 목표 가져오는 api
- Loading branch information
Showing
12 changed files
with
117 additions
and
7 deletions.
There are no files selected for viewing
3 changes: 1 addition & 2 deletions
3
...ay/server/v2/domain/Book/entity/Book.java → ...ay/server/v2/domain/book/entity/Book.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/com/mindway/server/v2/domain/goal/exception/NotExistGoalException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
14 changes: 10 additions & 4 deletions
14
src/main/java/com/mindway/server/v2/domain/goal/presentation/GoalController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,34 @@ | ||
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 | ||
@RequestMapping("/api/v2/goal") | ||
public class GoalController { | ||
|
||
private final GoalAddService goalAddService; | ||
private final GoalGetService goalGetService; | ||
|
||
@PostMapping | ||
public ResponseEntity<Void> addGoal(@Valid @RequestBody GoalAddRequestDto goalAddRequestDto) { | ||
goalAddService.execute(goalAddRequestDto); | ||
return ResponseEntity.status(HttpStatus.CREATED).build(); | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<GoalGetResponse> getGoal() { | ||
GoalGetResponse response = goalGetService.execute(); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...ain/java/com/mindway/server/v2/domain/goal/presentation/dto/response/GoalGetResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/com/mindway/server/v2/domain/goal/service/GoalGetService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/mindway/server/v2/domain/goal/service/impl/GoalGetServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/java/com/mindway/server/v2/domain/goal/util/GoalConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters