Compare commits

...

36 Commits

Author SHA1 Message Date
m.razaghi
dcea6423ff Fixed api issue 2026-07-12 16:52:28 +03:30
m.razaghi
51c4570f97 Fixed api issue 2026-07-12 16:49:12 +03:30
m.razaghi
19db0fd24d Fixed api issue 2026-07-12 16:40:27 +03:30
m.razaghi
4d15014621 Fixed api issue 2026-07-12 16:24:16 +03:30
m.razaghi
6c0b1f83f2 Fixed api issue 2026-07-12 16:19:20 +03:30
m.razaghi
cad3fa9e1f Fixed api issue 2026-07-12 16:11:38 +03:30
m.razaghi
1a3f41ca8a Merge remote-tracking branch 'upstream-local/new-api' into clean-main 2026-07-12 16:05:05 +03:30
m.razaghi
e4dad6f9a4 Fixed api issue 2026-07-12 16:02:53 +03:30
16e68c3048 Merge pull request 'Fixed api issue' (#11) from new-api into clean-main
Reviewed-on: #11
2026-07-12 12:27:18 +00:00
m.razaghi
10463e2f71 Fixed api issue 2026-07-12 15:46:34 +03:30
ed95f5b3ee Merge pull request 'Fixed api issue' (#10) from new-api into clean-main
Reviewed-on: #10
2026-07-12 11:56:37 +00:00
m.razaghi
1eedb30acc Fixed api issue 2026-07-12 15:21:01 +03:30
0962801c96 Merge pull request 'Fixed api issue' (#9) from new-api into clean-main
Reviewed-on: #9
2026-07-12 10:42:17 +00:00
m.razaghi
b2ac3d6ec8 Fixed api issue 2026-07-12 14:03:45 +03:30
ecccab9edc Merge pull request 'new-api' (#8) from new-api into clean-main
Reviewed-on: #8
2026-07-12 09:50:32 +00:00
m.razaghi
737f06f68e Fixed api issue 2026-07-12 13:16:57 +03:30
370f4c0a78 Merge pull request 'Fixed api issue' (#7) from new-api into clean-main
Reviewed-on: #7
2026-07-12 09:13:47 +00:00
m.razaghi
a95826e5e5 Fixed api issue 2026-07-12 12:43:28 +03:30
m.razaghi
398fcb4eec Fixed api issue 2026-07-12 11:58:07 +03:30
4214a4b007 Merge pull request 'new-api' (#6) from new-api into clean-main
Reviewed-on: #6
2026-07-12 06:07:23 +00:00
m.razaghi
9d124a07c1 Fixed api issue 2026-07-11 17:27:55 +03:30
m.razaghi
ffea0e3c11 Fixed api issue 2026-07-11 12:25:46 +03:30
2a6313802b Merge pull request 'updated apis' (#5) from new-api into clean-main
Reviewed-on: #5
2026-07-10 20:56:19 +00:00
m.razaghi
3b9fcd76df updated apis 2026-07-10 23:22:56 +03:30
d47f148f12 Merge pull request 'new-api' (#4) from new-api into clean-main
Reviewed-on: #4
2026-07-10 10:58:40 +00:00
m.razaghi
d19d4b8667 updated apis 2026-07-10 13:38:47 +03:30
m.razaghi
3b47d78ee8 Added new apis, fast search 2026-07-09 19:23:06 +03:30
m.razaghi
71a6f683a7 Fixed major bugs 2026-07-09 19:11:39 +03:30
m.razaghi
71dc7da8a4 Fixed major bugs 2026-07-09 17:06:07 +03:30
4ed77dd060 Merge pull request 'Fixed major bugs' (#3) from new-api into clean-main
Reviewed-on: #3
2026-07-08 07:24:33 +00:00
m.razaghi
b7f139b935 Fixed major bugs 2026-07-08 10:51:47 +03:30
0b6851ebe2 Update README.md 2026-07-08 05:44:27 +00:00
80a271d325 Merge pull request 'fixed major bugs' (#2) from new-api into clean-main
Reviewed-on: #2
2026-07-08 05:44:00 +00:00
m.razaghi
83ff22b5a4 fixed major bugs 2026-07-07 21:25:27 +03:30
d27c32c918 Merge pull request 'Added new api' (#1) from new-api into clean-main
Reviewed-on: #1
2026-07-05 10:22:22 +00:00
m.razaghi
ce5ccc00a1 Added new api 2026-07-04 17:05:50 +03:30
12 changed files with 1416 additions and 20 deletions

View File

@@ -1 +1 @@
Persian ping ## Law

View File

@@ -76,7 +76,7 @@ class AuthController extends Controller
$user = User::where('mobile', $request->mobile)->first(); $user = User::where('mobile', $request->mobile)->first();
if (! $user) { if (! $user) {
return response()->json(['error' => 'User not found'], 404); return response()->json(['error' => 'کاربر یافت نشد'], 404);
} }
$latestCode = UserCode::where('user_id', $user->id) $latestCode = UserCode::where('user_id', $user->id)

View File

@@ -0,0 +1,349 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Models\BylawDocument;
use App\Models\BylawLegalAuthority;
use App\Models\BylawSubjectCategory;
use App\Models\BylawNode;
use App\Models\BylawCodificationLink;
use App\Traits\BaseApiResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class BylawApiController extends Controller
{
use BaseApiResponse;
public function categories()
{
$categories = BylawSubjectCategory::all()->map(function ($category) {
return [
'id' => $category->id,
'name' => $category->name,
];
});
return $this->success($categories, 'Success', 'Bylaw Categories List');
}
public function authorities()
{
$authorities = BylawLegalAuthority::all()->map(function ($authority) {
return [
'id' => $authority->id,
'name' => $authority->name,
'authority_type' => $authority->authority_type,
];
});
return $this->success($authorities, 'Success', 'Bylaw Authorities List');
}
public function index(Request $request)
{
$request->validate([
'category_id' => 'nullable|exists:bylaw_subject_categories,id',
'approval_authority_id' => 'nullable|exists:bylaw_legal_authorities,id',
'bylaw_type' => 'nullable|in:executive,delegated,independent',
'sort_by' => 'nullable|in:date,number',
'sort' => 'nullable|in:asc,desc',
'per_page' => 'nullable|integer|min:1|max:100',
]);
$query = BylawDocument::with(['category', 'approvalAuthority', 'promulgationAuthority'])
->where('is_published', true);
if ($request->filled('category_id')) {
$query->where('category_id', $request->category_id);
}
if ($request->filled('approval_authority_id')) {
$query->where('approval_authority_id', $request->approval_authority_id);
}
if ($request->filled('bylaw_type')) {
$query->where('bylaw_type', $request->bylaw_type);
}
$sortBy = $request->input('sort_by', 'date');
$sortOrder = $request->input('sort', 'desc');
$sortColumn = $sortBy === 'number' ? 'promulgation_number' : 'approval_date';
if ($sortBy === 'number') {
$query->orderByRaw("LENGTH({$sortColumn}) {$sortOrder}")->orderBy($sortColumn, $sortOrder);
} else {
$query->orderBy($sortColumn, $sortOrder);
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$paginator = $query->paginate($perPage);
$items = collect($paginator->items())->map(function ($item) {
return $this->formatBylaw($item);
});
$responseData = [
'items' => $items,
'current_page' => $paginator->currentPage(),
'last_page' => $paginator->lastPage(),
'per_page' => $paginator->perPage(),
'total' => $paginator->total(),
];
return $this->success($responseData, 'Success', 'Bylaws Fetched');
}
public function single($id)
{
$bylaw = BylawDocument::with(['category', 'approvalAuthority', 'promulgationAuthority'])
->where('is_published', true)
->find($id);
if (!$bylaw) {
return $this->failed([], [
'title' => 'خطا',
'message' => 'آیین‌نامه مورد نظر یافت نشد.'
], 404);
}
$formatted = $this->formatBylaw($bylaw);
if (!$formatted['is_locked']) {
$nodes = BylawNode::with('type')
->where('document_id', $bylaw->id)
->orderBy('sort_order', 'asc')
->get()
->map(function ($node) {
return [
'id' => $node->id,
'parent_id' => $node->parent_id,
'node_type' => optional($node->type)->name,
'node_identifier' => $node->node_identifier,
'title' => $node->title,
'node_content' => $node->node_content,
'sort_order' => $node->sort_order,
'valid_from' => $node->valid_from,
'valid_to' => $node->valid_to,
'node_status' => $node->node_status,
];
});
$formatted['nodes'] = $nodes->toArray();
$links = BylawCodificationLink::where('source_entity_type', 'bylaw_doc')
->where('source_entity_id', $bylaw->id)
->get()
->map(function ($link) {
return [
'id' => $link->id,
'target_entity_type' => $link->target_entity_type,
'target_entity_id' => $link->target_entity_id,
'link_type' => $link->link_type,
'effective_date' => $link->effective_date,
'justification' => $link->justification,
];
});
$formatted['links'] = $links->toArray();
}
return $this->success($formatted, 'Success', 'Bylaw Document Details Fetched');
}
public function search(Request $request)
{
$request->validate([
'search' => 'nullable|string',
'sort_by' => 'nullable|in:date,number',
'sort' => 'nullable|in:asc,desc',
'per_page' => 'nullable|integer|min:1|max:100',
]);
$query = BylawDocument::with(['category', 'approvalAuthority', 'promulgationAuthority'])
->where('is_published', true);
if ($request->filled('search')) {
$searchTerm = $request->input('search');
$query->where(function ($q) use ($searchTerm) {
$q->where('title', 'LIKE', "%{$searchTerm}%")
->orWhere('description', 'LIKE', "%{$searchTerm}%")
->orWhere('promulgation_number', 'LIKE', "%{$searchTerm}%")
->orWhere('official_gazette_number', 'LIKE', "%{$searchTerm}%")
->orWhereIn('id', function($subQuery) use ($searchTerm) {
$subQuery->select('document_id')
->from('bylaw_nodes')
->where('node_content', 'LIKE', "%{$searchTerm}%");
});
});
}
$sortBy = $request->input('sort_by', 'date');
$sortOrder = $request->input('sort', 'desc');
$sortColumn = $sortBy === 'number' ? 'promulgation_number' : 'approval_date';
if ($sortBy === 'number') {
$query->orderByRaw("LENGTH({$sortColumn}) {$sortOrder}")->orderBy($sortColumn, $sortOrder);
} else {
$query->orderBy($sortColumn, $sortOrder);
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$paginator = $query->paginate($perPage);
$items = collect($paginator->items())->map(function ($item) {
return $this->formatBylaw($item);
});
$responseData = [
'items' => $items,
'current_page' => $paginator->currentPage(),
'last_page' => $paginator->lastPage(),
'per_page' => $paginator->perPage(),
'total' => $paginator->total(),
];
return $this->success($responseData, 'Success', 'Search Results Fetched');
}
public function fast_search(Request $request)
{
$searchTerm = $request->input('search');
$query = BylawDocument::with(['category', 'approvalAuthority', 'promulgationAuthority'])
->where('is_published', true);
if (!empty($searchTerm)) {
$query->where(function ($q) use ($searchTerm) {
$q->where('title', 'LIKE', "%{$searchTerm}%")
->orWhere('description', 'LIKE', "%{$searchTerm}%")
->orWhere('promulgation_number', 'LIKE', "%{$searchTerm}%")
->orWhere('official_gazette_number', 'LIKE', "%{$searchTerm}%")
->orWhereIn('id', function($subQuery) use ($searchTerm) {
$subQuery->select('document_id')
->from('bylaw_nodes')
->where('node_content', 'LIKE', "%{$searchTerm}%");
});
});
}
$count = $query->count();
$items = $query->orderBy('approval_date', 'desc')->take(5)->get()->map(function ($item) {
return $this->formatBylaw($item);
});
return $this->success([
'items' => $items,
'count' => $count
], 'Success', 'Fast Search Results');
}
public function pager($id)
{
$current = BylawDocument::with(['category', 'approvalAuthority', 'promulgationAuthority'])
->where('is_published', true)
->find($id);
if (!$current) {
return $this->failed([], [
'title' => 'خطا',
'message' => 'آیین‌نامه مورد نظر یافت نشد.'
], 404);
}
$previousItem = BylawDocument::with(['category', 'approvalAuthority', 'promulgationAuthority'])
->where('is_published', true)
->where(function ($query) use ($current) {
if ($current->approval_date) {
$query->where('approval_date', '<', $current->approval_date)
->orWhere(function ($subQuery) use ($current) {
$subQuery->where('approval_date', '=', $current->approval_date)
->where('id', '<', $current->id);
});
} else {
$query->whereNull('approval_date')->where('id', '<', $current->id);
}
})
->orderBy('approval_date', 'desc')
->orderBy('id', 'desc')
->first();
$nextItem = BylawDocument::with(['category', 'approvalAuthority', 'promulgationAuthority'])
->where('is_published', true)
->where(function ($query) use ($current) {
if ($current->approval_date) {
$query->where('approval_date', '>', $current->approval_date)
->orWhere(function ($subQuery) use ($current) {
$subQuery->where('approval_date', '=', $current->approval_date)
->where('id', '>', $current->id);
});
} else {
$query->whereNotNull('approval_date')
->orWhere(function ($subQuery) use ($current) {
$subQuery->whereNull('approval_date')->where('id', '>', $current->id);
});
}
})
->orderBy('approval_date', 'asc')
->orderBy('id', 'asc')
->first();
$results = array_values(array_filter([
$previousItem ? $this->formatBylaw($previousItem) : null,
$this->formatBylaw($current),
$nextItem ? $this->formatBylaw($nextItem) : null
]));
return $this->success($results, 'Success', 'Pager Window Details');
}
private function isLockedForCurrentUser($item): bool
{
return ! auth()->user()->isSubscriber() && (bool) ($item->is_locked ?? false);
}
private function formatBylaw($item)
{
$isLocked = $this->isLockedForCurrentUser($item);
$description = $item->description;
// Check if description is practically empty (null, empty string, or just empty WYSIWYG HTML like <p></p>)
$cleanDesc = trim(strip_tags($description ?? ''));
// Direct Query Fallback: Fetch node_content manually via DB facade to bypass any Model restrictions
if (empty($cleanDesc)) {
$nodeContents = DB::table('bylaw_nodes')
->where('document_id', $item->id)
->orderBy('sort_order', 'asc')
->pluck('node_content')
->toArray();
$description = implode("\n\n", array_filter($nodeContents));
}
return [
'id' => $item->id,
'title' => $item->title,
'category_id' => $item->category_id,
'category_name' => optional($item->category)->name,
'approval_authority_id' => $item->approval_authority_id,
'approval_authority_name' => optional($item->approvalAuthority)->name,
'approval_date' => $item->approval_date,
'promulgation_authority_id' => $item->promulgation_authority_id,
'promulgation_authority_name'=> optional($item->promulgationAuthority)->name,
'promulgation_date' => $item->promulgation_date,
'promulgation_number' => $item->promulgation_number,
'official_gazette_number' => $item->official_gazette_number,
'official_gazette_date' => $item->official_gazette_date,
'execution_date' => $item->execution_date,
'bylaw_type' => $item->bylaw_type,
'global_status' => $item->global_status,
'pdf_file_url' => $isLocked ? null : ($item->pdf_file_path ? asset('storage/' . $item->pdf_file_path) : null),
'description' => $isLocked ? null : $description,
'is_locked' => $isLocked,
];
}
}

View File

@@ -0,0 +1,461 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Models\Art;
use App\Models\Book;
use App\Models\Branch;
use App\Models\BylawDocument;
use App\Models\Chapter;
use App\Models\Division;
use App\Models\Gate;
use App\Models\JudicialPrecedent;
use App\Models\Law;
use App\Models\LegalOpinion;
use App\Models\Part;
use App\Models\Section;
use App\Models\Volum;
use App\Traits\BaseApiResponse;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\DB;
class GlobalSearchApiController extends Controller
{
use BaseApiResponse;
/**
* Massive Search across ALL data types
*/
public function search(Request $request)
{
$request->validate([
'search' => 'nullable|string',
'sort_by' => 'nullable|in:date,number',
'sort' => 'nullable|in:asc,desc',
'per_page' => 'nullable|integer|min:1|max:100',
'page' => 'nullable|integer|min:1',
]);
$searchTerm = $request->input('search');
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$page = (int) $request->input('page', 1);
$staticResults = collect(); // Arts and Structures (Always at the top)
$sortableResults = collect(); // Bylaws, Opinions, Precedents (Sorted if requested)
if (!empty($searchTerm)) {
$limitPerTable = 100;
// =========================================================
// 1. Search Arts (Exact match to ArtController)
// =========================================================
$arts = Art::with(['law.category', 'chapter', 'part', 'volum', 'book', 'section', 'gate'])
->where(function ($q) use ($searchTerm) {
$q->where('title', 'LIKE', "%{$searchTerm}%")
->orWhere('text', 'LIKE', "%{$searchTerm}%");
})
->take($limitPerTable)->get()->map(function($item) use ($searchTerm) {
$formatted = $this->formatArt($item, $searchTerm, Art::class);
$formatted['type'] = 'art';
return $formatted;
});
$staticResults = $staticResults->concat($arts);
// =========================================================
// 2. Search Laws and Structural Models (Exact match to ArtController)
// =========================================================
$structuralModels = [
Law::class, Volum::class, Book::class, Division::class,
Section::class, Chapter::class, Part::class, Gate::class,
Branch::class
];
foreach ($structuralModels as $modelClass) {
$query = $modelClass::query();
$modelInstance = new $modelClass;
$table = $modelInstance->getTable();
$query->where('title', 'LIKE', "%{$searchTerm}%");
$items = $query->take($limitPerTable)->get()->map(function($item) use ($modelClass, $table) {
$formatted = $this->formatStructure($item, $modelClass);
$formatted['type'] = ($table === 'section') ? 'sections' : $table;
return $formatted;
});
$staticResults = $staticResults->concat($items);
}
// =========================================================
// 3. Search Bylaw Documents
// =========================================================
$bylaws = BylawDocument::with(['category', 'approvalAuthority', 'promulgationAuthority'])
->where('is_published', true)
->where(function ($q) use ($searchTerm) {
$q->where('title', 'LIKE', "%{$searchTerm}%")
->orWhere('description', 'LIKE', "%{$searchTerm}%")
->orWhere('promulgation_number', 'LIKE', "%{$searchTerm}%")
->orWhere('official_gazette_number', 'LIKE', "%{$searchTerm}%")
->orWhereIn('id', function($subQuery) use ($searchTerm) {
$subQuery->select('document_id')
->from('bylaw_nodes')
->where('node_content', 'LIKE', "%{$searchTerm}%");
});
})->take($limitPerTable)->get()->map(function($item) {
$formatted = $this->formatBylaw($item);
$formatted['type'] = 'bylaw';
return $formatted;
});
$sortableResults = $sortableResults->concat($bylaws);
// =========================================================
// 4. Search Judicial Precedents
// =========================================================
$judicials = JudicialPrecedent::with('category')
->where(function ($q) use ($searchTerm) {
$q->where('ruling_number', 'LIKE', "%{$searchTerm}%")
->orWhere('subject', 'LIKE', "%{$searchTerm}%")
->orWhere('full_text', 'LIKE', "%{$searchTerm}%");
})->take($limitPerTable)->get()->map(function($item) {
$formatted = $this->formatJudicial($item);
$formatted['type'] = 'judicial_precedent';
return $formatted;
});
$sortableResults = $sortableResults->concat($judicials);
// =========================================================
// 5. Search Legal Opinions
// =========================================================
$opinions = LegalOpinion::with('category')
->where(function ($q) use ($searchTerm) {
$q->where('opinion_number', 'LIKE', "%{$searchTerm}%")
->orWhere('subject', 'LIKE', "%{$searchTerm}%")
->orWhere('full_text', 'LIKE', "%{$searchTerm}%")
->orWhere('issuing_authority', 'LIKE', "%{$searchTerm}%");
})->take($limitPerTable)->get()->map(function($item) {
$formatted = $this->formatOpinion($item);
$formatted['type'] = 'legal_opinion';
return $formatted;
});
$sortableResults = $sortableResults->concat($opinions);
}
// --- Apply Dynamic Memory Sorting ONLY to Legal Docs ---
if ($request->has('sort_by') && $request->input('sort_by') != null) {
$sortBy = $request->input('sort_by');
$sortOrder = $request->input('sort', 'desc');
if ($sortBy === 'number') {
$sortCallback = function ($item) {
return (string) ($item['promulgation_number'] ?? $item['ruling_number'] ?? $item['opinion_number'] ?? '0');
};
if ($sortOrder === 'asc') {
$sortableResults = $sortableResults->sortBy($sortCallback, SORT_NATURAL)->values();
} else {
$sortableResults = $sortableResults->sortByDesc($sortCallback, SORT_NATURAL)->values();
}
} elseif ($sortBy === 'date') {
$sortCallback = function ($item) {
return (string) ($item['approval_date'] ?? $item['ruling_date'] ?? $item['opinion_date'] ?? '1970-01-01');
};
if ($sortOrder === 'asc') {
$sortableResults = $sortableResults->sortBy($sortCallback)->values();
} else {
$sortableResults = $sortableResults->sortByDesc($sortCallback)->values();
}
}
}
// Combine Results: Arts and Structures ALWAYS pin to the top!
$results = $staticResults->concat($sortableResults);
// --- Execute Manual Pagination on the final Collection ---
$total = $results->count();
$paginatedItems = $results->forPage($page, $perPage)->values();
$paginator = new LengthAwarePaginator(
$paginatedItems,
$total,
$perPage,
$page,
['path' => $request->url(), 'query' => $request->query()]
);
$responseData = [
'items' => $paginator->items(),
'current_page' => $paginator->currentPage(),
'last_page' => $paginator->lastPage(),
'per_page' => $paginator->perPage(),
'total' => $paginator->total(),
];
return $this->success($responseData, '', '');
}
/**
* Top-level fast search for quick dropdown UI elements
*/
public function fast_search(Request $request)
{
$searchTerm = $request->input('search');
$results = collect();
$totalCount = 0;
$limitPerTable = 3;
if (!empty($searchTerm)) {
// 1. Search Arts FIRST
$artQuery = Art::with(['law', 'law.category', 'chapter', 'part', 'volum', 'book', 'section', 'gate'])
->where(function ($q) use ($searchTerm) {
$q->where('title', 'LIKE', "%{$searchTerm}%")
->orWhere('text', 'LIKE', "%{$searchTerm}%");
});
$totalCount += $artQuery->count();
$arts = $artQuery->take($limitPerTable)->get()->map(function($item) use ($searchTerm) {
$formatted = $this->formatArt($item, $searchTerm, Art::class);
$formatted['type'] = 'art';
return $formatted;
});
$results = $results->concat($arts);
// 2. Structural Models
$structuralModels = [
Law::class, Volum::class, Book::class, Division::class,
Section::class, Chapter::class, Part::class, Gate::class,
Branch::class
];
foreach ($structuralModels as $modelClass) {
$query = $modelClass::query();
$modelInstance = new $modelClass;
$table = $modelInstance->getTable();
$query->where('title', 'LIKE', "%{$searchTerm}%");
$totalCount += $query->count();
if ($results->count() < 15) {
$items = $query->take($limitPerTable)->get()->map(function($item) use ($modelClass, $table) {
$formatted = $this->formatStructure($item, $modelClass);
$formatted['type'] = ($table === 'section') ? 'sections' : $table;
return $formatted;
});
$results = $results->concat($items);
}
}
// 3. Bylaw Documents
$bylawQuery = BylawDocument::with(['category', 'approvalAuthority', 'promulgationAuthority'])
->where('is_published', true)
->where(function ($q) use ($searchTerm) {
$q->where('title', 'LIKE', "%{$searchTerm}%")
->orWhere('description', 'LIKE', "%{$searchTerm}%")
->orWhere('promulgation_number', 'LIKE', "%{$searchTerm}%")
->orWhere('official_gazette_number', 'LIKE', "%{$searchTerm}%")
->orWhereIn('id', function($subQuery) use ($searchTerm) {
$subQuery->select('document_id')
->from('bylaw_nodes')
->where('node_content', 'LIKE', "%{$searchTerm}%");
});
});
$totalCount += $bylawQuery->count();
$bylaws = $bylawQuery->take($limitPerTable)->get()->map(function($item) {
$formatted = $this->formatBylaw($item);
$formatted['type'] = 'bylaw';
return $formatted;
});
$results = $results->concat($bylaws);
// 4. Judicial Precedents
$judicialQuery = JudicialPrecedent::with('category')
->where(function ($q) use ($searchTerm) {
$q->where('ruling_number', 'LIKE', "%{$searchTerm}%")
->orWhere('subject', 'LIKE', "%{$searchTerm}%")
->orWhere('full_text', 'LIKE', "%{$searchTerm}%");
});
$totalCount += $judicialQuery->count();
$judicials = $judicialQuery->take($limitPerTable)->get()->map(function($item) {
$formatted = $this->formatJudicial($item);
$formatted['type'] = 'judicial_precedent';
return $formatted;
});
$results = $results->concat($judicials);
// 5. Legal Opinions
$opinionQuery = LegalOpinion::with('category')
->where(function ($q) use ($searchTerm) {
$q->where('opinion_number', 'LIKE', "%{$searchTerm}%")
->orWhere('subject', 'LIKE', "%{$searchTerm}%")
->orWhere('full_text', 'LIKE', "%{$searchTerm}%")
->orWhere('issuing_authority', 'LIKE', "%{$searchTerm}%");
});
$totalCount += $opinionQuery->count();
$opinions = $opinionQuery->take($limitPerTable)->get()->map(function($item) {
$formatted = $this->formatOpinion($item);
$formatted['type'] = 'legal_opinion';
return $formatted;
});
$results = $results->concat($opinions);
}
return $this->success([
'items' => $results->take(15)->values(),
'count' => $totalCount
], '', '');
}
/* -----------------------------------------------------------------
* FORMATTING HELPERS
* ----------------------------------------------------------------- */
private function isLockedForCurrentUserGeneric($item): bool
{
return ! auth()->user()->isSubscriber() && (bool) ($item->is_locked ?? false);
}
private function formatBylaw($item)
{
$isLocked = $this->isLockedForCurrentUserGeneric($item);
$description = $item->description;
$cleanDesc = trim(strip_tags($description ?? ''));
if (empty($cleanDesc)) {
$nodeContents = DB::table('bylaw_nodes')
->where('document_id', $item->id)
->orderBy('sort_order', 'asc')
->pluck('node_content')
->toArray();
$description = implode("\n\n", array_filter($nodeContents));
}
return [
'id' => $item->id,
'title' => $item->title,
'category_name' => optional($item->category)->name,
'approval_authority_name' => optional($item->approvalAuthority)->name,
'approval_date' => $item->approval_date,
'promulgation_number' => $item->promulgation_number,
'description' => $isLocked ? null : $description,
'is_locked' => $isLocked,
];
}
private function formatJudicial($item)
{
$isLocked = $this->isLockedForCurrentUserGeneric($item);
return [
'id' => $item->id,
'title' => $item->subject,
'ruling_number' => $item->ruling_number,
'ruling_date' => $item->ruling_date,
'text' => $isLocked ? null : $item->full_text,
'issuing_authority' => $item->issuing_authority,
'category_name' => optional($item->category)->name,
'is_locked' => $isLocked,
];
}
private function formatOpinion($item)
{
$isLocked = $this->isLockedForCurrentUserGeneric($item);
return [
'id' => $item->id,
'title' => $item->subject,
'opinion_number' => $item->opinion_number,
'opinion_date' => $item->opinion_date,
'text' => $isLocked ? null : $item->full_text,
'issuing_authority' => $item->issuing_authority,
'category_name' => optional($item->category)->name,
'is_locked' => $isLocked,
];
}
/**
* Exact 1:1 match with ArtController::searchModel mapping
* All relations (law, chapter, etc) are strictly Strings to prevent App Crashes!
*/
private function formatArt($item, $searchTerm, $modelClass)
{
$law = $item->law ?? Law::find($item->law_id);
$isLocked = ! auth()->user()->isSubscriber() && (bool) ($law?->is_locked ?? false);
$text = $item->text ?? '';
$searchQuoted = preg_quote($searchTerm, '/');
if (!empty($searchTerm) && preg_match('/\b(.{0,50})\b('.$searchQuoted.')\b(.{0,50})\b/i', $text, $matches)) {
$context = trim($matches[1] ?? '').' '.($matches[2] ?? '').' '.trim($matches[3] ?? '');
} else {
$context = $text;
}
return [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'text' => $isLocked ? null : $context,
'is_locked' => $isLocked,
'route' => array_values($this->route($modelClass, $item)),
'category' => optional($law?->category)->name,
'law' => $law?->title ?? '', // STRICLY STRING! Prevents Android App Crash!
'count_art' => $law?->arts?->count() ?? 0,
'count_volums' => $law?->volums?->count() ?? 0, // WITH S
'count_volum' => $law?->volums?->count() ?? 0, // WITHOUT S (Fallback)
'price' => $law?->price,
'image' => $law?->image,
];
}
private function formatStructure($item, $modelClass)
{
$law = Law::find($item?->law_id ?? $item->id);
$isLocked = ! auth()->user()->isSubscriber() && (bool) ($law?->is_locked ?? false);
$payload = [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'is_locked' => $isLocked,
'route' => array_values($this->route($modelClass, $item)),
'law' => $law?->title ?? '', // STRICTLY STRING
];
if ((new $modelClass)->getTable() == 'laws') {
$payload['category'] = optional($law?->category)?->name ?? '';
$payload['image'] = $law?->image;
}
return $payload;
}
private function route($modelClass, $query)
{
if ((new $modelClass)->getTable() == 'art') {
$route = array_filter([
$query->relationLoaded('law') ? $query->law?->title : Law::find($query->law_id)?->title,
$query->relationLoaded('volum') ? $query->volum?->title : Volum::find($query->volum_id)?->title,
$query->relationLoaded('book') ? $query->book?->title : Book::find($query->book_id)?->title,
Division::find($query->division_id)?->title,
$query->relationLoaded('section') ? $query->section?->title : Section::find($query->section_id)?->title,
$query->relationLoaded('chapter') ? $query->chapter?->title : Chapter::find($query->chapter_id)?->title,
$query->relationLoaded('part') ? $query->part?->title : Part::find($query->part_id)?->title,
$query->relationLoaded('gate') ? $query->gate?->title : Gate::find($query->gate_id)?->title,
Branch::find($query->branch_id)?->title,
]);
return array_values($route);
}
if ((new $modelClass)->getTable() == 'laws') {
return array_values(array_filter([Law::find($query->id)?->title]));
}
return [];
}
}

View File

@@ -5,6 +5,7 @@ namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Law; use App\Models\Law;
use App\Models\Notification; use App\Models\Notification;
use App\Models\Category;
use App\Models\RecentArt; use App\Models\RecentArt;
use App\Models\UserSubscriber; use App\Models\UserSubscriber;
use App\Services\AppMarketPurchaseVerifier; use App\Services\AppMarketPurchaseVerifier;
@@ -19,6 +20,139 @@ class HomeController extends Controller
{ {
} }
public function homeV2()
{
$user = auth()->user();
$this->refreshMarketSubscriptionAfterResponse($user);
$recent = RecentArt::query()->where('user_id', $user->id)->get()->map(function ($q) {
return [
'id' => $q->law?->id,
'name' => $q->law?->title,
'is_locked' => $q->law?->is_locked,
];
});
$laws = Law::orderBy('created_at')->get()->map(function ($q) {
return [
'id' => $q->id,
'name' => $q->title,
'is_locked' => $q->is_locked,
];
});
$categories = ['hagigi', 'kifari'];
$lawsByCategory = [];
foreach ($categories as $category) {
$lawsByCategory[$category] = Law::whereHas('category', function ($q) use ($category) {
$q->where('type', $category);
})->get()->map(function ($q) {
return [
'id' => $q->id,
'title' => $q->title,
'is_locked' => $q->is_locked,
'category_id' => $q->category_id,
'price' => $q->price,
'image' => $q->image,
'type' => 'law',
];
});
}
$free_law = Law::where('is_locked', false)->orderBy('created_at')->get()->map(function ($q) {
return [
'id' => $q->id,
'name' => $q->title,
'is_locked' => $q->is_locked,
];
});
$freeSubscription = $user->userSubscribers()
->whereHas('subscribe', function ($query) {
$query->where('is_free', true);
})
->where('expired_at', '>=', now())
->first();
$current_plan = null;
if ($freeSubscription) {
$current_plan = [
'id' => $freeSubscription->id,
'name' => $freeSubscription->subscribe->name,
'price' => $freeSubscription->subscribe->price,
'expired_day' => $freeSubscription->expired_at->diffInDays(now()),
'is_free' => true,
];
}
$latestSubscription = $user->userSubscribers()
->where('expired_at', '>=', now())
->latest('expired_at')
->first();
$expiredDays = UserSubscriber::query()->where('user_id', $user->id)->where('expired_at', '>=', now())->get()->sum(function ($subscriber) {
return $subscriber->expired_at->diffInDays(now());
});
if ($latestSubscription) {
$current_plan = [
'id' => $latestSubscription->id,
'name' => $latestSubscription->subscribe->name ?? 'Subscription',
'price' => $latestSubscription->subscribe->price ?? 100,
'expired_day' => $expiredDays,
'is_free' => (bool)$latestSubscription->is_free,
];
}
$unread_notifications_count = Notification::unreadForUser($user->id)->count();
$homeData = [
'recent' => $recent,
'laws' => $lawsByCategory,
'last_law' => $laws,
'free' => $free_law,
'current_plan' => $current_plan,
'unread_notifications_count' => $unread_notifications_count,
];
return $this->success([
'home' => $homeData,
'hoqoqi_list' => $this->getCategoryList(1), // Category 1
'keyfari_list' => $this->getCategoryList(2), // Category 2
]);
}
private function getCategoryList(int $categoryId)
{
$type = $categoryId === 1 ? 'hagigi' : 'kifari';
$categories = Category::with(['laws'])->where('type', $type)->get()->pluck('id');
$items = Law::query()->whereIn('category_id', $categories)->get();
$data = [];
$user = auth()->user();
foreach ($items as $item) {
$data[] = [
'id' => $item->id,
'title' => $item->title,
'number' => $item->number,
'type' => 'laws',
'is_locked' => $user->isSubscriber() !== false ? false : Law::where('id', $item->id)->first()?->is_locked,
'image' => $item?->image,
'law' => $item?->title,
'count_art' => $item->arts->count(),
'count_volums' => $item->volums->count(),
'price' => $item->price,
];
}
return $data;
}
public function index() public function index()
{ {
$user = auth()->user(); $user = auth()->user();

View File

@@ -0,0 +1,207 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Models\JudicialPrecedent;
use App\Models\JudicialPrecedentCategory;
use App\Traits\BaseApiResponse;
use Illuminate\Http\Request;
class JudicialPrecedentApiController extends Controller
{
use BaseApiResponse;
public function categories()
{
$categories = JudicialPrecedentCategory::all()->map(function ($category) {
return [
'id' => $category->id,
'name' => $category->name,
];
});
return $this->success($categories, 'Success', 'Categories List');
}
public function index(Request $request)
{
$request->validate([
'category_id' => 'nullable|exists:judicial_precedent_categories,id',
'sort_by' => 'nullable|in:date,number',
'sort' => 'nullable|in:asc,desc',
'per_page' => 'nullable|integer|min:1|max:100',
]);
$query = JudicialPrecedent::query();
if ($request->filled('category_id')) {
$query->where('category_id', $request->category_id);
}
$sortBy = $request->input('sort_by', 'date');
$sortOrder = $request->input('sort', 'desc');
$sortColumn = $sortBy === 'number' ? 'ruling_number' : 'ruling_date';
if ($sortBy === 'number') {
// Natural numeric sorting for string numbers
$query->orderByRaw("LENGTH({$sortColumn}) {$sortOrder}")->orderBy($sortColumn, $sortOrder);
} else {
$query->orderBy($sortColumn, $sortOrder);
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$paginator = $query->paginate($perPage);
$items = collect($paginator->items())->map(function ($item) {
return $this->formatItem($item);
});
$responseData = [
'items' => $items,
'current_page' => $paginator->currentPage(),
'last_page' => $paginator->lastPage(),
'per_page' => $paginator->perPage(),
'total' => $paginator->total(),
];
return $this->success($responseData, 'Success', 'Judicial Precedents Fetched');
}
public function search(Request $request)
{
$request->validate([
'search' => 'nullable|string',
'sort_by' => 'nullable|in:date,number',
'sort' => 'nullable|in:asc,desc',
'per_page' => 'nullable|integer|min:1|max:100',
]);
$query = JudicialPrecedent::query();
if ($request->filled('search')) {
$searchTerm = $request->input('search');
$query->where(function ($q) use ($searchTerm) {
$q->where('ruling_number', 'LIKE', "%{$searchTerm}%")
->orWhere('subject', 'LIKE', "%{$searchTerm}%")
->orWhere('full_text', 'LIKE', "%{$searchTerm}%");
});
}
$sortBy = $request->input('sort_by', 'date');
$sortOrder = $request->input('sort', 'desc');
$sortColumn = $sortBy === 'number' ? 'ruling_number' : 'ruling_date';
if ($sortBy === 'number') {
$query->orderByRaw("LENGTH({$sortColumn}) {$sortOrder}")->orderBy($sortColumn, $sortOrder);
} else {
$query->orderBy($sortColumn, $sortOrder);
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$paginator = $query->paginate($perPage);
$items = collect($paginator->items())->map(function ($item) {
return $this->formatItem($item);
});
$responseData = [
'items' => $items,
'current_page' => $paginator->currentPage(),
'last_page' => $paginator->lastPage(),
'per_page' => $paginator->perPage(),
'total' => $paginator->total(),
];
return $this->success($responseData, 'Success', 'Search Results Fetched');
}
public function fast_search(Request $request)
{
$searchTerm = $request->input('search');
$query = JudicialPrecedent::query();
if (!empty($searchTerm)) {
$query->where(function ($q) use ($searchTerm) {
$q->where('ruling_number', 'LIKE', "%{$searchTerm}%")
->orWhere('subject', 'LIKE', "%{$searchTerm}%")
->orWhere('full_text', 'LIKE', "%{$searchTerm}%");
});
}
$count = $query->count();
$items = $query->orderBy('ruling_date', 'desc')->take(5)->get()->map(function ($item) {
return $this->formatItem($item);
});
return $this->success([
'items' => $items,
'count' => $count
], 'Success', 'Fast Search Results');
}
public function pager($id)
{
$current = JudicialPrecedent::find($id);
if (!$current) {
return $this->failed([], [
'title' => 'خطا',
'message' => 'رأی وحدت رویه مورد نظر یافت نشد.'
], 404);
}
$previousItem = JudicialPrecedent::where(function ($query) use ($current) {
$query->where('ruling_date', '<', $current->ruling_date)
->orWhere(function ($subQuery) use ($current) {
$subQuery->where('ruling_date', '=', $current->ruling_date)
->where('id', '<', $current->id);
});
})
->orderBy('ruling_date', 'desc')
->orderBy('id', 'desc')
->first();
$nextItem = JudicialPrecedent::where(function ($query) use ($current) {
$query->where('ruling_date', '>', $current->ruling_date)
->orWhere(function ($subQuery) use ($current) {
$subQuery->where('ruling_date', '=', $current->ruling_date)
->where('id', '>', $current->id);
});
})
->orderBy('ruling_date', 'asc')
->orderBy('id', 'asc')
->first();
$results = array_values(array_filter([
$previousItem ? $this->formatItem($previousItem) : null,
$this->formatItem($current),
$nextItem ? $this->formatItem($nextItem) : null
]));
return $this->success($results, 'Success', 'Pager Window Details');
}
private function isLockedForCurrentUser($item): bool
{
return ! auth()->user()->isSubscriber() && (bool) ($item->is_locked ?? false);
}
private function formatItem($item)
{
$isLocked = $this->isLockedForCurrentUser($item);
return [
'id' => $item->id,
'ruling_number' => $item->ruling_number,
'ruling_date' => $item->ruling_date,
'subject' => $item->subject,
'full_text' => $isLocked ? null : $item->full_text,
'issuing_authority' => $item->issuing_authority,
'category_id' => $item->category_id,
'category_name' => optional($item->category)->name,
'is_locked' => $isLocked,
];
}
}

View File

@@ -0,0 +1,219 @@
<?php
namespace App\Http\Controllers\api;
use App\Http\Controllers\Controller;
use App\Models\LegalOpinion;
use App\Models\LegalOpinionCategory;
use App\Traits\BaseApiResponse;
use Illuminate\Http\Request;
class LegalOpinionApiController extends Controller
{
use BaseApiResponse;
public function categories()
{
$categories = LegalOpinionCategory::all()->map(function ($category) {
return [
'id' => $category->id,
'name' => $category->name,
];
});
return $this->success($categories, 'Success', 'Categories List');
}
public function index(Request $request)
{
$request->validate([
'category_id' => 'nullable|exists:legal_opinion_categories,id',
'sort_by' => 'nullable|in:date,number',
'sort' => 'nullable|in:asc,desc',
'per_page' => 'nullable|integer|min:1|max:100',
]);
$query = LegalOpinion::query();
if ($request->filled('category_id')) {
$query->where('category_id', $request->category_id);
}
$sortBy = $request->input('sort_by', 'date');
$sortOrder = $request->input('sort', 'desc');
$sortColumn = $sortBy === 'number' ? 'opinion_number' : 'opinion_date';
if ($sortBy === 'number') {
$query->orderByRaw("LENGTH({$sortColumn}) {$sortOrder}")->orderBy($sortColumn, $sortOrder);
} else {
$query->orderBy($sortColumn, $sortOrder);
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$paginator = $query->paginate($perPage);
$items = collect($paginator->items())->map(function ($item) {
return $this->formatItem($item);
});
$responseData = [
'items' => $items,
'current_page' => $paginator->currentPage(),
'last_page' => $paginator->lastPage(),
'per_page' => $paginator->perPage(),
'total' => $paginator->total(),
];
return $this->success($responseData, 'Success', 'Legal Opinions Fetched');
}
public function search(Request $request)
{
$request->validate([
'search' => 'nullable|string',
'sort_by' => 'nullable|in:date,number',
'sort' => 'nullable|in:asc,desc',
'per_page' => 'nullable|integer|min:1|max:100',
]);
$query = LegalOpinion::query();
if ($request->filled('search')) {
$searchTerm = $request->input('search');
$query->where(function ($q) use ($searchTerm) {
$q->where('opinion_number', 'LIKE', "%{$searchTerm}%")
->orWhere('subject', 'LIKE', "%{$searchTerm}%")
->orWhere('full_text', 'LIKE', "%{$searchTerm}%")
->orWhere('issuing_authority', 'LIKE', "%{$searchTerm}%");
});
}
$sortBy = $request->input('sort_by', 'date');
$sortOrder = $request->input('sort', 'desc');
$sortColumn = $sortBy === 'number' ? 'opinion_number' : 'opinion_date';
if ($sortBy === 'number') {
$query->orderByRaw("LENGTH({$sortColumn}) {$sortOrder}")->orderBy($sortColumn, $sortOrder);
} else {
$query->orderBy($sortColumn, $sortOrder);
}
$perPage = min(max((int) $request->input('per_page', 15), 10), 100);
$paginator = $query->paginate($perPage);
$items = collect($paginator->items())->map(function ($item) {
return $this->formatItem($item);
});
$responseData = [
'items' => $items,
'current_page' => $paginator->currentPage(),
'last_page' => $paginator->lastPage(),
'per_page' => $paginator->perPage(),
'total' => $paginator->total(),
];
return $this->success($responseData, 'Success', 'Search Results Fetched');
}
public function fast_search(Request $request)
{
$searchTerm = $request->input('search');
$query = LegalOpinion::query();
if ($request->filled('search')) {
$query->where(function ($q) use ($searchTerm) {
$q->where('opinion_number', 'LIKE', "%{$searchTerm}%")
->orWhere('subject', 'LIKE', "%{$searchTerm}%")
->orWhere('full_text', 'LIKE', "%{$searchTerm}%")
->orWhere('issuing_authority', 'LIKE', "%{$searchTerm}%");
});
}
$count = $query->count();
$items = $query->orderBy('opinion_date', 'desc')->take(5)->get()->map(function ($item) {
return $this->formatItem($item);
});
return $this->success([
'items' => $items,
'count' => $count
], 'Success', 'Fast Search Results');
}
public function pager($id)
{
$current = LegalOpinion::find($id);
if (!$current) {
return $this->failed([], [
'title' => 'خطا',
'message' => 'نظریه قانونی مورد نظر یافت نشد.'
], 404);
}
$previousItem = LegalOpinion::where(function ($query) use ($current) {
if ($current->opinion_date) {
$query->where('opinion_date', '<', $current->opinion_date)
->orWhere(function ($subQuery) use ($current) {
$subQuery->where('opinion_date', '=', $current->opinion_date)
->where('id', '<', $current->id);
});
} else {
$query->whereNull('opinion_date')->where('id', '<', $current->id);
}
})
->orderBy('opinion_date', 'desc')
->orderBy('id', 'desc')
->first();
$nextItem = LegalOpinion::where(function ($query) use ($current) {
if ($current->opinion_date) {
$query->where('opinion_date', '>', $current->opinion_date)
->orWhere(function ($subQuery) use ($current) {
$subQuery->where('opinion_date', '=', $current->opinion_date)
->where('id', '>', $current->id);
});
} else {
$query->whereNotNull('opinion_date')
->orWhere(function ($subQuery) use ($current) {
$subQuery->whereNull('opinion_date')->where('id', '>', $current->id);
});
}
})
->orderBy('opinion_date', 'asc')
->orderBy('id', 'asc')
->first();
$results = array_values(array_filter([
$previousItem ? $this->formatItem($previousItem) : null,
$this->formatItem($current),
$nextItem ? $this->formatItem($nextItem) : null
]));
return $this->success($results, 'Success', 'Pager Window Details');
}
private function isLockedForCurrentUser($item): bool
{
return ! auth()->user()->isSubscriber() && (bool) ($item->is_locked ?? false);
}
private function formatItem($item)
{
$isLocked = $this->isLockedForCurrentUser($item);
return [
'id' => $item->id,
'opinion_number' => $item->opinion_number,
'opinion_date' => $item->opinion_date,
'subject' => $item->subject,
'full_text' => $isLocked ? null : $item->full_text,
'issuing_authority' => $item->issuing_authority,
'category_id' => $item->category_id,
'category_name' => optional($item->category)->name,
'is_locked' => $isLocked,
];
}
}

View File

@@ -29,7 +29,7 @@ class NoteController extends Controller
] ]
); );
return $this->success([], 'successfully created.'); return $this->success([], 'با موفقیت اضافه شد');
} }
public function update($id, Request $request) public function update($id, Request $request)
@@ -45,7 +45,7 @@ class NoteController extends Controller
'color_code' => $validated['color_code'], 'color_code' => $validated['color_code'],
]); ]);
return $this->success([], 'successfully updated.'); return $this->success([], 'بروز شد');
} }
public function destroy($id) public function destroy($id)
@@ -53,6 +53,6 @@ class NoteController extends Controller
$note = Note::findOrFail($id); $note = Note::findOrFail($id);
$note->delete(); $note->delete();
return $this->success([], 'successfully deleted.'); return $this->success([], 'حذف شد');
} }
} }

View File

@@ -72,14 +72,14 @@ class PayController extends Controller
'expired_at' => $expiredAt, 'expired_at' => $expiredAt,
]); ]);
return $this->success([], 'Payment Successful', 'Subscription successfully activated.'); return $this->success([], 'موفق', 'اشتراک با موفقیت فعال شد');
} }
return $this->failed([], ['title' => 'Payment Failed', 'message' => 'Payment verification failed.']); return $this->failed([], ['title' => 'پرداخت ناموفق', 'message' => 'پرداخت ناموفق']);
} catch (\Exception $e) { } catch (\Exception $e) {
Log::info('error in callback function', ['error' => $e->getMessage()]); Log::info('error in callback function', ['error' => $e->getMessage()]);
return $this->failed([], ['title' => 'Payment Failed', 'message' => 'Payment verification failed.']); return $this->failed([], ['title' => 'پرداخت ناموفق', 'message' => 'پرداخت ناموفق']);
} }
} }

View File

@@ -62,7 +62,7 @@ class SubscribePlanController extends Controller
->first(); ->first();
if ($activeSubscription && ! $activeSubscription?->subscribe?->is_free && ! $subscribePlan->is_free) { if ($activeSubscription && ! $activeSubscription?->subscribe?->is_free && ! $subscribePlan->is_free) {
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'You already have an active subscription. Please wait until it expires.']); return $this->failed(null, ['title' => 'اشتراک', 'message' => 'شما درحال حاظر اشتراک فعال دارید']);
} }
if ($subscribePlan->is_free) { if ($subscribePlan->is_free) {
@@ -72,7 +72,7 @@ class SubscribePlanController extends Controller
})->exists(); })->exists();
if ($hasUsedFreePlan) { if ($hasUsedFreePlan) {
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'You have already used the free plan.']); return $this->failed(null, ['title' => 'اشتراک', 'message' => 'شما قبلا اشتراک رایگان فعال کردید']);
} }
$expiredAt = now()->addDays($subscribePlan->expired_day + 1); $expiredAt = now()->addDays($subscribePlan->expired_day + 1);
@@ -82,7 +82,7 @@ class SubscribePlanController extends Controller
'expired_at' => $expiredAt, 'expired_at' => $expiredAt,
]); ]);
return $this->success(null, 'Subscribe Plan', 'Free Subscribe Plan Successfully Activated'); return $this->success(null, 'اشتراک', 'اشتراک رایگان شما فعال شد');
} }
try { try {
@@ -133,7 +133,7 @@ class SubscribePlanController extends Controller
->exists(); ->exists();
if ($hasUsedFreePlan) { if ($hasUsedFreePlan) {
return $this->failed(null, ['title' => 'Subscribe Plan', 'message' => 'You have already used the free plan.']); return $this->failed(null, ['title' => 'اشتراک', 'message' => 'شما قبلا اشتراک رایگان فعال کردید']);
} }
$expiredAt = $activeSubscription ? $activeSubscription->expired_at->addDays($subscribePlan->expired_day) : now()->addDays($subscribePlan->expired_day); $expiredAt = $activeSubscription ? $activeSubscription->expired_at->addDays($subscribePlan->expired_day) : now()->addDays($subscribePlan->expired_day);
@@ -144,7 +144,7 @@ class SubscribePlanController extends Controller
'is_free' => true, 'is_free' => true,
]); ]);
return $this->success(null, 'Subscribe Plan', 'Free Subscribe Plan Successfully Activated'); return $this->success(null, 'اشتراک', 'اشتراک رایگان فعال شد');
} }
$subscription_id = $request->input('subscription_id'); $subscription_id = $request->input('subscription_id');
@@ -177,7 +177,7 @@ class SubscribePlanController extends Controller
'is_free' => false, 'is_free' => false,
]); ]);
return $this->success(null, 'Subscribe Plan', 'Subscription successfully activated.'); return $this->success(null, 'اشتراک', 'اشتراک شما فعال شد');
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error('Error in subscription', ['Error' => $e->getMessage()]); Log::error('Error in subscription', ['Error' => $e->getMessage()]);

2
package-lock.json generated
View File

@@ -1,5 +1,5 @@
{ {
"name": "persian-ping", "name": "law-api",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {

View File

@@ -25,16 +25,16 @@ Route::prefix('v1')->group(function () {
Route::post('verify', [AuthController::class, 'verify']); Route::post('verify', [AuthController::class, 'verify']);
Route::post('version', [VersionController::class, 'index']); Route::post('version', [VersionController::class, 'index']);
Route::post('/payment/callback', [SubscribePlanController::class, 'paymentCallback'])->name('payment.callback'); Route::post('/payment/callback', [SubscribePlanController::class, 'paymentCallback'])->name('payment.callback');
}); });
Route::prefix('v1')->middleware('auth:sanctum')->group(function () { Route::prefix('v1')->middleware('auth:sanctum')->group(function () {
Route::get('home', [HomeController::class, 'index']); Route::get('home', [HomeController::class, 'index']);
Route::get('home-v2', [HomeController::class, 'homeV2']);
Route::get('notifications', [NotificationController::class, 'index']); Route::get('notifications', [NotificationController::class, 'index']);
Route::get('art', [ArtController::class, 'index']); Route::get('art', [ArtController::class, 'index']);
Route::get('categories', [CategoriesController::class, 'index']); Route::get('categories', [CategoriesController::class, 'index']);
Route::post('art/search', [ArtController::class, 'search']); Route::post('art/search', [ArtController::class, 'search']);
Route::post('fast-search', [ArtController::class, 'fash_search']); Route::post('fast-search', [ArtController::class, 'fash_search']); // Legacy Art fast search
Route::post('art/note', [NoteController::class, 'create']); Route::post('art/note', [NoteController::class, 'create']);
Route::put('art/note/{id}', [NoteController::class, 'update']); Route::put('art/note/{id}', [NoteController::class, 'update']);
Route::delete('art/note/{id}', [NoteController::class, 'destroy']); Route::delete('art/note/{id}', [NoteController::class, 'destroy']);
@@ -69,4 +69,30 @@ Route::prefix('v1')->middleware('auth:sanctum')->group(function () {
Route::delete('folders/{id}/art/{art_id}', [FolderController::class, 'delete_art']); Route::delete('folders/{id}/art/{art_id}', [FolderController::class, 'delete_art']);
Route::post('suggestions', [SuggestionController::class, 'index']); Route::post('suggestions', [SuggestionController::class, 'index']);
// Judicial Precedents
Route::get('judicial-precedents/categories', [\App\Http\Controllers\api\JudicialPrecedentApiController::class, 'categories']);
Route::get('judicial-precedents', [\App\Http\Controllers\api\JudicialPrecedentApiController::class, 'index']);
Route::get('judicial-precedents/{id}/pager', [\App\Http\Controllers\api\JudicialPrecedentApiController::class, 'pager']);
Route::post('judicial-precedents/search', [\App\Http\Controllers\api\JudicialPrecedentApiController::class, 'search']);
Route::post('judicial-precedents/fast-search', [\App\Http\Controllers\api\JudicialPrecedentApiController::class, 'fast_search']); // NEW
// Legal Opinions
Route::get('legal-opinions/categories', [\App\Http\Controllers\api\LegalOpinionApiController::class, 'categories']);
Route::get('legal-opinions', [\App\Http\Controllers\api\LegalOpinionApiController::class, 'index']);
Route::get('legal-opinions/{id}/pager', [\App\Http\Controllers\api\LegalOpinionApiController::class, 'pager']);
Route::post('legal-opinions/search', [\App\Http\Controllers\api\LegalOpinionApiController::class, 'search']);
Route::post('legal-opinions/fast-search', [\App\Http\Controllers\api\LegalOpinionApiController::class, 'fast_search']); // NEW
// Bylaws
Route::get('bylaws/categories', [\App\Http\Controllers\api\BylawApiController::class, 'categories']);
Route::get('bylaws/authorities', [\App\Http\Controllers\api\BylawApiController::class, 'authorities']);
Route::get('bylaws', [\App\Http\Controllers\api\BylawApiController::class, 'index']);
Route::get('bylaws/{id}/pager', [\App\Http\Controllers\api\BylawApiController::class, 'pager']);
Route::post('bylaws/search', [\App\Http\Controllers\api\BylawApiController::class, 'search']);
Route::post('bylaws/fast-search', [\App\Http\Controllers\api\BylawApiController::class, 'fast_search']); // NEW
// Global Search
Route::post('global-search', [\App\Http\Controllers\api\GlobalSearchApiController::class, 'search']);
Route::post('global-search/fast-search', [\App\Http\Controllers\api\GlobalSearchApiController::class, 'fast_search']); // NEW
}); });