Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functional fix of BlogService.saveOrUpdate #65

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading