added questions_count to UserTest
This commit is contained in:
parent
e832391b85
commit
3f8667cb98
@ -71,7 +71,7 @@ class TestController extends Controller
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Test::with(['author', 'category']);
|
||||
$query = Test::with(['author', 'category'])->withCount('questions');
|
||||
|
||||
if ($request->has('category_id')) {
|
||||
$query->where('category_id', $request->query('category_id'));
|
||||
@ -161,7 +161,7 @@ class TestController extends Controller
|
||||
*/
|
||||
public function show(Test $test)
|
||||
{
|
||||
$test->load(['author', 'category', 'questions']);
|
||||
$test->load(['author', 'category', 'questions'])->loadCount('questions');
|
||||
return new TestResource($test);
|
||||
}
|
||||
|
||||
|
||||
@ -130,10 +130,8 @@ class UserTestController extends Controller
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="User test created successfully",
|
||||
* @OA\JsonContent(
|
||||
* @OA\Property(property="message", type="string", example="This test isn't available now!")
|
||||
* )
|
||||
* description="UserTest created successfully",
|
||||
* @OA\JsonContent(ref="#/components/schemas/UserTestResource")
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=422,
|
||||
|
||||
@ -25,6 +25,7 @@ class TestResource extends JsonResource
|
||||
* type="array",
|
||||
* @OA\Items(ref="#/components/schemas/QuestionResource")
|
||||
* ),
|
||||
* @OA\Property(property="questions_count", type="integer", example=2),
|
||||
*
|
||||
* @OA\Property(property="is_available", type="boolean", example=true),
|
||||
* @OA\Property(property="author_id", type="integer", nullable=true, example=2),
|
||||
@ -46,6 +47,7 @@ class TestResource extends JsonResource
|
||||
'category' => new CategoryResource($this->whenLoaded('category')),
|
||||
|
||||
'questions' => QuestionResource::collection($this->whenLoaded('questions')),
|
||||
'questions_count' => $this->when(isset($this->questions_count), $this->questions_count, 0),
|
||||
|
||||
'is_available' => $this->isAvailable(),
|
||||
'author_id' => $this->author_id,
|
||||
|
||||
@ -42,7 +42,5 @@ class Test extends Model
|
||||
{
|
||||
return $this->belongsToMany(Question::class)
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -2442,17 +2442,11 @@
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "User test created successfully",
|
||||
"description": "UserTest created successfully",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"message": {
|
||||
"type": "string",
|
||||
"example": "This test isn't available now!"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
"$ref": "#/components/schemas/UserTestResource"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2995,6 +2989,10 @@
|
||||
"$ref": "#/components/schemas/QuestionResource"
|
||||
}
|
||||
},
|
||||
"questions_count": {
|
||||
"type": "integer",
|
||||
"example": 2
|
||||
},
|
||||
"is_available": {
|
||||
"type": "boolean",
|
||||
"example": true
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user