Skip to content

Commit

Permalink
Merge branch 'QB-41' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
phjppo0918 committed Jan 1, 2024
2 parents f404da7 + a3c90b9 commit 4c9a27f
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AnswerDao(
}

private fun mapToRes(
summary: MutableList<AnswerSummary>,
summary: List<AnswerSummary>,
comments: MutableMap<AnswerId, MutableList<AnswerCommentRes>>
) = summary.map {
AnswerRes(it, comments[getAnswerId(it)] ?: emptyList())
Expand Down
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())
}
}
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)
}
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>,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package site.qbox.qboxserver.domain.member.command.entity

import jakarta.persistence.Column
import jakarta.persistence.ElementCollection
import jakarta.persistence.EmbeddedId
import jakarta.persistence.Entity
import org.springframework.security.crypto.password.PasswordEncoder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package site.qbox.qboxserver.domain.member.email.svc

import org.springframework.context.ApplicationEventPublisher
import org.springframework.stereotype.Service
import site.qbox.qboxserver.domain.member.email.dto.CertifyKeyReq
import site.qbox.qboxserver.domain.member.email.dto.RegisterEmailReq
import site.qbox.qboxserver.domain.member.email.dto.event.RegisteredEmailEvent
Expand Down
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()
}

}


}
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"),
)
)
)

}
}
}

0 comments on commit 4c9a27f

Please sign in to comment.