Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 역량 키워드 등록 API 구현(#46) #50

Merged
merged 26 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5941429
refactor: Mapper 클래스 코틀린 -> 자바로 변경(#46)
whereami2048 May 15, 2024
c4a6246
refactor: 경험 RepositoryImpl 클래스 코틀린 -> 자바로 변경(#46)
whereami2048 May 15, 2024
82bf4c4
refactor: 태그, 역량 키워드 애그리거트 분리(#46)
whereami2048 May 15, 2024
1389459
feat: 역량 키워드 Repositoy 인터페이스 및 구현체 클래스 구현(#46)
whereami2048 May 15, 2024
2e09fe2
feat: 도메인 계층 역량 키워드 저장 & 유저 역량 키워드 전체 조회 기능 구현(#46)
whereami2048 May 15, 2024
35e9fbf
feat: 역량 키워드 등록 API 스펙 정의(#46)
whereami2048 May 15, 2024
27f2d6f
feat: 애플리케이션 계층 역량 키워드 등록 로직 작성(#46)
whereami2048 May 15, 2024
333d0f2
feat: 역량 키워드 중복 예외 처리 구현(#46)
whereami2048 May 15, 2024
0cbea5a
refactor: 유저 반환 방식 변경(#46)
whereami2048 May 15, 2024
509df7c
test: 역량 키워드 등록 API 테스트 코드 작성(#46)
whereami2048 May 15, 2024
ed6d3c4
refactor: 역량 키워드 생성 DTO 클래스 명 변경(#46)
whereami2048 May 15, 2024
e853e77
refactor: 태그, 역량 키워드 애그리거트 분리(#46)
whereami2048 May 15, 2024
35635fd
refactor: Infra 모듈 태그, 역량 키워드 도메인 분리(#46)
whereami2048 May 15, 2024
cf8109b
refactor: 역량 키워드 저장 로직 리팩토링(#46)
whereami2048 May 15, 2024
66edd75
refactor: 생성 역량 키워드 id 반환 코드 리팩토링(#46)
whereami2048 May 15, 2024
a254623
chore: JPAEntity Id 변수명 변경(#46)
whereami2048 May 15, 2024
4104a9b
chore: 변수명 변경에 따른 get 함수명 변경(#46)
whereami2048 May 15, 2024
edc365b
refactor: 태그 저장 로직 리팩토링(#46)
whereami2048 May 15, 2024
9ecda89
chore: UserSecurityUtil 파일명 변경
whereami2048 May 15, 2024
579fc98
chore: UserSecurityUtil 파일명 변경(#46)
whereami2048 May 15, 2024
bcdee51
Merge branch 'develop' into feat/flight-46
whereami2048 May 15, 2024
8aaec6d
chore: 브랜치 충돌 해결(#46)
whereami2048 May 15, 2024
d10b2de
refactor: 역량 키워드 전체 조회 로직 리팩토링(#46)
whereami2048 May 15, 2024
398d260
refactor: 역량 키워드 이름 중복 예외 처리 리팩토링
whereami2048 May 15, 2024
46f2586
test: 역량 키워드 이름 중복 등록 예외 테스트 코드 추가(#46)
whereami2048 May 15, 2024
3bf4fcb
Merge branch 'feat/flight-46' of github.com:KUSITMS-29th-TEAM-B/Backe…
whereami2048 May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Api-Module/src/docs/asciidoc/StrongPoint.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[[StrongPoint-API]]
== Strong Point-API

[[CreateStrongPoint]]
=== 역량 키워드 등록 API

operation::StrongPointControllerTest/createStrongPointTest/[snippets='http-request,request-fields,http-response,response-fields']
1 change: 1 addition & 0 deletions Api-Module/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@

include::Auth.adoc[]
include::User.adoc[]
include::StrongPoint.adoc[]


Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package com.bamyanggang.apimodule.common
import org.springframework.security.core.context.SecurityContextHolder
import java.util.UUID

fun getAuthenticationPrincipal(): UUID {
return SecurityContextHolder.getContext().authentication.principal as UUID
fun getAuthenticationPrincipal(): UUID {
return SecurityContextHolder.getContext().authentication.principal as UUID
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.bamyanggang.apimodule.domain.strongpoint.application.dto

import java.util.*

class CreateStrongPoint {
data class Request(
val name: String,
)

data class Response(
val id: UUID,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.bamyanggang.apimodule.domain.strongpoint.application.exception

import com.bamyanggang.commonmodule.exception.CustomException
import org.springframework.http.HttpStatus
import org.springframework.http.HttpStatusCode

sealed class StrongPointException(
errorCode: Int,
httpStatusCode: HttpStatusCode,
message: String,
) : CustomException(CODE_PREFIX, errorCode, httpStatusCode , message) {

class DuplicatedStrongPointName(message: String = "역량 키워드 이름이 중복됩니다.") :
StrongPointException(errorCode = 1, httpStatusCode = HttpStatus.BAD_REQUEST, message = message)

companion object {
const val CODE_PREFIX = "STRONG_POINT"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.bamyanggang.apimodule.domain.strongpoint.application.service

import com.bamyanggang.apimodule.common.getAuthenticationPrincipal
import com.bamyanggang.apimodule.domain.strongpoint.application.dto.CreateStrongPoint
import com.bamyanggang.apimodule.domain.strongpoint.application.exception.StrongPointException
import com.bamyanggang.domainmodule.domain.strongpoint.aggregate.StrongPoint
import com.bamyanggang.domainmodule.domain.strongpoint.service.StrongPointAppender
import com.bamyanggang.domainmodule.domain.strongpoint.service.StrongPointReader
import org.springframework.stereotype.Service

@Service
class StrongPointCreateService(
val strongPointAppender: StrongPointAppender,
val strongPointReader: StrongPointReader,
) {
fun createStrongPoint(request: CreateStrongPoint.Request): CreateStrongPoint.Response {
return getAuthenticationPrincipal()
.also {
val userStrongPoints = strongPointReader.findAllByUserId(it)
validateDuplicatedName(userStrongPoints, request.name)
}.let {
val newStrongPointId = strongPointAppender.appendStrongPoint(request.name, it)
CreateStrongPoint.Response(newStrongPointId)
}
}

private fun validateDuplicatedName(userStrongPoints: List<StrongPoint>, name: String) {
userStrongPoints.forEach {
if (name == it.name) {
throw StrongPointException.DuplicatedStrongPointName()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.bamyanggang.apimodule.domain.strongpoint.presentation

object StrongPointApi {
const val BASE_URL = "/api/strong-points"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.bamyanggang.apimodule.domain.strongpoint.presentation

import com.bamyanggang.apimodule.domain.strongpoint.application.dto.CreateStrongPoint
import com.bamyanggang.apimodule.domain.strongpoint.application.service.StrongPointCreateService
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RestController

@RestController
class StrongPointController(
private val strongPointCreateService: StrongPointCreateService,
) {
@PostMapping(StrongPointApi.BASE_URL)
fun createStrongPoint(@RequestBody request: CreateStrongPoint.Request): CreateStrongPoint.Response {
return strongPointCreateService.createStrongPoint(request)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.bamyanggang.apimodule.domain.strongpoint.presentation

import com.bamyanggang.apimodule.BaseRestDocsTest
import com.bamyanggang.apimodule.domain.strongpoint.application.dto.CreateStrongPoint
import com.bamyanggang.commonmodule.fixture.generateFixture
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import org.mockito.BDDMockito.given
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.mockmvc.RestDocumentationRequestBuilders
import org.springframework.restdocs.payload.PayloadDocumentation.*
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status

@WebMvcTest(StrongPointController::class)
class StrongPointControllerTest : BaseRestDocsTest() {

@MockBean
private lateinit var strongPointController: StrongPointController

@Test
@DisplayName("역량 키워드를 저장한 뒤 생성된 역량 키워드 ID를 반환한다.")
fun createStrongPointTest() {
val createStrongPoint: CreateStrongPoint.Request = generateFixture()
val createStrongPointResponse: CreateStrongPoint.Response = generateFixture()

given(strongPointController.createStrongPoint(createStrongPoint)).willReturn(createStrongPointResponse)

val request = RestDocumentationRequestBuilders.post(StrongPointApi.BASE_URL)
.contentType(MediaType.APPLICATION_JSON_VALUE)
.content(objectMapper.writeValueAsString(createStrongPoint))

val result = mockMvc.perform(request)

result.andExpect(status().isOk)
.andDo(
resultHandler.document(
requestFields(
fieldWithPath("name").description("역량 키워드 이름"),
),
responseFields(
fieldWithPath("id").description("생성된 역량 키워드 id"),
)
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.bamyanggang.domainmodule.domain.experience.repository

import com.bamyanggang.domainmodule.domain.strongpoint.aggregate.StrongPoint
import java.util.*

interface StrongPointRepository {
fun save(newStrongPoint: StrongPoint): UUID
fun findAllByUserId(userId: UUID): List<StrongPoint>
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.bamyanggang.domainmodule.domain.experience.aggregate
package com.bamyanggang.domainmodule.domain.strongpoint.aggregate

import com.bamyanggang.domainmodule.common.entity.AggregateRoot
import com.bamyanggang.domainmodule.common.entity.DomainEntity
import com.example.uuid.UuidCreator
import java.util.*

data class StrongPoint(
override val id: UUID = UuidCreator.create(),
val name : String,
val userId : UUID?,
) : AggregateRoot{
) : DomainEntity{
companion object {
fun create(name: String, userId: UUID?): StrongPoint {
return StrongPoint(UuidCreator.create(), name, userId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.bamyanggang.domainmodule.domain.strongpoint.repository

interface StrongPointRepository {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.bamyanggang.domainmodule.domain.strongpoint.service

import com.bamyanggang.domainmodule.domain.experience.repository.StrongPointRepository
import com.bamyanggang.domainmodule.domain.strongpoint.aggregate.StrongPoint
import org.springframework.stereotype.Service
import java.util.*

@Service
class StrongPointAppender(
private val strongPointRepository: StrongPointRepository
) {
fun appendStrongPoint(name: String, userId: UUID): UUID {
return StrongPoint.create(name, userId).let {
strongPointRepository.save(it)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.bamyanggang.domainmodule.domain.strongpoint.service

import com.bamyanggang.domainmodule.domain.experience.repository.StrongPointRepository
import com.bamyanggang.domainmodule.domain.strongpoint.aggregate.StrongPoint
import org.springframework.stereotype.Service
import java.util.*

@Service
class StrongPointReader(
private val strongPointRepository: StrongPointRepository
) {
fun findAllByUserId(userId: UUID): List<StrongPoint> {
return strongPointRepository.findAllByUserId(userId)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.bamyanggang.domainmodule.domain.experience.aggregate
package com.bamyanggang.domainmodule.domain.tag.aggregate

import com.bamyanggang.domainmodule.common.entity.DomainEntity
import com.example.uuid.UuidCreator
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.bamyanggang.persistence.experience;

import com.bamyanggang.persistence.experience.jpa.repository.ExperienceJpaRepository;
import com.bamyanggang.persistence.experience.mapper.ExperienceMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class ExperienceRepositoryImpl {
private final ExperienceJpaRepository experienceJpaRepository;
private final ExperienceMapper experienceMapper;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class ExperienceContentJpaEntity {
@Id
@Column(name = "experience_content_id")
private UUID id;
private UUID experienceContentId;

@Column(columnDefinition = "TEXT")
private String question;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class ExperienceJpaEntity{
@Id
@Column(name = "experience_id")
private UUID id;
private UUID experienceId;

private String title;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bamyanggang.persistence.experience.jpa.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
Expand All @@ -11,7 +12,8 @@
@Table(name = "experience_strong_point")
public class ExperienceStrongPointJpaEntity {
@Id
private UUID id;
@Column(name = "experience_strong_point_id")
private UUID experienceStrongPointId;

private UUID experienceId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class ExperienceTagJpaEntity {
@Id
@Column(name = "experience_tag_id")
private UUID id;
private UUID experienceTagId;

private UUID experienceId;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.bamyanggang.persistence.experience.mapper;

import com.bamyanggang.domainmodule.domain.experience.aggregate.ExperienceContent;
import com.bamyanggang.persistence.experience.jpa.entity.ExperienceContentJpaEntity;
import org.springframework.stereotype.Component;

@Component
class ExperienceContentMapper {
public ExperienceContentJpaEntity toJpaEntity(ExperienceContent experienceContent) {
return ExperienceContentJpaEntity.of(
experienceContent.getId(),
experienceContent.getQuestion(),
experienceContent.getAnswer(),
experienceContent.getExperienceId());
}

public ExperienceContent toDomainEntity(ExperienceContentJpaEntity experienceContentJpaEntity) {
return ExperienceContent.Companion.toDomain(
experienceContentJpaEntity.getExperienceContentId(),
experienceContentJpaEntity.getQuestion(),
experienceContentJpaEntity.getAnswer(),
experienceContentJpaEntity.getExperienceId());
}
}

This file was deleted.

Loading
Loading