Skip to content

Commit

Permalink
Refactor : 컨트롤러 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
chanmin-00 committed Dec 27, 2024
1 parent 56d9a86 commit 3b91dd4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.ripple.BE.learning.controller;

import com.ripple.BE.global.dto.response.ApiResponse;
import com.ripple.BE.learning.dto.ConceptListDTO;
import com.ripple.BE.learning.dto.response.ConceptListResponse;
import com.ripple.BE.learning.service.ConceptService;
import com.ripple.BE.user.domain.CustomUserDetails;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
@RequestMapping("/api/v1/learning")
@Tag(name = "Learning", description = "학습 API")
public class ConceptController {

private final ConceptService conceptService;

@Operation(summary = "개념 학습 세트 조회", description = "개념 학습 세트를 조회합니다.")
@GetMapping("/{learningSetId}/concepts")
public ResponseEntity<ApiResponse<Object>> getConcepts(
final @PathVariable("learningSetId") long learningSetId) {

ConceptListDTO conceptListDTO = conceptService.getConcepts(learningSetId);

return ResponseEntity.status(HttpStatus.OK)
.body(ApiResponse.from(ConceptListResponse.toConceptListResponse(conceptListDTO)));
}

@Operation(summary = "개념 학습 완료 처리", description = "개념 학습을 완료 처리합니다.")
@PostMapping("/{learningSetId}/concepts/complete")
public ResponseEntity<ApiResponse<?>> completeConcept(
final @AuthenticationPrincipal CustomUserDetails currentUser,
final @PathVariable("learningSetId") long learningSetId) {

conceptService.completeConceptLearning(currentUser.getId(), learningSetId);
return ResponseEntity.status(HttpStatus.OK).body(ApiResponse.EMPTY_RESPONSE);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.ripple.BE.learning.controller;

import com.ripple.BE.global.dto.response.ApiResponse;
import com.ripple.BE.learning.dto.ConceptListDTO;
import com.ripple.BE.learning.dto.LearningSetCompleteListDTO;
import com.ripple.BE.learning.dto.ProgressDTO;
import com.ripple.BE.learning.dto.request.LearningSetRequest;
import com.ripple.BE.learning.dto.response.ConceptListResponse;
import com.ripple.BE.learning.dto.response.LearningSetPreviewListResponse;
import com.ripple.BE.learning.dto.response.LearningSetProgressResponse;
import com.ripple.BE.learning.service.ConceptService;
import com.ripple.BE.learning.service.LearningAdminService;
import com.ripple.BE.learning.service.LearningSetService;
import com.ripple.BE.user.domain.CustomUserDetails;
Expand All @@ -20,7 +17,6 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -34,7 +30,6 @@ public class LearningController {

private final LearningSetService learningSetService;
private final LearningAdminService learningAdminService;
private final ConceptService conceptService;

@Operation(summary = "학습 세트 생성", description = "엑셀 파일로부터 학습 세트를 생성합니다.")
@PostMapping("/excel")
Expand Down Expand Up @@ -73,25 +68,4 @@ public ResponseEntity<ApiResponse<Object>> getLearningSetProgress(
ApiResponse.from(
LearningSetProgressResponse.toLearningSetProgressResponse(progressDTO)));
}

@Operation(summary = "개념 학습 세트 조회", description = "개념 학습 세트를 조회합니다.")
@GetMapping("/{learningSetId}/concepts")
public ResponseEntity<ApiResponse<Object>> getConcepts(
final @PathVariable("learningSetId") long learningSetId) {

ConceptListDTO conceptListDTO = conceptService.getConcepts(learningSetId);

return ResponseEntity.status(HttpStatus.OK)
.body(ApiResponse.from(ConceptListResponse.toConceptListResponse(conceptListDTO)));
}

@Operation(summary = "개념 학습 완료 처리", description = "개념 학습을 완료 처리합니다.")
@PostMapping("/{learningSetId}/concepts/complete")
public ResponseEntity<ApiResponse<?>> completeConcept(
final @AuthenticationPrincipal CustomUserDetails currentUser,
final @PathVariable("learningSetId") long learningSetId) {

conceptService.completeConceptLearning(currentUser.getId(), learningSetId);
return ResponseEntity.status(HttpStatus.OK).body(ApiResponse.EMPTY_RESPONSE);
}
}

0 comments on commit 3b91dd4

Please sign in to comment.