You've already forked Atomcms-edit
Initial commit
This commit is contained in:
+342
@@ -0,0 +1,342 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Articles\WebsiteArticle;
|
||||
use App\Models\Game\Furniture\CatalogItem;
|
||||
use App\Models\Game\Furniture\CatalogPage;
|
||||
use App\Models\Game\Guild\Guild;
|
||||
use App\Models\Help\WebsiteHelpCenterTicket;
|
||||
use App\Models\Miscellaneous\CameraWeb;
|
||||
use App\Models\Miscellaneous\WebsiteSetting;
|
||||
use App\Models\Shop\WebsiteShopArticle;
|
||||
use App\Models\User;
|
||||
use App\Services\Community\StaffService;
|
||||
use App\Services\User\UserApiService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class HotelApiController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly UserApiService $userApiService,
|
||||
private readonly StaffService $staffService,
|
||||
) {}
|
||||
|
||||
public function fetchUser(string $username): JsonResponse
|
||||
{
|
||||
$user = $this->userApiService->fetchUser($username, ['username', 'motto', 'look']);
|
||||
|
||||
return response()->json([
|
||||
'data' => $user,
|
||||
]);
|
||||
}
|
||||
|
||||
public function onlineUsers(): JsonResponse
|
||||
{
|
||||
$users = $this->userApiService->onlineUsers(['username', 'motto', 'look'], true);
|
||||
|
||||
return response()->json([
|
||||
'data' => $users,
|
||||
]);
|
||||
}
|
||||
|
||||
public function onlineUserCount(): JsonResponse
|
||||
{
|
||||
$count = $this->userApiService->onlineUserCount();
|
||||
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'onlineCount' => $count,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function articles(): JsonResponse
|
||||
{
|
||||
$articles = WebsiteArticle::with(['user:id,username,look'])
|
||||
->latest('id')
|
||||
->paginate(12);
|
||||
|
||||
return response()->json([
|
||||
'data' => $articles->items(),
|
||||
'meta' => [
|
||||
'current_page' => $articles->currentPage(),
|
||||
'last_page' => $articles->lastPage(),
|
||||
'per_page' => $articles->perPage(),
|
||||
'total' => $articles->total(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function article(string $slug): JsonResponse
|
||||
{
|
||||
$article = WebsiteArticle::with(['user:id,username,look', 'comments.user:id,username,look'])
|
||||
->where('slug', $slug)
|
||||
->firstOrFail();
|
||||
|
||||
return response()->json([
|
||||
'data' => $article,
|
||||
]);
|
||||
}
|
||||
|
||||
public function photos(): JsonResponse
|
||||
{
|
||||
$photos = CameraWeb::query()
|
||||
->where('visible', true)
|
||||
->latest('id')
|
||||
->paginate(12);
|
||||
|
||||
return response()->json([
|
||||
'data' => $photos->items(),
|
||||
'meta' => [
|
||||
'current_page' => $photos->currentPage(),
|
||||
'last_page' => $photos->lastPage(),
|
||||
'per_page' => $photos->perPage(),
|
||||
'total' => $photos->total(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function staff(): JsonResponse
|
||||
{
|
||||
$employees = $this->staffService->fetchStaffPositions();
|
||||
|
||||
return response()->json([
|
||||
'data' => $employees,
|
||||
]);
|
||||
}
|
||||
|
||||
public function shopPackages(Request $request): JsonResponse
|
||||
{
|
||||
$packages = WebsiteShopArticle::latest('id')->paginate(12);
|
||||
|
||||
$mapped = $packages->items()->map(fn ($pkg) => [
|
||||
'id' => $pkg->id,
|
||||
'title' => $pkg->name,
|
||||
'description' => $pkg->description,
|
||||
'price' => $pkg->price(),
|
||||
'credits' => null,
|
||||
'pixels' => null,
|
||||
'diamonds' => null,
|
||||
'image' => null,
|
||||
'currency' => 'credits',
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'data' => $mapped,
|
||||
'meta' => [
|
||||
'current_page' => $packages->currentPage(),
|
||||
'last_page' => $packages->lastPage(),
|
||||
'per_page' => $packages->perPage(),
|
||||
'total' => $packages->total(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function shopCategories(): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'data' => ['furniture', 'badges', 'ranks'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function teams(): JsonResponse
|
||||
{
|
||||
$teams = Guild::with('members')
|
||||
->latest('id')
|
||||
->paginate(12);
|
||||
|
||||
return response()->json([
|
||||
'data' => $teams->items(),
|
||||
'meta' => [
|
||||
'current_page' => $teams->currentPage(),
|
||||
'last_page' => $teams->lastPage(),
|
||||
'per_page' => $teams->perPage(),
|
||||
'total' => $teams->total(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function leaderboard(Request $request): JsonResponse
|
||||
{
|
||||
$type = $request->query('type', 'credits');
|
||||
$limit = (int) $request->query('limit', 100);
|
||||
|
||||
$validTypes = ['credits', 'pixels'];
|
||||
if (! in_array($type, $validTypes)) {
|
||||
$type = 'credits';
|
||||
}
|
||||
|
||||
$users = User::orderByDesc($type)
|
||||
->limit($limit)
|
||||
->get(['id', 'username', 'look', 'motto', 'credits', 'pixels']);
|
||||
|
||||
return response()->json([
|
||||
'data' => $users,
|
||||
'type' => $type,
|
||||
]);
|
||||
}
|
||||
|
||||
public function rareValues(Request $request): JsonResponse
|
||||
{
|
||||
$categoryId = $request->query('category');
|
||||
|
||||
$query = CatalogItem::query();
|
||||
|
||||
if ($categoryId) {
|
||||
$query->where('page_id', $categoryId);
|
||||
}
|
||||
|
||||
$items = $query->with('itemBase')
|
||||
->latest('id')
|
||||
->paginate(24);
|
||||
|
||||
return response()->json([
|
||||
'data' => $items->items(),
|
||||
'meta' => [
|
||||
'current_page' => $items->currentPage(),
|
||||
'last_page' => $items->lastPage(),
|
||||
'per_page' => $items->perPage(),
|
||||
'total' => $items->total(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function rareValuesCategories(): JsonResponse
|
||||
{
|
||||
$categories = CatalogPage::where('catalog_name', '!=', '')
|
||||
->where('visible', 1)
|
||||
->orderBy('order_number')
|
||||
->get(['id', 'catalog_name', 'icon']);
|
||||
|
||||
return response()->json([
|
||||
'data' => $categories,
|
||||
]);
|
||||
}
|
||||
|
||||
public function settings(): JsonResponse
|
||||
{
|
||||
$settings = Cache::remember('api_all_settings', 60, fn () => WebsiteSetting::all()->pluck('value', 'key'));
|
||||
|
||||
return response()->json([
|
||||
'data' => $settings,
|
||||
]);
|
||||
}
|
||||
|
||||
public function userProfile(string $username): JsonResponse
|
||||
{
|
||||
$user = User::where('username', $username)
|
||||
->firstOrFail();
|
||||
|
||||
return response()->json([
|
||||
'id' => $user->id,
|
||||
'username' => $user->username,
|
||||
'look' => $user->look,
|
||||
'motto' => $user->motto,
|
||||
'account_created' => $user->account_created,
|
||||
'online' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function helpTickets(Request $request): JsonResponse
|
||||
{
|
||||
$tickets = WebsiteHelpCenterTicket::with('user:id,username,look')
|
||||
->when($request->user(), fn ($q) => $q->where('user_id', $request->user()->id))
|
||||
->latest()
|
||||
->paginate(10);
|
||||
|
||||
return response()->json([
|
||||
'data' => $tickets->items(),
|
||||
'meta' => [
|
||||
'current_page' => $tickets->currentPage(),
|
||||
'last_page' => $tickets->lastPage(),
|
||||
'total' => $tickets->total(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function helpTicket(string $id): JsonResponse
|
||||
{
|
||||
$ticket = WebsiteHelpCenterTicket::with(['user:id,username,look', 'replies.user:id,username,look'])
|
||||
->where('id', $id)
|
||||
->firstOrFail();
|
||||
|
||||
return response()->json(['data' => $ticket]);
|
||||
}
|
||||
|
||||
public function helpTicketCreate(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'subject' => ['required', 'string', 'max:200'],
|
||||
'category' => ['required', 'string', 'max:100'],
|
||||
'message' => ['required', 'string', 'max:5000'],
|
||||
]);
|
||||
|
||||
$ticket = WebsiteHelpCenterTicket::create([
|
||||
'user_id' => $request->user()->id,
|
||||
'subject' => $validated['subject'],
|
||||
'category' => $validated['category'],
|
||||
'status' => 'open',
|
||||
]);
|
||||
|
||||
$ticket->replies()->create([
|
||||
'user_id' => $request->user()->id,
|
||||
'message' => $validated['message'],
|
||||
]);
|
||||
|
||||
return response()->json(['data' => $ticket], 201);
|
||||
}
|
||||
|
||||
public function helpTicketReply(Request $request, string $id): JsonResponse
|
||||
{
|
||||
$validated = $request->validate(['message' => 'required', 'string', 'max:5000']);
|
||||
|
||||
$ticket = WebsiteHelpCenterTicket::where('id', $id)
|
||||
->where('user_id', $request->user()->id)
|
||||
->firstOrFail();
|
||||
|
||||
$reply = $ticket->replies()->create([
|
||||
'user_id' => $request->user()->id,
|
||||
'message' => $validated['message'],
|
||||
]);
|
||||
|
||||
return response()->json(['data' => $reply->load('user:id,username,look')], 201);
|
||||
}
|
||||
|
||||
public function uploadPhoto(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'image' => ['required', 'image', 'max:5120'],
|
||||
]);
|
||||
|
||||
$path = $validated['image']->store('photos', 'public');
|
||||
|
||||
$photo = CameraWeb::create([
|
||||
'user_id' => $request->user()->id,
|
||||
'image' => '/storage/' . $path,
|
||||
'visible' => true,
|
||||
]);
|
||||
|
||||
return response()->json(['data' => $photo], 201);
|
||||
}
|
||||
|
||||
public function purchasePackage(Request $request, int $packageId): JsonResponse
|
||||
{
|
||||
$package = WebsiteShopArticle::findOrFail($packageId);
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
$cost = $package->costs;
|
||||
|
||||
if ($user->credits < $cost) {
|
||||
return response()->json(['error' => 'Not enough credits'], 400);
|
||||
}
|
||||
|
||||
$user->decrement('credits', $cost);
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'Purchase successful']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user