Skip to content

Commit

Permalink
fix user relationships at microservices.
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Aug 13, 2022
1 parent 9049075 commit 6f0d97e
Show file tree
Hide file tree
Showing 16 changed files with 250 additions and 251 deletions.
4 changes: 4 additions & 0 deletions generators/entity-server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ module.exports = class extends BaseBlueprintGenerator {
entity.entityInstanceDbSafe = entity.entityInstance;
}
},
prepareForTemplates() {
this.mapOrFlatMap = this.entity.reactive ? 'flatMap' : 'map';
this.optionalOrMono = this.entity.reactive ? 'Mono' : 'Optional';
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,19 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
<%_ const instanceType = restClass;
const instanceName = restInstance;
const mapper = entityInstance + 'Mapper';
const dtoToEntity = mapper + '.' + 'toEntity';
const entityToDtoReference = mapper + '::' + 'toDto';
_%>
<%_ if (viaService) { _%>
return <%= entityInstance %>Service.save(<%= instanceName %>)
<%_ } else { _%>
return <%= entityInstance %>Repository.save(<%if (dtoMapstruct) { %><%= dtoToEntity %>(<% } %><%= instanceName %><%if (dtoMapstruct) { %>)<% } -%>)
<%_ if (searchEngineElasticsearch) { %>
<%_ if (returnDirectly) { _%>
return Mono.just(<%= restInstance %>)
<%_ } _%>
<%_ if (dtoMapstruct) { _%>
.map(<%= entityInstance %>Mapper::toEntity)
<%_ } _%>
.flatMap(<%= entityInstance %>Repository::save)
<%_ if (searchEngineElasticsearch) { _%>
.flatMap(<%= entityInstance %>SearchRepository::save)
<%_ } -%>
<%_ if (dtoMapstruct) { %>
.map(<%= entityToDtoReference %>)
<%_ } -%>
<%_ if (returnDirectly) { _%>;<%_ } _%>
<%_ } _%>
<%_ if (dtoMapstruct) { _%>
.map(<%= entityInstance %>Mapper::toDto)
<%_ } _%>
<%_ if (returnDirectly) { -%>
;
<%_ } _%>
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,32 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
<%_ const instanceType = restClass;
const instanceName = restInstance;
const mapper = entityInstance + 'Mapper';
const dtoToEntity = mapper + '.' + 'toEntity';
const entityToDtoReference = mapper + '::' + 'toDto';
_%>
<%_ if (viaService) { _%>
return <%= entityInstance %>Service.update(<%= instanceName %>)
<%_ if (updatableEntity) { _%>
<%_ if (returnDirectly) { _%>
return Mono.just(<%= restInstance %>)
<%_ } _%>
<%_ if (dtoMapstruct) { %>
.map(<%= entityInstance %>Mapper::toEntity)
<%_ } -%>
<%_ if (isPersisted) { _%>
.map(<%= entityInstance %> -> <%= entityInstance %>.setIsPersisted())
<%_ } -%>
.<%= mapOrFlatMap %>(<%= entityInstance %>Repository::save)
<%_ if (searchEngineElasticsearch) { %>
.<%= mapOrFlatMap %>(<%= entityInstance %>SearchRepository::save)
<%_ } -%>
<%_ } else { _%>
<%_ if (updatableEntity) { _%>
return <%= entityInstance %>Repository.save(<%if (dtoMapstruct) { %><%= dtoToEntity %>(<% } %><%= instanceName %><%if (dtoMapstruct) { %>)<% } -%><% if (isPersisted) { %>.setIsPersisted()<% } %>)
<%_ } else { _%>
<%_ if (returnDirectly) { _%>
// no save call needed as we have no fields that can be updated
return <%= entityInstance %>Repository.findById(<%= instanceName %>.get<%= primaryKey.nameCapitalized %>())
<%_ } _%>
<%_ if (searchEngineElasticsearch) { %>
.flatMap(<%= entityInstance %>SearchRepository::save)
<%_ } -%>
<%_ if (dtoMapstruct) { %>
.map(<%= entityToDtoReference %>)
<%_ } -%>
<%_ if (returnDirectly) { _%>;<%_ } _%>
return <%= entityInstance %>Repository.findById(<%= primaryKey.name %>)
<%_ } else { _%>
// no save call needed as we have no fields that can be updated
.then(<%= entityInstance %>Repository.findById(<%= primaryKey.name %>))
<%_ } _%>
<%_ } _%>
<%_ if (dtoMapstruct) { %>
.map(<%= entityInstance %>Mapper::toDto)
<%_ } -%>
<%_ if (returnDirectly) { -%>
;
<%_ } _%>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
const mapsIdRepoInstance = `${mapsIdEntityInstance}Repository`;
beans.push({class: `${mapsIdEntity}Repository`, instance: mapsIdRepoInstance});
}
if (dtoMapstruct && reactive) {
beans.push({class: `${entityClass}Mapper`, instance: `${entityInstance}Mapper`});
}
} else {
beans.push({class: `${entityClass}Repository`, instance: `${entityInstance}Repository`});
if (dtoMapstruct) {
Expand All @@ -45,6 +48,13 @@
beans.push({class: `${mapsIdEntity}Repository`, instance: mapsIdRepoInstance});
}
}
if (constructorName.endsWith('Resource')) {
beans.push({class: 'ConversionService', instance: 'conversionService'});
beans.push({class: 'SmartValidator', instance: 'validator'});
beans.push({class: 'ObjectMapper', instance: 'mapper'});
}
if (saveUserSnapshot && (viaService || constructorName.endsWith('Resource'))) {
beans.push({class: 'UserRepository', instance: 'userRepository'});
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@ public interface <%= entityClass %>Service {
*/
<% if (reactive) { %>Mono<<% } %><%= instanceType %><% if (reactive) { %>><% } %> update(<%= instanceType %> <%= instanceName %>);

/**
* Partially updates a <%= entityInstance %>.
*
* @param <%= instanceName %> the entity to update partially.
* @return the persisted entity.
*/
<% if (reactive) { %>Mono<% } else { %>Optional<% } %><<%= instanceType %>> partialUpdate(<%= instanceType %> <%= instanceName %>);

/**
* Get all the <%= entityInstancePlural %>.
*<% if (!paginationNo) { %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,6 @@ public class <%= serviceClassName %><% if (serviceImpl) { %> implements <%= enti
<%- include('/partials/update_template', {updatableEntity, viaService: false, returnDirectly: true, isUsingMapsId: isUsingMapsId, mapsIdAssoc: mapsIdAssoc, isController: false, isPersisted: requiresPersistableImplementation}); -%>
}

<%_ if (!serviceImpl) { _%>
/**
* Partially update a <%= entityInstance %>.
*
* @param <%= instanceName %> the entity to update partially.
* @return the persisted entity.
*/
<%_ } _%>
<%_ if (serviceImpl) { _%>
@Override
<%_ } _%>
public <% if (reactive) { %>Mono<% } else { %>Optional<% } %><<%= instanceType %>> partialUpdate(<%= instanceType %> <%= instanceName %>) {
log.debug("Request to partially update <%= entityClass %> : {}", <%= instanceName %>);
<%- include('../../common/patch_template', {asEntity, asDto, isService: true, viaService: false}); -%>
}

<%_ if (!serviceImpl) { _%>
/**
* Get all the <%= entityInstancePlural %>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,4 @@ public interface EntityMapper <D, E> {
List <E> toEntity(List<D> dtoList);

List <D> toDto(List<E> entityList);

@Named("partialUpdate")
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
void partialUpdate(@MappingTarget E entity, D dto);
}
Loading

0 comments on commit 6f0d97e

Please sign in to comment.