Преглед изворни кода

Merge branch 'master' into Nate

maa3444 пре 2 година
родитељ
комит
366bdaeb92

+ 2 - 8
app/Http/Controllers/API/UserController.php

@@ -50,18 +50,12 @@ class UserController extends Controller
      * @param  int  $id
      * @return \Illuminate\Http\Response
      */
-    public function show(Request $request,User $user)
+    public function show(Request $request, User $user)
     {
-        $user = User::where('user_id', '=', $request->id)->get()[0];
-        $department = Department::where('department_id','=',$user->department_id)->get()[0];
-        $user->department = $department->department_name;
-        $checkIn = CheckIn::where('user_id', '=', $request->id)->
-        where('activity_id', '=', $request->activity_id)->get()[0];
-        $user->checkIn = $checkIn->is_checked_in;
+        $user = User::where('user_id', '=', $request->id)->first();
         $response = [
             'user' => $user,
         ];
-
         return response($response, 201);
     }
 

+ 10 - 1
app/Http/Controllers/CheckInController.php

@@ -4,8 +4,10 @@ namespace App\Http\Controllers;
 
 use App\Models\CheckIn;
 use App\Models\User;
+use Illuminate\Http\Request;
 use App\Http\Requests\StoreCheckInRequest;
 use App\Http\Requests\UpdateCheckInRequest;
+use App\Models\Department;
 
 class CheckInController extends Controller
 {
@@ -65,9 +67,16 @@ class CheckInController extends Controller
      * @param  \App\Models\CheckIn  $checkIn
      * @return \Illuminate\Http\Response
      */
-    public function show(CheckIn $checkIn)
+    public function show(Request $request, CheckIn $checkIn)
     {
         //
+        $checkIn = CheckIn::where('user_id', '=', $request->id)->where('activity_id', '=', $request->activity_id)->first();
+        $department = Department::where('department_id', '=', $checkIn->department_id)->first();
+        $checkIn->department = $department->department_name;
+        $response = [
+            'checkIn' => $checkIn,
+        ];
+        return response($response, 201);
     }
 
     /**

+ 1 - 0
app/Http/Controllers/DrawController.php

@@ -27,6 +27,7 @@ class DrawController extends Controller
             ->where('is_checked_in', 'true')
             ->whereTime('check_ins.updated_at', '<=', $activity->deadline)
             ->whereIn('region', $request->region)
+            ->inRandomOrder()
             ->get()
             ->random($request->number);
 

+ 6 - 1
database/MAA_department.json

@@ -178,5 +178,10 @@
     "department_id": "X12",
     "department_name": "萬大果菜市場專案",
     "manager": "X12"
-  }
+  },
+  {
+    "department_id": "guest",
+    "department_name": "來賓",
+    "manager": "X05"
+  }  
 ]

+ 2 - 1
routes/api.php

@@ -15,6 +15,7 @@ use App\Http\Controllers\CheckInController;
 use App\Http\Controllers\RecipientsController;
 use App\Http\Controllers\DepartmentController;
 use App\Http\Controllers\DrawController;
+use App\Models\CheckIn;
 
 /*
 |--------------------------------------------------------------------------
@@ -111,7 +112,7 @@ Route::middleware(['auth:sanctum', 'abilities:Admin'])->group(function () {
 
     // Recipients
 
-    Route::post('/user/show', [UserController::class, 'show']);
+    Route::post('/checkin/show', [CheckInController::class, 'show']);
 });
 Route::post('/user/index', [UserController::class, 'index']);
 Route::post('/department/index', [DepartmentController::class, 'index']);