Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import umc7th.bulk.recordedFood.entity.RecordedFood;
import umc7th.bulk.recordedFood.repository.RecordedFoodRepository;
import umc7th.bulk.user.domain.User;
import umc7th.bulk.user.repository.UserRepository;
import umc7th.bulk.user.service.UserService;

import java.io.IOException;
Expand All @@ -39,6 +40,7 @@ public class RecordServiceImpl implements RecordService {
private final S3Service s3Service;
private final AiCallService aiCallService;
private final UserService userService;
private final UserRepository userRepository;

@Transactional
public RecordResponseDto createRecord(RecordRequestDto.Create requestDto) {
Expand Down Expand Up @@ -109,6 +111,10 @@ public RecordResponseDto createRecord(RecordRequestDto.Create requestDto) {
Long totalProtein = recordedFoods.stream().mapToLong(RecordedFood::getProteins).sum();
Long totalFat = recordedFoods.stream().mapToLong(RecordedFood::getFats).sum();

// **✅ 사용자 현재 영양소 값 업데이트**
user.updateCurrentNutrients(totalCalories, totalCarbs, totalProtein, totalFat);
userRepository.save(user);

// Record에 영양소 값 업데이트
savedRecord.updateNutrients(totalCalories, totalCarbs, totalProtein, totalFat);
recordRepository.save(savedRecord);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/umc7th/bulk/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,11 @@ public void setGroup(Group group) {
group.getMembers().add(this);
}
}

public void updateCurrentNutrients(Long calories, Long carbos, Long proteins, Long fats) {
this.curCalories += calories;
this.curCarbos += carbos;
this.curProteins += proteins;
this.curFats += fats;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public UserResponseDTO.UserTokenDTO signup(UserRequestDTO.SignupDTO dto) {
.accessToken(accessToken)
.refreshToken(refreshToken)
.bulkCharacter(bulkCharacter) // 🔥 BulkCharacter 설정
.curCalories(0L)
.curCarbos(0L)
.curProteins(0L)
.curFats(0L)
.recordComplete(false)
.group(group)
.build();
Expand Down