Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMN-657 GET EService descriptor by ID #712

Merged
merged 34 commits into from
Jul 25, 2024
Merged

Conversation

Viktor-K
Copy link
Collaborator

@Viktor-K Viktor-K commented Jul 8, 2024

Part of BFF Catalog Routes
Closes IMN-657

Description

Implements route /producers/eservices/:eserviceId/descriptors/:descriptorId

TEST

✅ HTTP Status 200 - BFF returns expected descriptor
Screenshot 2024-07-10 at 16 59 52


✅ HTTP Status 404 - Descriptor not Found
Screenshot 2024-07-10 at 17 13 50


✅ HTTP Status - 403 Invalid Eservice Requester
Screenshot 2024-07-10 at 17 20 04

@Viktor-K Viktor-K changed the base branch from main to IMN-604-catalog-router July 8, 2024 09:34
Base automatically changed from IMN-604-catalog-router to main July 9, 2024 10:03
@Viktor-K Viktor-K force-pushed the IMN-657-getEserviceDescriptorById branch from 356946c to 2c04084 Compare July 9, 2024 12:56
@Viktor-K Viktor-K force-pushed the IMN-657-getEserviceDescriptorById branch 3 times, most recently from ec02c5e to 62f2849 Compare July 10, 2024 15:07
@Viktor-K Viktor-K force-pushed the IMN-657-getEserviceDescriptorById branch from 62f2849 to 56a0277 Compare July 10, 2024 15:10
@Viktor-K Viktor-K marked this pull request as ready for review July 10, 2024 15:35
@Viktor-K Viktor-K requested a review from sandrotaje July 11, 2024 09:38
Copy link
Collaborator

@ecamellini ecamellini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some minor comments

Comment on lines 233 to 252
const descriptorAttributes = {
certified: [
toBffCatalogApiDescriptorAttribute(
attributes,
descriptor.attributes.certified.flat()
),
],
declared: [
toBffCatalogApiDescriptorAttribute(
attributes,
descriptor.attributes.declared.flat()
),
],
verified: [
toBffCatalogApiDescriptorAttribute(
attributes,
descriptor.attributes.verified.flat()
),
],
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also become a function toBffCatalogApiDescriptorAttributes(descriptorAttributes)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in this commit

producer: tenantApi.Tenant
): bffApi.ProducerDescriptorEService {
const producerMail = producer.mails.find(
(m) => m.kind === tenantMailKind.ContactEmail
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the values are the same and that TS probably helps with this, but here you are comparing enums of different types: tenantApi.Tenant and our internal TenantMailKind. To be safer I would refactor as follows:

Suggested change
(m) => m.kind === tenantMailKind.ContactEmail
(m) => m.kind === tenantApi.MailKind.Values.CONTACT_EMAIL

Copy link
Collaborator Author

@Viktor-K Viktor-K Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Furthermore this commit move it to separate file

headers: Headers,
descriptorAttributeIds: string[]
) => {
// Fetched all attributes in a recursive way
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Fetched all attributes in a recursive way
// Fetch all attributes in a recursive way

Comment on lines 15 to 17
descriptorNotFound: "0006",
attributeNotExists: "0008",
invalidEserviceRequester: "0009",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doubt: in the BFF do we have to use the same codes used in Scala, being exposed directly to the FE, or can we do like in the processes and redefine our codes from scratch just incrementing whenever we add a new error?
cc @galales

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline with @Carminepo2 and @beetlecrunch, this code could be different from the Scala codebase

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, so let's do the increment by one since we don't need to adhere to Scala codes:

Suggested change
descriptorNotFound: "0006",
attributeNotExists: "0008",
invalidEserviceRequester: "0009",
descriptorNotFound: "0004",
attributeNotExists: "0005",
invalidEserviceRequester: "0006",

export function toBffCatalogApiEserviceRiskAnalysis(
riskAnalysis: catalogApi.EServiceRiskAnalysis
): bffApi.EServiceRiskAnalysis {
const answers: { [key: string]: string[] } =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you reuse type from bffApi.RiskAnalysisForm?

Suggested change
const answers: { [key: string]: string[] } =
const answers: bffApi.RiskAnalysisForm["answers"] =

@@ -129,6 +124,36 @@ const getBulkAttributes = async (
return await attributesBulk(0, []);
};

const getEserviceDesciptor = (
Copy link
Contributor

@AsterITA AsterITA Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const getEserviceDesciptor = (
const retrieveEserviceDescriptor = (

We can align this name with the other retrieves like this and we can fix the typo

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with this commit

Comment on lines 38 to 55
const isUpgradable = (agreement: agreementApi.Agreement): boolean => {
const eserviceDescriptor = eservice.descriptors.find(
(e) => e.id === agreement.descriptorId
);

return (
eserviceDescriptor !== undefined &&
eservice.descriptors
.filter((d) => Number(d.version) > Number(eserviceDescriptor.version))
.find(
(d) =>
(d.state === descriptorApiState.PUBLISHED ||
d.state === descriptorApiState.SUSPENDED) &&
(agreement.state === agreementApiState.ACTIVE ||
agreement.state === agreementApiState.SUSPENDED)
) !== undefined
);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference: an almost the same function is present here in another PR

Copy link
Collaborator Author

@Viktor-K Viktor-K Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Carminepo2 in this commit have introduced a new file mappers.ts, my intent is to move here the commons function used to pick, transform or evaluate data.
Also in this next PR I'm using this approach, but in this case probably I prefer to place this method in mapper.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this commit move this logic in a specific file

Comment on lines +194 to +214
export function toEserviceAttribute(
attributes: catalogApi.Attribute[]
): EServiceAttribute[] {
return attributes.map((attribute) => ({
...attribute,
id: unsafeBrandId(attribute.id),
}));
}

export function toDescriptorWithOnlyAttributes(
descriptor: catalogApi.EServiceDescriptor
): DescriptorWithOnlyAttributes {
return {
...descriptor,
attributes: {
certified: descriptor.attributes.certified.map(toEserviceAttribute),
declared: descriptor.attributes.declared.map(toEserviceAttribute),
verified: descriptor.attributes.verified.map(toEserviceAttribute),
},
};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using runtime resources to change something at type level, I know the performance impact could be negligible but I saw this in a lot of part of the monorepo and I'm wondering if it is worth discussing.
What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Carminepo2 good point 👍🏻
unfortunately branded type usages requires mapping like this, so we need to choose what we want encourage. Id as string are very error prone when they are function's parameter, branded type is a sort of guard to avoid bugs, meanwhile every time we convert models it's necessary this wrapping...
I suggest to discuss a possible policy offline.

@Viktor-K Viktor-K requested a review from Carminepo2 July 22, 2024 13:26
Copy link
Collaborator

@ecamellini ecamellini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me! Just left some minor comments but consider it approved on my side :)

Comment on lines 15 to 17
descriptorNotFound: "0006",
attributeNotExists: "0008",
invalidEserviceRequester: "0009",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, so let's do the increment by one since we don't need to adhere to Scala codes:

Suggested change
descriptorNotFound: "0006",
attributeNotExists: "0008",
invalidEserviceRequester: "0009",
descriptorNotFound: "0004",
attributeNotExists: "0005",
invalidEserviceRequester: "0006",

packages/bff/src/model/mappers.ts Outdated Show resolved Hide resolved
packages/bff/src/model/validators.ts Outdated Show resolved Hide resolved
packages/bff/src/routers/catalogRouter.ts Outdated Show resolved Hide resolved
@Viktor-K Viktor-K merged commit a9561da into main Jul 25, 2024
27 checks passed
@Viktor-K Viktor-K deleted the IMN-657-getEserviceDescriptorById branch July 25, 2024 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants