Skip to content

Commit d704c7c

Browse files
committed
fix: using uuid
1 parent 413b8d2 commit d704c7c

File tree

7 files changed

+34
-4
lines changed

7 files changed

+34
-4
lines changed

docs/awesome/awesome-gradle.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Awesome Gradle
2+
3+
A curated list of awesome Gradle build tool tips and blogs.

docs/awesome/awesome-spring.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Awesome Spring
2+
3+
A curated list of awesome Spring Framework libraries and blogs.
4+
5+
## Architecture
6+
- [Hexagonal Architecture on Spring Boot](https://jivimberg.io/blog/2020/02/01/hexagonal-architecture-on-spring-boot/)
7+
- [Using UUID on Spring Data JPA Entities](https://jivimberg.io/blog/2018/11/05/using-uuid-on-spring-data-jpa-entities/)
8+
9+
### Event Driven Architecture
10+
- [How Wix manages Schemas for Kafka (and gRPC) used by 2000 microservices](https://medium.com/wix-engineering/how-wix-manages-schemas-for-kafka-and-grpc-used-by-2000-microservices-2117416ea17b)
11+
- [Spring Cloud Data Flow: The Core Components](https://www.zaloni.com/resources/blogs/the-core-components-of-spring-cloud-data-flow/)
12+
13+
## Testing
14+
- [Mockk All the Things](https://jivimberg.io/blog/2019/05/09/mockk-features-rundown/)

docs/concepts/testing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Testing
22

33
- [Testing Koin applications with Kotest](https://dev.to/kerooker/testing-koin-applications-with-kotlintest-1iip)
4+
- [Mockk All the Things](https://jivimberg.io/blog/2019/05/09/mockk-features-rundown/)

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ spring-boot-starter-security = { module = "org.springframework.boot:spring-boot-
188188
spring-boot-starter-oauth2-resource-server = { module = "org.springframework.boot:spring-boot-starter-oauth2-resource-server" }
189189
spring-boot-reactor-kotlin-extensions = { module = "io.projectreactor.kotlin:reactor-kotlin-extensions" }
190190
spring-boot-reactor-kafka = { module = "io.projectreactor.kafka:reactor-kafka" }
191+
spring-boot-kafka = { module = "org.springframework.kafka:spring-kafka" }
191192

192193
spring-boot-starter-graphql = { module = "org.springframework.boot:spring-boot-starter-graphql" }
193194
spring-boot-starter-validation = { module = "org.springframework.boot:spring-boot-starter-validation" }
@@ -354,6 +355,7 @@ spring-boot-mockk-test = { module = "com.ninja-squad:springmockk", version.ref =
354355
spring-boot-reactor-test = { module = "io.projectreactor:reactor-test" }
355356
spring-boot-graphql-test = { module = "org.springframework.graphql:spring-graphql-test" }
356357
spring-boot-security-test = { module = "org.springframework.security:spring-security-test" }
358+
spring-boot-kafka-test = { module = "org.springframework.kafka:spring-kafka-test" }
357359
turbine-test = { module = "app.cash.turbine:turbine", version.ref = "turbine" }
358360
junit4-test = { module = "junit:junit", version.ref = "junit4" }
359361
spring-boot-flyway-test = { module = "org.flywaydb.flyway-test-extensions:flyway-spring-test", version.ref = "flywayTest" }

services/spring-graphql-r2dbc/src/main/kotlin/micro/apps/service/domain/book/BookService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ class BookService(private val bookRepository: BookRepository, private val author
1414
// @Transactional
1515
suspend fun createBook(input: CreateBookInput): Book {
1616
val book = bookRepository.save(
17-
Book(/*id = UuidCreator.getTimeOrderedEpoch(),*/ title = input.title, pages = input.pages, category = input.category)
17+
Book(title = input.title, pages = input.pages, category = input.category)
1818
)
1919
logger.atDebug().addKeyValue("book", book).log("saved book")
2020
authorRepository.save(
21-
Author(/*id = UuidCreator.getTimeOrderedEpoch(),*/ name = input.author, age = 0, bookId = book.id)
21+
Author( name = input.author, age = 0, bookId = book.id)
2222
)
2323
return book
2424
}

services/spring-graphql-r2dbc/src/main/kotlin/micro/apps/service/domain/book/models.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package micro.apps.service.domain.book
22

3+
import com.github.f4b6a3.uuid.UuidCreator
34
import org.springframework.data.annotation.CreatedBy
45
import org.springframework.data.annotation.CreatedDate
56
import org.springframework.data.annotation.Id
@@ -13,7 +14,14 @@ import java.util.UUID
1314

1415
@Table("books")
1516
data class Book(
16-
@Id val id: UUID? = null,
17+
// setting id = null, lets database set UUID if supported.
18+
// @Id val id: UUID? = null,
19+
/**
20+
* Having application generated ids means the id is known even before the entity is persisted.
21+
* This lets us model our entities as immutable objects and we avoid having to handle null values on the id
22+
* https://jivimberg.io/blog/2018/11/05/using-uuid-on-spring-data-jpa-entities/
23+
*/
24+
@Id val id: UUID = UuidCreator.getTimeOrderedEpoch(),
1725
val title: String,
1826
val pages: Int,
1927
val category: Category,
@@ -42,7 +50,7 @@ enum class Category {
4250

4351
@Table("authors")
4452
data class Author(
45-
@Id val id: UUID? = null,
53+
@Id val id: UUID = UuidCreator.getTimeOrderedEpoch(),
4654
val name: String,
4755
val age: Int?,
4856
@Column("book_id")

services/spring-graphql-r2dbc/src/main/resources/graphql/book.graphqls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
extend type Query {
22
bookById(id: UUID!): Book
3+
bookByTitle(title: String!): Book
4+
books : [Book!]
35
}
46

57
extend type Mutation {

0 commit comments

Comments
 (0)