Phase 1: Foundation - Database schema, core PHP structure, JWT auth, and User CRUD
Implemented: - Database schema (SQLite) with tables: users, profiles, posts, swipes, matches, chats, chat_messages, events, notifications, relationships, post_likes, post_comments, refresh_tokens, media - Core PHP structure following skeleton pattern (www/api/) - JWT Authentication (register, login, refresh, logout) - User profile CRUD (show, update, delete, search) - User sub-resources (posts, friends, followers, following) - Minimal Firebase JWT implementation for PHP without Composer
This commit is contained in:
60
www/api/src/core/Response.php
Normal file
60
www/api/src/core/Response.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* HTTP Response Helper
|
||||
*/
|
||||
|
||||
namespace Core;
|
||||
|
||||
class Response
|
||||
{
|
||||
public static function json(mixed $data, int $status = 200): void
|
||||
{
|
||||
http_response_code($status);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function success(mixed $data = null, string $message = 'OK', int $status = 200): void
|
||||
{
|
||||
self::json([
|
||||
'success' => true,
|
||||
'message' => $message,
|
||||
'data' => $data
|
||||
], $status);
|
||||
}
|
||||
|
||||
public static function error(string $message, int $status = 400, mixed $errors = null): void
|
||||
{
|
||||
$response = [
|
||||
'success' => false,
|
||||
'error' => $message
|
||||
];
|
||||
|
||||
if ($errors !== null) {
|
||||
$response['errors'] = $errors;
|
||||
}
|
||||
|
||||
self::json($response, $status);
|
||||
}
|
||||
|
||||
public static function notFound(string $message = 'Resource not found'): void
|
||||
{
|
||||
self::error($message, 404);
|
||||
}
|
||||
|
||||
public static function unauthorized(string $message = 'Unauthorized'): void
|
||||
{
|
||||
self::error($message, 401);
|
||||
}
|
||||
|
||||
public static function forbidden(string $message = 'Forbidden'): void
|
||||
{
|
||||
self::error($message, 403);
|
||||
}
|
||||
|
||||
public static function validationError(mixed $errors): void
|
||||
{
|
||||
self::error('Validation failed', 422, $errors);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user