-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ade99b0
commit de04944
Showing
15 changed files
with
377 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Services\ReserveTimeOptionService; | ||
use Illuminate\Http\Request; | ||
|
||
use App\Models\Room; | ||
|
||
/** | ||
* House Room | ||
* Class RoomController | ||
* @package App\Http\Controllers\Www | ||
*/ | ||
class RoomController extends Controller | ||
{ | ||
public function __construct() | ||
{ | ||
$this->middleware('auth:api'); | ||
} | ||
|
||
/** | ||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | ||
*/ | ||
public function index() | ||
{ | ||
$rooms = Room::all(); | ||
$rooms->load('roomScores', 'roomFiles.file'); | ||
|
||
// foreach ($rooms as $key => $room) { | ||
// $room = $room->toArray(); | ||
// foreach ($room['room_scores'] as $key => $value) { | ||
// $room['totalScore'] = $value['score'] ++; | ||
// } | ||
// } | ||
|
||
return response()->json(['rooms' => $rooms]); | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | ||
*/ | ||
public function create(Request $request) | ||
{ | ||
$reserveTimeOptionService = new ReserveTimeOptionService(); | ||
$now = Carbon::now(); | ||
$timeOptions = $reserveTimeOptionService->makeTimeOptions($now); | ||
|
||
// $params = [ | ||
// 'timeOptions' => $timeOptions, | ||
// 'baseTime' => $now, | ||
// ]; | ||
return response()->json([ | ||
'timeOptions' => $timeOptions, | ||
'baseTime' => $now | ||
]); | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
$post = Post::create([ | ||
'category_id' => $request->get('category_id'), | ||
'name' => $request->get('name'), | ||
'content' => $request->get('content') | ||
]); | ||
return response()->json(['post' => $post]); | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* @param Reservation $reservation | ||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | ||
*/ | ||
public function show(Request $request, Post $post) | ||
{ | ||
$post->load('category'); | ||
return response()->json(['post' => $post]); | ||
} | ||
|
||
/** | ||
* @param Request $request | ||
* @param Reservation $reservation | ||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | ||
*/ | ||
public function update(Request $request, Post $post) | ||
{ | ||
$post->update($request->all()); | ||
$post->load('category'); | ||
|
||
return response()->json(['post' => $post]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class File extends Model | ||
{ | ||
protected $table = 'files'; | ||
|
||
protected $fillable = [ | ||
'url', | ||
'title', | ||
'entity_type', | ||
's3_key', | ||
's3_bucket', | ||
's3_region', | ||
]; | ||
|
||
// Relations | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Room extends Model | ||
{ | ||
|
||
protected $table = 'rooms'; | ||
|
||
protected $fillable = [ | ||
'name', | ||
'content' | ||
]; | ||
|
||
// Relations | ||
public function roomScores() | ||
{ | ||
return $this->hasMany(\App\Models\RoomScore::class, 'room_id', 'id'); | ||
} | ||
|
||
public function roomFiles() | ||
{ | ||
return $this->hasMany(\App\Models\RoomFile::class, 'room_id', 'id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class RoomFile extends Model | ||
{ | ||
protected $table = 'room_files'; | ||
|
||
protected $fillable = [ | ||
'room_id', | ||
'file_id', | ||
]; | ||
|
||
// Relations | ||
public function file() | ||
{ | ||
return $this->belongsTo(\App\Models\File::class, 'file_id', 'id'); | ||
} | ||
|
||
public function room() | ||
{ | ||
return $this->belongsTo(\App\Models\Room::class, 'room_id', 'id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class RoomScore extends Model | ||
{ | ||
protected $table = 'room_scores'; | ||
|
||
protected $fillable = [ | ||
'room_id', | ||
'user_id', | ||
'score' | ||
]; | ||
|
||
// Relations | ||
public function user() | ||
{ | ||
return $this->belongsTo(\App\Models\User::class, 'user_id', 'id'); | ||
} | ||
|
||
public function room() | ||
{ | ||
return $this->belongsTo(\App\Models\Room::class, 'room_id', 'id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.