Person {
UUID id;
...
List contact
}
Contact {
UUID id;
boolean main;
...
List details;
@JsonIgnore
UUID personId;
}
ContactDetails {
UUID id;
String value
@JsonIgnore
UUID contactId;
}
< /code>
Теперь следующая часть: необходимо управлять контроллерами с некоторыми правилами для этого: < /p>
[list]
[*] У каждого объекта есть собственный контроллер. Если это зависимая сущность, то родительский идентификатор должен быть указан;
[*] Должно быть возможно создать/извлечь/обновить детей, хотя родительский контроллер
[/list]
Итак, мы должны иметь:
POST /person - it takes person model as body and it create itself plus contact and contact details (all children)
RETRIEVE /person/{id} - it takes only id and return full structure (with all children and children with their children)
PATCH /person/{id} - it takes person model as body and it update itself plus contact and contact details
DELETE /person/{id} - it delete entities with CASCADE
POST /contact - it takes contact model as body and it create itself plus contact details (all children)
RETRIEVE /contact/{id} - it takes only id and return full structure (with all children and children with their children)
PATCH /contact/{id} - it takes contact model as body and it update itself plus contact details
DELETE /contact/{id} - it delete entities with CASCADE (itself + children)
POST /contact-details - it takes contact-details model as body and it create itself. It doesnt have children so only itself
RETRIEVE /contact/{id} - it takes only id and return full structure (itself means because it doesnt have children)
PATCH /contact/{id} - it takes contact-details model as body and it update itself
DELETE /contact/{id} - it delete itself
< /code>
Кажется, это не имеет большого значения, но то, что я пытаюсь сделать: разделить операцию CRUD на службы модели домена. Что это значит? Как вы можете видеть, должно быть возможное создание детей, хотя и родительский контроллер, но в то же время это должно быть возможно с помощью собственного контроллера: та же самая операция создания, те же валидации для детей. Итак, я пытаюсь разделить это, так что: < /p>
public class PersonService {
PersonRepository repository;
ContactService contactService;
Person create(Person person){
...
person.setId(UUID.random());
PersionEntity entity = PersonMapper.INSTANCE.toEntity(person);
repository.save(entity);
person.getContacts().forEach(contact -> contact.setPersonId(person.getId());
contactService.create(person.getContacts());
return repository.findById(person.getId())
}
Person update(Person person) {
...
person.setId(UUID.random());
PersionEntity entity = PersonMapper.INSTANCE.toEntity(person);
repository.save(entity);
contactService.update(person.getContacts());
return repository.findById(person.getId())
}
...
}
public class ContactService {
ContactRepository repository;
ContactDetailsService cdService;
Contact create(Contact contact) { //
Подробнее здесь: [url]https://stackoverflow.com/questions/79737025/how-to-split-into-services-per-each-jpa-entity-or-how-to-avoid-code-duplicate[/url]
Я не могу решить следующую проблему. Давайте представим, что у нас есть вложенная структура: < /p> [code]@Entity PersonEntity { UUID id; ... @OneToMany(mappedBy...) List contact }
@Entity ContactDetailsEntity { UUID id; String value; @ManyToOne ContactEntity } [/code] У нас также есть модели для наших слоев. Мы используем его в теле контроллера и для услуг. Каждая модель знает только о детях: < /p> [code]Person { UUID id; ... List contact }
ContactDetails { UUID id; String value @JsonIgnore UUID contactId; } < /code> Теперь следующая часть: необходимо управлять контроллерами с некоторыми правилами для этого: < /p> [list] [*] У каждого объекта есть собственный контроллер. Если это зависимая сущность, то родительский идентификатор должен быть указан; [*] Должно быть возможно создать/извлечь/обновить детей, хотя родительский контроллер [/list] Итак, мы должны иметь: POST /person - it takes person model as body and it create itself plus contact and contact details (all children) RETRIEVE /person/{id} - it takes only id and return full structure (with all children and children with their children) PATCH /person/{id} - it takes person model as body and it update itself plus contact and contact details DELETE /person/{id} - it delete entities with CASCADE
POST /contact - it takes contact model as body and it create itself plus contact details (all children) RETRIEVE /contact/{id} - it takes only id and return full structure (with all children and children with their children) PATCH /contact/{id} - it takes contact model as body and it update itself plus contact details DELETE /contact/{id} - it delete entities with CASCADE (itself + children)
POST /contact-details - it takes contact-details model as body and it create itself. It doesnt have children so only itself RETRIEVE /contact/{id} - it takes only id and return full structure (itself means because it doesnt have children) PATCH /contact/{id} - it takes contact-details model as body and it update itself DELETE /contact/{id} - it delete itself < /code> Кажется, это не имеет большого значения, но то, что я пытаюсь сделать: разделить операцию CRUD на службы модели домена. Что это значит? Как вы можете видеть, должно быть возможное создание детей, хотя и родительский контроллер, но в то же время это должно быть возможно с помощью собственного контроллера: та же самая операция создания, те же валидации для детей. Итак, я пытаюсь разделить это, так что: < /p> public class PersonService {
В настоящее время я создаю свою первую тему WordPress и хочу отображать таксономию пользовательского типа сообщения (но только имя, а не ссылку) при его предварительном просмотре, а также дату его публикации. Я осмотрелся, но обнаружил только, что...
Цель состоит в том, чтобы разделить содержимое mylist на два других списка в зависимости от того, соответствуют ли они условию.
Как это сделать более элегантно? Могу ли я избежать двух отдельных итераций над...
Если я хочу добавить значение в поле в буфере протокола, которое неизвестно во время компиляции, я сейчас выполняю setattr. Обычно мне не нравится использовать setattr, поскольку он кажется менее безопасным. Но когда я знаю, что объект является...
Я не могу решить следующую проблему. Давайте представим, что у нас есть вложенная структура:
@Entity
PersonEntity {
UUID id;
...
@OneToMany(mappedBy...)
List contact
}
Привет всем, у меня возникла проблема в моем окне pygame, когда я играю в него, окно открывается, затем воспроизводится вступление игры, но во время него или иногда после его сбоя, не могли бы вы помочь мне найти ответ на эту проблему?
>
здесь код...