Skip to content

Commit

Permalink
functional fix of BlogService.saveOrUpdate (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
jactor-rises authored May 24, 2024
2 parents badb372 + 4598ca9 commit f7da00e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class BlogEntryEntity : PersistentEntity<BlogEntryEntity?> {
}

constructor(blogEntryDto: BlogEntryDto) {
blog = blogEntryDto.blog?.let { BlogEntity(it) }
blog = BlogEntity(blogDto = blogEntryDto.blog ?: error("Entry must belong to a blog"))
entryEmbeddable = EntryEmbeddable(blogEntryDto.notNullableCreator, blogEntryDto.notNullableEntry)
id = blogEntryDto.id
persistentDataEmbeddable = PersistentDataEmbeddable(blogEntryDto.persistentDto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ class DefaultBlogService(
}

override fun saveOrUpdate(blogEntryDto: BlogEntryDto): BlogEntryDto {
val userDto = userService.find(username = fetchUsername(blogEntryDto.blog))
blogEntryDto.blog!!.userInternal = userDto
blogEntryDto.blog?.also {
it.id ?: error("An entry must belong to a persistent blog!")
} ?: error("An entry must belong to a blog!")

val blogEntryEntity = BlogEntryEntity(blogEntryDto)
val blogEntryEntity = BlogEntryEntity(blogEntryDto = blogEntryDto)

return blogEntryRepository.save(blogEntryEntity).asDto()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.jactor.persistence.aop

import java.time.LocalDateTime
import java.util.UUID
import org.aspectj.lang.JoinPoint
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
Expand Down Expand Up @@ -71,7 +72,14 @@ internal class ModifierAspectTest {
@Test
fun `should modify timestamp on blogEntry when used`() {
val blogEntryWithoutId = BlogBuilder.new().withUnchangedEntry(
blogEntryDto = BlogEntryDto(persistentDto, BlogEntryDto(creatorName = "me", entry = "some shit"))
blogEntryDto = BlogEntryDto(
persistentDto = persistentDto,
blogEntry = BlogEntryDto(
blog = BlogDto(persistentDto = PersistentDto(id = UUID.randomUUID())),
creatorName = "me",
entry = "some shit"
)
)
).buildBlogEntryEntity()

val blogEntry = BlogBuilder.new().withEntry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ internal class BlogServiceTest {
fun `should save BlogEntryDto as BlogEntryEntity`() {
val blogEntryEntitySlot = slot<BlogEntryEntity>()
val blogEntryDto = BlogEntryDto()
blogEntryDto.blog = BlogDto(userInternal = UserInternalDto(username = "itsme"))
blogEntryDto.blog = BlogDto(
persistentDto = PersistentDto(id = UUID.randomUUID()),
userInternal = UserInternalDto(username = "itsme")
)

blogEntryDto.creatorName = "me"
blogEntryDto.entry = "if i where a rich man..."

Expand Down

0 comments on commit f7da00e

Please sign in to comment.