Skip to content

Commit

Permalink
Merge pull request #71 from AI-SIP/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
KiSeungMin authored Nov 6, 2024
2 parents 45b2b78 + 0d0a3ed commit dfeeb00
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public PasswordEncoder passwordEncoder() {

@Bean
public AuthenticationEntryPoint authenticationEntryPoint() {
return (request, response, authException) -> response.sendRedirect("/home");
return (request, response, authException) -> response.sendRedirect("https://ono-app.com/home");
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
@AllArgsConstructor
public class ProblemPracticeRegisterDto {

private Long practiceCount;
private Long practiceId;

private String practiceTitle;

private List<Long> registerProblemIds;

private List<Long> removeProblemIds;
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,14 @@ public ResponseEntity<?> addPracticeCount(
}
}

@PatchMapping("/{practiceId}")
@PatchMapping("")
public ResponseEntity<?> updatePractice(
Authentication authentication,
@PathVariable("practiceId") Long practiceId,
@RequestBody ProblemPracticeRegisterDto problemPracticeRegisterDto
) {
try {
Long userId = (Long) authentication.getPrincipal();
boolean isUpdated = problemPracticeService.updatePractice(userId, problemPracticeRegisterDto);
boolean isUpdated = problemPracticeService.updatePractice(problemPracticeRegisterDto);

if(isUpdated){
log.info("userId: " + userId + " register problem practice");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface ProblemPracticeService {

boolean addPracticeCount(Long practiceId);

boolean updatePractice(Long practiceId, ProblemPracticeRegisterDto problemPracticeRegisterDto);
boolean updatePractice(ProblemPracticeRegisterDto problemPracticeRegisterDto);

void deletePractice(Long practiceId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.aisip.OnO.backend.entity.User.User;
import com.aisip.OnO.backend.exception.ProblemNotFoundException;
import com.aisip.OnO.backend.exception.ProblemPracticeNotFoundException;
import com.aisip.OnO.backend.exception.UserNotAuthorizedException;
import com.aisip.OnO.backend.exception.UserNotFoundException;
import com.aisip.OnO.backend.repository.ProblemPracticeRepository;
import com.aisip.OnO.backend.repository.ProblemRepository;
Expand Down Expand Up @@ -130,34 +131,37 @@ public boolean addPracticeCount(Long practiceId) {
}

@Override
public boolean updatePractice(Long practiceId, ProblemPracticeRegisterDto problemPracticeRegisterDto) {
public boolean updatePractice(ProblemPracticeRegisterDto problemPracticeRegisterDto){
Long practiceId = problemPracticeRegisterDto.getPracticeId();

ProblemPractice practice = problemPracticeRepository.findById(practiceId)
.orElseThrow(() -> new ProblemPracticeNotFoundException("Invalid practice practiceId: " + practiceId));

if(problemPracticeRegisterDto.getPracticeTitle() != null){
// 제목 업데이트
if (problemPracticeRegisterDto.getPracticeTitle() != null) {
practice.setTitle(problemPracticeRegisterDto.getPracticeTitle());
}

if(problemPracticeRegisterDto.getPracticeCount() != null && problemPracticeRegisterDto.getPracticeCount() > practice.getPracticeCount()){
practice.setPracticeCount(problemPracticeRegisterDto.getPracticeCount());
}
// 문제 ID 목록 업데이트
List<Long> newProblemIds = problemPracticeRegisterDto.getRegisterProblemIds();
List<Long> existingProblemIds = practice.getProblems().stream()
.map(Problem::getId).toList();

if(problemPracticeRegisterDto.getRegisterProblemIds() != null){
List<Long> registerProblemIds = problemPracticeRegisterDto.getRegisterProblemIds();
// 새로 추가할 문제: newProblemIds에만 포함된 문제 ID
List<Long> problemsToAdd = newProblemIds.stream()
.filter(problemId -> !existingProblemIds.contains(problemId)).toList();

registerProblemIds.forEach(problemId -> {
addProblemToPractice(practiceId, problemId);
});
}
// 삭제할 문제: 기존 문제 목록에만 포함된 문제 ID
List<Long> problemsToRemove = existingProblemIds.stream()
.filter(problemId -> !newProblemIds.contains(problemId)).toList();

if(problemPracticeRegisterDto.getRemoveProblemIds() != null){
List<Long> removeProblemIds = problemPracticeRegisterDto.getRemoveProblemIds();
// 문제 추가
problemsToAdd.forEach(problemId -> addProblemToPractice(practiceId, problemId));

removeProblemIds.forEach(problemId -> {
removeProblemFromPractice(practiceId, problemId);
});
}
// 문제 삭제
problemsToRemove.forEach(problemId -> removeProblemFromPractice(practiceId, problemId));

// 연습 문제 저장
problemPracticeRepository.save(practice);
return true;
}
Expand Down Expand Up @@ -192,7 +196,7 @@ public void removeProblemFromPractice(Long practiceId, Long problemId) {
.map(Problem::getId)
.collect(Collectors.toSet());

if(!existingProblemIds.contains(problem.getId())){
if(existingProblemIds.contains(problem.getId())){
practice.getProblems().remove(problem);
}

Expand Down

0 comments on commit dfeeb00

Please sign in to comment.