From 2c24bb843ed98374f7853a3153efd41f88fa18a3 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 8 Apr 2024 16:48:13 +0900 Subject: [PATCH 01/12] =?UTF-8?q?:memo:=20EnvironmentRepository=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../output/persistence/repository/EnvironmentRepository.kt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/repository/EnvironmentRepository.kt diff --git a/src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/repository/EnvironmentRepository.kt b/src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/repository/EnvironmentRepository.kt new file mode 100644 index 00000000..c0549224 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/repository/EnvironmentRepository.kt @@ -0,0 +1,6 @@ +package andreas311.miso.domain.environment.adapter.output.persistence.repository + +import andreas311.miso.domain.environment.adapter.output.persistence.entity.EnvironmentEntity +import org.springframework.data.repository.CrudRepository + +interface EnvironmentRepository : CrudRepository \ No newline at end of file From c17b6f8f323ae783d21003cfe5fb024c43b95708 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 8 Apr 2024 16:48:35 +0900 Subject: [PATCH 02/12] =?UTF-8?q?:memo:=20EnvironmentMapper=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20=EB=B0=8F=20toEntity,=20toDomain=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/mapper/EnvironmentMapper.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/mapper/EnvironmentMapper.kt diff --git a/src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/mapper/EnvironmentMapper.kt b/src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/mapper/EnvironmentMapper.kt new file mode 100644 index 00000000..221c5139 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/mapper/EnvironmentMapper.kt @@ -0,0 +1,26 @@ +package andreas311.miso.domain.environment.adapter.output.persistence.mapper + +import andreas311.miso.domain.environment.adapter.output.persistence.entity.EnvironmentEntity +import andreas311.miso.domain.environment.domain.Environment +import org.springframework.stereotype.Component + +@Component +class EnvironmentMapper { + infix fun toEntity(domain: Environment): EnvironmentEntity = + EnvironmentEntity( + id = domain.id, + title = domain.title, + content = domain.content, + imageUrl = domain.imageUrl + ) + + infix fun toDomain(entity: EnvironmentEntity?): Environment? = + entity?.let { + Environment( + id = entity.id, + title = entity.title, + content = entity.content, + imageUrl = entity.imageUrl + ) + } +} \ No newline at end of file From e34d43321e1bb8124f237a823d6baad4778f4084 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 8 Apr 2024 16:49:20 +0900 Subject: [PATCH 03/12] =?UTF-8?q?:memo:=20EnvironmentEntity=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/entity/EnvironmentEntity.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/entity/EnvironmentEntity.kt diff --git a/src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/entity/EnvironmentEntity.kt b/src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/entity/EnvironmentEntity.kt new file mode 100644 index 00000000..33e0320e --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/entity/EnvironmentEntity.kt @@ -0,0 +1,21 @@ +package andreas311.miso.domain.environment.adapter.output.persistence.entity + +import javax.persistence.* + +@Entity +@Table(name = "environment") +data class EnvironmentEntity( + @Id + @Column(name = "environment_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long, + + @Column(name = "title", nullable = false) + val title: String, + + @Column(name = "content", nullable = false, length = 10000) + val content: String, + + @Column(name = "imageUrl", nullable = true) + val imageUrl: String?, +) \ No newline at end of file From 679e4debe7cb6e738e3ad4c05584c5f20947accb Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 8 Apr 2024 16:49:40 +0900 Subject: [PATCH 04/12] =?UTF-8?q?:memo:=20EnvironmentDataMapper=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20=EB=B0=8F=20toDto=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/input/mapper/EnvironmentDataMapper.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/environment/adapter/input/mapper/EnvironmentDataMapper.kt diff --git a/src/main/kotlin/andreas311/miso/domain/environment/adapter/input/mapper/EnvironmentDataMapper.kt b/src/main/kotlin/andreas311/miso/domain/environment/adapter/input/mapper/EnvironmentDataMapper.kt new file mode 100644 index 00000000..1a25e4ea --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/environment/adapter/input/mapper/EnvironmentDataMapper.kt @@ -0,0 +1,14 @@ +package andreas311.miso.domain.environment.adapter.input.mapper + +import andreas311.miso.domain.environment.adapter.input.data.request.CreateEnvironmentRequest +import andreas311.miso.domain.environment.application.port.input.dto.CreateEnvironmentDto +import org.springframework.stereotype.Component + +@Component +class EnvironmentDataMapper { + infix fun toDto(createEnvironmentRequest: CreateEnvironmentRequest): CreateEnvironmentDto = + CreateEnvironmentDto( + title = createEnvironmentRequest.title, + content = createEnvironmentRequest.content + ) +} \ No newline at end of file From bdb61a2dc6e79754da82f192ba71ae6876d3997f Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 8 Apr 2024 16:49:57 +0900 Subject: [PATCH 05/12] =?UTF-8?q?:memo:=20CommandEnvironmentPort=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20=EB=B0=8F=20saveEnvironment=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/port/output/CommandEnvironmentPort.kt | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/environment/application/port/output/CommandEnvironmentPort.kt diff --git a/src/main/kotlin/andreas311/miso/domain/environment/application/port/output/CommandEnvironmentPort.kt b/src/main/kotlin/andreas311/miso/domain/environment/application/port/output/CommandEnvironmentPort.kt new file mode 100644 index 00000000..3868699b --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/environment/application/port/output/CommandEnvironmentPort.kt @@ -0,0 +1,7 @@ +package andreas311.miso.domain.environment.application.port.output + +import andreas311.miso.domain.environment.domain.Environment + +interface CommandEnvironmentPort { + fun saveEnvironment(environment: Environment): Environment +} \ No newline at end of file From 135af0fb3745bba011d27888e0fdb9da7e9a70bd Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 8 Apr 2024 16:50:10 +0900 Subject: [PATCH 06/12] =?UTF-8?q?:memo:=20CommandEnvironmentPersistenceAda?= =?UTF-8?q?pter=20=EA=B5=AC=ED=98=84=20=EB=B0=8F=20saveEnvironment=20?= =?UTF-8?q?=ED=95=A8=EC=88=98=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CommandEnvironmentPersistenceAdapter.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/CommandEnvironmentPersistenceAdapter.kt diff --git a/src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/CommandEnvironmentPersistenceAdapter.kt b/src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/CommandEnvironmentPersistenceAdapter.kt new file mode 100644 index 00000000..c882ae8a --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/environment/adapter/output/persistence/CommandEnvironmentPersistenceAdapter.kt @@ -0,0 +1,18 @@ +package andreas311.miso.domain.environment.adapter.output.persistence + +import andreas311.miso.domain.environment.adapter.output.persistence.mapper.EnvironmentMapper +import andreas311.miso.domain.environment.adapter.output.persistence.repository.EnvironmentRepository +import andreas311.miso.domain.environment.application.port.output.CommandEnvironmentPort +import andreas311.miso.domain.environment.domain.Environment +import org.springframework.stereotype.Component + +@Component +class CommandEnvironmentPersistenceAdapter( + private val environmentMapper: EnvironmentMapper, + private val environmentRepository: EnvironmentRepository +) : CommandEnvironmentPort { + override fun saveEnvironment(environment: Environment): Environment { + val environmentEntity = environmentRepository.save(environmentMapper toEntity environment) + return environmentMapper.toDomain(environmentEntity)!! + } +} \ No newline at end of file From 79b99c12f4663a3d7072d1c41fd9f1b4d6b4bde7 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 8 Apr 2024 16:52:02 +0900 Subject: [PATCH 07/12] =?UTF-8?q?:memo:=20CreateEnvironmentDto=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/port/input/dto/CreateEnvironmentDto.kt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/environment/application/port/input/dto/CreateEnvironmentDto.kt diff --git a/src/main/kotlin/andreas311/miso/domain/environment/application/port/input/dto/CreateEnvironmentDto.kt b/src/main/kotlin/andreas311/miso/domain/environment/application/port/input/dto/CreateEnvironmentDto.kt new file mode 100644 index 00000000..bba14481 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/environment/application/port/input/dto/CreateEnvironmentDto.kt @@ -0,0 +1,6 @@ +package andreas311.miso.domain.environment.application.port.input.dto + +data class CreateEnvironmentDto( + val title: String, + val content: String, +) From 4f6d1f00259a43098be5a241065e806b77ba3754 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 8 Apr 2024 16:52:11 +0900 Subject: [PATCH 08/12] =?UTF-8?q?:memo:=20CreateEnvironmentRequest=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../input/data/request/CreateEnvironmentRequest.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/environment/adapter/input/data/request/CreateEnvironmentRequest.kt diff --git a/src/main/kotlin/andreas311/miso/domain/environment/adapter/input/data/request/CreateEnvironmentRequest.kt b/src/main/kotlin/andreas311/miso/domain/environment/adapter/input/data/request/CreateEnvironmentRequest.kt new file mode 100644 index 00000000..6059c92a --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/environment/adapter/input/data/request/CreateEnvironmentRequest.kt @@ -0,0 +1,10 @@ +package andreas311.miso.domain.environment.adapter.input.data.request + +import javax.validation.constraints.NotNull + +data class CreateEnvironmentRequest( + @field:NotNull + val title: String, + @field:NotNull + val content: String, +) From 51cae8761dd5ea5dcf5e284b16e87a5297d93b16 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 8 Apr 2024 16:52:20 +0900 Subject: [PATCH 09/12] =?UTF-8?q?:memo:=20Environment=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../miso/domain/environment/domain/Environment.kt | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/environment/domain/Environment.kt diff --git a/src/main/kotlin/andreas311/miso/domain/environment/domain/Environment.kt b/src/main/kotlin/andreas311/miso/domain/environment/domain/Environment.kt new file mode 100644 index 00000000..0e1f552d --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/environment/domain/Environment.kt @@ -0,0 +1,8 @@ +package andreas311.miso.domain.environment.domain + +data class Environment( + val id: Long, + val title: String, + val content: String, + val imageUrl: String?, +) From f1ee48cd9dfb4a801106288279ddc857934adad5 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 8 Apr 2024 16:52:41 +0900 Subject: [PATCH 10/12] =?UTF-8?q?:sparkles:=20=ED=99=98=EA=B2=BD=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EA=B8=80=20=EC=83=9D=EC=84=B1=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../port/input/CreateEnvironmentUseCase.kt | 8 +++++ .../service/CreateEnvironmentService.kt | 31 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/environment/application/port/input/CreateEnvironmentUseCase.kt create mode 100644 src/main/kotlin/andreas311/miso/domain/environment/application/service/CreateEnvironmentService.kt diff --git a/src/main/kotlin/andreas311/miso/domain/environment/application/port/input/CreateEnvironmentUseCase.kt b/src/main/kotlin/andreas311/miso/domain/environment/application/port/input/CreateEnvironmentUseCase.kt new file mode 100644 index 00000000..8b5232f8 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/environment/application/port/input/CreateEnvironmentUseCase.kt @@ -0,0 +1,8 @@ +package andreas311.miso.domain.environment.application.port.input + +import andreas311.miso.domain.environment.application.port.input.dto.CreateEnvironmentDto +import org.springframework.web.multipart.MultipartFile + +interface CreateEnvironmentUseCase { + fun execute(createEnvironmentDto: CreateEnvironmentDto, multipartFile: MultipartFile?) +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/environment/application/service/CreateEnvironmentService.kt b/src/main/kotlin/andreas311/miso/domain/environment/application/service/CreateEnvironmentService.kt new file mode 100644 index 00000000..7e077726 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/environment/application/service/CreateEnvironmentService.kt @@ -0,0 +1,31 @@ +package andreas311.miso.domain.environment.application.service + +import andreas311.miso.common.annotation.RollbackService +import andreas311.miso.domain.environment.application.port.input.CreateEnvironmentUseCase +import andreas311.miso.domain.environment.application.port.input.dto.CreateEnvironmentDto +import andreas311.miso.domain.environment.application.port.output.CommandEnvironmentPort +import andreas311.miso.domain.environment.domain.Environment +import andreas311.miso.thirdparty.aws.s3.util.S3Util +import org.springframework.web.multipart.MultipartFile + +@RollbackService +class CreateEnvironmentService( + private val s3Util: S3Util, + private val commandEnvironmentPort: CommandEnvironmentPort +) : CreateEnvironmentUseCase { + override fun execute(createEnvironmentDto: CreateEnvironmentDto, multipartFile: MultipartFile?) { + val imageUrl = + if (multipartFile != null) { + s3Util.execute(multipartFile) + } else null + + commandEnvironmentPort.saveEnvironment( + Environment( + id = 0L, + title = createEnvironmentDto.title, + content = createEnvironmentDto.content, + imageUrl = imageUrl + ) + ) + } +} \ No newline at end of file From a294939f94cb52a255a1c051386294d68a377601 Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 8 Apr 2024 16:52:54 +0900 Subject: [PATCH 11/12] =?UTF-8?q?:sparkles:=20EnvironmentAdapter=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20=EB=B0=8F=20=ED=99=98=EA=B2=BD=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EA=B8=80=20=EC=83=9D=EC=84=B1=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?api=20=EA=B4=80=EB=A0=A8=20=ED=95=A8=EC=88=98=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/input/EnvironmentAdapter.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/kotlin/andreas311/miso/domain/environment/adapter/input/EnvironmentAdapter.kt diff --git a/src/main/kotlin/andreas311/miso/domain/environment/adapter/input/EnvironmentAdapter.kt b/src/main/kotlin/andreas311/miso/domain/environment/adapter/input/EnvironmentAdapter.kt new file mode 100644 index 00000000..4f402d0b --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/environment/adapter/input/EnvironmentAdapter.kt @@ -0,0 +1,26 @@ +package andreas311.miso.domain.environment.adapter.input + +import andreas311.miso.common.annotation.RequestController +import andreas311.miso.domain.environment.adapter.input.data.request.CreateEnvironmentRequest +import andreas311.miso.domain.environment.adapter.input.mapper.EnvironmentDataMapper +import andreas311.miso.domain.environment.application.port.input.CreateEnvironmentUseCase +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestPart +import org.springframework.web.multipart.MultipartFile +import javax.validation.Valid + +@RequestController("/environment") +class EnvironmentAdapter( + private val environmentDataMapper: EnvironmentDataMapper, + private val createEnvironmentUseCase: CreateEnvironmentUseCase +) { + @PostMapping + fun create( + @RequestPart(value = "file") multipartFile: MultipartFile?, + @RequestPart(value = "environment") @Valid createEnvironmentRequest: CreateEnvironmentRequest + ): ResponseEntity = + createEnvironmentUseCase.execute(environmentDataMapper toDto createEnvironmentRequest, multipartFile) + .let { ResponseEntity.status(HttpStatus.CREATED).build() } +} \ No newline at end of file From dbe6d7c82dcfe970083aecec28866593a917e5ce Mon Sep 17 00:00:00 2001 From: uuuuuuuk Date: Mon, 8 Apr 2024 16:53:19 +0900 Subject: [PATCH 12/12] =?UTF-8?q?:memo:=20SecurityConfig=20=EC=97=90=20?= =?UTF-8?q?=ED=99=98=EA=B2=BD=20=EC=A0=95=EB=B3=B4=20=EA=B8=80=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=ED=95=98=EA=B8=B0=20api=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../andreas311/miso/global/security/config/SecurityConfig.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/andreas311/miso/global/security/config/SecurityConfig.kt b/src/main/kotlin/andreas311/miso/global/security/config/SecurityConfig.kt index 6657ee5b..02fadf43 100644 --- a/src/main/kotlin/andreas311/miso/global/security/config/SecurityConfig.kt +++ b/src/main/kotlin/andreas311/miso/global/security/config/SecurityConfig.kt @@ -77,6 +77,7 @@ class SecurityConfig( .antMatchers(HttpMethod.GET, "/notification/{id}").authenticated() .antMatchers(HttpMethod.GET, "/environment").authenticated() + .antMatchers(HttpMethod.POST, "/environment").hasAuthority("ROLE_ADMIN") .anyRequest().denyAll() .and()