Skip to content

Instantly share code, notes, and snippets.

data class Search(
val id: UUID = randomUUID(),
val criteria: Criteria,
val spaceTrains: SpaceTrains,
val selection: Selection = Selection())
data class SpaceTrain(
val number: String,
val bound: Bound,
val originId: String,
package org.craftsrecords.talkadvisor.infra.resources
import org.springframework.hateoas.Identifiable
import java.util.*
import org.craftsrecords.talkadvisor.recommendation.Recommendation as DomainRecommendation
import org.craftsrecords.talkadvisor.recommendation.talk.Talk as DomainTalk
class Recommendation(private val id: UUID, val talks: List<Talk>) : Identifiable<UUID> {
override fun getId() = id
}
package org.craftsrecords.talkadvisor.infra.resources
import org.craftsrecords.talkadvisor.recommendation.preferences.Preferences as DomainPreferences
import org.craftsrecords.talkadvisor.recommendation.preferences.Topic as DomainTopic
import org.craftsrecords.talkadvisor.recommendation.talk.TalkFormat as DomainTalkFormat
data class Preferences(val topics: List<Topic>, val talksFormats: List<String>) {
fun toDomainObject(): DomainPreferences {
return DomainPreferences(topics.toDomainObjects(), talksFormats.toDomainTalkFormats())
}
@RestController
@RequestMapping(path = ["/profiles"])
class ProfileController(private val createProfile: CreateProfile) {
/**
* simulating an authentication context by passing the userId in a header,
* no need to set up all the security frameworks for this demo, but never do that in production !!!
*/
@PostMapping
fun createProfile(@RequestHeader("User-Id") userId: String, @RequestBody preferences: Preferences): ResponseEntity<Profile> {
package org.craftsrecords.talkadvisor.recommendation.stepdefs
import cucumber.api.java.en.Then
import cucumber.api.java.en.When
import org.craftsrecords.talkadvisor.recommendation.api.RecommendTalks
import org.craftsrecords.talkadvisor.recommendation.assertions.that
import org.craftsrecords.talkadvisor.recommendation.criteria.GuestCriteria
import org.craftsrecords.talkadvisor.recommendation.talk.TalkFormat
import java.time.Duration.ofMinutes
@Test
fun `should retrieve talks`() {
val mockedTalk = mock(Talk::class.java)
given(mockedTalk.format).willReturn(IGNITE)
given(mockedTalk.duration).willReturn(Duration.ofHours(1))
// this resulted Talk Object is invalid, the source of truth is the duration
// but here with mockito we overload the format computation logic
given(searchTalks.forTopics(anySet())).willReturn(setOf(mockedTalk))
class Talk private constructor(id: String,
title: String,
duration: Duration) {
val id = notBlank(id, "Cannot create a Talk is a blank id")!!
val title = notBlank(title, "Cannot create a Talk is a blank title")!!
val duration = notNegative(duration)
val format = TalkFormat.ofDuration(duration)
}
package org.craftsrecords.talkadvisor.recommendation.spi.stubs
import org.craftsrecords.hexarch.Stub
import org.craftsrecords.talkadvisor.recommendation.preferences.Topic
import org.craftsrecords.talkadvisor.recommendation.spi.SearchTalks
import org.craftsrecords.talkadvisor.recommendation.talk.Talk
import org.craftsrecords.talkadvisor.recommendation.talk.TalkFormat
import java.util.*
@Stub
Feature: As a frequent user,
In order not repeat my preferences at each request,
I want to create my profile with my preferences
Scenario: The user is creating his profile with his preferences
Given a user
And he wants to learn
| DDD | hexagonal architecture |
And he only wants to see
package org.craftsrecords.talkadvisor.recommendation.spi
import org.craftsrecords.hexarch.Repository
import org.craftsrecords.talkadvisor.recommendation.profile.Profile
@Repository
interface Profiles {
fun save(profile: Profile): Profile
fun fetch(userId: String): Profile?