Repository navigation
Feat/profile suggestions #195
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
15 commits
Select commit
Hold shift + click to select a range
0ed810a
Create not liked profile table (DB) and add security to like
7763c13
Create Pass controller/DB to users skip other one
152838f
Create suggestion profiles (backend) with filters and sorts
ea00b0f
Fix bug with empty suggestion profiles array
e789192
Merge branch 'main' of github.com:ltuffery/Matcha into feat/profile_s…
c11779f
create frontend function to suggestion call
1e8d9df
Merge branch 'main' of github.com:ltuffery/Matcha into feat/profile_s…
0ed0624
Merge branch 'main' of github.com:ltuffery/Matcha into feat/profile_s…
11d791d
Fix bug, add sort dropdown (front) and add values in preferences inte…
c6968a5
Beautify the sort dropdown and add infinite scroll system
bb1a064
Connect filter to api
5cadc39
Clean the code
b711799
rename wrong name and remove old commented code
4c79378
add forgotten coma
3fffb07
Fix unit test
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| CREATE TABLE passes ( | ||
| user_id INT NOT NULL, | ||
| target_id INT NOT NULL, | ||
| created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
|
||
| PRIMARY KEY (user_id, target_id), | ||
|
|
||
| CONSTRAINT passes_user_fk | ||
| FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, | ||
| CONSTRAINT passes_target_fk | ||
| FOREIGN KEY (target_id) REFERENCES users(id) ON DELETE CASCADE, | ||
| CONSTRAINT passes_no_self_pass CHECK (user_id <> target_id) | ||
| ); |
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,3 @@ | ||
| ALTER TABLE `preferences` | ||
| ADD `fame_gap` INTEGER DEFAULT 0, | ||
| DROP COLUMN `is_custom_loc`; |
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,26 @@ | ||
| <?php | ||
|
|
||
| namespace Matcha\Api\Controllers; | ||
|
|
||
| use Flight; | ||
| use Matcha\Api\Model\User; | ||
|
|
||
| class PassController | ||
| { | ||
| public function store(string $username) | ||
| { | ||
| $target = User::find(['username' => $username]); | ||
|
|
||
| if (is_null($target)) { | ||
| Flight::json([ | ||
| 'success' => false, | ||
| 'message' => 'User not found' | ||
| ], 404); | ||
| return; | ||
| } | ||
|
|
||
| Flight::user()->pass($target); | ||
|
|
||
| Flight::json(['success' => true,], 204); | ||
| } | ||
| } |
74 changes: 0 additions & 74 deletions
74
api/src/Controllers/Profile/ProfileSuggestionController.php
This file was deleted.
Oops, something went wrong.
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,45 @@ | ||
| <?php | ||
|
|
||
| namespace Matcha\Api\Controllers; | ||
|
|
||
| use Flight; | ||
| use Matcha\Api\Model\User; | ||
|
|
||
| class SuggestionController | ||
| { | ||
| private const SORTS = ['distance', 'fame', 'common_tags', 'age']; | ||
| private const MAX_LIMIT = 50; | ||
|
|
||
| public function index() | ||
| { | ||
| $query = Flight::request()->query; | ||
|
|
||
| $sort = $query['sort'] ?? null; | ||
| $order = strtolower($query['order'] ?? 'desc'); | ||
| $offset = (int) ($query['offset'] ?? 0); | ||
| $limit = (int) ($query['limit'] ?? 20); | ||
|
|
||
| if ($sort !== null && !in_array($sort, self::SORTS, true)) { | ||
| Flight::json(['message' => 'Invalid sort'], 422); | ||
| return; | ||
| } | ||
|
|
||
| if (!in_array($order, ['asc', 'desc'], true)) { | ||
| Flight::json(['message' => 'Invalid order'], 422); | ||
| return; | ||
| } | ||
|
|
||
| if ($offset < 0 || $limit < 1 || $limit > self::MAX_LIMIT) { | ||
| Flight::json(['message' => 'Invalid pagination'], 422); | ||
| return; | ||
| } | ||
|
|
||
| $result = Flight::user()->suggestions($sort, $order, $offset, $limit); | ||
|
|
||
| Flight::json([ | ||
| 'count' => count($result['profiles']), | ||
| 'has_more' => $result['has_more'], | ||
| 'profiles' => $result['profiles'], | ||
| ]); | ||
| } | ||
| } |
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,15 @@ | ||
| <?php | ||
|
|
||
| namespace Matcha\Api\Exceptions; | ||
|
|
||
| use Exception; | ||
|
|
||
| class AutoPassException extends Exception | ||
| { | ||
|
|
||
| public function __construct() | ||
| { | ||
| parent::__construct("A user cannot pass themselves."); | ||
| } | ||
|
|
||
| } |
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,26 @@ | ||
| <?php | ||
|
|
||
| namespace Matcha\Api\Model; | ||
|
|
||
| /** | ||
| * @method static Pass find(array $where) | ||
| */ | ||
| class Pass extends Model | ||
| { | ||
| protected string $table = 'passes'; | ||
| protected array $uniques = ['user_id', 'target_id']; | ||
|
|
||
| public int $user_id; | ||
| public int $target_id; | ||
| public string $created_at; | ||
|
|
||
| public function passed(): User | ||
| { | ||
| return User::find(['id' => $this->target_id]); | ||
| } | ||
|
|
||
| public function user(): User | ||
| { | ||
| return User::find(['id' => $this->user_id]); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.