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 package names #64

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
@@ -1,11 +1,11 @@
package com.github.jactor.persistence.command
package com.github.jactor.persistence.api.command

import java.util.UUID
import com.github.jactor.persistence.dto.AddressInternalDto
import com.github.jactor.persistence.dto.PersistentDto
import com.github.jactor.persistence.dto.PersonInternalDto
import com.github.jactor.persistence.dto.UserInternalDto
import com.github.jactor.shared.dto.CreateUserCommandDto
import com.github.jactor.shared.api.CreateUserCommandDto

@JvmRecord
data class CreateUserCommand(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jactor.persistence.controller
package com.github.jactor.persistence.api.controller

import java.util.UUID
import com.github.jactor.persistence.dto.BlogDto
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jactor.persistence.controller
package com.github.jactor.persistence.api.controller

import java.util.UUID
import com.github.jactor.persistence.dto.GuestBookDto
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jactor.persistence.controller
package com.github.jactor.persistence.api.controller

import java.util.UUID
import org.springframework.http.HttpStatus
Expand All @@ -12,19 +12,19 @@ import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import com.github.jactor.persistence.command.CreateUserCommand
import com.github.jactor.persistence.command.CreateUserCommandResponse
import com.github.jactor.persistence.api.command.CreateUserCommand
import com.github.jactor.persistence.api.command.CreateUserCommandResponse
import com.github.jactor.persistence.dto.UserInternalDto
import com.github.jactor.persistence.entity.UserEntity
import com.github.jactor.persistence.service.UserService
import com.github.jactor.shared.dto.CreateUserCommandDto
import com.github.jactor.shared.dto.UserDto
import com.github.jactor.shared.api.CreateUserCommandDto
import com.github.jactor.shared.api.UserDto
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.responses.ApiResponses

@RestController
@RequestMapping(path = [UserController.USER], produces = [MediaType.APPLICATION_JSON_VALUE])
@RequestMapping(path = ["/user"], produces = [MediaType.APPLICATION_JSON_VALUE])
class UserController(private val userService: UserService) {
@Operation(description = "Find a user by its username")
@ApiResponses(
Expand Down Expand Up @@ -96,8 +96,4 @@ class UserController(private val userService: UserService) {
): ResponseEntity<List<String>> {
return ResponseEntity(userService.findUsernames(UserEntity.UserType.valueOf(userType)), HttpStatus.OK)
}

companion object {
const val USER = "/user"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.jactor.persistence.dto

import com.github.jactor.shared.dto.AddressDto
import com.github.jactor.shared.api.AddressDto

data class AddressInternalDto(
override val persistentDto: PersistentDto = PersistentDto(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.jactor.persistence.dto

import com.github.jactor.shared.dto.PersonDto
import com.github.jactor.shared.api.PersonDto

data class PersonInternalDto(
override val persistentDto: PersistentDto = PersistentDto(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.jactor.persistence.dto

import com.github.jactor.shared.dto.UserDto
import com.github.jactor.shared.dto.UserType
import com.github.jactor.shared.api.UserDto
import com.github.jactor.shared.api.UserType

data class UserInternalDto(
override val persistentDto: PersistentDto = PersistentDto(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.github.jactor.persistence.service
import java.util.UUID
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import com.github.jactor.persistence.command.CreateUserCommand
import com.github.jactor.persistence.api.command.CreateUserCommand
import com.github.jactor.persistence.dto.UserInternalDto
import com.github.jactor.persistence.entity.UserEntity
import com.github.jactor.persistence.repository.UserRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.github.jactor.persistence

import java.util.UUID
import org.junit.jupiter.api.Test
import com.github.jactor.shared.dto.UserDto
import com.github.jactor.shared.dto.UserType
import com.github.jactor.shared.api.UserDto
import com.github.jactor.shared.api.UserType
import assertk.assertAll
import assertk.assertThat
import assertk.assertions.contains
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import assertk.assertions.isNotNull
internal class JactorPersistenceTest : AbstractSpringBootNoDirtyContextTest() {

@Autowired
private lateinit var commandLineRunner: CommandLineRunner
private var commandLineRunner: CommandLineRunner? = null

@Test
fun `should contain bean named CommandlineRunner`() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jactor.persistence.controller
package com.github.jactor.persistence.api.controller

import java.util.UUID
import org.junit.jupiter.api.Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jactor.persistence.controller
package com.github.jactor.persistence.api.controller

import java.util.UUID
import org.junit.jupiter.api.Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.jactor.persistence.controller
package com.github.jactor.persistence.api.controller

import org.junit.jupiter.api.Test
import org.springframework.http.HttpEntity
import org.springframework.http.HttpStatus
import com.github.jactor.persistence.AbstractSpringBootNoDirtyContextTest
import com.github.jactor.persistence.command.CreateUserCommand
import com.github.jactor.persistence.command.CreateUserCommandResponse
import com.github.jactor.persistence.api.command.CreateUserCommand
import com.github.jactor.persistence.api.command.CreateUserCommandResponse
import com.github.jactor.persistence.entity.UniqueUsername
import assertk.assertAll
import assertk.assertThat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jactor.persistence.controller
package com.github.jactor.persistence.api.controller

import java.util.Optional
import java.util.UUID
Expand All @@ -10,11 +10,11 @@ import org.springframework.http.HttpStatus
import com.github.jactor.persistence.AbstractSpringBootNoDirtyContextTest
import com.github.jactor.persistence.dto.UserInternalDto
import com.github.jactor.persistence.entity.UserEntity
import com.github.jactor.shared.dto.AddressDto
import com.github.jactor.shared.dto.CreateUserCommandDto
import com.github.jactor.shared.dto.PersonDto
import com.github.jactor.shared.dto.UserDto
import com.github.jactor.shared.dto.UserType
import com.github.jactor.shared.api.AddressDto
import com.github.jactor.shared.api.CreateUserCommandDto
import com.github.jactor.shared.api.PersonDto
import com.github.jactor.shared.api.UserDto
import com.github.jactor.shared.api.UserType
import assertk.assertAll
import assertk.assertThat
import assertk.assertions.isEqualTo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.util.UUID
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import com.github.jactor.persistence.AbstractSpringBootNoDirtyContextTest
import com.github.jactor.persistence.command.CreateUserCommand
import com.github.jactor.persistence.api.command.CreateUserCommand
import com.github.jactor.persistence.dto.AddressInternalDto
import com.github.jactor.persistence.dto.PersistentDto
import com.github.jactor.persistence.dto.PersonInternalDto
Expand Down Expand Up @@ -100,7 +100,7 @@ internal class UserServiceTest : AbstractSpringBootNoDirtyContextTest() {

@Test
fun `should create and save person for the user`() {
val createUserCommand = CreateUserCommand("jactor", "Jacobsen")
val createUserCommand = CreateUserCommand(username = "jactor", surname = "Jacobsen")
val userDto = UserInternalDto()
val userEntity = UserEntity(userDto)
val personEntitySlot = slot<PersonEntity>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Egenskap: Applikasjonen jactor-persistence

Scenario: BlogController skal være mappet
Så skal statuskoden være 200
Og responsen skal inneholde 'com.github.jactor.persistence.controller.BlogController'
Og responsen skal inneholde 'com.github.jactor.persistence.api.controller.BlogController'
Og responsen skal inneholde '/blog/{blogId}'
Og responsen skal inneholde '/blog/{id}/entries'
Og responsen skal inneholde '/blog/entry'
Expand All @@ -17,15 +17,15 @@ Egenskap: Applikasjonen jactor-persistence

Scenario: GuestBook skal være mappet
Så skal statuskoden være 200
Og responsen skal inneholde 'com.github.jactor.persistence.controller.GuestBookController'
Og responsen skal inneholde 'com.github.jactor.persistence.api.controller.GuestBookController'
Og responsen skal inneholde '/guestBook'
Og responsen skal inneholde '/guestBook/{id}'
Og responsen skal inneholde '/guestBook/entry'
Og responsen skal inneholde '/guestBook/entry/{id}'

Scenario: UserController skal være mappet
Så skal statuskoden være 200
Og responsen skal inneholde 'com.github.jactor.persistence.controller.UserController'
Og responsen skal inneholde 'com.github.jactor.persistence.api.controller.UserController'
Og responsen skal inneholde '/user/{id}'
Og responsen skal inneholde '/user/name/{username}'
Og responsen skal inneholde '/user/usernames'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jactor.shared.dto
package com.github.jactor.shared.api

import java.util.UUID
import io.swagger.v3.oas.annotations.media.Schema
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.jactor.shared.dto
package com.github.jactor.shared.api

import io.swagger.v3.oas.annotations.media.Schema

Expand Down
29 changes: 14 additions & 15 deletions web/src/main/kotlin/com/github/jactor/web/JactorWebBeans.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import org.springframework.context.annotation.PropertySource
import org.springframework.context.annotation.Scope
import org.springframework.web.client.RestTemplate
import org.springframework.web.util.DefaultUriBuilderFactory
import com.github.jactor.web.consumer.DefaultUserConsumer
import com.github.jactor.web.consumer.UserConsumer
import org.springframework.web.util.UriTemplateHandler
import com.github.jactor.web.menu.Menu
import com.github.jactor.web.menu.MenuFacade
import com.github.jactor.web.menu.MenuItem
Expand Down Expand Up @@ -45,26 +44,26 @@ class JactorWebBeans {
)
}

@Bean(name = ["userConsumer"])
fun userConsumer(
restTemplate: RestTemplate,
@Bean
fun jactorWebUriTemplateHandler(
@Value("\${jactor-persistence.url.root}") rootUrlPersistence: String?
): UserConsumer {
val uriTemplateHandler = DefaultUriBuilderFactory()
uriTemplateHandler.setDefaultUriVariables(mapOf("uri" to rootUrlPersistence))
restTemplate.uriTemplateHandler = uriTemplateHandler
): JactorWebUriTemplateHandler = rootUrlPersistence?.let {
val uriTemplateHandler = DefaultUriBuilderFactory(it)

return DefaultUserConsumer(restTemplate)
}
JactorWebUriTemplateHandler(
uriTemplateHandler = uriTemplateHandler
)
} ?: throw IllegalArgumentException("No root url given!")

@Bean
@Scope("prototype")
fun restTemplate(@Value("\${jactor-persistence.url.root}") rootUrlPersistence: String?): RestTemplate {
fun restTemplate(jactorWebUriTemplateHandler: JactorWebUriTemplateHandler): RestTemplate {
val restTemplate = RestTemplate()
val uriTemplateHandler = DefaultUriBuilderFactory()
uriTemplateHandler.setDefaultUriVariables(mapOf("uri" to rootUrlPersistence))
restTemplate.uriTemplateHandler = uriTemplateHandler
restTemplate.uriTemplateHandler = jactorWebUriTemplateHandler.uriTemplateHandler

return restTemplate
}

@JvmRecord
data class JactorWebUriTemplateHandler(val uriTemplateHandler: UriTemplateHandler)
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package com.github.jactor.web.consumer
package com.github.jactor.web.client

import org.springframework.http.HttpStatusCode
import org.springframework.http.ResponseEntity
import org.springframework.stereotype.Service
import org.springframework.web.client.RestTemplate
import com.github.jactor.shared.dto.UserDto
import com.github.jactor.shared.api.UserDto
import com.github.jactor.web.JactorWebBeans

@Service
class DefaultUserConsumer(private val restTemplate: RestTemplate) : UserConsumer {
class DefaultUserClient(
private val restTemplate: RestTemplate,
jactorWebUriTemplateHandler: JactorWebBeans.JactorWebUriTemplateHandler
) : UserClient {

init {
restTemplate.uriTemplateHandler = jactorWebUriTemplateHandler.uriTemplateHandler
}

override fun find(username: String): UserDto? {
return bodyOf(restTemplate.getForEntity("/user/name/$username", UserDto::class.java))
Expand Down Expand Up @@ -38,7 +46,7 @@ class DefaultUserConsumer(private val restTemplate: RestTemplate) : UserConsumer
}
}

interface UserConsumer {
interface UserClient {
fun find(username: String): UserDto?
fun findAllUsernames(): List<String>
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.github.jactor.web.controller

import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.beans.factory.annotation.Value
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.servlet.ModelAndView
import com.github.jactor.web.JactorWebBeans
import com.github.jactor.web.consumer.UserConsumer
import com.github.jactor.web.client.UserClient
import com.github.jactor.web.dto.UserModel
import com.github.jactor.web.menu.MenuFacade
import com.github.jactor.web.menu.MenuItem

@RestController
class UserController(
private val userConsumer: UserConsumer,
@Qualifier("defaultUserClient") private val userClient: UserClient,
private val menuFacade: MenuFacade,
@param:Value("\${server.servlet.context-path}") private val contextPath: String
) {
Expand All @@ -32,7 +33,7 @@ class UserController(
}

private fun populateUser(username: String?, modelAndView: ModelAndView) {
val user = userConsumer.find(username!!)
val user = userClient.find(username!!)
val modelMap = modelAndView.model

if (user != null) {
Expand All @@ -43,7 +44,7 @@ class UserController(
}

private fun populateUserMenu(modelAndView: ModelAndView) {
val menuItems = userConsumer.findAllUsernames()
val menuItems = userClient.findAllUsernames()
.map { chooseUserItem(it) }

modelAndView.addObject(
Expand Down
6 changes: 3 additions & 3 deletions web/src/main/kotlin/com/github/jactor/web/dto/UserModel.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.jactor.web.dto

import com.github.jactor.shared.dto.AddressDto
import com.github.jactor.shared.dto.PersonDto
import com.github.jactor.shared.dto.UserDto
import com.github.jactor.shared.api.AddressDto
import com.github.jactor.shared.api.PersonDto
import com.github.jactor.shared.api.UserDto

class UserModel(private val address: AddressDto?, private val person: PersonDto?, private val user: UserDto) {
constructor(user: UserDto) : this(address = user.person?.address, person = user.person, user = user)
Expand Down
6 changes: 3 additions & 3 deletions web/src/main/kotlin/com/github/jactor/web/model/models.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.github.jactor.web.model

import com.github.jactor.shared.dto.AddressDto
import com.github.jactor.shared.dto.PersonDto
import com.github.jactor.shared.dto.UserDto
import com.github.jactor.shared.api.AddressDto
import com.github.jactor.shared.api.PersonDto
import com.github.jactor.shared.api.UserDto
import com.github.jactor.web.Technology

data class HomePageModel(val technologies: List<Technology> = ArrayList())
Expand Down
Loading
Loading