-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[feat] 소비 목표 업데이트 관련 로직 수정 및 구현
- Loading branch information
Showing
9 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
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
15 changes: 15 additions & 0 deletions
15
...java/com/bbteam/budgetbuddies/domain/consumptiongoal/dto/UserConsumptionGoalResponse.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,15 @@ | ||
package com.bbteam.budgetbuddies.domain.consumptiongoal.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Getter | ||
@Builder | ||
public class UserConsumptionGoalResponse { | ||
private Long categoryId; | ||
private LocalDate goalMonth; | ||
private Long consumeAmount; | ||
private Long goalAmount; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/bbteam/budgetbuddies/domain/user/controller/UserController.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,23 @@ | ||
package com.bbteam.budgetbuddies.domain.user.controller; | ||
|
||
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.UserConsumptionGoalResponse; | ||
import com.bbteam.budgetbuddies.domain.user.service.UserService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/users") | ||
@RequiredArgsConstructor | ||
public class UserController { | ||
|
||
private final UserService userService; | ||
|
||
@PostMapping("/{userId}/add/default-categories/consumption-goal") | ||
public ResponseEntity<List<UserConsumptionGoalResponse>> createConsumptionGoals(@PathVariable Long userId) { | ||
List<UserConsumptionGoalResponse> consumptionGoals = userService.createConsumptionGoalWithDefaultGoals(userId); | ||
return ResponseEntity.ok(consumptionGoals); | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
src/main/java/com/bbteam/budgetbuddies/domain/user/controller/package-info.java
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserService.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,8 @@ | ||
package com.bbteam.budgetbuddies.domain.user.service; | ||
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.UserConsumptionGoalResponse; | ||
|
||
import java.util.List; | ||
|
||
public interface UserService { | ||
List<UserConsumptionGoalResponse> createConsumptionGoalWithDefaultGoals(Long userId); | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/bbteam/budgetbuddies/domain/user/service/UserServiceImpl.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,51 @@ | ||
package com.bbteam.budgetbuddies.domain.user.service; | ||
|
||
import com.bbteam.budgetbuddies.domain.category.entity.Category; | ||
import com.bbteam.budgetbuddies.domain.category.repository.CategoryRepository; | ||
import com.bbteam.budgetbuddies.domain.consumptiongoal.converter.ConsumptionGoalConverter; | ||
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.UserConsumptionGoalResponse; | ||
import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal; | ||
import com.bbteam.budgetbuddies.domain.consumptiongoal.repository.ConsumptionGoalRepository; | ||
import com.bbteam.budgetbuddies.domain.user.entity.User; | ||
import com.bbteam.budgetbuddies.domain.user.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserServiceImpl implements UserService { | ||
|
||
private final UserRepository userRepository; | ||
private final CategoryRepository categoryRepository; | ||
private final ConsumptionGoalRepository consumptionGoalRepository; | ||
private final ConsumptionGoalConverter consumptionGoalConverter; | ||
|
||
@Override | ||
@Transactional | ||
public List<UserConsumptionGoalResponse> createConsumptionGoalWithDefaultGoals(Long userId) { | ||
User user = userRepository.findById(userId) | ||
.orElseThrow(() -> new IllegalArgumentException("User not found")); | ||
|
||
List<Category> defaultCategories = categoryRepository.findAllByIsDefaultTrue(); | ||
List<ConsumptionGoal> consumptionGoals = defaultCategories.stream() | ||
.map(category -> ConsumptionGoal.builder() | ||
.user(user) | ||
.category(category) | ||
.goalMonth(LocalDate.now().withDayOfMonth(1)) | ||
.consumeAmount(0L) | ||
.goalAmount(0L) | ||
.build()) | ||
.collect(Collectors.toList()); | ||
|
||
List<ConsumptionGoal> savedConsumptionGoals = consumptionGoalRepository.saveAll(consumptionGoals); | ||
|
||
return savedConsumptionGoals.stream() | ||
.map(consumptionGoalConverter::toUserConsumptionGoalResponse) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
src/main/java/com/bbteam/budgetbuddies/domain/user/service/package-info.java
This file was deleted.
Oops, something went wrong.