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

Тестовое выполнено #5

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Implemented data layer
BlueXTX committed May 2, 2023
commit 3efffbecd00500ffe7bd05f75af6761a36ae03ee
11 changes: 10 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
@@ -56,7 +56,13 @@
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
"namedChunks": true,
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.development.ts"
}
]
}
},
"defaultConfiguration": "production"
@@ -100,5 +106,8 @@
}
}
}
},
"cli": {
"analytics": false
}
}
54 changes: 54 additions & 0 deletions src/data/data.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {NgModule} from "@angular/core";
import {CommonModule} from "@angular/common";
import {HttpClientModule} from "@angular/common/http";
import {ThesisRepository} from "../domain/repositories/thesis.repository";
import {GetAllUseCase} from "../domain/usecases/get-all.usecase";
import {Thesis} from "../domain/models/thesis.model";
import {GetUseCase} from "../domain/usecases/get.usecase";
import {UpdateUseCase} from "../domain/usecases/update.usecase";
import {DeleteUseCase} from "../domain/usecases/delete.usecase";
import {CreateUseCase} from "../domain/usecases/create.usecase";

const getAllUseCaseFactory = (thesisRepository: ThesisRepository) => new GetAllUseCase(thesisRepository);
export const getAllUseCaseProvider = {
provide: GetAllUseCase,
useFactory: getAllUseCaseFactory,
deps: [ThesisRepository]
}

const getUseCaseFactory = (thesisRepository: ThesisRepository) => new GetUseCase(thesisRepository);
export const getUseCaseProvider = {
provide: GetUseCase,
useFactory: getUseCaseFactory,
deps: [ThesisRepository]
}

const createUseCaseFactory = (thesisRepository: ThesisRepository) => new CreateUseCase(thesisRepository);
export const createUseCaseProvider = {
provide: CreateUseCase,
useFactory: createUseCaseFactory,
deps: [ThesisRepository]
}

const updateUseCaseFactory = (thesisRepository: ThesisRepository) => new UpdateUseCase(thesisRepository);
export const updateUseCaseProvider = {
provide: UpdateUseCase,
useFactory: updateUseCaseFactory,
deps: [ThesisRepository]
}

const deleteUseCaseFactory = (thesisRepository: ThesisRepository) => new DeleteUseCase(thesisRepository);
export const deleteUseCaseProvider = {
provide: DeleteUseCase,
useFactory: deleteUseCaseFactory,
deps: [ThesisRepository]
}

@NgModule({
providers: [],
imports: [
CommonModule,
HttpClientModule
]
})
export class DataModule {}
12 changes: 12 additions & 0 deletions src/data/repositories/thesis/entities/thesis-entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {Person} from "../../../../domain/models/person.model";

export interface ThesisEntity {
id: number,
mainAuthor: Person,
contactEmail: string,
otherAuthors: Array<Person>,
topic: string,
content: string,
created: Date,
updated: Date
}
31 changes: 31 additions & 0 deletions src/data/repositories/thesis/mappers/thesis-repository.mapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {Mapper} from "../../../../base/utils/mapper";
import {ThesisEntity} from "../entities/thesis-entity";
import {Thesis} from "../../../../domain/models/thesis.model";

export class ThesisRepositoryMapper extends Mapper<ThesisEntity, Thesis> {
mapFrom(param: ThesisEntity): Thesis {
return {
id: param.id,
mainAuthor: param.mainAuthor,
contactEmail: param.contactEmail,
otherAuthors: param.otherAuthors,
topic: param.topic,
content: param.content,
created: param.created,
updated: param.updated
}
}

mapTo(param: Thesis): ThesisEntity {
return {
id: param.id,
mainAuthor: param.mainAuthor,
contactEmail: param.contactEmail,
otherAuthors: param.otherAuthors,
topic: param.topic,
content: param.content,
created: param.created,
updated: param.updated
}
}
}
57 changes: 57 additions & 0 deletions src/data/repositories/thesis/thesis-web.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {Observable} from "rxjs";
import {ThesisRepository} from "../../../domain/repositories/thesis.repository";
import {Thesis} from "../../../domain/models/thesis.model";
import {Person} from "../../../domain/models/person.model";
import {environment} from "../../../environments/environment";
import {HttpClient} from "@angular/common/http";
import {ThesisShort} from "../../../domain/models/thesis-short.model";

export class ThesisWebRepository extends ThesisRepository {
private readonly baseUrl = environment.apiUrl;
private readonly API_ROUTES = {
get: (id: number) => this.baseUrl + `/theses/${id}`,
getAll: () => this.baseUrl + `/theses/all`,
create: () => this.baseUrl + `/theses`,
update: (id: number) => this.baseUrl + `/theses/${id}`,
delete: (id: number) => this.baseUrl + `/theses/${id}`
}

constructor(private http: HttpClient) {
super();
}


create(params: {
mainAuthor: Person;
contactEmail: string;
otherAuthors: Array<Person>;
topic: string;
content: string
}): Observable<Thesis> {
return this.http.post<Thesis>(this.API_ROUTES.create(), params);
}

delete(params: { id: number }): Observable<void> {
return this.http.delete<void>(this.API_ROUTES.delete(params.id));
}

get(params: { id: number }): Observable<Thesis> {
return this.http.get<Thesis>(this.API_ROUTES.get(params.id));
}

getAll(): Observable<Array<ThesisShort>> {
return this.http.get<Array<ThesisShort>>(this.API_ROUTES.getAll());
}

update(params: {
id: number;
mainAuthor: Person;
contactEmail: string;
otherAuthors: Array<Person>;
topic: string;
content: string
}): Observable<Thesis> {
const {id: _, ...updateParams} = params;
return this.http.put<Thesis>(this.API_ROUTES.update(params.id), updateParams);
}
}
4 changes: 4 additions & 0 deletions src/environments/environment.development.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const environment = {
production: false,
apiUrl: "https://conf.antibiotic.ru/demo/api"
};
4 changes: 4 additions & 0 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const environment = {
production: true,
apiUrl: "https://conf.antibiotic.ru/demo/api"
};