Skip to content

Commit

Permalink
Merge pull request #77 from TeamMiso/feat/recyclables-create
Browse files Browse the repository at this point in the history
๐Ÿ”€ :: ์žฌํ™œ์šฉํ’ˆ ๋ฐฉ๋ฒ• ๊ธ€ ์ƒ์„ฑํ•˜๊ธฐ API ๊ตฌํ˜„
  • Loading branch information
uuuuuuuk authored Mar 28, 2024
2 parents f116b29 + 7592e3b commit d5552f1
Show file tree
Hide file tree
Showing 29 changed files with 276 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)!!
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ 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 =
emailRepository.existsByEmail(email)

override fun findByRandomKeyOrNull(randomKey: String): Email? {
val emailEntity = emailRepository.findByRandomKey(randomKey)
return emailMapper.toDomain(emailEntity)
return emailMapper toDomain emailEntity
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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,
randomKey = domain.randomKey,
authentication = domain.authentication
)

fun toDomain(entity: EmailEntity?): Email? =
infix fun toDomain(entity: EmailEntity?): Email? =
entity?.let {
Email(
id = entity.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Inquiry> {
Expand All @@ -27,7 +27,7 @@ class QueryInquiryPersistenceAdapter(
}

override fun findAllByUser(user: User): List<Inquiry> {
val inquiryList = inquiryRepository.findByUserOrderByCreatedDateDesc(userMapper.toEntity(user))
val inquiryList = inquiryRepository.findByUserOrderByCreatedDateDesc(userMapper toEntity user)
return inquiryList.map { inquiryMapper.toDomain(it)!! }
}

Expand All @@ -37,7 +37,7 @@ class QueryInquiryPersistenceAdapter(
}

override fun findAllByUserAndInquiryStatus(user: User, inquiryStatus: InquiryStatus): List<Inquiry> {
val inquiryList = inquiryRepository.findByUserAndInquiryStatusOrderByCreatedDateDesc(userMapper.toEntity(user), inquiryStatus)
val inquiryList = inquiryRepository.findByUserAndInquiryStatusOrderByCreatedDateDesc(userMapper toEntity user, inquiryStatus)
return inquiryList.map { inquiryMapper.toDomain(it)!! }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)!!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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? =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class QueryPurchasePersistenceAdapter(
private val purchaseRepository: PurchaseRepository
) : QueryPurchasePort {
override fun findAllByUser(user: User): List<Purchase> {
val purchaseList = purchaseRepository.findAllByUserOrderByCreatedDateDesc(userMapper.toEntity(user))
val purchaseList = purchaseRepository.findAllByUserOrderByCreatedDateDesc(userMapper toEntity user)
return purchaseList.map { purchaseMapper.toDomain(it)!! }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Void> =
createRecyclablesUseCase.execute(recyclablesDataMapper toDto createRecyclablesRequest, multipartFile)
.let { ResponseEntity.status(HttpStatus.CREATED).build() }
}
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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
)
}
Original file line number Diff line number Diff line change
@@ -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)!!
}
}
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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
)
}
}
Original file line number Diff line number Diff line change
@@ -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<RecyclablesEntity, Long> {
}
Original file line number Diff line number Diff line change
@@ -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?)
}
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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
}
Loading

0 comments on commit d5552f1

Please sign in to comment.