spring-projects / spring-projects/spring-hateoas

Cannot build link using Spring-MVC and router functions dsl

Open
#1,964 1 comment 0 reactions 1 assignee View on GitHub

@odrotbohm is already working on this.

Since May 3, 2023.

in: core kotlin type: enhancement
Dominant language
Java
Stars
1.1k
Forks
476
PR merge metrics
No merged PRs in 30d

Description

Trying to add spring-hateoas in a Spring-Mvc / Kotlin / router functions DSL context.

Constructing link with :

fun Survey.toDto(): SurveyDto {
    return SurveyDto(
        id = id,
        description = description,
        questions = questions.map { it.toDto() },
        tags = tags.map { it.toDto() },
        state = state.name,
        createdAt = createdAt,
        updatedAt = updatedAt
    ).add(SurveyHandler::class) {
        linkTo { getSurvey(id.toString()) } withRel SELF
    }
}

With SurveryService

@Component
class SurveyHandler(private val surveyService: SurveyService) {
    private val logger = KotlinLogging.logger {}

    fun getSurvey(id: String): SurveyDto {
        logger.info { "Calling GET survey with id: $id" }
        return surveyService.findSurvey(UUID.fromString(id)).toDto()
    }

And Routing

@Configuration
class RoutesConfiguration(private val surveyHandler: SurveyHandler) {
    @Bean
    fun surveyRoutes() = router {
        "/v1/admin/survey".nest {
            GET("/{id}") {
                ok().body(surveyHandler.getSurvey(it.pathVariable("id")))
            }
        }
        onError<Exception>(::handleExceptions)
    }

}

Throws exception
java.lang.IllegalArgumentException: No mapping found for public com.liksi.questionr.server.survey.dto.SurveyDto com.liksi.questionr.server.survey.handler.SurveyHandler.getSurvey(java.lang.String)!

As seen here it seems to only handle @RequestMapping annotated method :
https://github.com/spring-projects/spring-hateoas/blob/main/src/main/java/org/springframework/hateoas/server/core/SpringAffordanceBuilder.java

Am i missing something ?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.