- Added new apis
This commit is contained in:
58
app/Http/Controllers/api/ArtHighlightController.php
Normal file
58
app/Http/Controllers/api/ArtHighlightController.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ArtHighlight;
|
||||
use App\Traits\BaseApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ArtHighlightController extends Controller
|
||||
{
|
||||
use BaseApiResponse;
|
||||
|
||||
public function create(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'art_id' => 'required',
|
||||
'start_index' => 'required|integer',
|
||||
'end_index' => 'required|integer',
|
||||
'selected_text' => 'nullable|string',
|
||||
'color_code' => 'nullable|string',
|
||||
]);
|
||||
|
||||
ArtHighlight::create([
|
||||
'user_id' => auth()->id(),
|
||||
'art_id' => $validated['art_id'],
|
||||
'start_index' => $validated['start_index'],
|
||||
'end_index' => $validated['end_index'],
|
||||
'selected_text' => $validated['selected_text'],
|
||||
'color_code' => $validated['color_code'],
|
||||
]);
|
||||
|
||||
return $this->success([], 'موفق', 'هایلایت با موفقیت اضافه شد');
|
||||
}
|
||||
|
||||
public function update($id, Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'start_index' => 'required|integer',
|
||||
'end_index' => 'required|integer',
|
||||
'selected_text' => 'nullable|string',
|
||||
'color_code' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$highlight = ArtHighlight::where('user_id', auth()->id())->findOrFail($id);
|
||||
$highlight->update($validated);
|
||||
|
||||
return $this->success([], 'بروزرسانی', 'هایلایت با موفقیت بروزرسانی شد');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$highlight = ArtHighlight::where('user_id', auth()->id())->findOrFail($id);
|
||||
$highlight->delete();
|
||||
|
||||
return $this->success([], 'حذف', 'هایلایت با موفقیت حذف شد');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user