Skip to content

Commit

Permalink
feat(account-feature-about): adiciona página pública para usuário
Browse files Browse the repository at this point in the history
closed #77
  • Loading branch information
guiseek committed Nov 26, 2024
1 parent fdb6122 commit 87ca74d
Show file tree
Hide file tree
Showing 61 changed files with 620 additions and 92 deletions.
Binary file added apps/devmx/public/images/resume-folder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/devmx/public/images/resume-folder.webp
Binary file not shown.
7 changes: 7 additions & 0 deletions apps/devmx/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import { NotFoundContainer } from './containers';
import { Route } from '@angular/router';

export const appRoutes: Route[] = [
{
path: 'sobre',
loadChildren: () =>
import('@devmx/account-feature-about').then(
(m) => m.accountFeatureAboutRoutes
),
},
{
path: 'evento',
loadChildren: () =>
Expand Down
1 change: 1 addition & 0 deletions packages/account/data-access/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './lib/account.providers';
export * from './lib/application';
export * from './lib/resolvers';
export * from './lib/dtos';
17 changes: 15 additions & 2 deletions packages/account/data-access/src/lib/application/user.facade.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { createClientProvider, EntityFacade } from '@devmx/shared-data-access';
import { User } from '@devmx/shared-api-interfaces';
import { toAboutUserSchema } from '../mappers';
import { filter, map, take } from 'rxjs';
import {
FindUsersUseCase,
DeleteUserUseCase,
Expand All @@ -8,14 +10,14 @@ import {
UpdateProfileUseCase,
UpdatePasswordUseCase,
UpdateRolesUseCase,
FindUserByNameUseCase,
} from '@devmx/account-domain/client';
import {
UpdateProfile,
UpdatePassword,
UpdateSocial,
UpdateRoles,
} from '@devmx/account-domain';
import { take } from 'rxjs';

export class UserFacade extends EntityFacade<User> {
profile$ = this.select((state) => {
Expand All @@ -36,14 +38,20 @@ export class UserFacade extends EntityFacade<User> {
return null;
});

schema$ = this.selected$.pipe(
filter((selected) => !!selected),
map((selected) => toAboutUserSchema(selected))
);

constructor(
private findUsersUseCase: FindUsersUseCase,
private findUserByIDUseCase: FindUserByIDUseCase,
private updateProfileUseCase: UpdateProfileUseCase,
private updatePasswordUseCase: UpdatePasswordUseCase,
private updateSocialUseCase: UpdateSocialUseCase,
private updateRolesUseCase: UpdateRolesUseCase,
private deleteUserUseCase: DeleteUserUseCase
private deleteUserUseCase: DeleteUserUseCase,
private findUserByNameUseCase: FindUserByNameUseCase
) {
super({
response: { data: [], items: 0, pages: 0 },
Expand All @@ -60,6 +68,10 @@ export class UserFacade extends EntityFacade<User> {
this.onLoadOne(this.findUserByIDUseCase.execute(id));
}

loadOneByName(name: string) {
this.onLoadOne(this.findUserByNameUseCase.execute(name));
}

updateProfile(data: UpdateProfile) {
this.updateProfileUseCase.execute(data).pipe(take(1)).subscribe();
}
Expand Down Expand Up @@ -90,5 +102,6 @@ export function provideUserFacade() {
UpdateSocialUseCase,
UpdateRolesUseCase,
DeleteUserUseCase,
FindUserByNameUseCase
]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export class UserHttpServiceImpl
extends HttpService<User>
implements UserService
{
findOneByName(name: string) {
const url = [this.url, 'about', name];

return this.http.get<User>(url.join('/'));
}

updatePassword(data: UpdatePassword) {
const url = [this.url, data.id, 'password'];

Expand Down
1 change: 1 addition & 0 deletions packages/account/data-access/src/lib/mappers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './to-user-schema';
13 changes: 13 additions & 0 deletions packages/account/data-access/src/lib/mappers/to-user-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { AboutUserSchema, User } from '@devmx/shared-api-interfaces';

export function toAboutUserSchema(user: User): AboutUserSchema {
return {
'@context': 'https://schema.org',
'@type': 'Person',
name: user.displayName,
// image: 'janedoe.jpg',
// jobTitle: 'Professor',
email: `mailto:${user.contact.email}`,
url: `https://devparana.mx/sobre/${user.name}`,
};
}
6 changes: 6 additions & 0 deletions packages/account/data-access/src/lib/providers/use-cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ValidateUserCodeUseCase,
LoadAuthenticationUseCase,
UpdateRolesUseCase,
FindUserByNameUseCase,
} from '@devmx/account-domain/client';

export function provideCreateUserUseCase() {
Expand All @@ -27,6 +28,10 @@ export function provideFindUserByIDUseCase() {
return createUseCaseProvider(FindUserByIDUseCase, [UserService]);
}

export function provideFindUserByNameUseCase() {
return createUseCaseProvider(FindUserByNameUseCase, [UserService]);
}

export function provideFindUsersUseCase() {
return createUseCaseProvider(FindUsersUseCase, [UserService]);
}
Expand Down Expand Up @@ -68,6 +73,7 @@ export function provideUseCases() {
provideCreateUserUseCase(),
provideDeleteUserUseCase(),
provideFindUserByIDUseCase(),
provideFindUserByNameUseCase(),
provideFindUsersUseCase(),
provideLoadAuthenticationUseCase(),
provideSendUserCodeUseCase(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Params } from '@devmx/shared-api-interfaces';
import { distinctUntilChanged, filter } from 'rxjs';
import { UserFacade } from '../application';

export const aboutUserResolverWrapped = (
facade: UserFacade,
params: Params
) => {
facade.loadOneByName(params['name']);

return facade.selected$.pipe(
distinctUntilChanged(),
filter((event) => !!event)
);
};
2 changes: 2 additions & 0 deletions packages/account/data-access/src/lib/resolvers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './about-user-resolver-wrapped';
export * from './user-schema-resolver-wrapped';
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Params } from '@devmx/shared-api-interfaces';
import { distinctUntilChanged, filter } from 'rxjs';
import { UserFacade } from '../application';

export const userSchemaResolverWrapped = (
facade: UserFacade,
params: Params
) => {
facade.loadOneByName(params['name']);

return facade.schema$.pipe(
distinctUntilChanged(),
filter((user) => !!user)
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
FindUserByIDUseCase,
DeleteUserUseCase,
UpdateRolesUseCase,
FindUserByNameUseCase,
} from '@devmx/account-domain/server';
import {
UserDto,
Expand All @@ -30,7 +31,8 @@ export class UsersFacade {
private updateProfileUseCase: UpdateProfileUseCase,
private updateSocialUseCase: UpdateSocialUseCase,
private updatePasswordUseCase: UpdatePasswordUseCase,
private updateRolesUseCase: UpdateRolesUseCase
private updateRolesUseCase: UpdateRolesUseCase,
private findUserByNameUseCase: FindUserByNameUseCase
) {}

async find(params: QueryParamsDto<User>) {
Expand All @@ -44,6 +46,11 @@ export class UsersFacade {
return plainToInstance(UserDto, user);
}

async findOneByName(name: string) {
const user = await this.findUserByNameUseCase.execute(name);
return plainToInstance(UserDto, user);
}

async updateProfile(data: UpdateProfileDto) {
return await this.updateProfileUseCase.execute(data);
}
Expand Down Expand Up @@ -74,5 +81,6 @@ export function provideUsersFacade() {
UpdateSocialUseCase,
UpdatePasswordUseCase,
UpdateRolesUseCase,
FindUserByNameUseCase,
]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ import {
UserProfile,
UserSocial,
} from '@devmx/shared-api-interfaces';

export class UsersMongoServiceImpl
extends MongoService<UserCollection>
implements UsersService
{
async findByName(value: string) {
const name = new RegExp(value);
const entity = await this.entityModel.findOne({ name }).exec();
return entity ? (entity.toJSON() as UserCollection) : null;
}

async updateCode(id: string, code: UserCode) {
const updated = await this.entityModel
.findByIdAndUpdate(id, { code })
Expand Down
6 changes: 6 additions & 0 deletions packages/account/data-source/src/lib/providers/use-cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
FindUserByIDUseCase,
DeleteUserUseCase,
UpdateRolesUseCase,
FindUserByNameUseCase,
} from '@devmx/account-domain/server';

export function provideSendUserCodeUseCase() {
Expand Down Expand Up @@ -44,6 +45,10 @@ export function provideFindUserByIDUseCase() {
return createUseCaseProvider(FindUserByIDUseCase, [UsersService]);
}

export function provideFindUserByNameUseCase() {
return createUseCaseProvider(FindUserByNameUseCase, [UsersService]);
}

export function provideDeleteUserUseCase() {
return createUseCaseProvider(DeleteUserUseCase, [UsersService]);
}
Expand Down Expand Up @@ -76,6 +81,7 @@ export function provideUseCases() {

provideFindUsersUseCase(),
provideFindUserByIDUseCase(),
provideFindUserByNameUseCase(),
provideDeleteUserUseCase(),
provideUpdatePasswordUseCase(),
provideUpdateProfileUseCase(),
Expand Down
2 changes: 1 addition & 1 deletion packages/account/data-source/src/lib/schemas/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Document } from 'mongoose';
export class UserCollection extends Document implements User {
override id: string;

@Prop({ required: true, unique: true, index: 'text', type: String })
@Prop({ required: true, unique: true, index: true, type: String })
name: string;

@Prop({ required: true, type: String })
Expand Down
2 changes: 2 additions & 0 deletions packages/account/domain/src/client/services/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
} from '../../lib/dtos';

export abstract class UserService extends EntityService<User> {
abstract findOneByName(name: string): Observable<User>;

abstract updatePassword(data: UpdatePassword): Observable<User | null>;

abstract updateProfile(data: UpdateProfile): Observable<User | null>;
Expand Down
10 changes: 10 additions & 0 deletions packages/account/domain/src/client/use-cases/find-user-by-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { UseCase, User } from '@devmx/shared-api-interfaces';
import { UserService } from '../services';

export class FindUserByNameUseCase implements UseCase<string, User | null> {
constructor(private userService: UserService) {}

execute(name: string) {
return this.userService.findOneByName(name);
}
}
23 changes: 12 additions & 11 deletions packages/account/domain/src/client/use-cases/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export * from './create-user';
export * from './delete-user';
export * from './find-user-by-id';
export * from './find-users';
export * from './load-authentication';
export * from './send-user-code';
export * from './update-password';
export * from './update-profile';
export * from './update-roles';
export * from './update-social';
export * from './validate-user-code';
export * from './create-user';
export * from './delete-user';
export * from './find-user-by-id';
export * from './find-user-by-name';
export * from './find-users';
export * from './load-authentication';
export * from './send-user-code';
export * from './update-password';
export * from './update-profile';
export * from './update-roles';
export * from './update-social';
export * from './validate-user-code';
2 changes: 2 additions & 0 deletions packages/account/domain/src/server/services/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
} from '@devmx/shared-api-interfaces';

export abstract class UsersService extends EntityService<User> {
abstract findByName(name: string): Promise<User | null>;

abstract updateCode(id: string, code: UserCode): Promise<User | null>;

abstract updatePassword(
Expand Down
10 changes: 10 additions & 0 deletions packages/account/domain/src/server/use-cases/find-user-by-name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { UseCase, User } from '@devmx/shared-api-interfaces';
import { UsersService } from '../services';

export class FindUserByNameUseCase implements UseCase<string, User | null> {
constructor(private usersService: UsersService) {}

async execute(name: string) {
return this.usersService.findByName(name);
}
}
21 changes: 11 additions & 10 deletions packages/account/domain/src/server/use-cases/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
export * from './authentication';
export * from './create-user';
export * from './delete-user';
export * from './find-user-by-id';
export * from './find-users';
export * from './send-user-code';
export * from './update-password';
export * from './update-profile';
export * from './update-roles';
export * from './update-social';
export * from './authentication';
export * from './create-user';
export * from './delete-user';
export * from './find-user-by-id';
export * from './find-user-by-name';
export * from './find-users';
export * from './send-user-code';
export * from './update-password';
export * from './update-profile';
export * from './update-roles';
export * from './update-social';
42 changes: 42 additions & 0 deletions packages/account/feature-about/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "devmx",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "devmx",
"style": "kebab-case"
}
],
"@angular-eslint/component-class-suffix": [
"error",
{
"suffixes": ["Component", "Container", "Dialog"]
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nx/angular-template"],
"rules": {}
}
]
}
Loading

0 comments on commit 87ca74d

Please sign in to comment.