Skip to content

Commit

Permalink
Merge pull request #13 from Kusitms-Hackathon-B/jaehyeon
Browse files Browse the repository at this point in the history
Feat: 로그인 회원가입 시 request type 을 body 로 수정
  • Loading branch information
versatile0010 authored Oct 7, 2023
2 parents 23ffab7 + 6e711a5 commit 68dddf4
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -31,15 +34,24 @@ public ResponseEntity<MainPageResponse> getMainPage(@PathVariable(name = "userId
return ResponseEntity.ok(response);
}


@Operation(summary = "가장 최근에 섭취한 식단에서, 탄당지, 콜레스테롤, 당류, 총열량 제공", description =
"""
탄수화물, 당류, 지방, 콜레스테롤, 당류, 총열량을 제공합니다.
""")
@GetMapping("/{userId}/detail")
public ResponseEntity<GetPreviousDietInfoResponse> 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<MemberAuthResponseDto> signUp(@RequestParam String email,
@RequestParam String nickName,
@RequestParam int age,
@RequestParam String fcmToken) {
MemberAuthResponseDto responseDto = memberService.signUp(email, nickName, age, fcmToken);
public ResponseEntity<MemberAuthResponseDto> signUp(@RequestBody SignUpRequest request) {
MemberAuthResponseDto responseDto = memberService.signUp(request);
return ResponseEntity.ok(responseDto);
}

Expand All @@ -49,10 +61,10 @@ public ResponseEntity<MemberAuthResponseDto> signUp(@RequestParam String email,
""")
@GetMapping("/signIn")
public ResponseEntity<MemberAuthResponseDto> 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);
}


}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;// 열량
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<HealthLog> 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<String, Float> 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();
}
}

0 comments on commit 68dddf4

Please sign in to comment.