From 4eb52449e177eac793816d406186ece48f7631fd Mon Sep 17 00:00:00 2001 From: seeunjang Date: Mon, 20 May 2024 19:05:28 +0900 Subject: [PATCH 1/7] =?UTF-8?q?feat=20:=20Bookmark=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=84=A4=EA=B3=84(#107)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/bookmark/aggregate/Bookmark.kt | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/aggregate/Bookmark.kt diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/aggregate/Bookmark.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/aggregate/Bookmark.kt new file mode 100644 index 00000000..5bc96093 --- /dev/null +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/aggregate/Bookmark.kt @@ -0,0 +1,34 @@ +package com.bamyanggang.domainmodule.domain.bookmark.aggregate + +import com.bamyanggang.domainmodule.common.entity.AggregateRoot +import com.bamyanggang.domainmodule.domain.bookmark.enums.BookmarkStatus +import java.util.UUID + +data class Bookmark( + override val id: UUID = UUID.randomUUID(), + val jobDescriptionId: UUID, + val experienceId:UUID, + val bookmarkStatus: BookmarkStatus +): AggregateRoot { + + fun changeBookmarkStatus(): Bookmark { + return when (bookmarkStatus) { + BookmarkStatus.ON -> copy(bookmarkStatus = BookmarkStatus.OFF) + BookmarkStatus.OFF -> copy(bookmarkStatus = BookmarkStatus.ON) + } + } + + companion object { + fun create( + jobDescriptionId: UUID, + experienceId: UUID + ): Bookmark { + return Bookmark( + jobDescriptionId = jobDescriptionId, + experienceId = experienceId, + bookmarkStatus = BookmarkStatus.ON + ) + } + } + +} From 11567fb8ba5426c184cfafed39f9275521a07870 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Mon, 20 May 2024 19:05:47 +0900 Subject: [PATCH 2/7] =?UTF-8?q?feat=20:=20Bookmark=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20service=20=EA=B5=AC=ED=98=84(#107)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/bookmark/service/BookmarkAppender.kt | 16 ++++++++++++++++ .../domain/bookmark/service/BookmarkModifier.kt | 15 +++++++++++++++ .../domain/bookmark/service/BookmarkReader.kt | 17 +++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkAppender.kt create mode 100644 Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkModifier.kt create mode 100644 Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkReader.kt diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkAppender.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkAppender.kt new file mode 100644 index 00000000..5dd5a76c --- /dev/null +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkAppender.kt @@ -0,0 +1,16 @@ +package com.bamyanggang.domainmodule.domain.bookmark.service + +import com.bamyanggang.domainmodule.domain.bookmark.aggregate.Bookmark +import com.bamyanggang.domainmodule.domain.bookmark.repository.BookmarkRepository +import org.springframework.stereotype.Service +import java.util.* + +@Service +class BookmarkAppender( + private val bookmarkRepository: BookmarkRepository +) { + fun appendBookmark(jobDescriptionId: UUID, experienceId: UUID) { + Bookmark.create(jobDescriptionId, experienceId).also { bookmarkRepository.save(it) } + } + +} diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkModifier.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkModifier.kt new file mode 100644 index 00000000..de6a9965 --- /dev/null +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkModifier.kt @@ -0,0 +1,15 @@ +package com.bamyanggang.domainmodule.domain.bookmark.service + +import com.bamyanggang.domainmodule.domain.bookmark.aggregate.Bookmark +import com.bamyanggang.domainmodule.domain.bookmark.repository.BookmarkRepository +import org.springframework.stereotype.Service + +@Service +class BookmarkModifier( + private val bookmarkRepository: BookmarkRepository +) { + fun modifyBookmarkStatus(bookmark: Bookmark) { + bookmark.changeBookmarkStatus().also { bookmarkRepository.save(it) } + } + +} 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 new file mode 100644 index 00000000..f75abc1d --- /dev/null +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkReader.kt @@ -0,0 +1,17 @@ +package com.bamyanggang.domainmodule.domain.bookmark.service + +import com.bamyanggang.domainmodule.domain.bookmark.aggregate.Bookmark +import com.bamyanggang.domainmodule.domain.bookmark.repository.BookmarkRepository +import org.springframework.stereotype.Service +import java.util.* + +@Service +class BookmarkReader( + private val bookmarkRepository: BookmarkRepository +) { + + fun readBookmark(jobDescriptionId: UUID, experienceId: UUID) : Bookmark? { + return bookmarkRepository.findByIds(jobDescriptionId, experienceId) + } + +} From b0329dd7c97c782e54fbda90d68a8f4013117a46 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Mon, 20 May 2024 19:06:37 +0900 Subject: [PATCH 3/7] =?UTF-8?q?feat=20:=20Bookmark=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EA=B4=80=EB=A0=A8=20persistence=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84(#107)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bookmark/repository/BookmarkRepository.kt | 12 +++++ .../bookmark/BookmarkRepositoryImpl.java | 31 ++++++++++++ .../jpa/entity/BookmarkJpaEntity.java | 47 +++++++++++++++++++ .../jpa/repository/BookmarkJpaRepository.java | 12 +++++ .../bookmark/mapper/BookmarkMapper.java | 28 +++++++++++ 5 files changed, 130 insertions(+) create mode 100644 Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/repository/BookmarkRepository.kt create mode 100644 Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/BookmarkRepositoryImpl.java create mode 100644 Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/jpa/entity/BookmarkJpaEntity.java create mode 100644 Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/jpa/repository/BookmarkJpaRepository.java create mode 100644 Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/mapper/BookmarkMapper.java 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 new file mode 100644 index 00000000..fad1e5f1 --- /dev/null +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/repository/BookmarkRepository.kt @@ -0,0 +1,12 @@ +package com.bamyanggang.domainmodule.domain.bookmark.repository + +import com.bamyanggang.domainmodule.domain.bookmark.aggregate.Bookmark +import java.util.* + +interface BookmarkRepository { + + fun findByIds(jobDescriptionId : UUID, experienceId : UUID) : Bookmark? + + fun save(bookmark: Bookmark) + +} 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 new file mode 100644 index 00000000..9a0c6bf9 --- /dev/null +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/BookmarkRepositoryImpl.java @@ -0,0 +1,31 @@ +package com.bamyanggang.persistence.bookmark; + +import com.bamyanggang.domainmodule.domain.bookmark.aggregate.Bookmark; +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.UUID; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class BookmarkRepositoryImpl implements BookmarkRepository { + private final BookmarkJpaRepository bookmarkJpaRepository; + private final BookmarkMapper bookmarkMapper; + + @Override + public Bookmark findByIds(UUID jobDescriptionId, UUID experienceId) { + return bookmarkJpaRepository.findByJobDescriptionIdAndExperienceId(jobDescriptionId, experienceId) + .map(bookmarkMapper::toDomainEntity) + .orElse(null); + } + + @Override + public void save(Bookmark bookmark) { + BookmarkJpaEntity bookmarkJpaEntity = bookmarkMapper.toJpaEntity(bookmark); + bookmarkJpaRepository.save(bookmarkJpaEntity); + } + +} diff --git a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/jpa/entity/BookmarkJpaEntity.java b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/jpa/entity/BookmarkJpaEntity.java new file mode 100644 index 00000000..d7c48d3b --- /dev/null +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/jpa/entity/BookmarkJpaEntity.java @@ -0,0 +1,47 @@ +package com.bamyanggang.persistence.bookmark.jpa.entity; + +import com.bamyanggang.domainmodule.domain.bookmark.enums.BookmarkStatus; +import com.bamyanggang.persistence.common.UUIDBinaryConverter; +import jakarta.persistence.Column; +import jakarta.persistence.Convert; +import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import java.util.UUID; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter +@Table(name = "bookmark") +public class BookmarkJpaEntity { + + @Id + @Column(name = "bookmarkId", columnDefinition = "BINARY(16)") + @Convert(converter = UUIDBinaryConverter.class) + private UUID bookmarkId; + + @Column(name = "bookmark_status", columnDefinition = "VARCHAR(255)") + @Enumerated(EnumType.STRING) + private BookmarkStatus bookmarkStatus; + + @Column(name = "job_description_id", columnDefinition = "BINARY(16)") + @Convert(converter = UUIDBinaryConverter.class) + private UUID jobDescriptionId; + + @Column(name = "experience_id", columnDefinition = "BINARY(16)") + @Convert(converter = UUIDBinaryConverter.class) + private UUID experienceId; + + public BookmarkJpaEntity(UUID bookmarkId, BookmarkStatus bookmarkStatus, UUID jobDescriptionId, UUID experienceId) { + this.bookmarkId = bookmarkId; + this.bookmarkStatus = bookmarkStatus; + this.jobDescriptionId = jobDescriptionId; + this.experienceId = experienceId; + } + +} 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 new file mode 100644 index 00000000..48085863 --- /dev/null +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/jpa/repository/BookmarkJpaRepository.java @@ -0,0 +1,12 @@ +package com.bamyanggang.persistence.bookmark.jpa.repository; + +import com.bamyanggang.persistence.bookmark.jpa.entity.BookmarkJpaEntity; +import java.util.Optional; +import java.util.UUID; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface BookmarkJpaRepository extends JpaRepository { + + Optional findByJobDescriptionIdAndExperienceId(UUID jobDescriptionId, UUID experienceId); + +} diff --git a/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/mapper/BookmarkMapper.java b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/mapper/BookmarkMapper.java new file mode 100644 index 00000000..45e85b5a --- /dev/null +++ b/Infrastructure-Module/persistence/src/main/java/com/bamyanggang/persistence/bookmark/mapper/BookmarkMapper.java @@ -0,0 +1,28 @@ +package com.bamyanggang.persistence.bookmark.mapper; + +import com.bamyanggang.domainmodule.domain.bookmark.aggregate.Bookmark; +import com.bamyanggang.persistence.bookmark.jpa.entity.BookmarkJpaEntity; +import org.springframework.stereotype.Component; + +@Component +public class BookmarkMapper { + + public BookmarkJpaEntity toJpaEntity(Bookmark bookmark) { + return new BookmarkJpaEntity( + bookmark.getId(), + bookmark.getBookmarkStatus(), + bookmark.getJobDescriptionId(), + bookmark.getExperienceId() + ); + } + + public Bookmark toDomainEntity(BookmarkJpaEntity bookmarkJpaEntity) { + return new Bookmark( + bookmarkJpaEntity.getBookmarkId(), + bookmarkJpaEntity.getJobDescriptionId(), + bookmarkJpaEntity.getExperienceId(), + bookmarkJpaEntity.getBookmarkStatus() + ); + } + +} From a1871d9ab9e7fb77767d5b65ec083e15d46fb6ce Mon Sep 17 00:00:00 2001 From: seeunjang Date: Mon, 20 May 2024 19:07:10 +0900 Subject: [PATCH 4/7] =?UTF-8?q?feat=20:=20Bookmark=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EA=B4=80=EB=A0=A8=20enum=20=EC=83=9D=EC=84=B1(#107?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domainmodule/domain/bookmark/enums/BookmarkStatus.kt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/enums/BookmarkStatus.kt diff --git a/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/enums/BookmarkStatus.kt b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/enums/BookmarkStatus.kt new file mode 100644 index 00000000..93f1b305 --- /dev/null +++ b/Domain-Module/src/main/kotlin/com/bamyanggang/domainmodule/domain/bookmark/enums/BookmarkStatus.kt @@ -0,0 +1,6 @@ +package com.bamyanggang.domainmodule.domain.bookmark.enums + +enum class BookmarkStatus { + ON, + OFF +} From 4aa89ede4768b3602b7560557bffd4d9a460101e Mon Sep 17 00:00:00 2001 From: seeunjang Date: Mon, 20 May 2024 19:07:27 +0900 Subject: [PATCH 5/7] =?UTF-8?q?feat=20:=20=EB=B6=81=EB=A7=88=ED=81=AC=20AP?= =?UTF-8?q?I=20=EA=B5=AC=ED=98=84(#107)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bookmark/application/BookmarkService.kt | 24 +++++++++++++++++++ .../bookmark/presentation/BookmarkApi.kt | 6 +++++ .../presentation/BookmarkController.kt | 22 +++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/bookmark/application/BookmarkService.kt create mode 100644 Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/bookmark/presentation/BookmarkApi.kt create mode 100644 Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/bookmark/presentation/BookmarkController.kt 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 new file mode 100644 index 00000000..07bc3671 --- /dev/null +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/bookmark/application/BookmarkService.kt @@ -0,0 +1,24 @@ +package com.bamyanggang.apimodule.domain.bookmark.application + +import com.bamyanggang.domainmodule.domain.bookmark.service.BookmarkAppender +import com.bamyanggang.domainmodule.domain.bookmark.service.BookmarkModifier +import com.bamyanggang.domainmodule.domain.bookmark.service.BookmarkReader +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import java.util.* + +@Service +class BookmarkService( + private val bookmarkReader: BookmarkReader, + private val bookmarkModifier: BookmarkModifier, + private val bookmarkAppender: BookmarkAppender +) { + + @Transactional + fun bookmark(jobDescriptionId: UUID, experienceId: UUID) { + bookmarkReader.readBookmark(jobDescriptionId, experienceId)?.let { + bookmarkModifier.modifyBookmarkStatus(it) + } ?: bookmarkAppender.appendBookmark(jobDescriptionId, experienceId) + } + +} diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/bookmark/presentation/BookmarkApi.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/bookmark/presentation/BookmarkApi.kt new file mode 100644 index 00000000..75cf8e01 --- /dev/null +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/bookmark/presentation/BookmarkApi.kt @@ -0,0 +1,6 @@ +package com.bamyanggang.apimodule.domain.bookmark.presentation + +object BookmarkApi { + const val BASE_URL = "/api/bookmark" + const val BOOKMARK = "$BASE_URL/{jobDescriptionId}/{experienceId}" +} diff --git a/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/bookmark/presentation/BookmarkController.kt b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/bookmark/presentation/BookmarkController.kt new file mode 100644 index 00000000..75a0f0ed --- /dev/null +++ b/Api-Module/src/main/kotlin/com/bamyanggang/apimodule/domain/bookmark/presentation/BookmarkController.kt @@ -0,0 +1,22 @@ +package com.bamyanggang.apimodule.domain.bookmark.presentation + +import com.bamyanggang.apimodule.domain.bookmark.application.BookmarkService +import org.springframework.web.bind.annotation.PatchMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RestController +import java.util.UUID + +@RestController +class BookmarkController( + private val bookmarkService: BookmarkService +) { + + @PatchMapping(BookmarkApi.BOOKMARK) + fun bookmark( + @PathVariable("jobDescriptionId") jobDescriptionId: UUID, + @PathVariable("experienceId") experienceId: UUID + ) { + bookmarkService.bookmark(jobDescriptionId, experienceId) + } + +} From 4f4e41a41dcc9df39a02bc6910051812c0f2764e Mon Sep 17 00:00:00 2001 From: seeunjang Date: Mon, 20 May 2024 19:07:48 +0900 Subject: [PATCH 6/7] =?UTF-8?q?test=20:=20=EB=B6=81=EB=A7=88=ED=81=AC=20AP?= =?UTF-8?q?I=20=EA=B5=AC=ED=98=84=20=EA=B4=80=EB=A0=A8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1(#1?= =?UTF-8?q?07)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/BookmarkServiceTest.kt | 45 ++++++++++++++++ .../presentation/BookmarkControllerTest.kt | 54 +++++++++++++++++++ .../domain/bookmark/aggregate/BookmarkTest.kt | 43 +++++++++++++++ .../bookmark/service/BookmarkAppenderTest.kt | 26 +++++++++ .../bookmark/service/BookmarkModifierTest.kt | 28 ++++++++++ .../bookmark/service/BookmarkReaderTest.kt | 29 ++++++++++ 6 files changed, 225 insertions(+) create mode 100644 Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/bookmark/application/BookmarkServiceTest.kt create mode 100644 Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/bookmark/presentation/BookmarkControllerTest.kt create mode 100644 Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/aggregate/BookmarkTest.kt create mode 100644 Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkAppenderTest.kt create mode 100644 Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkModifierTest.kt create mode 100644 Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkReaderTest.kt diff --git a/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/bookmark/application/BookmarkServiceTest.kt b/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/bookmark/application/BookmarkServiceTest.kt new file mode 100644 index 00000000..53081d2a --- /dev/null +++ b/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/bookmark/application/BookmarkServiceTest.kt @@ -0,0 +1,45 @@ +package com.bamyanggang.apimodule.domain.bookmark.application + +import com.bamyanggang.domainmodule.domain.bookmark.aggregate.Bookmark +import com.bamyanggang.domainmodule.domain.bookmark.service.BookmarkAppender +import com.bamyanggang.domainmodule.domain.bookmark.service.BookmarkModifier +import com.bamyanggang.domainmodule.domain.bookmark.service.BookmarkReader +import io.kotest.core.spec.style.BehaviorSpec +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import java.util.* + +class BookmarkServiceTest: BehaviorSpec({ + val mockBookmarkReader = mockk(relaxed = true) + val mockBookmarkModifier = mockk(relaxed = true) + val mockBookmarkAppender = mockk(relaxed = true) + val service = BookmarkService(mockBookmarkReader, mockBookmarkModifier, mockBookmarkAppender) + + given("BookmarkService.bookmark") { + val jobDescriptionId = UUID.randomUUID() + val experienceId = UUID.randomUUID() + + `when`("readBookmark가 null을 반환하면") { + every { mockBookmarkReader.readBookmark(jobDescriptionId, experienceId) } returns null + service.bookmark(jobDescriptionId, experienceId) + then("appendBookmark가 호출된다.") { + verify { + mockBookmarkAppender.appendBookmark(jobDescriptionId, experienceId) + } + } + } + + `when`("readBookmark가 null이 아닌 값을 반환하면") { + val bookmark = mockk() + every { mockBookmarkReader.readBookmark(jobDescriptionId, experienceId) } returns bookmark + service.bookmark(jobDescriptionId, experienceId) + then("modifyBookmarkStatus가 호출된다.") { + verify { + mockBookmarkModifier.modifyBookmarkStatus(bookmark) + } + } + } + } + +}) diff --git a/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/bookmark/presentation/BookmarkControllerTest.kt b/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/bookmark/presentation/BookmarkControllerTest.kt new file mode 100644 index 00000000..06a8fe1b --- /dev/null +++ b/Api-Module/src/test/kotlin/com/bamyanggang/apimodule/domain/bookmark/presentation/BookmarkControllerTest.kt @@ -0,0 +1,54 @@ +package com.bamyanggang.apimodule.domain.bookmark.presentation + +import com.bamyanggang.apimodule.BaseRestDocsTest +import com.bamyanggang.apimodule.domain.bookmark.application.BookmarkService +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest +import org.springframework.boot.test.mock.mockito.MockBean +import org.springframework.http.MediaType +import org.springframework.restdocs.headers.HeaderDocumentation.headerWithName +import org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders +import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders +import org.springframework.restdocs.request.RequestDocumentation.parameterWithName +import org.springframework.restdocs.request.RequestDocumentation.pathParameters +import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status +import java.util.* + +@WebMvcTest(BookmarkController::class) +class BookmarkControllerTest: BaseRestDocsTest() { + + @MockBean + private lateinit var bookmarkService: BookmarkService + + @Test + @DisplayName("북마크 추가") + fun createBookmark() { + // given + val jobDescriptionId = UUID.randomUUID() + val experienceId = UUID.randomUUID() + + val request = RestDocumentationRequestBuilders.patch(BookmarkApi.BOOKMARK, jobDescriptionId, experienceId) + .header("Authorization", "Bearer Access Token") + .contentType(MediaType.APPLICATION_JSON_VALUE) + + //when + val result = mockMvc.perform(request) + + // then + result.andExpect(status().isOk) + .andDo( + resultHandler.document( + requestHeaders( + headerWithName("Authorization").description("엑세스 토큰") + ), + pathParameters( + parameterWithName("jobDescriptionId").description("jd 공고 ID"), + parameterWithName("experienceId").description("경험 ID") + ) + ) + ) + } + + +} diff --git a/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/aggregate/BookmarkTest.kt b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/aggregate/BookmarkTest.kt new file mode 100644 index 00000000..54ba7e66 --- /dev/null +++ b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/aggregate/BookmarkTest.kt @@ -0,0 +1,43 @@ +package com.bamyanggang.domainmodule.domain.bookmark.aggregate + +import com.bamyanggang.commonmodule.fixture.generateFixture +import com.bamyanggang.domainmodule.domain.bookmark.enums.BookmarkStatus +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe +import java.util.* + +class BookmarkTest : FunSpec({ + test("북마크 생성") { + // arrange + val jobDescriptionId = UUID.randomUUID() + val experienceId = UUID.randomUUID() + + // act + val bookmark: Bookmark = generateFixture { + it.set("jobDescriptionId", jobDescriptionId) + it.set("experienceId", experienceId) + } + + // assert + bookmark.jobDescriptionId shouldBe jobDescriptionId + bookmark.experienceId shouldBe experienceId + } + + test("북마크 상태 변경") { + // arrange + val jobDescriptionId = UUID.randomUUID() + val experienceId = UUID.randomUUID() + val bookmark: Bookmark = generateFixture { + it.set("jobDescriptionId", jobDescriptionId) + it.set("experienceId", experienceId) + it.set("bookmarkStatus", BookmarkStatus.ON) + } + + // act + val changedBookmark = bookmark.changeBookmarkStatus() + + // assert + changedBookmark.bookmarkStatus shouldBe BookmarkStatus.OFF + } + +}) diff --git a/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkAppenderTest.kt b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkAppenderTest.kt new file mode 100644 index 00000000..1ef012e0 --- /dev/null +++ b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkAppenderTest.kt @@ -0,0 +1,26 @@ +package com.bamyanggang.domainmodule.domain.bookmark.service + +import com.bamyanggang.domainmodule.domain.bookmark.repository.BookmarkRepository +import io.kotest.core.spec.style.BehaviorSpec +import io.mockk.mockk +import io.mockk.verify +import java.util.* + +class BookmarkAppenderTest: BehaviorSpec({ + val mockBookmarkRepository = mockk(relaxed = true) + val bookmarkAppender = BookmarkAppender(mockBookmarkRepository) + + given("BookmarkAppender의 appendBookmark 메소드를 테스트한다") { + val jobDescriptionId = UUID.randomUUID() + val experienceId = UUID.randomUUID() + `when`("북마크를 추가하면") { + bookmarkAppender.appendBookmark(jobDescriptionId, experienceId) + then("북마크가 저장된다") { + verify(exactly = 1) { + mockBookmarkRepository.save(any()) + } + } + } + } + +}) diff --git a/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkModifierTest.kt b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkModifierTest.kt new file mode 100644 index 00000000..18741122 --- /dev/null +++ b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkModifierTest.kt @@ -0,0 +1,28 @@ +package com.bamyanggang.domainmodule.domain.bookmark.service + +import com.bamyanggang.domainmodule.domain.bookmark.aggregate.Bookmark +import com.bamyanggang.domainmodule.domain.bookmark.repository.BookmarkRepository +import io.kotest.core.spec.style.BehaviorSpec +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify + +class BookmarkModifierTest: BehaviorSpec({ + val mockBookmarkRepository = mockk(relaxed = true) + val bookmarkModifier = BookmarkModifier(mockBookmarkRepository) + + given("BookmarkModifier의 modifyBookmarkStatus 메소드를 테스트한다") { + val bookmark = mockk() + every { bookmark.changeBookmarkStatus() } returns bookmark + + `when`("북마크 상태를 변경하면") { + bookmarkModifier.modifyBookmarkStatus(bookmark) + then("북마크가 저장된다") { + verify(exactly = 1) { + mockBookmarkRepository.save(bookmark) + } + } + } + } + +}) 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 new file mode 100644 index 00000000..7c0b63c2 --- /dev/null +++ b/Domain-Module/src/test/kotlin/com/bamyanggang/domainmodule/domain/bookmark/service/BookmarkReaderTest.kt @@ -0,0 +1,29 @@ +package com.bamyanggang.domainmodule.domain.bookmark.service + +import io.kotest.matchers.shouldBe +import com.bamyanggang.domainmodule.domain.bookmark.aggregate.Bookmark +import com.bamyanggang.domainmodule.domain.bookmark.repository.BookmarkRepository +import io.kotest.core.spec.style.BehaviorSpec +import io.mockk.every +import io.mockk.mockk +import java.util.* + +class BookmarkReaderTest: BehaviorSpec({ + val mockBookmarkRepository = mockk() + val bookmarkReader = BookmarkReader(mockBookmarkRepository) + + given("BookmarkReader의 readBookmark 메소드를 테스트한다") { + val jobDescriptionId = UUID.randomUUID() + val experienceId = UUID.randomUUID() + val expectedBookmark = mockk() + every { mockBookmarkRepository.findByIds(jobDescriptionId, experienceId) } returns expectedBookmark + + `when`("북마크를 조회하면") { + val result = bookmarkReader.readBookmark(jobDescriptionId, experienceId) + then("예상한 북마크가 반환된다") { + result shouldBe expectedBookmark + } + } + } + +}) From 02dea5faea0bf44c985ec37cf395ca0444ee1992 Mon Sep 17 00:00:00 2001 From: seeunjang Date: Mon, 20 May 2024 19:08:29 +0900 Subject: [PATCH 7/7] =?UTF-8?q?docs=20:=20=EB=B6=81=EB=A7=88=ED=81=AC=20AP?= =?UTF-8?q?I=20=EB=AA=85=EC=84=B8=20=EB=B0=98=EC=98=81(#107)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Api-Module/src/docs/asciidoc/BookMark.adoc | 7 +++++++ Api-Module/src/docs/asciidoc/index.adoc | 1 + 2 files changed, 8 insertions(+) create mode 100644 Api-Module/src/docs/asciidoc/BookMark.adoc diff --git a/Api-Module/src/docs/asciidoc/BookMark.adoc b/Api-Module/src/docs/asciidoc/BookMark.adoc new file mode 100644 index 00000000..22081bc5 --- /dev/null +++ b/Api-Module/src/docs/asciidoc/BookMark.adoc @@ -0,0 +1,7 @@ +[[Bookmark-API]] +== Bookmark-API + +[[CREATE-BOOKMARK]] +=== 북마크 생성 API + +operation::BookmarkControllerTest/createBookmark/[snippets='http-request,path-parameters,request-headers,http-response'] diff --git a/Api-Module/src/docs/asciidoc/index.adoc b/Api-Module/src/docs/asciidoc/index.adoc index 2baf3b1d..e5f83df7 100644 --- a/Api-Module/src/docs/asciidoc/index.adoc +++ b/Api-Module/src/docs/asciidoc/index.adoc @@ -12,3 +12,4 @@ include::StrongPoint.adoc[] include::Tag.adoc[] include::JobDescription.adoc[] include::Experience.adoc[] +include::BookMark.adoc[]