Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert: #66 #67

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,4 @@ public ResponseEntity<List<AssignmentResult>> createAssignments(

return ResponseEntity.created(location).body(assignmentResults);
}

@GetMapping("/my")
public ResponseEntity<List<StudyResponse>> myStudies(
@LoginUser AppUserDetails userDetails
) {

return ResponseEntity.ok(studyService.getMyStudies(userDetails.getId()).stream().map(
StudyResponse::fromResult
).toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,5 @@ public void startVoting(Long userId, Long studyId) {
studyRepository.save(study);
}

public List<StudyResult> getMyStudies(Long userId) {
List<Study> studies = studyRepository.findAllByLeader(userId);
return studies.stream().map(StudyResult::fromEntity).toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import static com.bombombom.devs.study.model.Study.MAX_DIFFICULTY_LEVEL;
import static com.bombombom.devs.study.model.Study.MIN_DIFFICULTY_LEVEL;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
Expand Down Expand Up @@ -199,70 +198,6 @@ public void init() {
bookRepository.save(testBook);
}


@Test
@DisplayName("자신이 개설한 스터디 목록을 조회할 수 있다.")
@WithUserDetails(value = "testuser",
setupBefore = TestExecutionEvent.TEST_EXECUTION)
void can_get_my_studies() throws Exception {
/*
* Given
*/
LocalDate roundStartDate = LocalDate.of(2024, 7, 22);
Study study = BookStudy.builder()
.name("스터디")
.introduce("안녕하세요")
.headCount(1)
.capacity(5)
.penalty(10000)
.reliabilityLimit(0)
.startDate(roundStartDate)
.weeks(2)
.leader(testuser)
.book(testBook)
.votingProcess(VotingProcess.READY)
.state(StudyStatus.RUNNING)
.duplicated(false)
.build();
studyRepository.save(study);

Study study2 = BookStudy.builder()
.name("스터디")
.introduce("안녕하세요")
.headCount(1)
.capacity(5)
.penalty(10000)
.reliabilityLimit(0)
.startDate(roundStartDate)
.weeks(2)
.leader(testuser)
.book(testBook)
.votingProcess(VotingProcess.READY)
.state(StudyStatus.RUNNING)
.duplicated(false)
.build();
studyRepository.save(study2);
/*
* When
*/
ResultActions resultActions = mockMvc.perform(
get("/api/v1/studies/my")
);

/*
* Then
*/

resultActions.andDo(print())
.andExpect(status().isOk())
.andExpect(
jsonPath("$.length()")
.value(equalTo(2)))
.andExpect(
jsonPath("$[*].id",
containsInAnyOrder(study.getId().intValue(), study2.getId().intValue())));
}

@Nested
@DisplayName("투표 통합 테스트")
class VoteTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.bombombom.devs.study.model.Study;
import jakarta.persistence.LockModeType;
import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -12,14 +11,6 @@

public interface StudyRepository extends JpaRepository<Study, Long> {


@Query(value = "SELECT s FROM Study s "
+ "LEFT JOIN FETCH s.leader "
+ "LEFT JOIN FETCH TREAT(s as AlgorithmStudy).difficulties "
+ "LEFT JOIN FETCH TREAT(s as BookStudy).book "
+ "WHERE s.leader.id = :id")
List<Study> findAllByLeader(Long id);

@Query("select s from Study s "
+ "join fetch s.leader "
+ "where s.id = :id")
Expand Down