Skip to content

Commit

Permalink
simplify update_template
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Jan 22, 2024
1 parent 0199ee0 commit 31b4d72
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ if (isUsingMapsId) {
mapsIdRepoInstance = `${mapsIdEntityInstance}Repository`;
otherEntityName = mapsIdAssoc.otherEntityName;
} _%>
<%_ if (!viaService) { _%>
<%_ if (dtoMapstruct) { _%>
<%_ resultEntity = persistInstance; _%>
<%_ if (dtoMapstruct) { _%>
<%_ resultEntity = persistInstance; _%>
<%= persistClass %> <%= persistInstance %> = <%= dtoToEntity %>(<%= instanceName %>);
<%_ if (isPersisted) { _%>
<%_ if (requiresPersistableImplementation) { _%>
<%= persistInstance %>.setIsPersisted();
<%_ } _%>
<%_ if (isUsingMapsId) { _%>
Expand All @@ -52,7 +51,7 @@ if (isUsingMapsId) {
<%= mapsIdAssoc.otherEntity.primaryKey.type %> <%= otherEntityName %>Id = <%= instanceName %>.get<%= mapsIdAssoc.relationshipNameCapitalized %>().get<%= primaryKey.nameCapitalized %>();
<%= mapsIdRepoInstance %>.findById(<%= otherEntityName %>Id).ifPresent(<%= instanceName %>::<%_ if (!fluentMethods) { _%>set<%= mapsIdAssoc.relationshipNameCapitalized %> <%_ } else { _%><%= otherEntityName %><%_ } _%>);
<%_ } _%>
<%_ if (isPersisted) { _%>
<%_ if (requiresPersistableImplementation) { _%>
<%= persistInstance %>.setIsPersisted();
<%_ } _%>
<%= returnPrefix %> <%= entityInstance %>Repository.save(<%= persistInstance %>);
Expand All @@ -63,6 +62,3 @@ if (isUsingMapsId) {
return result;
<%_ } _%>
<%_ } _%>
<%_ } else { _%>
<%= returnPrefix %> <%= entityInstance %>Service.update(<%= instanceName %>);
<%_ } _%>
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,16 @@
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 %>)
<%_ } else { _%>
return <%= entityInstance %>Repository.save(<%if (dtoMapstruct) { %><%= dtoToEntity %>(<% } %><%= instanceName %><%if (dtoMapstruct) { %>)<% } -%><% if (isPersisted) { %>.setIsPersisted()<% } %>)
<%_ if (searchEngineElasticsearch) { %>
return <%= entityInstance %>Repository.save(<%if (dtoMapstruct) { %><%= dtoToEntity %>(<% } %><%= restInstance %><%if (dtoMapstruct) { %>)<% } -%><% if (requiresPersistableImplementation) { %>.setIsPersisted()<% } %>)
<%_ if (searchEngineElasticsearch) { %>
.flatMap(<%= entityInstance %>SearchRepository::save)
<%_ } -%>
<%_ if (dtoMapstruct) { %>
<%_ } -%>
<%_ if (dtoMapstruct) { %>
.map(<%= entityToDtoReference %>)
<%_ } -%>
<%_ if (returnDirectly) { _%>;<%_ } _%>
<%_ } _%>
<%_ } -%>
<%_ if (returnDirectly) { _%>;<%_ } _%>
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public class <%= serviceClassName %><% if (serviceImpl) { %> implements <%= enti
<%_ } _%>
public <% if (reactive) { %>Mono<<% } %><%= instanceType %><% if (reactive) { %>><% } %> update(<%= instanceType %> <%= instanceName %>) {
log.debug("Request to update <%= entityClass %> : {}", <%= instanceName %>);
<%- include('/_global_partials_entity_/update_template', {viaService: false, returnDirectly: true, isUsingMapsId: isUsingMapsId, mapsIdAssoc: mapsIdAssoc, isController: false, isPersisted: requiresPersistableImplementation}); -%>
<%- include('/_global_partials_entity_/update_template', {returnDirectly: true, mapsIdAssoc: mapsIdAssoc}); -%>
}

<%_ if (!serviceImpl) { _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,23 @@ public class <%= entityClass %>Resource {
<%_ } _%>
<% } %>
<%_ } _%>
<%- include('/_global_partials_entity_/update_template', {viaService: viaService, returnDirectly: false, isUsingMapsId: false, mapsIdAssoc: mapsIdAssoc, isController: true, isPersisted: requiresPersistableImplementation}); -%>
<%_ if (serviceNo) { _%>
<%- include('/_global_partials_entity_/update_template', {returnDirectly: false, isUsingMapsId: false}); -%>
<%_ } _%>
<%_ if (reactive) { _%>
<%_ if (!serviceNo) { _%>
return <%= entityInstance %>Service.update(<%= instanceName %>)
<%_ } _%>
.switchIfEmpty(Mono.error(new ResponseStatusException(HttpStatus.NOT_FOUND)))
.map(result -> ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, <%= enableTranslation %>, ENTITY_NAME, result.get<%= primaryKey.nameCapitalized %>()<% if (!primaryKey.typeString) { %>.toString()<% } %>))
.body(result)
);
});
<%_ } else { _%>
<%_ if (!serviceNo) { _%>
<%- restClass %> result = <%= entityInstance %>Service.update(<%= instanceName %>);
<%_ } _%>
return ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert(applicationName, <%= enableTranslation %>, ENTITY_NAME, <%= instanceName %>.get<%= primaryKey.nameCapitalized %>()<% if (!primaryKey.typeString) { %>.toString()<% } %>))
.body(result);
Expand Down

0 comments on commit 31b4d72

Please sign in to comment.