Skip to content

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
guiseek committed Sep 6, 2024
1 parent 0a3da63 commit 4c5e984
Show file tree
Hide file tree
Showing 36 changed files with 462 additions and 125 deletions.
27 changes: 17 additions & 10 deletions apps/server/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
/**
* This is not a production server yet!
* This is only a minimal backend to get started.
*/

import { Logger } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { NestFactory } from '@nestjs/core';

import { Logger } from '@nestjs/common';
import { AppModule } from './app/app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const globalPrefix = 'api';
app.setGlobalPrefix(globalPrefix);
const prefix = 'api';
app.setGlobalPrefix(prefix);

const config = new DocumentBuilder()
.setTitle('DevParaná')
.setDescription('The DevParaná Platform API')
.setVersion('1.0')
.addBearerAuth()
.build();

const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('docs', app, document);

const port = process.env.PORT || 3000;
await app.listen(port);

Logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
`🚀 Application is running on: http://localhost:${port}/${prefix}`
);
}

Expand Down
45 changes: 45 additions & 0 deletions docs/data-source.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<h1>Data Source</h1>
<p>Esta camada tem como responsabilidade o acesso a dados no lado do servidor, contendo códigos que modela e se comunica com um ou mais tipos de fonte de dados e tudo que está relacionado diretamente, como gerenciamento de estado por exemplo.</p>
<blockquote>
<p>Aqui encontraremos muitas implementações concretas cujos contratos foram definidos na camada de domínio.</p>
</blockquote>
<h2>Estrutura</h2>
<pre><code class="language-sh">📂 src
└── 📂 lib
├── dtos
├── entities
├── facades
├── providers
├── repositories
├── services
└── providers.ts
</code></pre>
<h2>DTOs</h2>
<h2>Entities</h2>
<h2>Facades</h2>
<h2>Providers</h2>
<h2>Repositories</h2>
<h2>Services</h2>
<style>
body {
font-family: 'Segoe UI', sans-serif;
}
blockquote {
margin-left: 1em;
margin-top: 1em;
padding: 0.06em 0.6em;
background-color: #12e20b4a;
border-style: solid;
border-color: #12e20b;
border-width: 0 0.2em 0.2em 0;
border-radius: 0.3em;

transition: margin 500ms ease-in-out, border 500ms ease-in-out;
}
blockquote:hover {
margin-left: 0;
margin-top: 0;
border-width: 0 0.8em 0.8em 0;
}
</style>

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@nestjs/core": "^10.0.2",
"@nestjs/jwt": "^10.2.0",
"@nestjs/platform-express": "^10.0.2",
"@nestjs/swagger": "^7.4.0",
"@nestjs/typeorm": "^10.0.2",
"bcrypt": "^5.1.1",
"class-transformer": "^0.5.1",
Expand Down
5 changes: 4 additions & 1 deletion packages/data-source-account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"@platform/domain-account": "0.0.1",
"@platform/util-shared": "0.0.1",
"class-validator": "^0.14.1",
"typeorm": "^0.3.20"
"typeorm": "^0.3.20",
"@nestjs/typeorm": "^10.0.2",
"@nestjs/swagger": "^7.4.0",
"bcrypt": "^5.1.1"
},
"type": "commonjs",
"main": "./src/index.js",
Expand Down
31 changes: 31 additions & 0 deletions packages/data-source-account/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Data Source

Esta camada tem como responsabilidade o acesso a dados no lado do servidor, contendo códigos que modela e se comunica com um ou mais tipos de fonte de dados e tudo que está relacionado diretamente, como gerenciamento de estado por exemplo.

> Aqui encontraremos muitas implementações concretas cujos contratos foram definidos na camada de domínio.
## Estrutura

```sh
📂 src
└── 📂 lib
├── dtos
├── entities
├── facades
├── providers
├── repositories
├── services
└── providers.ts
```

## DTOs

## Entities

## Facades

## Providers

## Repositories

## Services

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions packages/data-source-account/src/lib/data-source-account.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/data-source-account/src/lib/dtos/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './create-user';
export * from './sign-in';
export * from './sign-up';
3 changes: 3 additions & 0 deletions packages/data-source-account/src/lib/dtos/sign-in.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { IsString, MinLength } from 'class-validator';
import { SignIn } from '@platform/domain-account';
import { ApiProperty } from '@nestjs/swagger';

export class SignInDto implements SignIn {
@IsString()
@ApiProperty()
username: string;

@IsString()
@MinLength(6)
@ApiProperty()
password: string;
}
30 changes: 30 additions & 0 deletions packages/data-source-account/src/lib/dtos/sign-up.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { IsEmail, IsString, MinLength } from 'class-validator';
import { SignUp } from '@platform/domain-account';
import { ApiProperty } from '@nestjs/swagger';

export class SignUpDto implements SignUp {
@IsString()
@ApiProperty()
firstName: string;

@IsString()
@ApiProperty()
lastName: string;

@IsEmail()
@ApiProperty()
email: string;

@IsString()
@ApiProperty()
username: string;

@IsString()
@MinLength(6)
@ApiProperty()
password: string;

phone?: string;

photo?: string;
}
13 changes: 10 additions & 3 deletions packages/data-source-account/src/lib/facades/auth.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { SignInServerUseCase } from '@platform/domain-account';
import { SignInDto } from '../dtos';
import { SignInServerUseCase, SignUpServerUseCase } from '@platform/domain-account';
import { SignInDto, SignUpDto } from '../dtos';

export class AuthFacade {
constructor(private readonly signInUseCase: SignInServerUseCase) {}
constructor(
private readonly signInUseCase: SignInServerUseCase,
private readonly signUpUseCase: SignUpServerUseCase
) {}

signIn(data: SignInDto) {
return this.signInUseCase.execute(data);
}

signUp(data: SignUpDto) {
return this.signUpUseCase.execute(data);
}
}
5 changes: 1 addition & 4 deletions packages/data-source-account/src/lib/facades/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ export class UserFacade {
constructor(
private readonly createUserUseCase: CreateUserServerUseCase,
private readonly findUsersUseCase: FindUsersServerUseCase
) {
console.log(createUserUseCase, findUsersUseCase);

}
) {}

createUser(data: CreateUserDto) {
return this.createUserUseCase.execute(data);
Expand Down
29 changes: 29 additions & 0 deletions packages/data-source-account/src/lib/providers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
provideAuthServerFacade,
provideCreateUserServerUseCase,
provideCryptoService,
provideFindUsersServerUseCase,
provideSignInServerUseCase,
provideSignUpServerUseCase,
provideUserRepository,
provideUserServerFacade,
} from './providers/index';
import { UserRepositoryImpl } from './repositories';
import { Provider } from '@platform/util-shared';
import { CryptoServiceImpl } from './services';

export const dataSourceAccountProviders: Provider[] = [
provideUserRepository(UserRepositoryImpl),

provideCreateUserServerUseCase(),
provideFindUsersServerUseCase(),

provideUserServerFacade(),

provideCryptoService(CryptoServiceImpl),

provideSignInServerUseCase(),
provideSignUpServerUseCase(),

provideAuthServerFacade(),
];
30 changes: 30 additions & 0 deletions packages/data-source-account/src/lib/providers/facade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
CreateUserServerUseCase,
FindUsersServerUseCase,
SignInServerUseCase,
SignUpServerUseCase,
} from '@platform/domain-account';
import { AuthFacade, UserFacade } from '../facades';

export function provideUserServerFacade() {
return {
provide: UserFacade,
useFactory(
createUser: CreateUserServerUseCase,
findUsers: FindUsersServerUseCase
) {
return new UserFacade(createUser, findUsers);
},
inject: [CreateUserServerUseCase, FindUsersServerUseCase],
};
}

export function provideAuthServerFacade() {
return {
provide: AuthFacade,
useFactory(signIn: SignInServerUseCase, signUp: SignUpServerUseCase) {
return new AuthFacade(signIn, signUp);
},
inject: [SignInServerUseCase, SignUpServerUseCase],
};
}
3 changes: 3 additions & 0 deletions packages/data-source-account/src/lib/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export * from './crypto';
export * from './facade';
export * from './jwt';
export * from './repository';
export * from './use-case';
22 changes: 22 additions & 0 deletions packages/data-source-account/src/lib/providers/repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { UserRepository } from '@platform/domain-account';
import { getRepositoryToken } from '@nestjs/typeorm';
import { Type } from '@platform/util-shared';
import { UserEntity } from '../entities';
import { Repository } from 'typeorm';

export function provideUserRepository(Repository: Type<UserRepository>) {
return {
provide: UserRepository,
useFactory(repository: Repository<UserEntity>) {
return new Repository(repository);
},
inject: [getRepositoryToken(UserEntity)],
};
}

export function provideUserRepositoryTest(Repository: UserRepository) {
return {
provide: UserRepository,
useValue: Repository,
};
}
Loading

0 comments on commit 4c5e984

Please sign in to comment.