diff --git a/src/main/kotlin/andreas311/miso/domain/auth/adapter/output/persistence/QueryRefreshTokenPersistenceAdapter.kt b/src/main/kotlin/andreas311/miso/domain/auth/adapter/output/persistence/QueryRefreshTokenPersistenceAdapter.kt index b1b8a322..94298ca8 100644 --- a/src/main/kotlin/andreas311/miso/domain/auth/adapter/output/persistence/QueryRefreshTokenPersistenceAdapter.kt +++ b/src/main/kotlin/andreas311/miso/domain/auth/adapter/output/persistence/QueryRefreshTokenPersistenceAdapter.kt @@ -15,11 +15,11 @@ class QueryRefreshTokenPersistenceAdapter( ) : QueryRefreshTokenPort { override fun findByUserIdOrNull(userId: UUID): RefreshToken? { val refreshTokenEntity = refreshTokenRepository.findByUserId(userId) - return refreshTokenMapper.toDomain(refreshTokenEntity) + return refreshTokenMapper toDomain refreshTokenEntity } override fun findByRefreshTokenOrNull(refreshToken: String): RefreshToken? { val refreshTokenEntity = refreshTokenRepository.findByIdOrNull(refreshToken) - return refreshTokenMapper.toDomain(refreshTokenEntity) + return refreshTokenMapper toDomain refreshTokenEntity } } \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/email/adapter/output/persistence/CommandEmailPersistenceAdapter.kt b/src/main/kotlin/andreas311/miso/domain/email/adapter/output/persistence/CommandEmailPersistenceAdapter.kt index 9aab0373..01c67260 100644 --- a/src/main/kotlin/andreas311/miso/domain/email/adapter/output/persistence/CommandEmailPersistenceAdapter.kt +++ b/src/main/kotlin/andreas311/miso/domain/email/adapter/output/persistence/CommandEmailPersistenceAdapter.kt @@ -12,7 +12,7 @@ class CommandEmailPersistenceAdapter( private val emailRepository: EmailRepository ) : CommandEmailPort { override fun saveEmail(email: Email): Email { - val emailEntity = emailRepository.save(emailMapper.toEntity(email)) + val emailEntity = emailRepository.save(emailMapper toEntity email) return emailMapper.toDomain(emailEntity)!! } diff --git a/src/main/kotlin/andreas311/miso/domain/email/adapter/output/persistence/QueryEmailPersistenceAdapter.kt b/src/main/kotlin/andreas311/miso/domain/email/adapter/output/persistence/QueryEmailPersistenceAdapter.kt index f30cdaab..d8aad8db 100644 --- a/src/main/kotlin/andreas311/miso/domain/email/adapter/output/persistence/QueryEmailPersistenceAdapter.kt +++ b/src/main/kotlin/andreas311/miso/domain/email/adapter/output/persistence/QueryEmailPersistenceAdapter.kt @@ -13,7 +13,7 @@ class QueryEmailPersistenceAdapter( ) : QueryEmailPort { override fun findByEmailOrNull(email: String): Email? { val emailEntity = emailRepository.findByEmail(email) - return emailMapper.toDomain(emailEntity) + return emailMapper toDomain emailEntity } override fun existsByEmail(email: String): Boolean = @@ -21,6 +21,6 @@ class QueryEmailPersistenceAdapter( override fun findByRandomKeyOrNull(randomKey: String): Email? { val emailEntity = emailRepository.findByRandomKey(randomKey) - return emailMapper.toDomain(emailEntity) + return emailMapper toDomain emailEntity } } \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/email/adapter/output/persistence/mapper/EmailMapper.kt b/src/main/kotlin/andreas311/miso/domain/email/adapter/output/persistence/mapper/EmailMapper.kt index 5181bc85..65ea978a 100644 --- a/src/main/kotlin/andreas311/miso/domain/email/adapter/output/persistence/mapper/EmailMapper.kt +++ b/src/main/kotlin/andreas311/miso/domain/email/adapter/output/persistence/mapper/EmailMapper.kt @@ -6,7 +6,7 @@ import org.springframework.stereotype.Component @Component class EmailMapper { - fun toEntity(domain: Email): EmailEntity = + infix fun toEntity(domain: Email): EmailEntity = EmailEntity( id = domain.id, email = domain.email, @@ -14,7 +14,7 @@ class EmailMapper { authentication = domain.authentication ) - fun toDomain(entity: EmailEntity?): Email? = + infix fun toDomain(entity: EmailEntity?): Email? = entity?.let { Email( id = entity.id, diff --git a/src/main/kotlin/andreas311/miso/domain/inquiry/adapter/output/persistence/QueryInquiryPersistenceAdapter.kt b/src/main/kotlin/andreas311/miso/domain/inquiry/adapter/output/persistence/QueryInquiryPersistenceAdapter.kt index 468656a0..da28a6a3 100644 --- a/src/main/kotlin/andreas311/miso/domain/inquiry/adapter/output/persistence/QueryInquiryPersistenceAdapter.kt +++ b/src/main/kotlin/andreas311/miso/domain/inquiry/adapter/output/persistence/QueryInquiryPersistenceAdapter.kt @@ -18,7 +18,7 @@ class QueryInquiryPersistenceAdapter( ) : QueryInquiryPort { override fun findByIdOrNull(id: Long): Inquiry? { val inquiryEntity = inquiryRepository.findByIdOrNull(id) - return inquiryMapper.toDomain(inquiryEntity) + return inquiryMapper toDomain inquiryEntity } override fun findAll(): List { @@ -27,7 +27,7 @@ class QueryInquiryPersistenceAdapter( } override fun findAllByUser(user: User): List { - val inquiryList = inquiryRepository.findByUserOrderByCreatedDateDesc(userMapper.toEntity(user)) + val inquiryList = inquiryRepository.findByUserOrderByCreatedDateDesc(userMapper toEntity user) return inquiryList.map { inquiryMapper.toDomain(it)!! } } @@ -37,7 +37,7 @@ class QueryInquiryPersistenceAdapter( } override fun findAllByUserAndInquiryStatus(user: User, inquiryStatus: InquiryStatus): List { - val inquiryList = inquiryRepository.findByUserAndInquiryStatusOrderByCreatedDateDesc(userMapper.toEntity(user), inquiryStatus) + val inquiryList = inquiryRepository.findByUserAndInquiryStatusOrderByCreatedDateDesc(userMapper toEntity user, inquiryStatus) return inquiryList.map { inquiryMapper.toDomain(it)!! } } } \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/inquiry/adapter/output/persistence/mapper/InquiryMapper.kt b/src/main/kotlin/andreas311/miso/domain/inquiry/adapter/output/persistence/mapper/InquiryMapper.kt index 88c5b6c5..1e3474bd 100644 --- a/src/main/kotlin/andreas311/miso/domain/inquiry/adapter/output/persistence/mapper/InquiryMapper.kt +++ b/src/main/kotlin/andreas311/miso/domain/inquiry/adapter/output/persistence/mapper/InquiryMapper.kt @@ -16,7 +16,7 @@ class InquiryMapper( content = domain.content, imageUrl = domain.imageUrl, inquiryStatus = domain.inquiryStatus, - user = userMapper.toEntity(domain.user), + user = userMapper toEntity domain.user, createdDate = domain.createdDate ) diff --git a/src/main/kotlin/andreas311/miso/domain/item/adapter/output/persistence/QueryItemPersistenceAdapter.kt b/src/main/kotlin/andreas311/miso/domain/item/adapter/output/persistence/QueryItemPersistenceAdapter.kt index abfcac6f..22d99c2d 100644 --- a/src/main/kotlin/andreas311/miso/domain/item/adapter/output/persistence/QueryItemPersistenceAdapter.kt +++ b/src/main/kotlin/andreas311/miso/domain/item/adapter/output/persistence/QueryItemPersistenceAdapter.kt @@ -14,7 +14,7 @@ class QueryItemPersistenceAdapter( ) : QueryItemPort { override fun findByIdOrNull(id: Long): Item? { val itemEntity = itemRepository.findByIdOrNull(id) - return itemMapper.toDomain(itemEntity) + return itemMapper toDomain itemEntity } override fun findAll(): List { diff --git a/src/main/kotlin/andreas311/miso/domain/notification/adapter/output/persistence/CommandNotificationPersistenceAdapter.kt b/src/main/kotlin/andreas311/miso/domain/notification/adapter/output/persistence/CommandNotificationPersistenceAdapter.kt index be7157d1..bb64caa2 100644 --- a/src/main/kotlin/andreas311/miso/domain/notification/adapter/output/persistence/CommandNotificationPersistenceAdapter.kt +++ b/src/main/kotlin/andreas311/miso/domain/notification/adapter/output/persistence/CommandNotificationPersistenceAdapter.kt @@ -12,7 +12,7 @@ class CommandNotificationPersistenceAdapter( private val notificationRepository: NotificationRepository ) : CommandNotificationPort { override fun saveNotification(notification: Notification): Notification { - val notificationEntity = notificationRepository.save(notificationMapper.toEntity(notification)) + val notificationEntity = notificationRepository.save(notificationMapper toEntity notification) return notificationMapper.toDomain(notificationEntity)!! } } \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/notification/adapter/output/persistence/QueryNotificationPersistenceAdapter.kt b/src/main/kotlin/andreas311/miso/domain/notification/adapter/output/persistence/QueryNotificationPersistenceAdapter.kt index 75a6a64c..bb492938 100644 --- a/src/main/kotlin/andreas311/miso/domain/notification/adapter/output/persistence/QueryNotificationPersistenceAdapter.kt +++ b/src/main/kotlin/andreas311/miso/domain/notification/adapter/output/persistence/QueryNotificationPersistenceAdapter.kt @@ -13,6 +13,6 @@ class QueryNotificationPersistenceAdapter( ) : QueryNotificationPort { override fun findByInquiryIdOrNull(id: Long): Notification? { val notificationEntity = notificationRepository.findByInquiryId(id) - return notificationMapper.toDomain(notificationEntity) + return notificationMapper toDomain notificationEntity } } \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/notification/adapter/output/persistence/mapper/NotificationMapper.kt b/src/main/kotlin/andreas311/miso/domain/notification/adapter/output/persistence/mapper/NotificationMapper.kt index ea1039e5..2cf21a39 100644 --- a/src/main/kotlin/andreas311/miso/domain/notification/adapter/output/persistence/mapper/NotificationMapper.kt +++ b/src/main/kotlin/andreas311/miso/domain/notification/adapter/output/persistence/mapper/NotificationMapper.kt @@ -15,8 +15,8 @@ class NotificationMapper( NotificationEntity( id = domain.id, answer = domain.answer, - user = userMapper.toEntity(domain.user), - inquiry = inquiryMapper.toEntity(domain.inquiry) + user = userMapper toEntity domain.user, + inquiry = inquiryMapper toEntity domain.inquiry ) infix fun toDomain(entity: NotificationEntity?): Notification? = diff --git a/src/main/kotlin/andreas311/miso/domain/purchase/adapter/output/persistence/QueryPurchasePersistenceAdapter.kt b/src/main/kotlin/andreas311/miso/domain/purchase/adapter/output/persistence/QueryPurchasePersistenceAdapter.kt index ef3cb2b7..da42aac5 100644 --- a/src/main/kotlin/andreas311/miso/domain/purchase/adapter/output/persistence/QueryPurchasePersistenceAdapter.kt +++ b/src/main/kotlin/andreas311/miso/domain/purchase/adapter/output/persistence/QueryPurchasePersistenceAdapter.kt @@ -15,7 +15,7 @@ class QueryPurchasePersistenceAdapter( private val purchaseRepository: PurchaseRepository ) : QueryPurchasePort { override fun findAllByUser(user: User): List { - val purchaseList = purchaseRepository.findAllByUserOrderByCreatedDateDesc(userMapper.toEntity(user)) + val purchaseList = purchaseRepository.findAllByUserOrderByCreatedDateDesc(userMapper toEntity user) return purchaseList.map { purchaseMapper.toDomain(it)!! } } } \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/purchase/adapter/output/persistence/mapper/PurchaseMapper.kt b/src/main/kotlin/andreas311/miso/domain/purchase/adapter/output/persistence/mapper/PurchaseMapper.kt index 1939eec4..fdb872e9 100644 --- a/src/main/kotlin/andreas311/miso/domain/purchase/adapter/output/persistence/mapper/PurchaseMapper.kt +++ b/src/main/kotlin/andreas311/miso/domain/purchase/adapter/output/persistence/mapper/PurchaseMapper.kt @@ -14,8 +14,8 @@ class PurchaseMapper( infix fun toEntity(domain: Purchase): PurchaseEntity = PurchaseEntity( id = domain.id, - user = userMapper.toEntity(domain.user), - item = itemMapper.toEntity(domain.item), + user = userMapper toEntity domain.user, + item = itemMapper toEntity domain.item, createdDate = domain.createdDate ) diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/RecyclablesAdapter.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/RecyclablesAdapter.kt new file mode 100644 index 00000000..87eb985d --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/RecyclablesAdapter.kt @@ -0,0 +1,26 @@ +package andreas311.miso.domain.recyclables.adapter.input + +import andreas311.miso.common.annotation.RequestController +import andreas311.miso.domain.recyclables.adapter.input.data.CreateRecyclablesRequest +import andreas311.miso.domain.recyclables.adapter.input.mapper.RecyclablesDataMapper +import andreas311.miso.domain.recyclables.application.port.input.CreateRecyclablesUseCase +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("/recyclables") +class RecyclablesAdapter( + private val recyclablesDataMapper: RecyclablesDataMapper, + private val createRecyclablesUseCase: CreateRecyclablesUseCase +) { + @PostMapping + fun execute( + @RequestPart(value = "file") multipartFile: MultipartFile?, + @RequestPart(value = "recyclables") @Valid createRecyclablesRequest: CreateRecyclablesRequest + ): ResponseEntity = + createRecyclablesUseCase.execute(recyclablesDataMapper toDto createRecyclablesRequest, multipartFile) + .let { ResponseEntity.status(HttpStatus.CREATED).build() } +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/data/CreateRecyclablesRequest.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/data/CreateRecyclablesRequest.kt new file mode 100644 index 00000000..ebf5e69f --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/data/CreateRecyclablesRequest.kt @@ -0,0 +1,21 @@ +package andreas311.miso.domain.recyclables.adapter.input.data + +import andreas311.miso.domain.recyclables.domain.RecyclablesType +import javax.validation.constraints.NotNull + +data class CreateRecyclablesRequest( + @field:NotNull + val title: String, + @field:NotNull + val subTitle: String, + @field:NotNull + val recycleMethod: String, + @field:NotNull + val recycleTip: String, + @field:NotNull + val recycleCaution: String, + @field:NotNull + val recyclablesType: RecyclablesType, + @field:NotNull + val recycleMark: String +) diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/mapper/RecyclablesDataMapper.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/mapper/RecyclablesDataMapper.kt new file mode 100644 index 00000000..611d5f62 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/input/mapper/RecyclablesDataMapper.kt @@ -0,0 +1,19 @@ +package andreas311.miso.domain.recyclables.adapter.input.mapper + +import andreas311.miso.domain.recyclables.adapter.input.data.CreateRecyclablesRequest +import andreas311.miso.domain.recyclables.application.port.input.dto.CreateRecyclablesDto +import org.springframework.stereotype.Component + +@Component +class RecyclablesDataMapper { + infix fun toDto(createRecyclablesRequest: CreateRecyclablesRequest): CreateRecyclablesDto = + CreateRecyclablesDto( + title = createRecyclablesRequest.title, + subTitle = createRecyclablesRequest.subTitle, + recycleMethod = createRecyclablesRequest.recycleMethod, + recycleTip = createRecyclablesRequest.recycleTip, + recycleCaution = createRecyclablesRequest.recycleCaution, + recyclablesType = createRecyclablesRequest.recyclablesType, + recycleMark = createRecyclablesRequest.recycleMark + ) +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/CommandRecyclablesPersistenceAdapter.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/CommandRecyclablesPersistenceAdapter.kt new file mode 100644 index 00000000..da0803d1 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/CommandRecyclablesPersistenceAdapter.kt @@ -0,0 +1,18 @@ +package andreas311.miso.domain.recyclables.adapter.output.persistence + +import andreas311.miso.domain.recyclables.adapter.output.persistence.mapper.RecyclablesMapper +import andreas311.miso.domain.recyclables.adapter.output.persistence.repository.RecyclablesRepository +import andreas311.miso.domain.recyclables.application.port.output.CommandRecyclablesPort +import andreas311.miso.domain.recyclables.domain.Recyclables +import org.springframework.stereotype.Component + +@Component +class CommandRecyclablesPersistenceAdapter( + private val recyclablesMapper: RecyclablesMapper, + private val recyclablesRepository: RecyclablesRepository +) : CommandRecyclablesPort { + override fun saveRecyclables(recyclables: Recyclables): Recyclables { + val recyclablesEntity = recyclablesRepository.save(recyclablesMapper toEntity recyclables) + return recyclablesMapper.toDomain(recyclablesEntity)!! + } +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/entity/RecyclablesEntity.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/entity/RecyclablesEntity.kt new file mode 100644 index 00000000..83a373fd --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/entity/RecyclablesEntity.kt @@ -0,0 +1,38 @@ +package andreas311.miso.domain.recyclables.adapter.output.persistence.entity + +import andreas311.miso.domain.recyclables.domain.RecyclablesType +import javax.persistence.* + +@Entity +@Table(name = "recyclables") +data class RecyclablesEntity( + @Id + @Column(name = "recyclables_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long, + + @Column(name = "title", nullable = false) + val title: String, + + @Column(name = "sub_title", nullable = false) + val subTitle: String, + + @Column(name = "recycle_method", nullable = false, length = 5000) + val recycleMethod: String, + + @Column(name = "recycle_tip", nullable = false, length = 5000) + val recycleTip: String, + + @Column(name = "recycle_caution", nullable = false, length = 5000) + val recycleCaution: String, + + @Column(name = "imageUrl", nullable = true) + val imageUrl: String?, + + @Enumerated(EnumType.STRING) + @Column(name = "recyclables_type", nullable = false) + val recyclablesType: RecyclablesType, + + @Column(name = "recycle_mark", nullable = false) + val recycleMark: String +) diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/mapper/RecyclablesMapper.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/mapper/RecyclablesMapper.kt new file mode 100644 index 00000000..11b525a2 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/mapper/RecyclablesMapper.kt @@ -0,0 +1,36 @@ +package andreas311.miso.domain.recyclables.adapter.output.persistence.mapper + +import andreas311.miso.domain.recyclables.adapter.output.persistence.entity.RecyclablesEntity +import andreas311.miso.domain.recyclables.domain.Recyclables +import org.springframework.stereotype.Component + +@Component +class RecyclablesMapper { + infix fun toEntity(domain: Recyclables): RecyclablesEntity = + RecyclablesEntity( + id = domain.id, + title = domain.title, + subTitle = domain.subTitle, + recycleMethod = domain.recycleMethod, + recycleTip = domain.recycleTip, + recycleCaution = domain.recycleCaution, + imageUrl = domain.imageUrl, + recyclablesType = domain.recyclablesType, + recycleMark = domain.recycleMark + ) + + infix fun toDomain(entity: RecyclablesEntity?): Recyclables? = + entity?.let { + Recyclables( + id = entity.id, + title = entity.title, + subTitle = entity.subTitle, + recycleMethod = entity.recycleMethod, + recycleTip = entity.recycleTip, + recycleCaution = entity.recycleCaution, + imageUrl = entity.imageUrl, + recyclablesType = entity.recyclablesType, + recycleMark = entity.recycleMark + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/repository/RecyclablesRepository.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/repository/RecyclablesRepository.kt new file mode 100644 index 00000000..430e4172 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/adapter/output/persistence/repository/RecyclablesRepository.kt @@ -0,0 +1,7 @@ +package andreas311.miso.domain.recyclables.adapter.output.persistence.repository + +import andreas311.miso.domain.recyclables.adapter.output.persistence.entity.RecyclablesEntity +import org.springframework.data.repository.CrudRepository + +interface RecyclablesRepository : CrudRepository { +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/CreateRecyclablesUseCase.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/CreateRecyclablesUseCase.kt new file mode 100644 index 00000000..bf4c96f8 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/CreateRecyclablesUseCase.kt @@ -0,0 +1,8 @@ +package andreas311.miso.domain.recyclables.application.port.input + +import andreas311.miso.domain.recyclables.application.port.input.dto.CreateRecyclablesDto +import org.springframework.web.multipart.MultipartFile + +interface CreateRecyclablesUseCase { + fun execute(createRecyclablesDto: CreateRecyclablesDto, multipartFile: MultipartFile?) +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/dto/CreateRecyclablesDto.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/dto/CreateRecyclablesDto.kt new file mode 100644 index 00000000..a87461da --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/input/dto/CreateRecyclablesDto.kt @@ -0,0 +1,13 @@ +package andreas311.miso.domain.recyclables.application.port.input.dto + +import andreas311.miso.domain.recyclables.domain.RecyclablesType + +data class CreateRecyclablesDto( + val title: String, + val subTitle: String, + val recycleMethod: String, + val recycleTip: String, + val recycleCaution: String, + val recyclablesType: RecyclablesType, + val recycleMark: String +) diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/output/CommandRecyclablesPort.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/output/CommandRecyclablesPort.kt new file mode 100644 index 00000000..cafc9bbf --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/application/port/output/CommandRecyclablesPort.kt @@ -0,0 +1,7 @@ +package andreas311.miso.domain.recyclables.application.port.output + +import andreas311.miso.domain.recyclables.domain.Recyclables + +interface CommandRecyclablesPort { + fun saveRecyclables(recyclables: Recyclables): Recyclables +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/CreateRecyclablesService.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/CreateRecyclablesService.kt new file mode 100644 index 00000000..f6f18676 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/application/service/CreateRecyclablesService.kt @@ -0,0 +1,36 @@ +package andreas311.miso.domain.recyclables.application.service + +import andreas311.miso.common.annotation.RollbackService +import andreas311.miso.domain.recyclables.application.port.input.CreateRecyclablesUseCase +import andreas311.miso.domain.recyclables.application.port.input.dto.CreateRecyclablesDto +import andreas311.miso.domain.recyclables.application.port.output.CommandRecyclablesPort +import andreas311.miso.domain.recyclables.domain.Recyclables +import andreas311.miso.thirdparty.aws.s3.util.S3Util +import org.springframework.web.multipart.MultipartFile + +@RollbackService +class CreateRecyclablesService( + private val s3Util: S3Util, + private val commandRecyclablesPort: CommandRecyclablesPort +) : CreateRecyclablesUseCase { + override fun execute(createRecyclablesDto: CreateRecyclablesDto, multipartFile: MultipartFile?) { + val imageUrl = + if (multipartFile != null) { + s3Util.execute(multipartFile) + } else null + + commandRecyclablesPort.saveRecyclables( + Recyclables( + id = 0L, + title = createRecyclablesDto.title, + subTitle = createRecyclablesDto.subTitle, + recycleMethod = createRecyclablesDto.recycleMethod, + recycleTip = createRecyclablesDto.recycleTip, + recycleCaution = createRecyclablesDto.recycleCaution, + imageUrl = imageUrl, + recyclablesType = createRecyclablesDto.recyclablesType, + recycleMark = createRecyclablesDto.recycleMark + ) + ) + } +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/domain/Recyclables.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/domain/Recyclables.kt new file mode 100644 index 00000000..695ff178 --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/domain/Recyclables.kt @@ -0,0 +1,13 @@ +package andreas311.miso.domain.recyclables.domain + +data class Recyclables( + val id: Long, + val title: String, + val subTitle: String, + val recycleMethod: String, + val recycleTip: String, + val recycleCaution: String, + val imageUrl: String?, + val recyclablesType: RecyclablesType, + val recycleMark: String +) diff --git a/src/main/kotlin/andreas311/miso/domain/recyclables/domain/RecyclablesType.kt b/src/main/kotlin/andreas311/miso/domain/recyclables/domain/RecyclablesType.kt new file mode 100644 index 00000000..dd7c1f4d --- /dev/null +++ b/src/main/kotlin/andreas311/miso/domain/recyclables/domain/RecyclablesType.kt @@ -0,0 +1,9 @@ +package andreas311.miso.domain.recyclables.domain + +enum class RecyclablesType { + BAG, BATTERY, CAN, CELL_PHONE, CLOTHES, + GENERAL_TRASH, GLASSES, LAPTOP, LDPE, + LIGHTER, MOUSE, PAPER, PAPER_PACK, + PET, PLASTIC, SHOES, TOOTHBRUSH, + VINYL +} \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/user/adapter/output/persistence/CommandUserPersistenceAdapter.kt b/src/main/kotlin/andreas311/miso/domain/user/adapter/output/persistence/CommandUserPersistenceAdapter.kt index 2ff087c8..3c7e1c03 100644 --- a/src/main/kotlin/andreas311/miso/domain/user/adapter/output/persistence/CommandUserPersistenceAdapter.kt +++ b/src/main/kotlin/andreas311/miso/domain/user/adapter/output/persistence/CommandUserPersistenceAdapter.kt @@ -12,7 +12,7 @@ class CommandUserPersistenceAdapter( private val userRepository: UserRepository ) : CommandUserPort { override fun saveUser(user: User): User { - val userEntity = userRepository.save(userMapper.toEntity(user)) + val userEntity = userRepository.save(userMapper toEntity user) return userMapper.toDomain(userEntity)!! } diff --git a/src/main/kotlin/andreas311/miso/domain/user/adapter/output/persistence/QueryUserPersistenceAdapter.kt b/src/main/kotlin/andreas311/miso/domain/user/adapter/output/persistence/QueryUserPersistenceAdapter.kt index ff3c6f01..7538b713 100644 --- a/src/main/kotlin/andreas311/miso/domain/user/adapter/output/persistence/QueryUserPersistenceAdapter.kt +++ b/src/main/kotlin/andreas311/miso/domain/user/adapter/output/persistence/QueryUserPersistenceAdapter.kt @@ -15,7 +15,7 @@ class QueryUserPersistenceAdapter( ) : QueryUserPort { override fun findByEmailOrNull(email: String): User? { val userEntity = userRepository.findByEmail(email) - return userMapper.toDomain(userEntity) + return userMapper toDomain userEntity } override fun existsByEmail(email: String): Boolean = @@ -23,6 +23,6 @@ class QueryUserPersistenceAdapter( override fun findByIdOrNull(id: UUID): User? { val userEntity = userRepository.findByIdOrNull(id) - return userMapper.toDomain(userEntity) + return userMapper toDomain userEntity } } \ No newline at end of file diff --git a/src/main/kotlin/andreas311/miso/domain/user/adapter/output/persistence/mapper/UserMapper.kt b/src/main/kotlin/andreas311/miso/domain/user/adapter/output/persistence/mapper/UserMapper.kt index a705b5cd..8d4de062 100644 --- a/src/main/kotlin/andreas311/miso/domain/user/adapter/output/persistence/mapper/UserMapper.kt +++ b/src/main/kotlin/andreas311/miso/domain/user/adapter/output/persistence/mapper/UserMapper.kt @@ -6,7 +6,7 @@ import org.springframework.stereotype.Component @Component class UserMapper { - fun toEntity(domain: User): UserEntity = + infix fun toEntity(domain: User): UserEntity = UserEntity( id = domain.id, email = domain.email, @@ -15,7 +15,7 @@ class UserMapper { role = domain.role ) - fun toDomain(entity: UserEntity?): User? = + infix fun toDomain(entity: UserEntity?): User? = entity?.let { User( id = entity.id, 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 c8d92f4d..5b21c315 100644 --- a/src/main/kotlin/andreas311/miso/global/security/config/SecurityConfig.kt +++ b/src/main/kotlin/andreas311/miso/global/security/config/SecurityConfig.kt @@ -65,6 +65,7 @@ class SecurityConfig( .antMatchers(HttpMethod.GET, "/inquiry/{id}").authenticated() .antMatchers(HttpMethod.PATCH, "/inquiry/respond/{id}").hasAuthority("ROLE_ADMIN") + .antMatchers(HttpMethod.POST, "/recyclables").hasAuthority("ROLE_ADMIN") .antMatchers(HttpMethod.POST, "/recyclables/process").authenticated() .antMatchers(HttpMethod.GET, "/recyclables").authenticated() .antMatchers(HttpMethod.GET, "/recyclables/search").authenticated()