Skip to content

Commit

Permalink
Feat : 개별 개념 학습 조회 추가 (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaen-ing committed Jan 23, 2025
1 parent 3c7d3b4 commit e75ebac
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.ripple.BE.learning.controller;

import com.ripple.BE.global.dto.response.ApiResponse;
import com.ripple.BE.learning.dto.ConceptDTO;
import com.ripple.BE.learning.dto.ConceptListDTO;
import com.ripple.BE.learning.dto.response.ConceptDetailResponse;
import com.ripple.BE.learning.dto.response.ConceptListResponse;
import com.ripple.BE.learning.service.concept.ConceptService;
import com.ripple.BE.user.domain.CustomUserDetails;
Expand Down Expand Up @@ -59,4 +61,15 @@ public ResponseEntity<ApiResponse<?>> scrapConcept(
conceptService.scrapConcept(currentUser.getId(), conceptId);
return ResponseEntity.status(HttpStatus.OK).body(ApiResponse.EMPTY_RESPONSE);
}

@Operation(summary = "개별 개념 학습 조회", description = "개별 개념 학습을 조회합니다.")
@GetMapping("/learning/{conceptId}")
public ResponseEntity<ApiResponse<Object>> getConcept(
final @PathVariable("conceptId") long conceptId) {

ConceptDTO concept = conceptService.getConcept(conceptId);

return ResponseEntity.status(HttpStatus.OK)
.body(ApiResponse.from(ConceptDetailResponse.toConceptDetailResponse(concept)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ripple.BE.learning.dto.response;

import com.ripple.BE.learning.dto.ConceptDTO;

public record ConceptDetailResponse(
long id, String name, String explanation, String level, String learningSetName) {
public static ConceptDetailResponse toConceptDetailResponse(ConceptDTO conceptDTO) {
return new ConceptDetailResponse(
conceptDTO.conceptId(),
conceptDTO.name(),
conceptDTO.explanation(),
conceptDTO.level().name(),
conceptDTO.learningSetName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.ripple.BE.learning.domain.concept.ConceptScrap;
import com.ripple.BE.learning.domain.learningset.LearningSet;
import com.ripple.BE.learning.domain.learningset.UserLearningSet;
import com.ripple.BE.learning.dto.ConceptDTO;
import com.ripple.BE.learning.dto.ConceptListDTO;
import com.ripple.BE.learning.exception.LearningException;
import com.ripple.BE.learning.exception.errorcode.LearningErrorCode;
Expand All @@ -23,6 +24,7 @@
@RequiredArgsConstructor
@Service
@Slf4j
@Transactional(readOnly = true)
public class ConceptService {

private final LearningSetService learningSetService;
Expand Down Expand Up @@ -91,4 +93,19 @@ public void scrapConcept(final long userId, final long conceptId) {

conceptScrapRepository.save(ConceptScrap.builder().user(user).concept(concept).build());
}

/**
* 개별 개념 조회
*
* @param conceptId
* @return 개념 반환
*/
public ConceptDTO getConcept(final long conceptId) {
Concept concept =
conceptRepository
.findById(conceptId)
.orElseThrow(() -> new LearningException(LearningErrorCode.CONCEPT_NOT_FOUND));

return ConceptDTO.toScrapConceptDTO(concept);
}
}

0 comments on commit e75ebac

Please sign in to comment.