Skip to content

Commit

Permalink
Adding find all posts use-case to inversify types and adding the prop…
Browse files Browse the repository at this point in the history
…osed router
  • Loading branch information
devbenho committed May 30, 2024
1 parent 2d1b457 commit 7cfac23
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
Binary file modified server/db.sqlite3
Binary file not shown.
1 change: 1 addition & 0 deletions server/src/infrastructure/shared/ioc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let TYPES = {
IRegisterInputPort: Symbol.for('IRegisterInputPort'),

ICreatePostInputPort: Symbol.for('ICreatePostInputPort'),
IFindAllPostInputPort: Symbol.for('IFindAllPostInputPort'),
ICreatePostOutputPort: Symbol.for('ICreatePostOutputPort'),

ILoginOutputPort: Symbol.for('ILoginOutputPort'),
Expand Down
6 changes: 3 additions & 3 deletions server/src/web/process.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{"level":30,"time":1716762101785,"msg":"Application is running on port 2105 🚀"}
{"level":30,"time":1716762101792,"msg":"Environment: development"}
{"level":30,"time":1716762101813,"msg":"Data source initialized"}
{"level":30,"time":1717071773671,"msg":"Application is running on port 2105 🚀"}
{"level":30,"time":1717071773674,"msg":"Environment: development"}
{"level":30,"time":1717071773694,"msg":"Data source initialized"}
21 changes: 21 additions & 0 deletions server/src/web/rest/controllers/posts.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,30 @@ import { ExpressHandler } from '../infrastucture/express-handler';
import BaseController from './base.controller';
import { LOGGER } from '../logger';
import { POST_STATUS } from '@domain/eums/post-status.enum';
import { FindAllPostRequest } from '@application/post/find-all/find-all-post.request';
import { PostResponseDto } from '@contracts/dtos/posts';

@injectable()
export class PostsController implements BaseController {
private _createPostUseCase: BaseUseCase<
CreatePostRequest,
CreatePostResponseDto
>;
private _findAllPostUseCase: BaseUseCase<
FindAllPostRequest,
PostResponseDto[]
>;
constructor(
@inject(TYPES.ICreatePostInputPort)
_createPostInteractor: BaseUseCase<
CreatePostRequest,
CreatePostResponseDto
>,
@inject(TYPES.IFindAllPostInputPort)
_findAllPostInteractor: BaseUseCase<FindAllPostRequest, PostResponseDto[]>,
) {
this._createPostUseCase = _createPostInteractor;
this._findAllPostUseCase = _findAllPostInteractor;
}

public create: ExpressHandler<CreatePostRequest, CreatePostResponseDto> =
Expand All @@ -45,4 +54,16 @@ export class PostsController implements BaseController {
const result = await this._createPostUseCase.execute(request);
return res.json(result);
};

public findAll: ExpressHandler<FindAllPostRequest, PostResponseDto[]> =
async (req, res) => {
LOGGER.info('PostsController.findAll');
const request = FindAllPostRequest.create(
new TriggeredByUser(res.locals.userId, []),
req.query.pageSize || 10,
req.query.pageNumber || 1,
);
const result = await this._findAllPostUseCase.execute(request);
return result;
};
}
3 changes: 2 additions & 1 deletion server/src/web/rest/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default class ApplicationRouter {
app.post('/auth/login', this.getController(this.authController, 'login'));
app
.use(AuthMiddleware.jwtParseMiddleware)
.post('/posts', this.getController(this.postsController, 'create'));
.post('/posts', this.getController(this.postsController, 'create'))
.get('/posts', this.getController(this.postsController, 'findAll'));
}
}

0 comments on commit 7cfac23

Please sign in to comment.