Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DC := docker compose

all: set_app_host up
all: up

up:
$(DC) up --build
Expand All @@ -26,4 +26,4 @@ set_app_host:
echo "\nAPP_HOST=$(shell hostname -i)" >> .env; \
fi

.PHONY: all re clean fclean up down
.PHONY: all re clean fclean up down
13 changes: 13 additions & 0 deletions api/database/migrations/016_create_table_passes.sql
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)
);
3 changes: 3 additions & 0 deletions api/database/migrations/017_alter_preferences.sql
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`;
20 changes: 8 additions & 12 deletions api/src/Controllers/LikeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,22 @@ class LikeController
{
public function store(string $username)
{
$user = User::find([
'username' => $username,
]);

if (is_null($user)) {
Flight::json([
'message' => 'User not found',
], 404);
$target = User::find(['username' => $username]);
$me = Flight::user();

if (is_null($target) || $target->isBlocking($me)) {
Flight::json(['message' => 'User not found'], 404);
return;
}

Flight::user()->like($user);
Flight::user()->like($target);

Flight::notifier()->publish("user/" . $user->id . "/notifications", [
Flight::notifier()->publish("user/" . $target->id . "/notifications", [
'type' => 'like',
'message' => Flight::user()->username . " a aimé ton profil",
'message' => Flight::user()->username . " has liked your profile",
], private: false);

Flight::json([], 203);
Flight::json([], 201);
}

public function destroy(string $username)
Expand Down
26 changes: 26 additions & 0 deletions api/src/Controllers/PassController.php
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 api/src/Controllers/Profile/ProfileSuggestionController.php

This file was deleted.

45 changes: 45 additions & 0 deletions api/src/Controllers/SuggestionController.php
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'],
]);
}
}
15 changes: 15 additions & 0 deletions api/src/Exceptions/AutoPassException.php
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.");
}

}
1 change: 1 addition & 0 deletions api/src/Factory/PreferenceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protected function define(): array
"by_tags" => (bool)rand(0, 1),
'lon' => 10,
'lat' => 10,
'fame_gap' => 10,
];
}
}
26 changes: 26 additions & 0 deletions api/src/Model/Pass.php
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]);
}

Comment thread
swotex marked this conversation as resolved.
public function user(): User
{
return User::find(['id' => $this->user_id]);
}
}
2 changes: 1 addition & 1 deletion api/src/Model/Preference.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Preference extends Model

public float $lon = 0;

public bool $is_custom_loc = false;
public int $fame_gap = 10;

public function user(): User
{
Expand Down
Loading
Loading