Skip to content

Commit

Permalink
[FEAT] 액션플랜 별 리뷰 작성 API 개발
Browse files Browse the repository at this point in the history
  • Loading branch information
yeseul106 committed Jan 7, 2024
1 parent 59e0a80 commit ca2ed3b
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,46 @@ public class ActionPlanController {

private final ActionPlanService actionPlanService;

@PostMapping("seed/{seedId}/actionPlan")
@PostMapping("seed/{seedId}/actionplan")
@ResponseStatus(HttpStatus.CREATED)
@Operation(summary = "ActionPlanPost",description = "액션 플랜 생성 API입니다.")
public ApiResponse createActionPlan(@PathVariable("seedId")Long seedId, @Valid @RequestBody ActionPlanCreateRequestDto actionPlanCreateRequestDto) {
actionPlanService.createActionPlan(seedId, actionPlanCreateRequestDto);
return ApiResponse.success(SuccessStatus.POST_ACTIONPLAN_SUCCESS.getStatusCode(), SuccessStatus.POST_ACTIONPLAN_SUCCESS.getMessage());
}

@GetMapping("seed/{seedId}/actionPlan")
@GetMapping("seed/{seedId}/actionplan")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "ActionPlanGet", description = "씨앗 별 액션 플랜 조회 API입니다.")
public ApiResponse<ActionPlanGetResponseDto> getActionPlan(@PathVariable Long seedId) {
return ApiResponse.success(SuccessStatus.GET_SEED_ACTIONPLAN_SUCCESS, actionPlanService.getActionPlan(seedId));
}

@PatchMapping("actionPlan/{actionPlanId}")
@PatchMapping("actionplan/{actionPlanId}")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "ActionPlanPatch", description = "액션 플랜 내용을 수정하는 API입니다.")
public ApiResponse updateActionPlan(@PathVariable Long actionPlanId, @Valid @RequestBody ActionPlanUpdateRequestDto actionPlanUpdateRequestDto) {
actionPlanService.updateActionPlan(actionPlanId, actionPlanUpdateRequestDto);
return ApiResponse.success(SuccessStatus.PATCH_ACTIONPLAN_SUCCESS.getStatusCode(), SuccessStatus.PATCH_ACTIONPLAN_SUCCESS.getMessage());
}

@DeleteMapping("actionPlan/{actionPlanId}")
@DeleteMapping("actionplan/{actionPlanId}")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "ActionPlanDelete", description = "액션 플랜을 삭제하는 API입니다.")
public ApiResponse deleteActionPlan(@PathVariable Long actionPlanId) {
actionPlanService.deleteActionPlan(actionPlanId);
return ApiResponse.success(SuccessStatus.DELETE_ACTIONPLAN_SUCCESS.getStatusCode(), SuccessStatus.DELETE_ACTIONPLAN_SUCCESS.getMessage());
}

@PatchMapping("actionPlan/{actionPlanId}/completion")
@PatchMapping("actionplan/{actionPlanId}/completion")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "ActionPlanComplete", description = "액션 플랜을 완료하는 API입니다.")
public ApiResponse completeActionPlan(@PathVariable Long actionPlanId) {
actionPlanService.completeActionPlan(actionPlanId);
return ApiResponse.success(SuccessStatus.COMPLETE_ACTIONPLAN_SUCCESS.getStatusCode(),SuccessStatus.COMPLETE_ACTIONPLAN_SUCCESS.getMessage());
}

@GetMapping("member/{memberId}/actionPlan/percent")
@GetMapping("member/{memberId}/actionplan/percent")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "ActionPlanPercent", description = "완료한 액션 플랜 퍼센트를 구하는 API입니다.")
public ApiResponse<Integer> getActionPlanPercent(@PathVariable Long memberId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.example.growthookserver.api.review.controller;

import com.example.growthookserver.api.review.dto.request.ReviewCreateRequestDto;
import com.example.growthookserver.api.review.service.ReviewService;
import com.example.growthookserver.common.response.ApiResponse;
import com.example.growthookserver.common.response.SuccessStatus;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("api/v1")
@Tag(name = "Review - 리뷰 관련 API", description = "Review API Document")
public class ReviewController {

private final ReviewService reviewService;
@PostMapping("actionplan/{actionPlanId}/review")
@ResponseStatus(HttpStatus.CREATED)
@Operation(summary = "ReviewPost", description = "리뷰 생성 API입니다.")
public ApiResponse createReview(@PathVariable("actionPlanId") Long actionPlanId, @Valid @RequestBody ReviewCreateRequestDto reviewCreateRequestDto) {
reviewService.createReview(actionPlanId, reviewCreateRequestDto);
return ApiResponse.success(
SuccessStatus.POST_REVIEW_SUCCESS.getStatusCode(), SuccessStatus.POST_REVIEW_SUCCESS.getMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.growthookserver.api.review.dto.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class ReviewCreateRequestDto {
@NotBlank
@Size(max = 300)
private String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.growthookserver.api.review.repository;

import com.example.growthookserver.api.review.domain.Review;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ReviewRepository extends JpaRepository<Review, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.growthookserver.api.review.service;

import com.example.growthookserver.api.review.dto.request.ReviewCreateRequestDto;

public interface ReviewService{

//* 액션 플랜별 리뷰 작성
void createReview(Long actionPlanId, ReviewCreateRequestDto reviewCreateRequestDto);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.growthookserver.api.review.service;

import com.example.growthookserver.api.actionplan.domain.ActionPlan;
import com.example.growthookserver.api.actionplan.repository.ActionPlanRepository;
import com.example.growthookserver.api.review.domain.Review;
import com.example.growthookserver.api.review.dto.request.ReviewCreateRequestDto;
import com.example.growthookserver.api.review.repository.ReviewRepository;
import com.example.growthookserver.api.seed.domain.Seed;
import com.example.growthookserver.api.seed.repository.SeedRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class ReviewServiceImpl implements ReviewService {

private final ReviewRepository reviewRepository;
private final ActionPlanRepository actionPlanRepository;

@Override
@Transactional
public void createReview(Long actionPlanId, ReviewCreateRequestDto reviewCreateRequestDto) {
ActionPlan actionPlan = actionPlanRepository.findActionPlanByIdOrThrow(actionPlanId);
Review review = Review.builder()
.content(reviewCreateRequestDto.getContent())
.actionPlan(actionPlan)
.build();
reviewRepository.save(review);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public enum SuccessStatus {
GET_FINISHED_ACTIONPLAN_PERCENT(HttpStatus.OK, "완료한 액션 플랜 퍼센트 조회 성공"),
GET_DOING_ACTIONPLAN_SUCCESS(HttpStatus.OK, "진행 중인 액션 플랜 리스트 조회 성공"),
GET_FINISHED_ACTIONPLAN_SUCCESS(HttpStatus.OK,"완료한 액션 플랜 리스트 조회 성공"),

/**
* review
*/
POST_REVIEW_SUCCESS(HttpStatus.CREATED, "리뷰 생성 성공"),
;

private final HttpStatus httpStatus;
Expand Down

0 comments on commit ca2ed3b

Please sign in to comment.