Skip to content

Commit

Permalink
feat : ProblemPractice 삭제 기능 구현 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
KiSeungMin committed Nov 4, 2024
1 parent 075965f commit a4c4bb7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ProblemPracticeController {
private final ProblemPracticeService problemPracticeService;

@GetMapping("/{practiceId}")
public ResponseEntity<?> getProblemPracticeDetail(
public ResponseEntity<?> getPracticeDetail(
Authentication authentication,
@PathVariable("practiceId") Long practiceId
) {
Expand All @@ -45,7 +45,7 @@ public ResponseEntity<?> getProblemPracticeDetail(
}

@GetMapping("/all")
public ResponseEntity<?> getAllProblemPracticeThumbnail(
public ResponseEntity<?> getAllPracticeThumbnail(
Authentication authentication
) {
try {
Expand All @@ -62,13 +62,13 @@ public ResponseEntity<?> getAllProblemPracticeThumbnail(
}

@PostMapping("")
public ResponseEntity<?> registerProblemPractice(
public ResponseEntity<?> registerPractice(
Authentication authentication,
@RequestBody ProblemPracticeRegisterDto problemPracticeRegisterDto
) {
try {
Long userId = (Long) authentication.getPrincipal();
boolean isSaved = problemPracticeService.createProblemPractice(userId, problemPracticeRegisterDto);
boolean isSaved = problemPracticeService.createPractice(userId, problemPracticeRegisterDto);

if(isSaved){
log.info("userId: " + userId + " register problem practice");
Expand Down Expand Up @@ -106,7 +106,7 @@ public ResponseEntity<?> addPracticeCount(
}

@PatchMapping("/{practiceId}")
public ResponseEntity<?> updateProblemPractice(
public ResponseEntity<?> updatePractice(
Authentication authentication,
@PathVariable("practiceId") Long practiceId,
@RequestBody ProblemPracticeRegisterDto problemPracticeRegisterDto
Expand All @@ -128,16 +128,16 @@ public ResponseEntity<?> updateProblemPractice(
}
}

@DeleteMapping("/{practiceId}")
public ResponseEntity<?> deleteProblemPractice(
@DeleteMapping("")
public ResponseEntity<?> deletePractices(
Authentication authentication,
@PathVariable("practiceId") Long practiceId
@RequestParam List<Long> deletePracticeIds
) {
try {
Long userId = (Long) authentication.getPrincipal();
problemPracticeService.deletePractice(practiceId);
problemPracticeService.deletePractices(deletePracticeIds);

log.info("userId: " + userId + " delete problem practice for practice id: " + practiceId);
log.info("userId: " + userId + " delete problem practice ids: " + deletePracticeIds.toString());
return ResponseEntity.ok("복습 리스트 삭제를 완료했습니다.");
} catch (Exception e) {
log.error(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public interface ProblemPracticeService {

boolean createProblemPractice(Long userId, ProblemPracticeRegisterDto problemPracticeRegisterDto);
boolean createPractice(Long userId, ProblemPracticeRegisterDto problemPracticeRegisterDto);

void addProblemToPractice(Long practiceId, Long problemId);

Expand All @@ -22,6 +22,8 @@ public interface ProblemPracticeService {

void deletePractice(Long practiceId);

void deletePractices(List<Long> practiceIds);

void removeProblemFromPractice(Long practiceId, Long problemId);

void deleteProblemFromAllPractice(Long problemId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ProblemPracticeServiceImpl implements ProblemPracticeService{
private final ProblemPracticeRepository problemPracticeRepository;

@Override
public boolean createProblemPractice(Long userId, ProblemPracticeRegisterDto problemPracticeRegisterDto) {
public boolean createPractice(Long userId, ProblemPracticeRegisterDto problemPracticeRegisterDto) {

Optional<User> optionalUserEntity = userRepository.findById(userId);
if(optionalUserEntity.isPresent()){
Expand Down Expand Up @@ -164,9 +164,22 @@ public boolean updatePractice(Long practiceId, ProblemPracticeRegisterDto proble

@Override
public void deletePractice(Long practiceId) {
ProblemPractice practice = problemPracticeRepository.findById(practiceId)
.orElseThrow(() -> new IllegalArgumentException("Invalid practice ID: " + practiceId));

// 연관 관계 제거
practice.getProblems().clear();
problemPracticeRepository.save(practice);

// 이제 ProblemPractice 엔티티 삭제
problemPracticeRepository.deleteById(practiceId);
}

@Override
public void deletePractices(List<Long> practiceIds) {
practiceIds.forEach(this::deletePractice);
}

@Override
public void removeProblemFromPractice(Long practiceId, Long problemId) {
ProblemPractice practice = problemPracticeRepository.findById(practiceId)
Expand Down

0 comments on commit a4c4bb7

Please sign in to comment.