Skip to content

Commit

Permalink
Merge pull request #67 from Team-BomBomBom/revert-66-feat/my_studies#…
Browse files Browse the repository at this point in the history
…BBB-145

Revert: #66
  • Loading branch information
msjang4 authored Oct 10, 2024
2 parents 341d355 + c4d5625 commit 049c23d
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 89 deletions.
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

0 comments on commit 049c23d

Please sign in to comment.