Skip to content

Commit

Permalink
Added fetch attribute by id in Attribute Store (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
anujgoyal1 authored Mar 27, 2024
1 parent 4420bc3 commit de98fa8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface AttributeStore {

Single<AttributeModel> getIdAttribute(GraphQlRequestContext context, String scope);

Single<AttributeModel> getAttributeById(GraphQlRequestContext context, String attributeId);

Single<AttributeModel> getForeignIdAttribute(
GraphQlRequestContext context, String scope, String foreignScope);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ public Single<AttributeModel> getForeignIdAttribute(
.flatMap(key -> this.get(context, scope, key));
}

@Override
public Single<AttributeModel> getAttributeById(
GraphQlRequestContext context, String attributeId) {
return grpcContextBuilder
.build(context)
.call(() -> cachingAttributeClient.get(attributeId))
.mapOptional(this.translator::translate)
.switchIfEmpty(Single.error(this.buildErrorForMissingAttributeId(attributeId)));
}

@Override
public Completable create(
final GraphQlRequestContext context, final List<AttributeMetadata> attributes) {
Expand Down Expand Up @@ -139,6 +149,11 @@ private NoSuchElementException buildErrorForMissingAttribute(String scope, Strin
String.format("No attribute available for scope '%s' and key '%s'", scope, key));
}

private NoSuchElementException buildErrorForMissingAttributeId(String attributeId) {
return new NoSuchElementException(
String.format("No attribute available for attribute id '%s'", attributeId));
}

private NoSuchElementException buildErrorForMissingForeignScopeMapping(
String scope, String foreignScope) {
return new NoSuchElementException(
Expand Down

0 comments on commit de98fa8

Please sign in to comment.