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

Add a Platform service #703

Merged
merged 12 commits into from
Nov 28, 2023
Merged

Add a Platform service #703

merged 12 commits into from
Nov 28, 2023

Conversation

fgravin
Copy link
Member

@fgravin fgravin commented Nov 24, 2023

Add a platform service interface + a gn4 implementation to centralize

  • user repository
  • auth
  • organization repository
  • api compatibility & version

Please read commit history for more information.
Only some parts of the code use this platform, mostly auth Observables, users and version things.

Incrementally, we could move the organizations repositories into it.

Code ready for a review.
Tests will come if it's ok.

@fgravin fgravin requested a review from jahow November 24, 2023 21:09
Copy link
Contributor

github-actions bot commented Nov 24, 2023

Affected libs: api-metadata-converter, feature-editor, api-repository, feature-catalog, feature-record, feature-router, feature-search, feature-map, feature-dataviz, feature-auth, ui-search, common-domain, common-fixtures, ui-elements, ui-catalog, util-shared, ui-widgets, ui-inputs, ui-map, ui-dataviz,
Affected apps: data-platform, datahub, metadata-converter, metadata-editor, webcomponents, demo, search, map-viewer, datafeeder,

  • 🚀 Build and deploy storybook and demo on GitHub Pages
  • 📦 Build and push affected docker images

Copy link
Collaborator

@jahow jahow left a comment

Choose a reason for hiding this comment

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

Thanks ✌️ I think this is going in the right direction. I would have liked the auth service to be gone completely though, but maybe this will take too much refactoring.

libs/common/domain/src/lib/platform.service.interface.ts Outdated Show resolved Hide resolved
libs/common/domain/src/lib/platform.service.interface.ts Outdated Show resolved Hide resolved
libs/common/domain/src/lib/platform.service.interface.ts Outdated Show resolved Hide resolved
readonly isApiCompatible$ = this.apiVersion$.pipe(
tap(
(version) =>
version < minApiVersion &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does that really work for semver? e.g. 4.10.0 might be considered "lower" than 4.2.0

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes this is not correct, I will add the test of the version in another PR and keep this one as just refactoring.
I don't want that some heavy work is started and brings conflicts because of this refactoring.

libs/common/domain/src/lib/model/user/user.model.ts Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Nov 27, 2023

Coverage Status

coverage: 82.889% (-3.1%) from 85.955%
when pulling 548263b on platform-service
into ef6a273 on main.

@fgravin fgravin requested a review from jahow November 27, 2023 21:19
Copy link
Collaborator

@jahow jahow left a comment

Choose a reason for hiding this comment

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

I did a first pass on the changes, most of it looks OK but I still stumbled on some possible improvements. I feel like it would have been a great opportunity to get rid of the AuthService as well, but maybe that was taking the refactoring too far?

apps/metadata-editor/src/app/app.module.ts Show resolved Hide resolved
libs/feature/search/src/lib/state/effects.spec.ts Outdated Show resolved Hide resolved
libs/common/domain/src/lib/model/user/user.model.ts Outdated Show resolved Hide resolved
provide: PlatformServiceInterface,
useClass: Gn4PlatformService,
},
Gn4PlatformMapper,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see why this should be provided? Isn't it an explicit dependency of Gn4PlatformService?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because it's not injected in root, so it has to be injected somehow.
There is no providers option from services.

import { AvatarServiceInterface } from '../auth/avatar.service.interface'

@Injectable()
export class Gn4PlatformMapper {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like these mappers could be simple pure functions exported as is, instead of an Angular service.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I actually wanted to create a static class, but the mappers need for instance the AvatarService which is injected.

credentialsNonExpired,
...user
} = apiUser
return { ...apiUser, id: id + '' } as UserModel
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
return { ...apiUser, id: id + '' } as UserModel
return { ...apiUser, id: id.toString() } as UserModel

Many repositories should be implemented.move record repository to this folder.
move all models to this folder
automatic refactoring created wrong path :/
remove code from AuthService and use the platform instead
make things clearer and move the User model in domain from gn4-api
which should be responsible of gathering all domain interface implementation for the gn4 strategy
move from AuthService to PlatformeService
to avoid using global subjects which could create side effects
@fgravin fgravin requested a review from jahow November 28, 2023 13:16
Copy link
Collaborator

@jahow jahow left a comment

Choose a reason for hiding this comment

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

Let's go!

@fgravin fgravin merged commit e7e9323 into main Nov 28, 2023
8 checks passed
@fgravin fgravin deleted the platform-service branch November 28, 2023 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants