Skip to content

Instantly share code, notes, and snippets.

View thomasmartin-whoz's full-sized avatar

thomasmartin-whoz

View GitHub Profile
/**
* A Micronaut adapter for Spring application listeners.
* Grails now uses micronaut so application events will be listened to here.
* To avoid rewriting event listening configuration, based on spring, this class dispatches events to the spring listeners.
*/
@Singleton
class ApplicationEventListenerAdapter implements ApplicationEventListener<WhozEvent> {
@Inject
@Slf4j
@EnableWhozEvent([ProfilePublisher, SkillPublisher])
class WhozPublisherEventConfig {
/**
* Application context from micronaut.
* Event listener must be registered on it as singletons,
* because the bean resolver of the micronaut application listener only evaluates singletons.
*/
class Person {
ObjectId id
String firstName
String lastName
static constraints = {
firstName nullable: false, index: true
lastName nullable: false, index: true
}
class Company {
ObjectId id
String name
List<Person> employees
static constraints = {
name nullable: false, index: true
}
static hasMany = [employees: Person]
class Company {
String name
static constraints = {
name nullable: false, index: true
}
}
class Person {
ObjectId id
String firstName
String lastName
ObjectId companyId
static constraints = {
firstName nullable: false, index: true
lastName nullable: false, index: true
public class PersonService {
public Person findByFirstName(String firstName){
return Person.findByFirstName(firstName)
}
}
public class PersonService {
@Inject
PersonRepository personRepository
public Person findByFirstName(String firstName){
return personRepository.findByFirstName(firstName)
}
}
class PersonGormRepositoryService implements PersonRepository {
@Override
Workspace findByFirstName(@NotNull String firstName) {
return Person.withStatelessSession { Person.findByFirstName(firstName) }
}
}
class PersonController {
PersonService personService
def create(CreatePersonCommand createPersonCommand) {
Person personToCreate = PersonConverter.convertCreateCommandToDomain(createPersonCommand)
Person person = personService.create(personToCreate)
PersonOutput personOutput = PersonConverter.convertDomainToOutput(person)
render personOutput
}