-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
191 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/site/qbox/qboxserver/domain/lecturebookmark/query/LectureBookmarkDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package site.qbox.qboxserver.domain.lecturebookmark.query | ||
|
||
import com.querydsl.core.group.GroupBy.groupBy | ||
import com.querydsl.core.group.GroupBy.list | ||
import com.querydsl.jpa.impl.JPAQueryFactory | ||
import site.qbox.qboxserver.domain.lecture.command.entity.QLecture.lecture | ||
import site.qbox.qboxserver.domain.lecture.query.dto.QLectureRes | ||
import site.qbox.qboxserver.domain.lecturebookmark.command.entity.QLectureBookmark.lectureBookmark | ||
import site.qbox.qboxserver.domain.lecturebookmark.query.dto.LectureBookmarkRes | ||
import site.qbox.qboxserver.domain.lecturebookmark.query.dto.QLectureBookmarkRes | ||
import site.qbox.qboxserver.global.annotation.QueryService | ||
|
||
@QueryService | ||
class LectureBookmarkDao( | ||
private val queryFactory: JPAQueryFactory, | ||
) { | ||
fun findAllByMemberId(memberId: String): LectureBookmarkRes { | ||
return queryFactory.from(lectureBookmark) | ||
.where(lectureBookmark.id.memberId.eq(memberId)) | ||
.join(lecture).on(lectureBookmark.id.lectureId.eq(lecture.id)) | ||
.transform(groupBy(lectureBookmark.id.memberId).`as`( | ||
QLectureBookmarkRes( | ||
lectureBookmark.id.memberId, | ||
list( | ||
QLectureRes( | ||
lecture.name, | ||
lecture.id.code, | ||
lecture.id.departId) | ||
)) | ||
))[memberId] ?: LectureBookmarkRes(memberId, emptyList()) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...main/kotlin/site/qbox/qboxserver/domain/lecturebookmark/query/LectureBookmarkQueryCtrl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package site.qbox.qboxserver.domain.lecturebookmark.query | ||
|
||
import org.springframework.security.core.Authentication | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import site.qbox.qboxserver.domain.lecturebookmark.query.dto.LectureBookmarkRes | ||
|
||
@RestController | ||
@RequestMapping("lecture-bookmarks") | ||
class LectureBookmarkQueryCtrl ( | ||
private val lectureBookmarkDao: LectureBookmarkDao | ||
) { | ||
@GetMapping("me") | ||
fun getByMe(auth: Authentication) : LectureBookmarkRes = | ||
lectureBookmarkDao.findAllByMemberId(auth.name) | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/site/qbox/qboxserver/domain/lecturebookmark/query/dto/LectureBookmarkRes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package site.qbox.qboxserver.domain.lecturebookmark.query.dto | ||
|
||
import com.querydsl.core.annotations.QueryProjection | ||
import site.qbox.qboxserver.domain.lecture.query.dto.LectureRes | ||
|
||
data class LectureBookmarkRes @QueryProjection constructor ( | ||
val memberId: String, | ||
val lectures: List<LectureRes>, | ||
) |
1 change: 1 addition & 0 deletions
1
src/main/kotlin/site/qbox/qboxserver/domain/member/command/entity/Member.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/main/kotlin/site/qbox/qboxserver/domain/member/email/svc/EmailAuthenticationSvc.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/test/kotlin/site/qbox/qboxserver/domain/lecturebookmark/query/LectureBookmarkDaoTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package site.qbox.qboxserver.domain.lecturebookmark.query | ||
|
||
import io.kotest.core.spec.DisplayName | ||
import io.kotest.core.spec.style.DescribeSpec | ||
import io.kotest.extensions.spring.SpringExtension | ||
import io.kotest.matchers.shouldBe | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import site.qbox.qboxserver.domain.lecture.command.LectureRepo | ||
import site.qbox.qboxserver.domain.lecture.command.entity.Lecture | ||
import site.qbox.qboxserver.domain.lecture.command.entity.LectureId | ||
import site.qbox.qboxserver.domain.lecturebookmark.command.LectureBookmarkRepo | ||
import site.qbox.qboxserver.domain.lecturebookmark.command.entity.LectureBookmark | ||
|
||
@SpringBootTest | ||
@DisplayName("LectureBookmarkDao") | ||
class LectureBookmarkDaoTest : DescribeSpec() { | ||
|
||
override fun extensions() = listOf(SpringExtension) | ||
|
||
@Autowired | ||
lateinit var lectureBookmarkDao: LectureBookmarkDao | ||
|
||
@Autowired | ||
lateinit var lectureBookmarkRepo: LectureBookmarkRepo | ||
|
||
@Autowired | ||
lateinit var lectureRepo: LectureRepo | ||
|
||
init { | ||
beforeEach { | ||
val lectureIds = listOf( | ||
LectureId("111", 1), | ||
LectureId("222", 2), | ||
LectureId("333", 3), | ||
LectureId("444", 4), | ||
LectureId("555", 5), | ||
LectureId("666", 5), | ||
) | ||
lectureRepo.saveAll( | ||
listOf( | ||
Lecture(lectureIds[0], "디자인기초"), | ||
Lecture(lectureIds[1], "한국사기초"), | ||
Lecture(lectureIds[2], "수학기초"), | ||
Lecture(lectureIds[3], "영어기초"), | ||
Lecture(lectureIds[4], "서양사기초"), | ||
Lecture(lectureIds[5], "동양사기초"), | ||
), | ||
) | ||
|
||
lectureBookmarkRepo.saveAll( | ||
listOf( | ||
LectureBookmark("aaa", lectureIds[0]), | ||
LectureBookmark("aaa", lectureIds[1]), | ||
LectureBookmark("aaa", lectureIds[2]), | ||
LectureBookmark("aaa", lectureIds[3]), | ||
LectureBookmark("aaa", lectureIds[4]), | ||
LectureBookmark("bbb", lectureIds[4]), | ||
LectureBookmark("bbb", lectureIds[5]), | ||
LectureBookmark("ccc", lectureIds[5]), | ||
) | ||
) | ||
} | ||
|
||
it("memberId를 통한 북마크 목록 조회를 수행한다.") { | ||
val result = lectureBookmarkDao.findAllByMemberId("aaa") | ||
|
||
result.lectures.count() shouldBe 5 | ||
|
||
} | ||
|
||
it("북마크 등록을 안한 유저의 letcure list는 비어있다.") { | ||
val result = lectureBookmarkDao.findAllByMemberId("kkk") | ||
result.lectures shouldBe emptyList() | ||
} | ||
|
||
} | ||
|
||
|
||
} |
51 changes: 51 additions & 0 deletions
51
.../kotlin/site/qbox/qboxserver/domain/lecturebookmark/query/LectureBookmarkQueryCtrlTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package site.qbox.qboxserver.domain.lecturebookmark.query | ||
|
||
import com.ninjasquad.springmockk.MockkBean | ||
import io.kotest.core.spec.DisplayName | ||
import io.mockk.every | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest | ||
import org.springframework.restdocs.payload.JsonFieldType | ||
import org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath | ||
import org.springframework.restdocs.payload.PayloadDocumentation.responseFields | ||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status | ||
import site.qbox.qboxserver.config.WebClientDocsTest | ||
import site.qbox.qboxserver.domain.lecture.query.dto.LectureRes | ||
import site.qbox.qboxserver.domain.lecturebookmark.query.dto.LectureBookmarkRes | ||
|
||
@WebMvcTest(LectureBookmarkQueryCtrl::class) | ||
@DisplayName("LectureBookmarkQueryCtrl") | ||
class LectureBookmarkQueryCtrlTest : WebClientDocsTest() { | ||
@MockkBean | ||
lateinit var lectureBookmarkDao: LectureBookmarkDao | ||
|
||
init { | ||
|
||
it("로그인한 사람의 lecture bookmark를 조회한다.") { | ||
val res = LectureBookmarkRes( | ||
"[email protected]", listOf( | ||
LectureRes("소프트웨어공학", "aaaa", 4), | ||
LectureRes("디자인원리", "bbbb", 5), | ||
LectureRes("C언어기초", "cccc", 6), | ||
)) | ||
|
||
every { lectureBookmarkDao.findAllByMemberId(any(String::class)) } returns res | ||
|
||
val action = performGet("/lecture-bookmarks/me") | ||
|
||
action.andExpect(status().isOk) | ||
|
||
action.andDo( | ||
print( | ||
"find-all-lecture-bookmarks-by-me", | ||
responseFields( | ||
fieldWithPath("memberId").type(JsonFieldType.STRING).description("조회자 ID"), | ||
fieldWithPath("lectures.[].name").type(JsonFieldType.STRING).description("강의명"), | ||
fieldWithPath("lectures.[].code").type(JsonFieldType.STRING).description("강의코드"), | ||
fieldWithPath("lectures.[].departId").type(JsonFieldType.NUMBER).description("강의 소속 학과 ID"), | ||
) | ||
) | ||
) | ||
|
||
} | ||
} | ||
} |