Skip to content

Commit

Permalink
[feat] 운동 루틴 완료 api 완성
Browse files Browse the repository at this point in the history
  • Loading branch information
ryulkim committed Nov 25, 2023
1 parent 3fb9ffd commit 1aad251
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/inha/how/Config/BaseResponseStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public enum BaseResponseStatus {

CALENDAR_NOT_FOUND(false, 2012, "해당하는 달력을 찾을 수 없습니다."),

MY_ROUTINE_NOT_FOUND(false, 2012, "해당하는 내 루틴을 찾을 수 없습니다."),

// [POST] /users
POST_USERS_EMPTY_EMAIL(false, 2015, "이메일을 입력해주세요."),
POST_USERS_INVALID_EMAIL(false, 2016, "이메일 형식을 확인해주세요."),
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/inha/how/Controller/RoutineController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -68,4 +69,14 @@ public BaseResponse RoutineMeSave(@RequestHeader("Authorization") String jws, @R

return new BaseResponse();
}

@Operation(summary = "내 운동 루틴 실행 완료", description = "운동 루틴을 실행을 완료할 때 사용하는 api다. 운동 횟수가 올라간다.")
@Parameter(name = "id", description = "나의 운동 루틴 id")
@GetMapping("/{id}/me")
public BaseResponse RoutineMeComplete(@RequestHeader("Authorization") String jws, @PathVariable(name = "id") Long id){
User user = userService.validUser(jws);
routineService.CompleteRoutine(id);

return new BaseResponse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

public interface RoutineMeDetailMapping {

Long getId();
Long getRoutineId();
String getRoutineSubject();
Integer getCount();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/inha/how/Domain/entity/MyRoutine.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ public class MyRoutine extends BaseTimeEntity{
private Routine routine;
private Integer count;

public void increaseCnt(){
this.count++;
}
}
8 changes: 8 additions & 0 deletions src/main/java/inha/how/Service/RoutineService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package inha.how.Service;

import inha.how.Config.exception.BaseException;
import inha.how.Domain.dto.Excercise.CateInfoMapping;
import inha.how.Domain.dto.Excercise.ImgUrlMapping;
import inha.how.Domain.dto.routine.*;
Expand All @@ -21,6 +22,8 @@
import java.util.List;
import java.util.Set;

import static inha.how.Config.BaseResponseStatus.MY_ROUTINE_NOT_FOUND;

@Slf4j
@RequiredArgsConstructor
@Service
Expand Down Expand Up @@ -150,4 +153,9 @@ public void increaseHits(Long id){
routine.addHits();
}

@Transactional
public void CompleteRoutine(Long id){
MyRoutine myRoutine= myRoutineReposiotry.findById(id).orElseThrow(()-> new BaseException(MY_ROUTINE_NOT_FOUND));
myRoutine.increaseCnt();
}
}

0 comments on commit 1aad251

Please sign in to comment.