Skip to content

Commit df97e2c

Browse files
authored
Dev (#110)
* fixed signup and login links and made register page public * replaced IAM view model with redux * replaced todo view model with redux * removed recoil from modules * added infinite scrolling to todo page * fixed infinite scroll and changed version * wrote test and moved slices to store directory * updated readme
1 parent 5769fd3 commit df97e2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+6655
-1026
lines changed

README.md

Lines changed: 284 additions & 235 deletions
Large diffs are not rendered by default.

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,4 @@
113113
"@tests/(.*)": "tests/$1"
114114
}
115115
}
116-
}
116+
}

backend/src/api/todo.rest.controller.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
Param,
1313
UseGuards,
1414
Request,
15+
Query,
1516
} from '@nestjs/common';
1617
import { ConfigService } from '@nestjs/config';
1718
import {
@@ -81,9 +82,10 @@ export class TodoController {
8182
@Get()
8283
@ApiOperation({ summary: 'Get all todos' })
8384
@ApiResponse({ status: 200, type: GetAllTodosResponseDto, description: 'Returns all todos' })
84-
async getAll() {
85-
const results = await this.queryBus.request(new GetTodosQuery());
86-
85+
async getAll(@Query('limit') limit: number, @Query('offset') offset: number) {
86+
const results = await this.queryBus.request(
87+
new GetTodosQuery(limit, offset),
88+
);
8789
if (results.isOk) {
8890
const data = results.data;
8991
const todos: TodoReadModel[] = data.map((todo) => TodoReadModel.fromPrimitives(todo));

backend/src/bounded-contexts/todo/todo/repository/todo-read.repository.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ export class TodoReadRepository implements TodoReadRepoPort {
4747
}
4848

4949
@Application.Repo.Decorators.ReturnUnexpectedError()
50-
async getAll(): Promise<
50+
async getAll(params?: {
51+
limit?: number;
52+
offset?: number;
53+
}): Promise<
5154
Either<TTodoReadModelSnapshot[], Application.Repo.Errors.Unexpected>
5255
> {
5356
const ctx = asyncLocalStorage.getStore()?.get('context');
@@ -62,9 +65,16 @@ export class TodoReadRepository implements TodoReadRepoPort {
6265
if (!userId) {
6366
throw new Error('Invalid userId');
6467
}
65-
const todos = await this.collection
66-
.find({ userId: { id: userId } })
67-
.toArray();
68+
let cursor = this.collection.find({ userId: { id: userId } });
69+
70+
if (params?.offset !== undefined) {
71+
cursor = cursor.skip(+params.offset);
72+
}
73+
if (params?.limit !== undefined) {
74+
cursor = cursor.limit(+params.limit);
75+
}
76+
77+
const todos = await cursor.toArray();
6878
return ok(
6979
todos.map((todo) => {
7080
const res = {

backend/src/lib/bounded-contexts/todo/todo/application/query-handlers/get-todos.handler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ export type GetTodosQueryHandlerResponse = Either<
1313
>;
1414

1515
export class GetTodosHandler
16-
implements Application.IQueryHandler<GetTodosQuery, TTodoReadModelSnapshot[]>
17-
{
16+
implements Application.IQueryHandler<GetTodosQuery, TTodoReadModelSnapshot[]> {
1817
constructor(
1918
@Inject(TodoReadRepoPortToken)
2019
private readonly todoRepo: TodoReadRepoPort,
21-
) {}
20+
) { }
2221

2322
get query() {
2423
return GetTodosQuery;
@@ -37,7 +36,8 @@ export class GetTodosHandler
3736
},
3837
})
3938
async execute(query: GetTodosQuery): Promise<GetTodosQueryHandlerResponse> {
40-
const results = await this.todoRepo.getAll();
39+
const { limit, offset } = query;
40+
const results = await this.todoRepo.getAll({ limit, offset });
4141
if (results.isFail()) return fail(results.value);
4242
if (results.value) return ok(results.value);
4343
return ok([]);
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
import { Application } from '@bitloops/bl-boilerplate-core';
1+
import { Application, Either } from '@bitloops/bl-boilerplate-core';
22
import { TTodoReadModelSnapshot } from '../domain/todo.read-model.js';
33

4-
export type TodoReadRepoPort =
5-
Application.Repo.ICRUDReadPort<TTodoReadModelSnapshot>;
6-
4+
export interface TodoReadRepoPort
5+
extends Application.Repo.ICRUDReadPort<TTodoReadModelSnapshot> {
6+
getAll(params?: {
7+
limit?: number;
8+
offset?: number;
9+
}): Promise<
10+
Either<TTodoReadModelSnapshot[], Application.Repo.Errors.Unexpected>
11+
>;
12+
}
713
// export interface ITodoReadRepository {
814
// findAll(): Promise<TodoReadModel[]>;
915
// }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Application } from '@bitloops/bl-boilerplate-core';
22

33
export class GetTodosQuery extends Application.Query {
4-
constructor() {
4+
constructor(public readonly limit?: number, public readonly offset?: number) {
55
super('Todo');
66
}
77
}

backend/src/main.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ async function bootstrap() {
2121
}),
2222
{ abortOnError: false },
2323
);
24-
24+
2525
// Swagger configuration
2626
const swaggerConfig = new DocumentBuilder()
2727
.setTitle('API Documentation')
2828
.setDescription('API description')
2929
.setVersion('1.0')
3030
.addBearerAuth()
3131
.build();
32-
32+
3333
const document = SwaggerModule.createDocument(api, swaggerConfig);
3434
SwaggerModule.setup('api', api, document);
35-
35+
3636
writeFileSync('swagger.json', JSON.stringify(document, null, 2));
3737

3838
api.enableCors({
39-
origin: ['http://localhost:5175', 'http://localhost:4173'],
39+
origin: ['http://localhost:5175', 'http://localhost:4173', 'http://localhost:5173'],
4040
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH'],
4141
allowedHeaders: ['Content-Type', 'Accept', 'Authorization', 'Cache-Control', 'Last-Event-ID', 'x-request-id', 'x-user-agent', 'cache-hash'],
4242
exposedHeaders: ['Authorization', 'Content-Type'],

backend/swagger.json

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,24 @@
9797
},
9898
"get": {
9999
"operationId": "TodoController_getAll",
100-
"parameters": [],
100+
"parameters": [
101+
{
102+
"name": "limit",
103+
"required": true,
104+
"in": "query",
105+
"schema": {
106+
"type": "number"
107+
}
108+
},
109+
{
110+
"name": "offset",
111+
"required": true,
112+
"in": "query",
113+
"schema": {
114+
"type": "number"
115+
}
116+
}
117+
],
101118
"responses": {
102119
"200": {
103120
"description": "Returns all todos",

frontend/package-lock.json

Lines changed: 109 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)