-
Notifications
You must be signed in to change notification settings - Fork 0
50 suggested profiles #51
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dcc98d4
add:(idk)
YoungMame 4650499
add:(filter and sort type)
YoungMame 7527f48
add:(sorting [NOT TESTED])
YoungMame eae2966
add:(sort by age)
YoungMame 0764ab6
add:(sorting and filtering [TEST})
YoungMame 3d7e165
add:(classic sort function)
YoungMame 69488ff
fix:(classic usert borwsing)
YoungMame d06bb1e
add:([WIP]: browse users route)
YoungMame 34a89ab
+
YoungMame 7da6081
add:(orientation specification in browsing)
YoungMame File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { FastifyRequest, FastifyReply } from 'fastify'; | ||
| import { AppError, UnauthorizedError } from '../../../utils/error'; | ||
| import { BrowsingFilter, BrowsingUser, BrowsingSort } from '../../../services/BrowsingService'; | ||
|
|
||
| export const browseUsersHandler = async (request: FastifyRequest, reply: FastifyReply) => { | ||
| try { | ||
| const { | ||
| minAge, | ||
| maxAge, | ||
| minFame, | ||
| maxFame, | ||
| tags, | ||
| lat, | ||
| lng, | ||
| radius, | ||
| sortBy, | ||
| offset, | ||
| limit | ||
| } = request.params as { minAge: number, maxAge: number, minFame: number, maxFame: number, tags: string, lat: number, lng: number, radius: number, sortBy: string, offset: number, limit: number }; | ||
|
|
||
| if (!request.user?.id) | ||
| throw new UnauthorizedError(); | ||
| const tagsArray = tags ? tags.split(',') : []; | ||
| let requestFilters: BrowsingFilter = { | ||
| age: { min: minAge, max: maxAge }, | ||
| fameRate: { min: minFame, max: maxFame }, | ||
| tags: tagsArray | ||
| }; | ||
| if (!(lat < -90 || lat > 90 || lng < -180 || lng > 180)) | ||
| requestFilters.location = { latitude: lat, longitude: lng }; | ||
| const users: BrowsingUser[] = await request.server.browsingService.browseUsers( | ||
| request.user.id, | ||
| limit || 20, | ||
| offset || 0, | ||
| radius, | ||
| requestFilters, | ||
| (sortBy ? sortBy as BrowsingSort : undefined) | ||
| ); | ||
| return reply.status(200).send({ users }); | ||
| } catch (error) { | ||
| if (error instanceof AppError) { | ||
| return reply.status(error.statusCode).send({ error: error.message }); | ||
| } | ||
| return reply.status(500).send({ error: 'Internal Server Error' }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { FastifyInstance } from 'fastify'; | ||
| import { browseUsersHandler } from '../../../controllers/private/browsing' | ||
|
|
||
| export default async function browsingRoutes(fastify: FastifyInstance) { | ||
| fastify.get('/:minAge/:maxAge/:minFame/:maxFame/:tags/:lat/:lng/:radius/:sortBy', { | ||
| schema: { | ||
| params: { | ||
| type: 'object', | ||
| properties: { | ||
| minAge: { type: 'number', minimum: 18, maximum: 100 }, | ||
| maxAge: { type: 'number', minimum: 18, maximum: 100 }, | ||
| minFame: { type: 'number', minimum: 0, maximum: 1000 }, | ||
| maxFame: { type: 'number', minimum: 0, maximum: 1000 }, | ||
| tags: { type: 'string' }, // comma separated tags | ||
| lat: { type: 'number' }, | ||
| lng: { type: 'number' }, | ||
| radius: { type: 'number', minimum: 0 }, | ||
| sortBy: { type: 'string', enum: ['distance', 'age', 'fameRate', 'tags', 'default'] }, | ||
| offset: { type: 'number', minimum: 0 }, | ||
| limit: { type: 'number', minimum: 1, maximum: 30 } | ||
| }, | ||
| required: ['minAge', 'maxAge', 'minFame', 'maxFame', 'tags', 'lat', 'lng', 'radius', 'sortBy'], | ||
| additionalProperties: false | ||
| }, | ||
| response: { | ||
| 200: { | ||
| type: 'object', | ||
| properties: { | ||
| users: { type: 'array', items: { | ||
| type: 'object', | ||
| properties: { | ||
| id: { type: 'number' }, | ||
| firstName: { type: 'string' }, | ||
| gender: { type: 'string' }, | ||
| tags: { type: 'array', items: { type: 'string' } }, | ||
| fameRate: { type: 'number' }, | ||
| profilePicture: { type: 'string' }, | ||
| bornAt: { type: 'string' }, | ||
| distance: { type: 'number' } | ||
| }, | ||
| required: ['id', 'firstName', 'gender', 'tags', 'fameRate', 'profilePicture', 'bornAt', 'distance'], | ||
| additionalProperties: false | ||
| } } | ||
| }, | ||
| additionalProperties: false | ||
| }, | ||
| 400: { | ||
| type: 'object', | ||
| properties: { | ||
| error: { type: 'string', } | ||
| }, | ||
| additionalProperties: false | ||
| }, | ||
| 500: { | ||
| type: 'object', | ||
| properties: { | ||
| error: { type: 'string' } | ||
| }, | ||
| additionalProperties: false | ||
| } | ||
| } | ||
| }, | ||
| handler: browseUsersHandler | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid location check logic: The condition
!(lat < -90 || lat > 90 || lng < -180 || lng > 180)is incorrect. It will set the location even when latitude is 1000 (which is outside the valid range of -90 to 90). The condition should be:lat >= -90 && lat <= 90 && lng >= -180 && lng <= 180.