diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/bookmark/application/BookmarkService.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/bookmark/application/BookmarkService.kt index 07bc3671..be28926d 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/bookmark/application/BookmarkService.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/bookmark/application/BookmarkService.kt @@ -20,5 +20,4 @@ class BookmarkService( bookmarkModifier.modifyBookmarkStatus(it) } ?: bookmarkAppender.appendBookmark(jobDescriptionId, experienceId) } - } diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/experience/application/dto/GetExperience.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/experience/application/dto/GetExperience.kt index 38c65b01..833ec77c 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/experience/application/dto/GetExperience.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/experience/application/dto/GetExperience.kt @@ -1,5 +1,6 @@ package com.bamyanggang.apimodule.domain.experience.application.dto +import com.bamyanggang.domainmodule.domain.bookmark.enums.BookmarkStatus import java.time.LocalDateTime import java.util.* @@ -19,6 +20,23 @@ class GetExperience { val endedAt: LocalDateTime, ) + data class BookmarkResponse( + val experience: List + ) + + data class BookmarkDetailExperience( + val id: UUID, + val title: String, + val parentTag: DetailTag, + val childTag: DetailTag, + val strongPoints: List, + val contents: List, + val startedAt: LocalDateTime, + val endedAt: LocalDateTime, + val bookmarked: BookmarkStatus, + ) + + data class DetailExperienceContent( val question: String, val answer: String, diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/experience/application/service/ExperienceGetService.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/experience/application/service/ExperienceGetService.kt index a7b489a6..d17ea50f 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/experience/application/service/ExperienceGetService.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/experience/application/service/ExperienceGetService.kt @@ -3,11 +3,16 @@ package com.bamyanggang.apimodule.domain.experience.application.service import com.bamyanggang.apimodule.common.getAuthenticationPrincipal import com.bamyanggang.apimodule.domain.experience.application.dto.ExperienceYear import com.bamyanggang.apimodule.domain.experience.application.dto.GetExperience +import com.bamyanggang.domainmodule.domain.bookmark.enums.BookmarkStatus +import com.bamyanggang.domainmodule.domain.bookmark.service.BookmarkReader import com.bamyanggang.domainmodule.domain.experience.aggregate.Experience +import com.bamyanggang.domainmodule.domain.experience.aggregate.ExperienceContent +import com.bamyanggang.domainmodule.domain.experience.aggregate.ExperienceStrongPoint import com.bamyanggang.domainmodule.domain.experience.service.ExperienceReader import com.bamyanggang.domainmodule.domain.strongpoint.service.StrongPointReader import com.bamyanggang.domainmodule.domain.tag.service.TagReader import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional import java.util.* @Service @@ -15,12 +20,15 @@ class ExperienceGetService( private val experienceReader: ExperienceReader, private val strongPointReader: StrongPointReader, private val tagReader: TagReader, + private val bookMarkReader: BookmarkReader, ) { + @Transactional(readOnly = true) fun getExperienceDetailById(experienceId: UUID) : GetExperience.DetailExperience { val oneExperience = experienceReader.readExperience(experienceId) return createExperienceDetailResponse(oneExperience) } + @Transactional(readOnly = true) fun getAllYearsByExistExperience(): ExperienceYear.Response { val currentUserId = getAuthenticationPrincipal() @@ -49,6 +57,7 @@ class ExperienceGetService( ) } + @Transactional(readOnly = true) fun getExperienceByYearAndParentTag(year: Int, parentTagId: UUID): GetExperience.Response { val experiences = experienceReader.readByYearAndParentTagId(year, parentTagId).map { createExperienceDetailResponse(it) @@ -57,6 +66,7 @@ class ExperienceGetService( return GetExperience.Response(experiences) } + @Transactional(readOnly = true) fun getExperienceByYearAndChildTag(year: Int, childTagId: UUID): GetExperience.Response { val experiences = experienceReader.readByChildTagIdAndYear(year, childTagId).map { createExperienceDetailResponse(it) @@ -65,11 +75,49 @@ class ExperienceGetService( return GetExperience.Response(experiences) } + @Transactional(readOnly = true) + fun getAllBookmarkExperiences(jobDescriptionId: UUID): GetExperience.BookmarkResponse { + val experienceIds = bookMarkReader.readByStatusAndJobDescriptionId(jobDescriptionId, BookmarkStatus.ON).map { it.experienceId } + + val userExperiences = experienceReader.readAllByUserId(getAuthenticationPrincipal()) + + val bookmarkExperienceDetails = userExperiences.map { + when { + it.id in experienceIds -> createBookmarkExperienceDetailResponse(it, BookmarkStatus.ON) + else -> createBookmarkExperienceDetailResponse(it, BookmarkStatus.OFF) + } + } + + return GetExperience.BookmarkResponse(bookmarkExperienceDetails) + } + + @Transactional(readOnly = true) + fun getBookmarkExperienceBySearch(jobDescriptionId: UUID, search: String): GetExperience.BookmarkResponse { + val currentUserId = getAuthenticationPrincipal() + + val experiencesIds = experienceReader.readByTitleContains(search) + + experienceReader.readByContentsContains(currentUserId, search) + + tagReader.readIdsByNameContains(search) + + strongPointReader.readIdsByNameContains(search) + + val searchExperiences = experienceReader.readByIds(experiencesIds) + val bookmarkExperienceIds = bookMarkReader.readByExperienceIds(experiencesIds).map { it.experienceId } + + val bookmarkExperienceDetails = searchExperiences.map { + when { + it.id in bookmarkExperienceIds -> createBookmarkExperienceDetailResponse(it, BookmarkStatus.ON) + else -> createBookmarkExperienceDetailResponse(it, BookmarkStatus.OFF) + } + } + + return GetExperience.BookmarkResponse(bookmarkExperienceDetails) + } + private fun createExperienceDetailResponse(experience: Experience): GetExperience.DetailExperience { - val detailExperienceContents = convertDetailExperienceContent(experience) - val strongPointDetails = convertStrongPoints(experience) - val detailParentTag = convertParentTag(experience) - val detailChildTag = convertChildTag(experience) + val detailExperienceContents = convertExperienceContent(experience.contents) + val strongPointDetails = convertStrongPoints(experience.strongPoints) + val detailParentTag = convertParentTag(experience.parentTagId) + val detailChildTag = convertChildTag(experience.childTagId) return GetExperience.DetailExperience( id = experience.id, @@ -83,31 +131,50 @@ class ExperienceGetService( ) } - private fun convertChildTag(oneExperience: Experience) = - tagReader.readById(oneExperience.childTagId).let { + private fun createBookmarkExperienceDetailResponse(experience: Experience, bookmarkStatus: BookmarkStatus): GetExperience.BookmarkDetailExperience { + val detailExperienceContents = convertExperienceContent(experience.contents) + val strongPointDetails = convertStrongPoints(experience.strongPoints) + val detailParentTag = convertParentTag(experience.parentTagId) + val detailChildTag = convertChildTag(experience.childTagId) + + return GetExperience.BookmarkDetailExperience( + id = experience.id, + title = experience.title, + parentTag = detailParentTag, + childTag = detailChildTag, + strongPoints = strongPointDetails, + contents = detailExperienceContents, + startedAt = experience.startedAt, + endedAt = experience.endedAt, + bookmarked = bookmarkStatus + ) + } + + private fun convertChildTag(childTagId: UUID) = + tagReader.readById(childTagId).let { GetExperience.DetailTag( it.id, it.name ) } - private fun convertParentTag(oneExperience: Experience) = - tagReader.readById(oneExperience.parentTagId).let { + private fun convertParentTag(parentTagId: UUID) = + tagReader.readById(parentTagId).let { GetExperience.DetailTag( it.id, it.name ) } - private fun convertDetailExperienceContent(experience: Experience) = - experience.contents.map { GetExperience.DetailExperienceContent( + private fun convertExperienceContent(contents: List) = + contents.map { GetExperience.DetailExperienceContent( it.question, it.answer ) } - private fun convertStrongPoints(experience: Experience) = - experience.strongPoints.map { it.strongPointId }.let { + private fun convertStrongPoints(strongPoints: List) = + strongPoints.map { it.strongPointId }.let { strongPointReader.readByIds(it).map { strongPoint -> GetExperience.DetailStrongPoint( strongPoint.id, diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/experience/presentation/ExperienceApi.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/experience/presentation/ExperienceApi.kt index 9f597e3f..2946ca96 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/experience/presentation/ExperienceApi.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/experience/presentation/ExperienceApi.kt @@ -4,4 +4,5 @@ object ExperienceApi { const val BASE_URL = "/api/experiences" const val EXPERIENCE_PATH_VARIABLE_URL = "$BASE_URL/{experienceId}" const val ALL_YEARS = "$BASE_URL/all-years" + const val BOOKMARK_EXPERIENCE_URL = "$BASE_URL/bookmark/{jobDescriptionId}" } diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/experience/presentation/ExperienceController.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/experience/presentation/ExperienceController.kt index 76c5141d..06c7bcdc 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/experience/presentation/ExperienceController.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/experience/presentation/ExperienceController.kt @@ -18,6 +18,16 @@ class ExperienceController( private val experienceEditService: ExperienceEditService, private val experienceGetService: ExperienceGetService ) { + @GetMapping(ExperienceApi.BOOKMARK_EXPERIENCE_URL) + fun getBookMarkExperiences( + @PathVariable("jobDescriptionId") jobDescriptionId: UUID, + @RequestParam("search", required = false) search: String?, + ) : GetExperience.BookmarkResponse = + when (search) { + null -> experienceGetService.getAllBookmarkExperiences(jobDescriptionId) + else -> experienceGetService.getBookmarkExperienceBySearch(jobDescriptionId, search.trim()) + } + @GetMapping(ExperienceApi.BASE_URL) fun getExperienceByFilter(@RequestParam("year") year: Int, @RequestParam("parent-tag", required = false) parentTagId: UUID?, diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/strongpoint/application/service/StrongPointDeleteService.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/strongpoint/application/service/StrongPointDeleteService.kt index 93022637..c8ba5485 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/strongpoint/application/service/StrongPointDeleteService.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/strongpoint/application/service/StrongPointDeleteService.kt @@ -1,14 +1,15 @@ package com.bamyanggang.apimodule.domain.strongpoint.application.service -import ch.qos.logback.core.rolling.helper.ArchiveRemover import com.bamyanggang.domainmodule.domain.strongpoint.service.StrongPointRemover import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional import java.util.* @Service class StrongPointDeleteService( private val strongPointRemover: StrongPointRemover ) { + @Transactional fun deleteStrongPoint(strongPointId: UUID) { strongPointRemover.removeStrongPoint(strongPointId) } diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/strongpoint/application/service/StrongPointGetService.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/strongpoint/application/service/StrongPointGetService.kt index d57f7099..381bb97f 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/strongpoint/application/service/StrongPointGetService.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/strongpoint/application/service/StrongPointGetService.kt @@ -4,11 +4,13 @@ import com.bamyanggang.apimodule.common.getAuthenticationPrincipal import com.bamyanggang.apimodule.domain.strongpoint.application.dto.GetStrongPoint import com.bamyanggang.domainmodule.domain.strongpoint.service.StrongPointReader import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional @Service class StrongPointGetService( private val strongPointReader: StrongPointReader, ) { + @Transactional(readOnly = true) fun getAllStrongPoints(): GetStrongPoint.Response { return getAuthenticationPrincipal().let { val detailStrongPoints = strongPointReader.readAllByUserId(it).map { strongPoint -> diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/tag/application/service/TagDeleteService.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/tag/application/service/TagDeleteService.kt index aa7839c8..f99f91de 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/tag/application/service/TagDeleteService.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/tag/application/service/TagDeleteService.kt @@ -1,5 +1,9 @@ package com.bamyanggang.apimodule.domain.tag.application.service +import com.bamyanggang.apimodule.common.getAuthenticationPrincipal +import com.bamyanggang.domainmodule.domain.experience.service.ExperienceReader +import com.bamyanggang.domainmodule.domain.experience.service.ExperienceRemover +import com.bamyanggang.domainmodule.domain.tag.service.TagReader import com.bamyanggang.domainmodule.domain.tag.service.TagRemover import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @@ -7,10 +11,24 @@ import java.util.* @Service class TagDeleteService( - private val tagRemover: TagRemover + private val tagRemover: TagRemover, + private val tagReader: TagReader, + private val experienceReader: ExperienceReader, + private val experienceRemover: ExperienceRemover ) { @Transactional fun deleteTag(tagId: UUID) { + val deleteTag = tagReader.readById(tagId) + + if (deleteTag.parentTagId == null) { + experienceReader.readByUserIdAndParentTagId(getAuthenticationPrincipal(), deleteTag.id) + .forEach { experienceRemover.remove(it.id) } + }else { + experienceReader.readByChildTag(tagId).forEach { + experienceRemover.remove(it.id) + } + } + tagRemover.removeTag(tagId) } } diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/tag/presentation/TagController.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/tag/presentation/TagController.kt index 127e42a5..33126e48 100644 --- a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/tag/presentation/TagController.kt +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/tag/presentation/TagController.kt @@ -69,7 +69,8 @@ class TagController( } @DeleteMapping(TagApi.TAG_PATH_VARIABLE_URL) - fun deleteTag( @PathVariable("tagId", required = false) tagId: UUID) { + fun deleteTag( @PathVariable("tagId") tagId: UUID) { + tagDeleteService.deleteTag(tagId) } } diff --git a/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/experience/presentation/ExperienceControllerTest.kt b/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/experience/presentation/ExperienceControllerTest.kt index c64956df..e10e8b97 100644 --- a/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/experience/presentation/ExperienceControllerTest.kt +++ b/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/experience/presentation/ExperienceControllerTest.kt @@ -435,6 +435,91 @@ class ExperienceControllerTest : BaseRestDocsTest() { ) } +// @Test +// @DisplayName("북마크 경험을 전체 조회한다.") +// fun getAllBookmarkExperienceYearTest() { +// val content1 = GetExperience.DetailExperienceContent("질문1", "답변1") +// val content2 = GetExperience.DetailExperienceContent("질문2", "답변2") +// val strongPoint1 = GetExperience.DetailStrongPoint(UUID.randomUUID(), "역량 키워드 이름 1") +// val strongPoint2 = GetExperience.DetailStrongPoint(UUID.randomUUID(), "역량 키워드 이름 2") +// val parentTag = GetExperience.DetailTag(UUID.randomUUID(), "상위 태그 이름") +// val childTag = GetExperience.DetailTag(UUID.randomUUID(), "하위 태그 이름") +// val startedAt = LocalDateTime.now() +// val endedAt = LocalDateTime.now().plusDays(1) +// +// val contentResponse = arrayListOf(content1, content2) +// val strongPointResponse = arrayListOf(strongPoint1, strongPoint2) +// +// val experienceResponses = +// GetExperience.BookmarkResponse( +// arrayListOf( +// GetExperience.BookmarkDetailExperience( +// id = UUID.randomUUID(), +// title = "경험 제목1 ", +// contents = contentResponse, +// strongPoints = strongPointResponse, +// parentTag = parentTag, +// childTag = childTag, +// startedAt = startedAt, +// endedAt = endedAt, +// bookmarked = BookmarkStatus.ON +// ), +// GetExperience.BookmarkDetailExperience( +// id = UUID.randomUUID(), +// title = "경험 제목 2", +// contents = contentResponse, +// strongPoints = strongPointResponse, +// parentTag = parentTag, +// childTag = childTag, +// startedAt = startedAt.minusYears(1), +// endedAt = endedAt, +// bookmarked = BookmarkStatus.OFF +// ) +// ) +// ) +// +// val year = 2024 +// given(experienceGetService.getAllBookmarkExperiences(UUID.randomUUID())).willReturn(experienceResponses) +// +// //given +// val request = RestDocumentationRequestBuilders.get(ExperienceApi.BOOKMARK_EXPERIENCE_URL, UUID.randomUUID()) +// .header("Authorization", "Bearer Access Token") +// .contentType(MediaType.APPLICATION_JSON_VALUE) +// .queryParam("year", year.toString()) +// .queryParam("parent-tag", parentTag.id.toString()) +// +// //when +// val result = mockMvc.perform(request) +// +// //then +// result.andExpect(status().isOk).andDo( +// resultHandler.document( +// requestHeaders( +// headerWithName("Authorization").description("엑세스 토큰") +// ), +// responseFields( +// fieldWithPath("experiences[].id").description("경험 id"), +// fieldWithPath("experiences[].title").description("경험 제목"), +// fieldWithPath("experiences[].contents").description("경험 내용"), +// fieldWithPath("experiences[].contents[].question").description("경험 내용 질문"), +// fieldWithPath("experiences[].contents[].answer").description("경험 내용 답변"), +// fieldWithPath("experiences[].strongPoints").description("관련된 역량 키워드"), +// fieldWithPath("experiences[].strongPoints[].id").description("역량 키워드 id"), +// fieldWithPath("experiences[].strongPoints[].name").description("역량 키워드 이름"), +// fieldWithPath("experiences[].parentTag").description("속한 상위 태그"), +// fieldWithPath("experiences[].parentTag.id").description("상위 태그 id"), +// fieldWithPath("experiences[].parentTag.name").description("상위 태그 이름"), +// fieldWithPath("experiences[].childTag").description("속한 하위 태그"), +// fieldWithPath("experiences[].childTag.id").description("하위 태그 id"), +// fieldWithPath("experiences[].childTag.name").description("하위 태그 이름"), +// fieldWithPath("experiences[].startedAt").description("경험 시작 날짜"), +// fieldWithPath("experiences[].endedAt").description("경험 종료 날짜"), +// fieldWithPath("experiences[].bookmarked").description("북마크 여부"), +// ), +// ) +// ) +// } + @Test @DisplayName("경험 목록을 하위 태그 id를 기준으로 조회한다.") fun getExperienceYearAndChildTagTest() { diff --git a/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/tag/presentation/TagControllerTest.kt b/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/tag/presentation/TagControllerTest.kt index 3cccd759..51a978b5 100644 --- a/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/tag/presentation/TagControllerTest.kt +++ b/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/tag/presentation/TagControllerTest.kt @@ -400,7 +400,7 @@ class TagControllerTest : BaseRestDocsTest() { fieldWithPath("tags[].name").description("태그 이름"), ) ) - ) + ) } @Test diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/repository/BookmarkRepository.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/repository/BookmarkRepository.kt index fad1e5f1..c258b238 100644 --- a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/repository/BookmarkRepository.kt +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/repository/BookmarkRepository.kt @@ -1,12 +1,13 @@ package com.bamyanggang.domainmodule.domain.bookmark.repository import com.bamyanggang.domainmodule.domain.bookmark.aggregate.Bookmark +import com.bamyanggang.domainmodule.domain.bookmark.enums.BookmarkStatus import java.util.* interface BookmarkRepository { - fun findByIds(jobDescriptionId : UUID, experienceId : UUID) : Bookmark? - + fun findById(jobDescriptionId : UUID, experienceId : UUID) : Bookmark? fun save(bookmark: Bookmark) - + fun findByStatusAndJobDescriptionId(jobDescriptionId: UUID, status: BookmarkStatus): List + fun findByExperienceIds(experiences: List): List } diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkReader.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkReader.kt index e8e8314e..01307311 100644 --- a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkReader.kt +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkReader.kt @@ -1,6 +1,7 @@ package com.bamyanggang.domainmodule.domain.bookmark.service import com.bamyanggang.domainmodule.domain.bookmark.aggregate.Bookmark +import com.bamyanggang.domainmodule.domain.bookmark.enums.BookmarkStatus import com.bamyanggang.domainmodule.domain.bookmark.repository.BookmarkRepository import java.util.* @@ -9,7 +10,14 @@ class BookmarkReader( ) { fun readBookmark(jobDescriptionId: UUID, experienceId: UUID) : Bookmark? { - return bookmarkRepository.findByIds(jobDescriptionId, experienceId) + return bookmarkRepository.findById(jobDescriptionId, experienceId) } + fun readByStatusAndJobDescriptionId(jobDescriptionId: UUID, status: BookmarkStatus): List { + return bookmarkRepository.findByStatusAndJobDescriptionId(jobDescriptionId, status) + } + + fun readByExperienceIds(experiencesIds: List) : List{ + return bookmarkRepository.findByExperienceIds(experiencesIds) + } } diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/experience/repository/ExperienceRepository.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/experience/repository/ExperienceRepository.kt index b2608fc9..42a3569c 100644 --- a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/experience/repository/ExperienceRepository.kt +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/experience/repository/ExperienceRepository.kt @@ -11,7 +11,10 @@ interface ExperienceRepository { fun findByUserIdAndYearDesc(year: Int, userId: UUID): List fun findByYearAndParentTagId(year: Int, parentTagId: UUID): List fun findByYearAndChildTagId(year: Int, childTagId: UUID): List + fun findByIds(experienceIds: List): List + fun findByTitleContains(search: String): List fun findByUserIdAndParentTagId(userId: UUID, parentTagId: UUID): List fun findByUserIdAndParentTagIdAndYearDesc(year: Int, parentTagId: UUID, userId: UUID): List fun findByYear(year: Int): List + fun findByChildTagId(childTag: UUID) : List } diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/experience/service/ExperienceReader.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/experience/service/ExperienceReader.kt index b9b761f3..a06364aa 100644 --- a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/experience/service/ExperienceReader.kt +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/experience/service/ExperienceReader.kt @@ -46,7 +46,28 @@ class ExperienceReader( return experienceRepository.findByYearAndChildTagId(year, childTagId) } + fun readByIds(experienceIds: List) : List { + return experienceRepository.findByIds(experienceIds) + } + + fun readByTitleContains(search: String): List { + return experienceRepository.findByTitleContains(search).map { it.id } + } + + fun readByContentsContains(userId: UUID, search: String): List { + val experiences = experienceRepository.findAllByUserId(userId) + + return experiences.filter { + it.contents.map { content -> + content.question.contains(search) || content.answer.contains(search) + }.contains(true) + }.map { it.id } + } fun readByYear(year: Int): List { return experienceRepository.findByYear(year) } + + fun readByChildTag(childTag: UUID): List { + return experienceRepository.findByChildTagId(childTag) + } } diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/strongpoint/repository/StrongPointRepository.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/strongpoint/repository/StrongPointRepository.kt index a7e63cd9..230a1775 100644 --- a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/strongpoint/repository/StrongPointRepository.kt +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/strongpoint/repository/StrongPointRepository.kt @@ -10,4 +10,5 @@ interface StrongPointRepository { fun isExistByStrongPointId(strongPointId: UUID): Boolean fun findByIds(strongPointIds: List) : List fun saveAll(strongPoints: List) + fun findByNameContains(search: String): List } diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/strongpoint/service/StrongPointReader.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/strongpoint/service/StrongPointReader.kt index 857d30f3..e135bf59 100644 --- a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/strongpoint/service/StrongPointReader.kt +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/strongpoint/service/StrongPointReader.kt @@ -16,4 +16,8 @@ class StrongPointReader( fun readByIds(strongPointIds: List) : List { return strongPointRepository.findByIds(strongPointIds) } + + fun readIdsByNameContains(search: String) : List { + return strongPointRepository.findByNameContains(search).map { it.id } + } } diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/tag/repository/TagRepository.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/tag/repository/TagRepository.kt index 808cd773..7d7c6dd3 100644 --- a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/tag/repository/TagRepository.kt +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/tag/repository/TagRepository.kt @@ -11,5 +11,6 @@ interface TagRepository { fun deleteByTagId(tagId: UUID) fun isExistById(tagId: UUID): Boolean fun findByParentTagIds(tagParentTagIds: List): List + fun findByNameContains(search: String): List fun findAllChildTagsByParentTagId(parentTagId: UUID) : List } diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/tag/service/TagReader.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/tag/service/TagReader.kt index 10383bc9..78c74ad5 100644 --- a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/tag/service/TagReader.kt +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/tag/service/TagReader.kt @@ -25,6 +25,10 @@ class TagReader( return tagRepository.findByParentTagIds(parentTagIds) } + fun readIdsByNameContains(search: String) : List { + return tagRepository.findByNameContains(search).map { it.id } + } + fun readChildTagsByParentTagId(parentTagId: UUID) : List { return tagRepository.findAllChildTagsByParentTagId(parentTagId) } diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/tag/service/TagRemover.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/tag/service/TagRemover.kt index 367b436f..ea91863c 100644 --- a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/tag/service/TagRemover.kt +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/tag/service/TagRemover.kt @@ -10,7 +10,7 @@ class TagRemover( private val tagRepository: TagRepository ) { fun removeTag(tagId: UUID) { - if (tagRepository.isExistById(tagId)) { + if (!tagRepository.isExistById(tagId)) { throw TagException.NotFoundTag() } tagRepository.deleteByTagId(tagId) diff --git a/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkReaderTest.kt b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkReaderTest.kt index 7c0b63c2..b1b61d35 100644 --- a/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkReaderTest.kt +++ b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkReaderTest.kt @@ -16,7 +16,7 @@ class BookmarkReaderTest: BehaviorSpec({ val jobDescriptionId = UUID.randomUUID() val experienceId = UUID.randomUUID() val expectedBookmark = mockk() - every { mockBookmarkRepository.findByIds(jobDescriptionId, experienceId) } returns expectedBookmark + every { mockBookmarkRepository.findById(jobDescriptionId, experienceId) } returns expectedBookmark `when`("북마크를 조회하면") { val result = bookmarkReader.readBookmark(jobDescriptionId, experienceId) diff --git a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/BookmarkRepositoryImpl.java b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/BookmarkRepositoryImpl.java index 9a0c6bf9..47e6c8df 100644 --- a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/BookmarkRepositoryImpl.java +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/BookmarkRepositoryImpl.java @@ -1,10 +1,12 @@ package com.bamyanggang.persistence.bookmark; import com.bamyanggang.domainmodule.domain.bookmark.aggregate.Bookmark; +import com.bamyanggang.domainmodule.domain.bookmark.enums.BookmarkStatus; import com.bamyanggang.domainmodule.domain.bookmark.repository.BookmarkRepository; import com.bamyanggang.persistence.bookmark.jpa.entity.BookmarkJpaEntity; import com.bamyanggang.persistence.bookmark.jpa.repository.BookmarkJpaRepository; import com.bamyanggang.persistence.bookmark.mapper.BookmarkMapper; +import java.util.List; import java.util.UUID; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; @@ -16,7 +18,7 @@ public class BookmarkRepositoryImpl implements BookmarkRepository { private final BookmarkMapper bookmarkMapper; @Override - public Bookmark findByIds(UUID jobDescriptionId, UUID experienceId) { + public Bookmark findById(UUID jobDescriptionId, UUID experienceId) { return bookmarkJpaRepository.findByJobDescriptionIdAndExperienceId(jobDescriptionId, experienceId) .map(bookmarkMapper::toDomainEntity) .orElse(null); @@ -28,4 +30,18 @@ public void save(Bookmark bookmark) { bookmarkJpaRepository.save(bookmarkJpaEntity); } + @Override + public List findByStatusAndJobDescriptionId(UUID jobDescriptionId, BookmarkStatus status) { + List bookmarkJpaEntities = bookmarkJpaRepository + .findByBookmarkStatusAndJobDescriptionId(status, jobDescriptionId); + + return bookmarkJpaEntities.stream().map(bookmarkMapper::toDomainEntity).toList(); + } + + @Override + public List findByExperienceIds(List experienceIds) { + List bookmarkJpaEntities = bookmarkJpaRepository.findByExperienceIds(experienceIds); + + return bookmarkJpaEntities.stream().map(bookmarkMapper::toDomainEntity).toList(); + } } diff --git a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/jpa/repository/BookmarkJpaRepository.java b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/jpa/repository/BookmarkJpaRepository.java index 48085863..e8642f7e 100644 --- a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/jpa/repository/BookmarkJpaRepository.java +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/jpa/repository/BookmarkJpaRepository.java @@ -1,12 +1,24 @@ package com.bamyanggang.persistence.bookmark.jpa.repository; +import com.bamyanggang.domainmodule.domain.bookmark.enums.BookmarkStatus; import com.bamyanggang.persistence.bookmark.jpa.entity.BookmarkJpaEntity; +import java.util.List; import java.util.Optional; import java.util.UUID; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface BookmarkJpaRepository extends JpaRepository { Optional findByJobDescriptionIdAndExperienceId(UUID jobDescriptionId, UUID experienceId); + @Query("select bm from BookmarkJpaEntity bm where bm.bookmarkStatus = :status and bm.jobDescriptionId = :jobDescriptionId") + List findByBookmarkStatusAndJobDescriptionId(@Param("status") BookmarkStatus status, + @Param("jobDescriptionId") UUID jobDescriptionId); + + @Modifying + @Query("select bm from BookmarkJpaEntity bm where bm.experienceId in :experienceIds") + List findByExperienceIds(@Param("experienceIds") List experienceIds); } diff --git a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/experience/ExperienceRepositoryImpl.java b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/experience/ExperienceRepositoryImpl.java index baca0baa..97a89c69 100644 --- a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/experience/ExperienceRepositoryImpl.java +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/experience/ExperienceRepositoryImpl.java @@ -71,12 +71,22 @@ public List findByYearAndChildTagId(int year, UUID childTagId) { LocalDateTime endYear = LocalDateTime.of(year, 12, 31, 23, 59); List experienceJpaEntities = experienceJpaRepository - .findByChildTagIdAndCreatedAtBetweenOrderByCreatedAtDesc(childTagId, startYear, endYear); + .findByChildTagIdAndStartedAtBetweenOrderByStartedAtDesc(childTagId, startYear, endYear); return experienceJpaEntities.stream().map(experienceMapper::toExperienceDomainEntity).toList(); } @Override + public List findByIds(List experienceIds) { + List experienceJpaEntities = experienceJpaRepository.findByIds(experienceIds); + return experienceJpaEntities.stream().map(experienceMapper::toExperienceDomainEntity).toList(); + } + + public List findByTitleContains(String search) { + List experienceJpaEntities = experienceJpaRepository.findByTitleContaining(search); + return experienceJpaEntities.stream().map(experienceMapper::toExperienceDomainEntity).toList(); + } + public List findByUserIdAndParentTagId(UUID userId, UUID parentTagId) { List experienceJpaEntities = experienceJpaRepository.findByUserIdAndParentTagId(userId, parentTagId); @@ -104,4 +114,10 @@ public List findByYear(int year) { return experienceJpaEntities.stream().map(experienceMapper::toExperienceDomainEntity).toList(); } + + @Override + public List findByChildTagId(UUID childTag) { + List experienceJpaEntities = experienceJpaRepository.findByChildTagId(childTag); + return experienceJpaEntities.stream().map(experienceMapper::toExperienceDomainEntity).toList(); + } } diff --git a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/experience/jpa/repository/ExperienceJpaRepository.java b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/experience/jpa/repository/ExperienceJpaRepository.java index 3e9c80e6..0619ba68 100644 --- a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/experience/jpa/repository/ExperienceJpaRepository.java +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/experience/jpa/repository/ExperienceJpaRepository.java @@ -5,14 +5,23 @@ import java.util.List; import java.util.UUID; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface ExperienceJpaRepository extends JpaRepository { List findAllByUserId(UUID userId); List findByUserIdAndCreatedAtBetweenOrderByCreatedAtDesc(UUID userId, LocalDateTime startYear, LocalDateTime endYear); List findByParentTagIdAndCreatedAtBetweenOrderByCreatedAtDesc(UUID parentTagId, LocalDateTime startYear, LocalDateTime endYear); - List findByChildTagIdAndCreatedAtBetweenOrderByCreatedAtDesc(UUID childTagId, LocalDateTime startYear, LocalDateTime endYear); + List findByChildTagIdAndStartedAtBetweenOrderByStartedAtDesc(UUID childTagId, LocalDateTime startYear, LocalDateTime endYear); + List findByTitleContaining(String title); + + @Query("select e from ExperienceJpaEntity e where e.experienceId in :experienceIds") + List findByIds(@Param("experienceIds") List experienceIds); + List findByCreatedAtBetween(LocalDateTime startYear, LocalDateTime endYear); List findByUserIdAndParentTagId(UUID userId, UUID parentTagId); List findByUserIdAndParentTagIdAndCreatedAtBetweenOrderByCreatedAtDesc( UUID userId, UUID parentTagId, LocalDateTime startYear, LocalDateTime endYear); + + List findByChildTagId(UUID childTag); } diff --git a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/jpa/repository/JobDescriptionJpaRepository.java b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/jpa/repository/JobDescriptionJpaRepository.java index 55cc7fc7..dafa712c 100644 --- a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/jpa/repository/JobDescriptionJpaRepository.java +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/jobDescription/jpa/repository/JobDescriptionJpaRepository.java @@ -2,7 +2,6 @@ import com.bamyanggang.domainmodule.domain.jobDescription.enums.WriteStatus; import com.bamyanggang.persistence.jobDescription.jpa.entity.JobDescriptionJpaEntity; -import java.time.LocalDateTime; import java.util.UUID; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; diff --git a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/strongpoint/StrongPointRepositoryImpl.java b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/strongpoint/StrongPointRepositoryImpl.java index f34a2465..f59dfb41 100644 --- a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/strongpoint/StrongPointRepositoryImpl.java +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/strongpoint/StrongPointRepositoryImpl.java @@ -51,4 +51,10 @@ public void saveAll(List strongPoints) { strongPointJpaRepository.saveAll(strongPointJpaEntities); } + + @Override + public List findByNameContains(String search) { + List strongPointJpaEntities = strongPointJpaRepository.findByNameContaining(search); + return strongPointJpaEntities.stream().map(strongPointMapper::toDomainEntity).toList(); + } } diff --git a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/strongpoint/jpa/repository/StrongPointJpaRepository.java b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/strongpoint/jpa/repository/StrongPointJpaRepository.java index 5ddf69d4..6e94df97 100644 --- a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/strongpoint/jpa/repository/StrongPointJpaRepository.java +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/strongpoint/jpa/repository/StrongPointJpaRepository.java @@ -4,14 +4,14 @@ import java.util.List; import java.util.UUID; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; public interface StrongPointJpaRepository extends JpaRepository { List findAllByUserId(UUID userId); - @Modifying @Query("select spe from StrongPointJpaEntity spe where spe.strongPointId in :strongPoints") List findByIds(@Param("strongPoints") List strongPointIds); + + List findByNameContaining(String search); } diff --git a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/tag/TagRepositoryImpl.java b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/tag/TagRepositoryImpl.java index 7cd2b210..d6b1508d 100644 --- a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/tag/TagRepositoryImpl.java +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/tag/TagRepositoryImpl.java @@ -42,6 +42,7 @@ public void deleteByTagId(UUID tagId) { @Override public boolean isExistById(UUID tagId) { + System.out.println(tagJpaRepository.existsById(tagId)); return tagJpaRepository.existsById(tagId); } @@ -58,8 +59,14 @@ public Tag findById(UUID tagId) { } @Override + public List findByNameContains(String search) { + List tagJpaEntities = tagJpaRepository.findByNameContaining(search); + return tagJpaEntities.stream().map(tagMapper::toDomainEntity).toList(); + } + public List findAllChildTagsByParentTagId(UUID parentTagId) { List tagJpaEntities = tagJpaRepository.findAllByParentTagId(parentTagId); + return tagJpaEntities.stream().map(tagMapper::toDomainEntity).toList(); } } diff --git a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/tag/jpa/repository/TagJpaRepository.java b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/tag/jpa/repository/TagJpaRepository.java index 6936fa9b..121a4b71 100644 --- a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/tag/jpa/repository/TagJpaRepository.java +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/tag/jpa/repository/TagJpaRepository.java @@ -7,6 +7,7 @@ public interface TagJpaRepository extends JpaRepository { List findAllByUserIdAndParentTagIdIsNull(UUID userId); - List findAllByUserIdAndParentTagId(UUID userId, UUID parentId); + List findAllByUserIdAndParentTagId(UUID parentTagId, UUID parentId); + List findByNameContaining(String search); List findAllByParentTagId(UUID parentTagId); }