diff --git a/src/main/java/com/example/kusitmshackthon/domain/member/controller/MemberController.java b/src/main/java/com/example/kusitmshackthon/domain/member/controller/MemberController.java index 7bc3a45..897f911 100644 --- a/src/main/java/com/example/kusitmshackthon/domain/member/controller/MemberController.java +++ b/src/main/java/com/example/kusitmshackthon/domain/member/controller/MemberController.java @@ -1,6 +1,9 @@ package com.example.kusitmshackthon.domain.member.controller; +import com.example.kusitmshackthon.domain.member.dto.request.SignInRequest; +import com.example.kusitmshackthon.domain.member.dto.request.SignUpRequest; +import com.example.kusitmshackthon.domain.member.dto.response.GetPreviousDietInfoResponse; import com.example.kusitmshackthon.domain.member.dto.response.MainPageResponse; import com.example.kusitmshackthon.domain.member.dto.response.MemberAuthResponseDto; import com.example.kusitmshackthon.domain.member.service.MemberService; @@ -31,15 +34,24 @@ public ResponseEntity getMainPage(@PathVariable(name = "userId return ResponseEntity.ok(response); } + + @Operation(summary = "가장 최근에 섭취한 식단에서, 탄당지, 콜레스테롤, 당류, 총열량 제공", description = + """ + 탄수화물, 당류, 지방, 콜레스테롤, 당류, 총열량을 제공합니다. + """) + @GetMapping("/{userId}/detail") + public ResponseEntity getPreviousDietInfo( + @PathVariable(name = "userId") Long userId){ + GetPreviousDietInfoResponse response = memberService.getPreviousDietInfo(userId); + return ResponseEntity.ok(response); + } + @Operation(summary = "카카오 회원가입 API 입니다.", description = """ email, nickName, age, fcmToken 을 보내주세요. """) @PostMapping("/singUp") - public ResponseEntity signUp(@RequestParam String email, - @RequestParam String nickName, - @RequestParam int age, - @RequestParam String fcmToken) { - MemberAuthResponseDto responseDto = memberService.signUp(email, nickName, age, fcmToken); + public ResponseEntity signUp(@RequestBody SignUpRequest request) { + MemberAuthResponseDto responseDto = memberService.signUp(request); return ResponseEntity.ok(responseDto); } @@ -49,10 +61,10 @@ public ResponseEntity signUp(@RequestParam String email, """) @GetMapping("/signIn") public ResponseEntity signIn( - @RequestParam String email, - @RequestParam String fcmToken) { - MemberAuthResponseDto responseDto = memberService.signIn(email, fcmToken); + @RequestBody SignInRequest request) { + MemberAuthResponseDto responseDto = memberService.signIn(request); return ResponseEntity.ok(responseDto); } + } diff --git a/src/main/java/com/example/kusitmshackthon/domain/member/dto/request/SignInRequest.java b/src/main/java/com/example/kusitmshackthon/domain/member/dto/request/SignInRequest.java new file mode 100644 index 0000000..da534aa --- /dev/null +++ b/src/main/java/com/example/kusitmshackthon/domain/member/dto/request/SignInRequest.java @@ -0,0 +1,13 @@ +package com.example.kusitmshackthon.domain.member.dto.request; + +import lombok.*; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Builder +@AllArgsConstructor +@ToString +public class SignInRequest { + String email; + String fcmToken; +} diff --git a/src/main/java/com/example/kusitmshackthon/domain/member/dto/request/SignUpRequest.java b/src/main/java/com/example/kusitmshackthon/domain/member/dto/request/SignUpRequest.java new file mode 100644 index 0000000..815e21a --- /dev/null +++ b/src/main/java/com/example/kusitmshackthon/domain/member/dto/request/SignUpRequest.java @@ -0,0 +1,15 @@ +package com.example.kusitmshackthon.domain.member.dto.request; + +import lombok.*; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Builder +@AllArgsConstructor +@ToString +public class SignUpRequest { + String email; + String nickName; + int age; + String fcmToken; +} diff --git a/src/main/java/com/example/kusitmshackthon/domain/member/dto/response/GetPreviousDietInfoResponse.java b/src/main/java/com/example/kusitmshackthon/domain/member/dto/response/GetPreviousDietInfoResponse.java new file mode 100644 index 0000000..4cdf46f --- /dev/null +++ b/src/main/java/com/example/kusitmshackthon/domain/member/dto/response/GetPreviousDietInfoResponse.java @@ -0,0 +1,17 @@ +package com.example.kusitmshackthon.domain.member.dto.response; + +import lombok.*; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Builder +@AllArgsConstructor +@ToString +public class GetPreviousDietInfoResponse { + Float carbohydrate; // 탄수화물 + Float protein; // 단백질 + Float fat;// 지방 + Float sugar;// 설탕 + Float cholesterol;// 콜레스테롤 + Float energy;// 열량 +} diff --git a/src/main/java/com/example/kusitmshackthon/domain/member/service/MemberService.java b/src/main/java/com/example/kusitmshackthon/domain/member/service/MemberService.java index ccee63d..2da03d4 100644 --- a/src/main/java/com/example/kusitmshackthon/domain/member/service/MemberService.java +++ b/src/main/java/com/example/kusitmshackthon/domain/member/service/MemberService.java @@ -5,6 +5,9 @@ import com.example.kusitmshackthon.domain.healthlog.entity.HealthLog; import com.example.kusitmshackthon.domain.healthlog.repository.HealthLogRepository; import com.example.kusitmshackthon.domain.healthlog.standard.StandardHealthLog; +import com.example.kusitmshackthon.domain.member.dto.request.SignInRequest; +import com.example.kusitmshackthon.domain.member.dto.request.SignUpRequest; +import com.example.kusitmshackthon.domain.member.dto.response.GetPreviousDietInfoResponse; import com.example.kusitmshackthon.domain.member.dto.response.MainPageResponse; import com.example.kusitmshackthon.domain.member.dto.response.MemberAuthResponseDto; import com.example.kusitmshackthon.domain.member.entity.Member; @@ -173,14 +176,21 @@ public String kor2eng(String name) { } @Transactional - public MemberAuthResponseDto signIn(String email, String fcmToken) { + public MemberAuthResponseDto signIn(SignInRequest request) { + String email = request.getEmail(); + String fcmToken = request.getFcmToken(); Member member = getMemberWithEmail(email); patchFCMtoken(member.getId(), fcmToken); return MemberAuthResponseDto.of(member); } @Transactional - public MemberAuthResponseDto signUp(String email, String nickname, int age, String fcmToken) { + public MemberAuthResponseDto signUp(SignUpRequest request) { + String email = request.getEmail(); + String nickname = request.getNickName(); + int age = request.getAge(); + String fcmToken = request.getFcmToken(); + Member craeatedMember = Member.createMember(nickname, age, email); validateDuplicateMember(email); saveMember(craeatedMember); @@ -210,4 +220,56 @@ private void validateDuplicateMember(String email) { } } + + + public GetPreviousDietInfoResponse getPreviousDietInfo(Long userId) { + Member member = memberRepository.findById(userId) + .orElseThrow(MemberNotFoundException::new); + LocalDate nowDate = LocalDate.now(); + + queryFactory = new JPAQueryFactory(entityManager); + + List healthLogs + = healthLogRepository.findByMemberIdAndIntakeDateEquals(userId, nowDate); + // 해당 회원의 식사 + QMember qMember = QMember.member; + + // 가장 가까운 시간에 섭취한 식단 영양 정보 + HealthLog recentlyHealthLog = queryFactory.selectFrom(healthLog) + .join(healthLog.member, qMember) + .where(healthLog.member.id.eq(qMember.id) + .and(healthLog.intakeDate.eq(nowDate))) + .orderBy(healthLog.intakeAt.desc()) + .limit(1) + .fetchOne(); + // 해당 회원의 베스트 영양 정보 get 하기 (탄 단 지 당 콜 열량) + + Map orignHashMap = new HashMap<>(); + + orignHashMap.put("칼숨", recentlyHealthLog.getCalcium()); + orignHashMap.put("나트륨", recentlyHealthLog.getSodium()); + orignHashMap.put("철분", recentlyHealthLog.getFe()); + orignHashMap.put("아연", recentlyHealthLog.getZinc()); + + + Float carbohydrate = recentlyHealthLog.getCarbohydrate(); // 탄수화물 + Float protein = recentlyHealthLog.getProtein(); // 단백질 + Float fat = recentlyHealthLog.getFat();// 지방 + Float sugar = recentlyHealthLog.getSugar();// 설탕 + Float cholesterol = recentlyHealthLog.getCholesterol();// 콜레스테롤 + Float energy = recentlyHealthLog.getEnergy();// 열량 + + if(energy < 1000){ + energy += 1000; + } + + return GetPreviousDietInfoResponse.builder() + .carbohydrate(carbohydrate*2) + .protein(protein*2) + .fat(fat*2) + .sugar(sugar*2) + .cholesterol(cholesterol*2) + .energy(energy) + .build(); + } } \ No newline at end of file