Skip to content

Commit 484b11b

Browse files
committed
User and Post service
1 parent f433039 commit 484b11b

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/services/post.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { TYPES } from "../types"
2+
import IPostRepositoryInterface from "../repositories/interfaces/postInterface"
3+
import { inject, injectable } from "inversify"
4+
import { ICreatePostDTO, IUpdatePostDTO } from "../dtos/postDTO"
5+
6+
7+
@injectable()
8+
export default class PostService {
9+
public postRepo: IPostRepositoryInterface
10+
11+
constructor(@inject(TYPES.IPostRepositoryInterface) postRepo: IPostRepositoryInterface) {
12+
this.postRepo = postRepo;
13+
}
14+
15+
public async getAll() {
16+
return await this.postRepo.all();
17+
}
18+
19+
public async find(id: number) {
20+
return await this.postRepo.find(id);
21+
}
22+
23+
public async create(inputData: ICreatePostDTO) {
24+
return await this.postRepo.create(inputData);
25+
}
26+
27+
public async update(id: number, inputData: IUpdatePostDTO) {
28+
return await this.postRepo.update(id, inputData);
29+
}
30+
31+
public async delete(id) {
32+
await this.postRepo.delete(id);
33+
}
34+
}

src/services/user.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { TYPES } from "../types"
2+
import IUserRepositoryInterface from "../repositories/interfaces/userInterface"
3+
import { inject, injectable } from "inversify"
4+
import { IUserDTO } from "../dtos/userDTO"
5+
6+
7+
@injectable()
8+
export default class userService {
9+
public userRepo: IUserRepositoryInterface
10+
11+
constructor(@inject(TYPES.IUserRepositoryInterface) userRepo: IUserRepositoryInterface) {
12+
this.userRepo = userRepo;
13+
}
14+
15+
public async getAll(): Promise<IUserDTO[]> {
16+
return await this.userRepo.all();
17+
}
18+
19+
public async find(id: number): Promise<IUserDTO> {
20+
return await this.userRepo.find(id);
21+
}
22+
}

0 commit comments

Comments
 (0)