-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
287 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { HttpCollaboratorAdapter } from '@src/languages/infrastructure/persistence/http/httpCollaboratorAdapter'; | ||
|
||
export const services = [ | ||
HttpCollaboratorAdapter | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { AggregateRoot } from '@src/shared/domain/aggregate/aggregateRoot'; | ||
import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; | ||
|
||
export type CollaboratorPrimitives = { | ||
id: string; | ||
name: string; | ||
photo: string; | ||
interests: string[]; | ||
}; | ||
|
||
export default class Collaborator extends AggregateRoot { | ||
constructor(private id: CollaboratorId, private name: string, private photo: string, private interests: string[]) { | ||
super(); | ||
} | ||
|
||
public getName(): string { | ||
return this.name; | ||
} | ||
|
||
public getPhoto(): string { | ||
return this.photo; | ||
} | ||
|
||
public getInterests(): string[] { | ||
return this.interests; | ||
} | ||
|
||
toPrimitives(): CollaboratorPrimitives { | ||
return { | ||
id: this.id.toString(), | ||
name: this.name, | ||
photo: this.photo, | ||
interests: this.interests, | ||
}; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/languages/domain/collaborator/collaboratorDoesNotExistsException.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import NotFoundException from '@src/shared/domain/exceptions/notFoundException'; | ||
|
||
export default class CollaboratorDoesNotExistsException extends NotFoundException { | ||
constructor(collaboratorId: string) { | ||
super(`Collaborator ${collaboratorId} does not exists`, 'collaborator_does_not_exists'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Uuid } from '@src/shared/domain/valueObjects/uuid'; | ||
|
||
export default class CollaboratorId extends Uuid { | ||
static of(value: string): CollaboratorId { | ||
return super.of(value) as CollaboratorId; | ||
} | ||
|
||
static fromPrimitives(value: string): CollaboratorId { | ||
return super.fromPrimitives(value) as CollaboratorId; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/languages/domain/collaborator/collaboratorRepository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Collaborator from '@src/languages/domain/collaborator/collaborator'; | ||
import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; | ||
|
||
interface CollaboratorRepository { | ||
findById(id: CollaboratorId): Promise<Collaborator | null>; | ||
} | ||
|
||
export default CollaboratorRepository; | ||
|
||
export const COLLABORATOR_REPOSITORY = Symbol('CollaboratorRepository'); |
14 changes: 14 additions & 0 deletions
14
src/languages/infrastructure/persistence/http/TranslatingCollaboratorRepository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import CollaboratorRepository from '@src/languages/domain/collaborator/collaboratorRepository'; | ||
import Collaborator from '@src/languages/domain/collaborator/collaborator'; | ||
import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { HttpCollaboratorAdapter } from '@src/languages/infrastructure/persistence/http/httpCollaboratorAdapter'; | ||
|
||
@Injectable() | ||
export class TranslatingCollaboratorRepository implements CollaboratorRepository { | ||
constructor(private readonly httpCollaboratorAdapter: HttpCollaboratorAdapter) {} | ||
|
||
async findById(id: CollaboratorId): Promise<Collaborator | null> { | ||
return this.httpCollaboratorAdapter.toCollaborator(id); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/languages/infrastructure/persistence/http/collaboratorTranslator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Collaborator from '@src/languages/domain/collaborator/collaborator'; | ||
import { AxiosResponse } from 'axios'; | ||
|
||
export class CollaboratorTranslator { | ||
static toCollaborator(collaboratorResponse: AxiosResponse): Collaborator { | ||
const collaborator = collaboratorResponse.data; | ||
return new Collaborator(collaborator.id, collaborator.name, collaborator.photo, collaborator.interests); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/languages/infrastructure/persistence/http/httpCollaboratorAdapter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { HttpService } from '@nestjs/axios'; | ||
import { firstValueFrom } from 'rxjs'; | ||
import CollaboratorId from '@src/languages/domain/collaborator/collaboratorId'; | ||
import Collaborator from '@src/languages/domain/collaborator/collaborator'; | ||
import { CollaboratorTranslator } from '@src/languages/infrastructure/persistence/http/collaboratorTranslator'; | ||
|
||
@Injectable() | ||
export class HttpCollaboratorAdapter { | ||
URL = '/users/{id}'; | ||
constructor(private readonly httpService: HttpService) {} | ||
|
||
async toCollaborator(id: CollaboratorId): Promise<Collaborator | null> { | ||
const { data } = await firstValueFrom(this.httpService.get(this.URL.replace('{id}', id.toString))); | ||
|
||
return CollaboratorTranslator.toCollaborator(data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.