buyer be able to view available product #75
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
This pull request implements the AvailableProducts function, which retrieves available products from the database with pagination support. The function allows clients to request available products with optional pagination parameters (limit and page). If pagination parameters are not provided, default values are used (limit=10, page=1).
Description
/getAvailableProducts
routeThis function should execute a database query to fetch available products where the
isAvailablefield
is set totrue
.Pagination should be applied to limit the number of products returned per page and to skip the appropriate number of records based on the page number.
The function should include the category relation to eagerly load associated categories for each product.
Handling pagination:
If pagination parameters (
limit and page
) are not provided in the query, default values should be used (limit=10, page=1
).Once the products are fetched, the function should construct a JSON response containing the retrieved products, total pages, and the current page.
Total pages should be calculated based on the total count of available products and the specified limit.
The function should include appropriate error handling to handle any errors that may occur during the execution of the function (e.g., database query error, server error).
If an error occurs, the function should return a 500-status code along with an error message.
Test the
getAvailableProducts
route to ensure it retrieves available products correctly with the expected pagination behavior.Verify that error handling is working as expected and that appropriate responses are returned in case of errors.
Testing: I have tested the getAvailableProducts route locally and verified that it retrieves available products correctly with the expected pagination behavior.
Related Issues:
#37
Screenshot:
Swagger:
Testing: