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

Feat: Questions repository filtering and sort #105

Open
wants to merge 37 commits into
base: main
Choose a base branch
from

Conversation

firwer
Copy link

@firwer firwer commented Sep 29, 2024

Feature:

  • Add filtering for difficulty and topics
  • Add sorting to table
    image
    image

github-classroom bot and others added 30 commits September 20, 2024 07:07
Use postcss for tailwind instead of cli. Followed shadcn manual
installation docs
- Add lint and type-check github workflows
- Fix files with issues
This PR adds API endpoints for questions-service:
`cmd`:
-`get_questions`
-`get_question`
-`create_question`
-`update_question`
-`delete_question`

Postman Collection:
https://www.postman.com/gold-station-786386/workspace/peerprep/collection/27342778-6fbf20dc-66a8-4c5a-b43d-a59d1efe03c7?action=share&creator=27342778&active-environment=27342778-f05ea77e-113b-46ee-a7e3-348077563858

Note: 
Need to add new env vars - check `README.md`
Supabase URL and key can be found
[here](https://supabase.com/dashboard/project/ncxgumrscmhhksignpks/settings/api)

---------

Co-authored-by: javinchua <[email protected]>
- Add `signIn`, `signOut`, `signUp`, `me` endpoints 
- Add `AuthGuard` to guard endpoints where users should be
authenticated. To use, just add this `@UseGuards(AuthGuard('supabase'))`
- Created profiles database with following columns:
<img width="972" alt="image"
src="https://github.com/user-attachments/assets/fba00cd9-32cf-4b7e-aac6-9432b3daf486">
- Added Row Level Security for selecting, inserting and modifying
- Uses Supabase generated types and added a `update-types` command (can
automate in workflow in future)
This PR improves error handling, validation, and filtering in the
`questions-services` module. The changes include updating exception
handling in the `RpcExceptionFilter`, enhancing validation in the
`QuestionsController`, and refining database error handling in the
`QuestionsService`.

### Error Handling Improvements:

*
[`project/apps/api-gateway/src/filters/rpc-exception.filter.ts`](diffhunk://#diff-d296104e4b77e6a77f90203da00e7b5c6e57dfcf641bf954420f8c420e07479fL12-R14):
Added a default status code of 500 if `error.statusCode` is undefined.
*
[`project/packages/pipes/src/zod-validation-pipe.pipe.ts`](diffhunk://#diff-5d1894d6f1391424e0b3b8f193c6472aad155978c55467ed8e0aa250ae37c760L1-R1):
Improved error formatting in `ZodValidationPipe` and added structured
error responses for validation failures.
[[1]](diffhunk://#diff-5d1894d6f1391424e0b3b8f193c6472aad155978c55467ed8e0aa250ae37c760L1-R1)
[[2]](diffhunk://#diff-5d1894d6f1391424e0b3b8f193c6472aad155978c55467ed8e0aa250ae37c760R10-R34)

### Validation Enhancements:

*
[`project/apps/api-gateway/src/questions/questions.controller.ts`](diffhunk://#diff-6d78e3581db5b3d5e0c2347d6bb808a1a71518a54e86de60ce58e2b7bd1e5eb6R14-R28):
Moved validation from `questions-service` module to `api-gateway`
module. Added `HttpException` and `HttpStatus` for better error
responses.
[[1]](diffhunk://#diff-6d78e3581db5b3d5e0c2347d6bb808a1a71518a54e86de60ce58e2b7bd1e5eb6R14-R28)
[[2]](diffhunk://#diff-6d78e3581db5b3d5e0c2347d6bb808a1a71518a54e86de60ce58e2b7bd1e5eb6L28-R41)
[[3]](diffhunk://#diff-6d78e3581db5b3d5e0c2347d6bb808a1a71518a54e86de60ce58e2b7bd1e5eb6R50)
[[4]](diffhunk://#diff-6d78e3581db5b3d5e0c2347d6bb808a1a71518a54e86de60ce58e2b7bd1e5eb6L51-R68)
*
[`project/packages/dtos/src/questions.ts`](diffhunk://#diff-7e9b2f555ea4cdd6633cac37c90e669ed96f8101a81fbb843f7b84647ce95e1dL3-R17):
Replaced enum schemas with string schemas for `category` and
`complexity`. Added `getQuestionsQuerySchema` for query validation.
[[1]](diffhunk://#diff-7e9b2f555ea4cdd6633cac37c90e669ed96f8101a81fbb843f7b84647ce95e1dL3-R17)
[[2]](diffhunk://#diff-7e9b2f555ea4cdd6633cac37c90e669ed96f8101a81fbb843f7b84647ce95e1dR33-R34)

### Database Error Handling:

*
[`project/apps/questions-service/src/questions.service.ts`](diffhunk://#diff-3a7f7758daf8d580911308d1a2a9847a586cad97e1192d50d2ed98f6701b9cb8R3-R14):
Refined error handling by introducing `RpcException` for database
operations. Updated `findAll` method to support filtering by `title`,
`category`, and `complexity`.
[[1]](diffhunk://#diff-3a7f7758daf8d580911308d1a2a9847a586cad97e1192d50d2ed98f6701b9cb8R3-R14)
[[2]](diffhunk://#diff-3a7f7758daf8d580911308d1a2a9847a586cad97e1192d50d2ed98f6701b9cb8L28-R67)
[[3]](diffhunk://#diff-3a7f7758daf8d580911308d1a2a9847a586cad97e1192d50d2ed98f6701b9cb8L60-R80)
[[4]](diffhunk://#diff-3a7f7758daf8d580911308d1a2a9847a586cad97e1192d50d2ed98f6701b9cb8L75-R111)
[[5]](diffhunk://#diff-3a7f7758daf8d580911308d1a2a9847a586cad97e1192d50d2ed98f6701b9cb8L112-R127)
**Description**
This PR initializes the frontend for the Question Repository page,
enabling CRUD operations for questions. The page includes a table
displaying all questions, with the ability to view, edit, delete, and
create new questions via modals. Each question's title, difficulty, and
categories are displayed, with navigation to a detailed view for each
question.

**Changes**
- Implemented Question Repository page displaying a table of questions.
- Each row displays the question title, difficulty (via
`DifficultyBadge`), and categories.
  - Clicking the question title navigates to the question detail page.
  
- Added modals for:
  - Creating new questions (`CreateModal`).
  - Editing existing questions with pre-filled data from (`EditModal`).
  - Deleting questions with a confirmation modal (`DeleteModal`).

- Implemented API integration:
- Fetched question data using `fetchQuestions` and individual question
details using `fetchQuestionById`.
- Integrated `createQuestion`, `updateQuestion`, and `deleteQuestion`
mutations.
- Added optimistic updates by invalidating queries after mutations using
React Query's `useMutation`.

**Future Enhancements**
- Implement pagination for the Question Repository table.
- Add search and filter functionality to find questions based on
difficulty, category, or title.
- Add Toast for success/error of CRUD operations.

---------

Co-authored-by: firwer <[email protected]>
Co-authored-by: javinchua <[email protected]>
This PR improves the validation messages for Questions DTO.

Updated:
<img width="529" alt="Screenshot 2024-09-29 at 5 57 40 PM"
src="https://github.com/user-attachments/assets/f8a56b91-57c0-4dd3-ac27-6e46cd38a5c9">
- Introduced `error` variant
- Rename `green` to `success`
- Added icons to `success` and `error` variants
<img width="434" alt="image"
src="https://github.com/user-attachments/assets/71edf1f7-c64e-4883-a7d9-8174c3807386">

<img width="422" alt="image"
src="https://github.com/user-attachments/assets/0d3c2450-0a60-498d-9a15-89516a1d67a4">
@firwer firwer force-pushed the wp/feat/questions-filtering-and-sort branch from 9262dee to f4620fa Compare October 2, 2024 06:14
@jeffrey-jian jeffrey-jian deleted the wp/feat/questions-filtering-and-sort branch October 5, 2024 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants