mirror of
https://github.com/Dannecron/spring-boot-demo.git
synced 2025-12-25 16:22:35 +03:00
add new dto, extend city service interface
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
package com.example.demo.services.database.city
|
package com.example.demo.services.database.city
|
||||||
|
|
||||||
import com.example.demo.models.City
|
import com.example.demo.models.City
|
||||||
import com.example.demo.services.database.exceptions.AlreadyDeletedException
|
|
||||||
import com.example.demo.services.database.city.exceptions.CityNotFoundException
|
import com.example.demo.services.database.city.exceptions.CityNotFoundException
|
||||||
|
import com.example.demo.services.database.exceptions.AlreadyDeletedException
|
||||||
|
import com.example.demo.services.kafka.dto.CityCreateDto
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ interface CityService {
|
|||||||
fun findByGuid(guid: UUID): City?
|
fun findByGuid(guid: UUID): City?
|
||||||
|
|
||||||
fun create(name: String): City?
|
fun create(name: String): City?
|
||||||
|
fun create(kafkaCityDto: CityCreateDto): City?
|
||||||
|
|
||||||
@Throws(CityNotFoundException::class, AlreadyDeletedException::class)
|
@Throws(CityNotFoundException::class, AlreadyDeletedException::class)
|
||||||
fun delete(guid: UUID): City?
|
fun delete(guid: UUID): City?
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ package com.example.demo.services.database.city
|
|||||||
|
|
||||||
import com.example.demo.models.City
|
import com.example.demo.models.City
|
||||||
import com.example.demo.providers.CityRepository
|
import com.example.demo.providers.CityRepository
|
||||||
import com.example.demo.services.database.exceptions.AlreadyDeletedException
|
|
||||||
import com.example.demo.services.database.city.exceptions.CityNotFoundException
|
import com.example.demo.services.database.city.exceptions.CityNotFoundException
|
||||||
|
import com.example.demo.services.database.exceptions.AlreadyDeletedException
|
||||||
|
import com.example.demo.services.kafka.dto.CityCreateDto
|
||||||
import java.time.OffsetDateTime
|
import java.time.OffsetDateTime
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class CityServiceImpl(
|
class CityServiceImpl(
|
||||||
@@ -25,6 +27,22 @@ class CityServiceImpl(
|
|||||||
return cityRepository.save(city)
|
return cityRepository.save(city)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun create(kafkaCityDto: CityCreateDto): City? {
|
||||||
|
val updatedAt = kafkaCityDto.updatedAt
|
||||||
|
val deletedAt = kafkaCityDto.deletedAt
|
||||||
|
|
||||||
|
val city = City(
|
||||||
|
id = null,
|
||||||
|
guid = UUID.fromString(kafkaCityDto.guid),
|
||||||
|
name = kafkaCityDto.name,
|
||||||
|
createdAt = OffsetDateTime.parse(kafkaCityDto.createdAt, DateTimeFormatter.ISO_OFFSET_DATE_TIME),
|
||||||
|
updatedAt = if (updatedAt != null) OffsetDateTime.parse(updatedAt, DateTimeFormatter.ISO_OFFSET_DATE_TIME) else null,
|
||||||
|
deletedAt = if (deletedAt != null) OffsetDateTime.parse(deletedAt, DateTimeFormatter.ISO_OFFSET_DATE_TIME) else null,
|
||||||
|
)
|
||||||
|
|
||||||
|
return cityRepository.save(city)
|
||||||
|
}
|
||||||
|
|
||||||
override fun delete(guid: UUID): City? {
|
override fun delete(guid: UUID): City? {
|
||||||
val city = findByGuid(guid) ?: throw CityNotFoundException()
|
val city = findByGuid(guid) ?: throw CityNotFoundException()
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.example.demo.services.kafka.dto
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
|
||||||
|
data class CityCreateDto (
|
||||||
|
@JsonProperty("guid")
|
||||||
|
val guid: String,
|
||||||
|
@JsonProperty("name")
|
||||||
|
val name: String,
|
||||||
|
@JsonProperty("createdAt")
|
||||||
|
val createdAt: String,
|
||||||
|
@JsonProperty("updatedAt")
|
||||||
|
val updatedAt: String?,
|
||||||
|
@JsonProperty("deletedAt")
|
||||||
|
val deletedAt: String?,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user