From aef368f52df70c39dcaca38b46070a8f2138f162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?JunhyeokPark=28=EB=B0=95=EC=A4=80=ED=98=81=29?= Date: Wed, 31 Jul 2024 21:56:49 +0900 Subject: [PATCH] =?UTF-8?q?[COZY-102]=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=EC=A0=95=EB=B3=B4=20=EC=88=98=EC=A0=95=20/?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [COZY-102] feat: 사용자 상세정보 수정 / 조회 [COZY-102] feat: Controller 코드 추가 [COZY-102] feat: 수정, 조회 Service 코드 추가 [COZY-102] feat: toEntity를 업데이트 로직과 함께 사용 가능하게 변경하기 [COZY-102] feat: Request DTO 클래스 생성(Query) [COZY-102] feat: Response DTO 세부 클래스 생성(Command) [COZY-102] feat: TimeUtil 오탈자 수정 [COZY-102] feat: 불필요한 Import 제거 * [COZY-102] fix: 중괄호 수정 * [COZY-102] refactor: fixed update logic, common code --- .../domain/memberstat/MemberStat.java | 30 +++++++ .../controller/MemberStatController.java | 46 +++++++++- .../converter/MemberStatConverter.java | 89 +++++++++++++------ .../memberstat/dto/MemberStatRequestDTO.java | 6 +- .../memberstat/dto/MemberStatResponseDTO.java | 38 ++++++++ .../service/MemberStatCommandService.java | 36 ++++++-- .../service/MemberStatQueryService.java | 23 ++++- .../response/code/status/ErrorStatus.java | 2 +- .../global/utils/TimeUtil.java | 4 +- 9 files changed, 230 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/cozymate/cozymate_server/domain/memberstat/MemberStat.java b/src/main/java/com/cozymate/cozymate_server/domain/memberstat/MemberStat.java index d87f7812..ce092ad7 100644 --- a/src/main/java/com/cozymate/cozymate_server/domain/memberstat/MemberStat.java +++ b/src/main/java/com/cozymate/cozymate_server/domain/memberstat/MemberStat.java @@ -1,8 +1,10 @@ package com.cozymate.cozymate_server.domain.memberstat; import com.cozymate.cozymate_server.domain.member.Member; +import com.cozymate.cozymate_server.domain.memberstat.dto.MemberStatRequestDTO.MemberStatCommandRequestDTO; import com.cozymate.cozymate_server.domain.university.University; import com.cozymate.cozymate_server.global.utils.BaseTimeEntity; +import com.cozymate.cozymate_server.global.utils.TimeUtil; import io.hypersistence.utils.hibernate.type.json.JsonType; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -90,4 +92,32 @@ public class MemberStat extends BaseTimeEntity{ @Type(JsonType.class) @Column(columnDefinition = "json") private Map> options; + + public void update(Member member, University university, MemberStatCommandRequestDTO memberStatCommandRequestDTO) { + this.member = member; + this.university = university; + this.acceptance = memberStatCommandRequestDTO.getAcceptance(); + this.admissionYear = Integer.parseInt(memberStatCommandRequestDTO.getAdmissionYear()); + this.major = memberStatCommandRequestDTO.getMajor(); + this.numOfRoommate = memberStatCommandRequestDTO.getNumOfRoommate(); + this.wakeUpTime = TimeUtil.convertTime(memberStatCommandRequestDTO.getWakeUpMeridian(),memberStatCommandRequestDTO.getWakeUpTime()); + this.sleepingTime = TimeUtil.convertTime(memberStatCommandRequestDTO.getSleepingMeridian(),memberStatCommandRequestDTO.getSleepingTime()); + this.turnOffTime = TimeUtil.convertTime(memberStatCommandRequestDTO.getTurnOffMeridian(),memberStatCommandRequestDTO.getTurnOffTime()); + this.smoking = memberStatCommandRequestDTO.getSmokingState(); + this.sleepingHabit = memberStatCommandRequestDTO.getSleepingHabit(); + this.airConditioningIntensity = memberStatCommandRequestDTO.getAirConditioningIntensity(); + this.heatingIntensity = memberStatCommandRequestDTO.getHeatingIntensity(); + this.lifePattern = memberStatCommandRequestDTO.getLifePattern(); + this.intimacy = memberStatCommandRequestDTO.getIntimacy(); + this.canShare = memberStatCommandRequestDTO.getCanShare(); + this.isPlayGame = memberStatCommandRequestDTO.getIsPlayGame(); + this.isPhoneCall = memberStatCommandRequestDTO.getIsPhoneCall(); + this.studying = memberStatCommandRequestDTO.getStudying(); + this.cleanSensitivity = memberStatCommandRequestDTO.getCleanSensitivity(); + this.noiseSensitivity = memberStatCommandRequestDTO.getNoiseSensitivity(); + this.cleaningFrequency = memberStatCommandRequestDTO.getCleaningFrequency(); + this.personality = memberStatCommandRequestDTO.getPersonality(); + this.mbti = memberStatCommandRequestDTO.getMbti(); + this.options = memberStatCommandRequestDTO.getOptions(); + } } diff --git a/src/main/java/com/cozymate/cozymate_server/domain/memberstat/controller/MemberStatController.java b/src/main/java/com/cozymate/cozymate_server/domain/memberstat/controller/MemberStatController.java index f2ebbe84..24e44aec 100644 --- a/src/main/java/com/cozymate/cozymate_server/domain/memberstat/controller/MemberStatController.java +++ b/src/main/java/com/cozymate/cozymate_server/domain/memberstat/controller/MemberStatController.java @@ -1,16 +1,20 @@ package com.cozymate.cozymate_server.domain.memberstat.controller; +import com.cozymate.cozymate_server.domain.memberstat.converter.MemberStatConverter; import com.cozymate.cozymate_server.domain.memberstat.dto.MemberStatRequestDTO; +import com.cozymate.cozymate_server.domain.memberstat.dto.MemberStatResponseDTO.MemberStatQueryResponseDTO; import com.cozymate.cozymate_server.domain.memberstat.service.MemberStatCommandService; +import com.cozymate.cozymate_server.domain.memberstat.service.MemberStatQueryService; import com.cozymate.cozymate_server.global.response.ApiResponse; -import com.cozymate.cozymate_server.global.response.code.status.SuccessStatus; import io.swagger.v3.oas.annotations.Operation; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -22,6 +26,7 @@ public class MemberStatController { private final MemberStatCommandService memberStatCommandService; + private final MemberStatQueryService memberStatQueryService; /** * TODO: member는 추후 시큐리티 인증 객체에서 받아오는 것으로 변경 예정, path 변경 예정 사항("/memberId" -> "/") @@ -35,9 +40,44 @@ public class MemberStatController { ) @PostMapping("/{memberId}") public ResponseEntity> createMemberStat( - @PathVariable("memberId") Long memberId,@Valid @RequestBody MemberStatRequestDTO.MemberStatCreateRequestDTO memberStatCreateRequestDTO) { + @PathVariable("memberId") Long memberId,@Valid @RequestBody MemberStatRequestDTO.MemberStatCommandRequestDTO memberStatCommandRequestDTO) { return ResponseEntity.ok( - ApiResponse.onSuccess(memberStatCommandService.createMemberStat(memberId,memberStatCreateRequestDTO))); + ApiResponse.onSuccess(memberStatCommandService.createMemberStat(memberId,memberStatCommandRequestDTO))); + } + + /** + * TODO: member는 추후 시큐리티 인증 객체에서 받아오는 것으로 변경 예정, path 변경 예정 사항("/memberId" -> "/") + */ + @Operation( + summary = "[포비] 사용자 상세정보 수정", + description = "Path Variable로 memberId, body로 사용자 상세정보를 넣어 사용합니다.\n\n" + + "시간은 형식에 맞춰 meridian은 오전, 오후, time은 값을 주시면 됩니다.\n\n" + + "에어컨, 히터, 예민도들은 모두 정수로 주시면 됩니다.\n\n" + + "학번의 경우 09학번-> \"09\"로 주시면 됩니다." + ) + @PutMapping("/{memberId}") + public ResponseEntity> modifyMemberStat( + @PathVariable("memberId") Long memberId,@Valid @RequestBody MemberStatRequestDTO.MemberStatCommandRequestDTO memberStatCommandRequestDTO) { + return ResponseEntity.ok( + ApiResponse.onSuccess(memberStatCommandService.modifyMemberStat(memberId,memberStatCommandRequestDTO))); + } + + /** + * TODO: member는 추후 시큐리티 인증 객체에서 받아오는 것으로 변경 예정, path 변경 예정 사항("/memberId" -> "/") + */ + @Operation( + summary = "[포비] 사용자 상세정보 조회", + description = "Path Variable로 memberId를 넣어 사용합니다.\n\n" + + "시간 관련 처리를 유의해주세요." + ) + @GetMapping("/{memberId}") + public ResponseEntity> getMemberStat( + @PathVariable("memberId") Long memberId) { + MemberStatQueryResponseDTO memberStatQueryResponseDTO = MemberStatConverter.toDto(memberStatQueryService.getMemberStat(memberId)); + return ResponseEntity.ok( + ApiResponse.onSuccess( + memberStatQueryResponseDTO + )); } } diff --git a/src/main/java/com/cozymate/cozymate_server/domain/memberstat/converter/MemberStatConverter.java b/src/main/java/com/cozymate/cozymate_server/domain/memberstat/converter/MemberStatConverter.java index 340630e8..3af89dfa 100644 --- a/src/main/java/com/cozymate/cozymate_server/domain/memberstat/converter/MemberStatConverter.java +++ b/src/main/java/com/cozymate/cozymate_server/domain/memberstat/converter/MemberStatConverter.java @@ -1,42 +1,77 @@ package com.cozymate.cozymate_server.domain.memberstat.converter; import com.cozymate.cozymate_server.domain.member.Member; -import com.cozymate.cozymate_server.domain.memberstat.dto.MemberStatRequestDTO; import com.cozymate.cozymate_server.domain.memberstat.MemberStat; -import com.cozymate.cozymate_server.domain.memberstat.dto.MemberStatRequestDTO.MemberStatCreateRequestDTO; +import com.cozymate.cozymate_server.domain.memberstat.MemberStat.MemberStatBuilder; +import com.cozymate.cozymate_server.domain.memberstat.dto.MemberStatRequestDTO.MemberStatCommandRequestDTO; +import com.cozymate.cozymate_server.domain.memberstat.dto.MemberStatResponseDTO.MemberStatQueryResponseDTO; import com.cozymate.cozymate_server.domain.university.University; import com.cozymate.cozymate_server.global.utils.TimeUtil; public class MemberStatConverter { public static MemberStat toEntity( - Member member, University university, MemberStatCreateRequestDTO memberStatCreateRequestDTO) { - return MemberStat.builder() + Long memberStatId, Member member, University university, MemberStatCommandRequestDTO memberStatCommandRequestDTO) { + MemberStatBuilder builder = MemberStat.builder() .member(member) .university(university) - .admissionYear(Integer.parseInt(memberStatCreateRequestDTO.getAdmissionYear())) - .major(memberStatCreateRequestDTO.getMajor()) - .numOfRoommate(memberStatCreateRequestDTO.getNumOfRoommate()) - .acceptance(memberStatCreateRequestDTO.getAcceptance()) - .wakeUpTime(TimeUtil.convertTime(memberStatCreateRequestDTO.getWakeUpMeridian(), memberStatCreateRequestDTO.getWakeUpTime())) - .sleepingTime(TimeUtil.convertTime(memberStatCreateRequestDTO.getSleepingMeridian(), memberStatCreateRequestDTO.getSleepingTime())) - .turnOffTime(TimeUtil.convertTime(memberStatCreateRequestDTO.getTurnOffMeridian(), memberStatCreateRequestDTO.getTurnOffTime())) - .smoking(memberStatCreateRequestDTO.getSmokingState()) - .sleepingHabit(memberStatCreateRequestDTO.getSleepingHabit()) - .airConditioningIntensity(memberStatCreateRequestDTO.getAirConditioningIntensity()) - .heatingIntensity(memberStatCreateRequestDTO.getHeatingIntensity()) - .lifePattern(memberStatCreateRequestDTO.getLifePattern()) - .intimacy(memberStatCreateRequestDTO.getIntimacy()) - .canShare(memberStatCreateRequestDTO.getCanShare()) - .isPlayGame(memberStatCreateRequestDTO.getIsPlayGame()) - .isPhoneCall(memberStatCreateRequestDTO.getIsPhoneCall()) - .studying(memberStatCreateRequestDTO.getStudying()) - .cleanSensitivity(memberStatCreateRequestDTO.getCleanSensitivity()) - .noiseSensitivity(memberStatCreateRequestDTO.getNoiseSensitivity()) - .cleaningFrequency(memberStatCreateRequestDTO.getCleaningFrequency()) - .personality(memberStatCreateRequestDTO.getPersonality()) - .mbti(memberStatCreateRequestDTO.getMbti()) - .options(memberStatCreateRequestDTO.getOptions()) + .admissionYear(Integer.parseInt(memberStatCommandRequestDTO.getAdmissionYear())) + .major(memberStatCommandRequestDTO.getMajor()) + .numOfRoommate(memberStatCommandRequestDTO.getNumOfRoommate()) + .acceptance(memberStatCommandRequestDTO.getAcceptance()) + .wakeUpTime(TimeUtil.convertTime(memberStatCommandRequestDTO.getWakeUpMeridian(), memberStatCommandRequestDTO.getWakeUpTime())) + .sleepingTime(TimeUtil.convertTime(memberStatCommandRequestDTO.getSleepingMeridian(), memberStatCommandRequestDTO.getSleepingTime())) + .turnOffTime(TimeUtil.convertTime(memberStatCommandRequestDTO.getTurnOffMeridian(), memberStatCommandRequestDTO.getTurnOffTime())) + .smoking(memberStatCommandRequestDTO.getSmokingState()) + .sleepingHabit(memberStatCommandRequestDTO.getSleepingHabit()) + .airConditioningIntensity(memberStatCommandRequestDTO.getAirConditioningIntensity()) + .heatingIntensity(memberStatCommandRequestDTO.getHeatingIntensity()) + .lifePattern(memberStatCommandRequestDTO.getLifePattern()) + .intimacy(memberStatCommandRequestDTO.getIntimacy()) + .canShare(memberStatCommandRequestDTO.getCanShare()) + .isPlayGame(memberStatCommandRequestDTO.getIsPlayGame()) + .isPhoneCall(memberStatCommandRequestDTO.getIsPhoneCall()) + .studying(memberStatCommandRequestDTO.getStudying()) + .cleanSensitivity(memberStatCommandRequestDTO.getCleanSensitivity()) + .noiseSensitivity(memberStatCommandRequestDTO.getNoiseSensitivity()) + .cleaningFrequency(memberStatCommandRequestDTO.getCleaningFrequency()) + .personality(memberStatCommandRequestDTO.getPersonality()) + .mbti(memberStatCommandRequestDTO.getMbti()) + .options(memberStatCommandRequestDTO.getOptions()); + + if (memberStatId != null) { + builder.id(memberStatId); + } + + return builder.build(); + } + + public static MemberStatQueryResponseDTO toDto(MemberStat memberStat){ + return MemberStatQueryResponseDTO.builder() + .universityId(memberStat.getUniversity().getId()) + .admissionYear(memberStat.getAdmissionYear()) + .major(memberStat.getMajor()) + .numOfRoommate(memberStat.getNumOfRoommate()) + .acceptance(memberStat.getAcceptance()) + .wakeUpTime(memberStat.getWakeUpTime()) + .sleepingTime(memberStat.getSleepingTime()) + .turnOffTime(memberStat.getTurnOffTime()) + .smokingState(memberStat.getSmoking()) + .sleepingHabit(memberStat.getSleepingHabit()) + .airConditioningIntensity(memberStat.getAirConditioningIntensity()) + .heatingIntensity(memberStat.getHeatingIntensity()) + .lifePattern(memberStat.getLifePattern()) + .intimacy(memberStat.getIntimacy()) + .canShare(memberStat.getCanShare()) + .isPlayGame(memberStat.getIsPlayGame()) + .isPhoneCall(memberStat.getIsPhoneCall()) + .studying(memberStat.getStudying()) + .cleanSensitivity(memberStat.getCleanSensitivity()) + .noiseSensitivity(memberStat.getNoiseSensitivity()) + .cleaningFrequency(memberStat.getCleaningFrequency()) + .personality(memberStat.getPersonality()) + .mbti(memberStat.getMbti()) + .options(memberStat.getOptions()) .build(); } } diff --git a/src/main/java/com/cozymate/cozymate_server/domain/memberstat/dto/MemberStatRequestDTO.java b/src/main/java/com/cozymate/cozymate_server/domain/memberstat/dto/MemberStatRequestDTO.java index 42cf00f1..6bfcd3f3 100644 --- a/src/main/java/com/cozymate/cozymate_server/domain/memberstat/dto/MemberStatRequestDTO.java +++ b/src/main/java/com/cozymate/cozymate_server/domain/memberstat/dto/MemberStatRequestDTO.java @@ -13,10 +13,12 @@ public class MemberStatRequestDTO { + + // Create, Update를 Command DTO로 관리하기 @Data @NoArgsConstructor @AllArgsConstructor - public static class MemberStatCreateRequestDTO { + public static class MemberStatCommandRequestDTO { @NotNull private Long universityId; //학번의 경우 처리하기 애매한 부분이 있어, String 2자리로 통일함. EX) 09 학번 -> "09" @@ -90,6 +92,4 @@ public static class MemberStatCreateRequestDTO { private String mbti; private Map> options; } - - } diff --git a/src/main/java/com/cozymate/cozymate_server/domain/memberstat/dto/MemberStatResponseDTO.java b/src/main/java/com/cozymate/cozymate_server/domain/memberstat/dto/MemberStatResponseDTO.java index ceb29aa5..d0694944 100644 --- a/src/main/java/com/cozymate/cozymate_server/domain/memberstat/dto/MemberStatResponseDTO.java +++ b/src/main/java/com/cozymate/cozymate_server/domain/memberstat/dto/MemberStatResponseDTO.java @@ -1,5 +1,43 @@ package com.cozymate.cozymate_server.domain.memberstat.dto; +import java.util.List; +import java.util.Map; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + public class MemberStatResponseDTO { + // Read를 Query DTO로 관리하기 + @Data + @NoArgsConstructor + @AllArgsConstructor + @Builder + public static class MemberStatQueryResponseDTO { + private Long universityId; + private Integer admissionYear; + private String major; + private Integer numOfRoommate; + private String acceptance; + private Integer wakeUpTime; + private Integer sleepingTime; + private Integer turnOffTime; + private String smokingState; + private String sleepingHabit; + private Integer airConditioningIntensity; + private Integer heatingIntensity; + private String lifePattern; + private String intimacy; + private Boolean canShare; + private Boolean isPlayGame; + private Boolean isPhoneCall; + private String studying; + private Integer cleanSensitivity; + private Integer noiseSensitivity; + private String cleaningFrequency; + private String personality; + private String mbti; + private Map> options; + } } diff --git a/src/main/java/com/cozymate/cozymate_server/domain/memberstat/service/MemberStatCommandService.java b/src/main/java/com/cozymate/cozymate_server/domain/memberstat/service/MemberStatCommandService.java index 52904389..93cf489f 100644 --- a/src/main/java/com/cozymate/cozymate_server/domain/memberstat/service/MemberStatCommandService.java +++ b/src/main/java/com/cozymate/cozymate_server/domain/memberstat/service/MemberStatCommandService.java @@ -4,13 +4,13 @@ import com.cozymate.cozymate_server.domain.member.MemberRepository; import com.cozymate.cozymate_server.domain.memberstat.converter.MemberStatConverter; import com.cozymate.cozymate_server.domain.memberstat.MemberStat; -import com.cozymate.cozymate_server.domain.memberstat.dto.MemberStatRequestDTO.MemberStatCreateRequestDTO; +import com.cozymate.cozymate_server.domain.memberstat.dto.MemberStatRequestDTO.MemberStatCommandRequestDTO; import com.cozymate.cozymate_server.domain.memberstat.repository.MemberStatRepository; -import com.cozymate.cozymate_server.domain.memberstat.dto.MemberStatRequestDTO; import com.cozymate.cozymate_server.domain.university.University; import com.cozymate.cozymate_server.domain.university.UniversityRepository; import com.cozymate.cozymate_server.global.response.code.status.ErrorStatus; import com.cozymate.cozymate_server.global.response.exception.GeneralException; +import java.util.Optional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -26,24 +26,46 @@ public class MemberStatCommandService { private final MemberRepository memberRepository; private final UniversityRepository universityRepository; - public Long createMemberStat(Long memberId, MemberStatCreateRequestDTO memberStatCreateRequestDTO) { + public Long createMemberStat( + Long memberId, MemberStatCommandRequestDTO memberStatCommandRequestDTO) { + // 멤버 상세정보가 이미 존재하는 경우 if (memberStatRepository.findByMemberId(memberId).isPresent()) { throw new GeneralException(ErrorStatus._MEMBERSTAT_EXISTS); } Member member = memberRepository.findById(memberId) - .orElseThrow(()->new GeneralException(ErrorStatus._MEMBER_NOT_FOUND)); - University university = universityRepository.findById(memberStatCreateRequestDTO.getUniversityId()) - .orElseThrow(()->new GeneralException(ErrorStatus._UNIVERSITY_NOT_FOUND)); + .orElseThrow(() -> new GeneralException(ErrorStatus._MEMBER_NOT_FOUND)); + University university = universityRepository.findById( + memberStatCommandRequestDTO.getUniversityId()) + .orElseThrow(() -> new GeneralException(ErrorStatus._UNIVERSITY_NOT_FOUND)); MemberStat saveMemberStat = memberStatRepository.save( MemberStatConverter.toEntity( - member, university, memberStatCreateRequestDTO + null, member, university, memberStatCommandRequestDTO ) ); return saveMemberStat.getId(); } + public Long modifyMemberStat( + + Long memberId, MemberStatCommandRequestDTO memberStatCommandRequestDTO) { + + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new GeneralException(ErrorStatus._MEMBER_NOT_FOUND)); + + University university = universityRepository.findById( + memberStatCommandRequestDTO.getUniversityId()) + .orElseThrow(() -> new GeneralException(ErrorStatus._UNIVERSITY_NOT_FOUND)); + + MemberStat updatedMemberStat = memberStatRepository.findByMemberId(memberId).orElseThrow( + () -> new GeneralException(ErrorStatus._MEMBERSTAT_NOT_EXISTS) + ); + + updatedMemberStat.update(member,university,memberStatCommandRequestDTO); + return updatedMemberStat.getId(); + + } } diff --git a/src/main/java/com/cozymate/cozymate_server/domain/memberstat/service/MemberStatQueryService.java b/src/main/java/com/cozymate/cozymate_server/domain/memberstat/service/MemberStatQueryService.java index b48be090..8f6e9223 100644 --- a/src/main/java/com/cozymate/cozymate_server/domain/memberstat/service/MemberStatQueryService.java +++ b/src/main/java/com/cozymate/cozymate_server/domain/memberstat/service/MemberStatQueryService.java @@ -1,6 +1,12 @@ package com.cozymate.cozymate_server.domain.memberstat.service; -import jakarta.persistence.criteria.CriteriaBuilder.In; +import com.cozymate.cozymate_server.domain.member.Member; +import com.cozymate.cozymate_server.domain.member.MemberRepository; +import com.cozymate.cozymate_server.domain.memberstat.MemberStat; +import com.cozymate.cozymate_server.domain.memberstat.repository.MemberStatRepository; +import com.cozymate.cozymate_server.global.response.code.status.ErrorStatus; +import com.cozymate.cozymate_server.global.response.exception.GeneralException; +import java.util.Optional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -12,4 +18,19 @@ @Transactional(readOnly = true) @Service public class MemberStatQueryService { + + private final MemberRepository memberRepository; + private final MemberStatRepository memberStatRepository; + + public MemberStat getMemberStat(Long memberId){ + + memberRepository.findById(memberId).orElseThrow( + ()-> new GeneralException(ErrorStatus._MEMBER_NOT_FOUND) + ); + + return memberStatRepository.findByMemberId(memberId) + .orElseThrow( + () -> new GeneralException(ErrorStatus._MEMBERSTAT_NOT_EXISTS) + ); + } } diff --git a/src/main/java/com/cozymate/cozymate_server/global/response/code/status/ErrorStatus.java b/src/main/java/com/cozymate/cozymate_server/global/response/code/status/ErrorStatus.java index 1d10d1be..46b85955 100644 --- a/src/main/java/com/cozymate/cozymate_server/global/response/code/status/ErrorStatus.java +++ b/src/main/java/com/cozymate/cozymate_server/global/response/code/status/ErrorStatus.java @@ -34,6 +34,7 @@ public enum ErrorStatus implements BaseErrorCode { // MemberStat 관련 에러 _MEMBERSTAT_EXISTS(HttpStatus.BAD_REQUEST,"MEMBERSTAT400","멤버 상세정보가 이미 존재합니다."), _MEMBERSTAT_MERIDIAN_NOT_VALID(HttpStatus.BAD_REQUEST,"MEMBERSTAT401","오전, 오후를 정확하게 입력하세요."), + _MEMBERSTAT_NOT_EXISTS(HttpStatus.BAD_REQUEST, "MEMBERSTAT402", "멤버 상세정보가 존재하지 않습니다."), // ChatRoom 관련 애러 _CHATROOM_NOT_FOUND(HttpStatus.BAD_REQUEST, "CHATROOM400", "쪽지방을 찾을 수 없습니다."), @@ -41,7 +42,6 @@ public enum ErrorStatus implements BaseErrorCode { // Mate 관련 _MATE_NOT_FOUND(HttpStatus.BAD_REQUEST, "MATE400", "해당하는 메이트 정보가 없습니다."), - ; diff --git a/src/main/java/com/cozymate/cozymate_server/global/utils/TimeUtil.java b/src/main/java/com/cozymate/cozymate_server/global/utils/TimeUtil.java index 0f908dac..233c31c6 100644 --- a/src/main/java/com/cozymate/cozymate_server/global/utils/TimeUtil.java +++ b/src/main/java/com/cozymate/cozymate_server/global/utils/TimeUtil.java @@ -9,8 +9,8 @@ public class TimeUtil { private static final String AFTERNOON = "오후"; private static final Integer HALFDAY = 12; - public static Integer convertTime(String median, Integer time){ - switch (median){ + public static Integer convertTime(String meridian, Integer time){ + switch (meridian){ case MORNING: if (!time.equals(HALFDAY)){ return time;