Skip to content

Commit

Permalink
Merge pull request #76 from snack-exercise/feat/#75
Browse files Browse the repository at this point in the history
feat : 운동 목표 시간 수정 기능 추가
  • Loading branch information
ohjinseo authored Nov 4, 2023
2 parents 33b84f5 + 370ea8e commit fa75a06
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 5 deletions.
1 change: 1 addition & 0 deletions snackpot-api/src/main/java/com/soma/advice/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum ErrorCode {
/* Member */
MEMBER_NOT_FOUND_EXCEPTION(-1100, "사용자가 존재하지 않습니다."),
MEMBER_ALREADY_EXIST(-1101, "이미 해당 이름을 가진 사용자가 존재합니다."),
EXCEED_DAILY_EXERCISE_GOAL__EXCEPTION(-1102, "하루 운동 목표 시간이 24시간을 초과합니다."),

/* Group */
ALREADY_JOINED_GROUP_EXCEPTION(-1200, "이미 가입한 그룹입니다."),
Expand Down
10 changes: 9 additions & 1 deletion snackpot-api/src/main/java/com/soma/advice/ExceptionAdvice.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.soma.exception.exercise.ExerciseNotFoundException;
import com.soma.exception.group.AlreadyJoinedGroupException;
import com.soma.exception.group.GroupNotFoundException;
import com.soma.exception.member.ExceedDailyExerciseGoalException;
import com.soma.exception.member.FCMTokenNotFoundException;
import com.soma.exception.member.MemberNicknameAlreadyExistsException;
import com.soma.exception.member.MemberNotFoundException;
Expand All @@ -22,13 +23,20 @@
@RequiredArgsConstructor
@RestControllerAdvice
public class ExceptionAdvice {
/* Group */
/* Member */
@ExceptionHandler(MemberNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public Response memberNotFoundExceptionHandler(MemberNotFoundException e){
return Response.failure(MEMBER_NOT_FOUND_EXCEPTION);
}

@ExceptionHandler(ExceedDailyExerciseGoalException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public Response memberNotFoundExceptionHandler(ExceedDailyExerciseGoalException e){
return Response.failure(EXCEED_DAILY_EXERCISE_GOAL__EXCEPTION);
}

/* Group */
@ExceptionHandler(GroupNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public Response groupNotFoundExceptionHandler(GroupNotFoundException e){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.soma.domain.member.controller;

import com.soma.domain.member.dto.request.UpdateDailyGoalTimeRequest;
import com.soma.domain.member.service.MemberService;
import com.soma.util.response.Response;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -10,10 +11,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "Member", description = "멤버 API")
Expand All @@ -36,4 +34,12 @@ public Response readTotalNum() {
public Response readMyInfo(@AuthenticationPrincipal UserDetails loginUser) {
return Response.success(memberService.readMyInfo(loginUser.getUsername()));
}

@Operation(summary = "운동 목표 시간 수정", description = "운동 목표 시간을 수정합니다.", security = { @SecurityRequirement(name = "Authorization") })
@ResponseStatus(HttpStatus.OK)
@PatchMapping("/dailyGoalTime")
public Response updateDailyGoalTime(@RequestBody UpdateDailyGoalTimeRequest request, @AuthenticationPrincipal UserDetails loginUser) {
memberService.updateDailyGoalTime(request, loginUser.getUsername());
return Response.success();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.soma.domain.member.dto.request;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Getter
public class UpdateDailyGoalTimeRequest {
private Integer dailyGoalTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.soma.common.constant.Status;
import com.soma.domain.exercise_record.entity.ExerciseRecord;
import com.soma.domain.exercise_record.repository.ExerciseRecordRepository;
import com.soma.domain.member.dto.request.UpdateDailyGoalTimeRequest;
import com.soma.domain.member.dto.response.DailyGoalTime;
import com.soma.domain.member.dto.response.MemberMyInfoResponse;
import com.soma.domain.member.dto.response.MemberTotalNumResponse;
import com.soma.domain.member.entity.Member;
import com.soma.domain.member.repository.MemberRepository;
import com.soma.exception.member.ExceedDailyExerciseGoalException;
import com.soma.exception.member.MemberNotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -64,4 +66,17 @@ private LocalDateTime getEndLocalDateTimeOfWeek(){
int dayOfWeek = today.getDayOfWeek().getValue(); // 오늘 요일(숫자), 월(1), 일(7)
return today.plusDays(8-dayOfWeek).withHour(0).withMinute(0).withSecond(0).withNano(0);
}

@Transactional
public void updateDailyGoalTime(UpdateDailyGoalTimeRequest request, String email) {

Member member = memberRepository.findByEmailAndStatus(email, Status.ACTIVE).orElseThrow(MemberNotFoundException::new);

// 하루 운동 목표 시간이 24시간을 초과한다면
if (request.getDailyGoalTime() > 1440) {
throw new ExceedDailyExerciseGoalException();
}

member.updateDailyGoalTime(request.getDailyGoalTime());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.soma.exception.member;

public class ExceedDailyExerciseGoalException extends RuntimeException{
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public Member(String name, String email, Integer dailyGoalTime, String profileIm
active();
}

public void updateDailyGoalTime(Integer dailyGoalTime) {
this.dailyGoalTime = dailyGoalTime;
}

public void updateFcmToken(String fcmToken){
this.fcmToken = fcmToken;
}
Expand Down

0 comments on commit fa75a06

Please sign in to comment.