Skip to content
This repository was archived by the owner on Oct 13, 2022. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
138 commits
Select commit Hold shift + click to select a range
7575738
feat: create reservations table migration
Takeno-hito Aug 25, 2020
2ef93f0
feat: create guests table migration
Takeno-hito Aug 25, 2020
09cd76c
feat: create activity_logs table migration
Takeno-hito Aug 25, 2020
f6af791
fix: to follow new doccument from afes-website/docs
Takeno-hito Aug 28, 2020
e1f094b
feat: create terms migration
Takeno-hito Aug 28, 2020
1ca1817
feat: add 4 models
Takeno-hito Aug 28, 2020
93396ff
fix: reservation model and reservation migration
Takeno-hito Aug 29, 2020
62f3f20
feat: add reservation create route
Takeno-hito Aug 29, 2020
06b9c1c
fix: to response if query has unnessesary content
Takeno-hito Aug 30, 2020
e90fd7a
feat: add reservation with private resource
Takeno-hito Aug 30, 2020
89c24bd
feat: add reservation resource
Takeno-hito Aug 30, 2020
0548652
feat: add reservation search method
Takeno-hito Aug 30, 2020
17b90a7
feat: add reservation show method
Takeno-hito Aug 30, 2020
1b2648c
feat: create HttpExceptionWithError
Takeno-hito Sep 4, 2020
8d04b6d
feat: add general/enter path about guest
Takeno-hito Sep 5, 2020
86ebd71
feat: add general exit method
Takeno-hito Sep 6, 2020
dac29c8
feat: craete manage config and write color
Takeno-hito Sep 6, 2020
27dd420
fix: add manage config
Takeno-hito Sep 6, 2020
772fb4a
feat: check wrong_wristband_color
Takeno-hito Sep 6, 2020
679cdf8
docs: change reservation prefix
Takeno-hito Sep 6, 2020
291aadc
fix: to use in MySQL
Takeno-hito Sep 6, 2020
af0942d
feat: now check wrish_band code
Takeno-hito Sep 6, 2020
c8c7e78
Merge branch 'develop' into feature/#85_afes_manage
Takeno-hito Sep 9, 2020
d381cb4
feat: add guest resource
Takeno-hito Sep 9, 2020
d796f58
feat: add guest show path
Takeno-hito Sep 9, 2020
2c39b07
feat: add guest index route
Takeno-hito Sep 9, 2020
358ad48
fix: change guestId format to (XX-XXXXX)
Takeno-hito Feb 14, 2021
5885af1
feat: update afes/docs
Takeno-hito Feb 15, 2021
e3bb6da
feat: Wristband prefix check
Takeno-hito Feb 15, 2021
7b2013b
feat: ALREADY_ENTERED_RESERVATION error
Takeno-hito Feb 16, 2021
c5c41e1
fix: problem of throw with not 400 code in guest/enter
Takeno-hito Feb 16, 2021
f978b2b
fix: don't always return WRONG_WRISTBAND_COLOR
su8ru Feb 16, 2021
0eac1a2
feat: reservetion->hasProblem method
Takeno-hito Feb 17, 2021
76c98ba
feat: reservation check
Takeno-hito Feb 17, 2021
9c6b312
feat: exhibition room model/migration
Takeno-hito Feb 18, 2021
f08e6a8
fix: set table name in exh_room model
Takeno-hito Feb 19, 2021
0b6aef0
feat: exhroom model: guest_relation
Takeno-hito Feb 19, 2021
ff3e792
feat: permission settings
Takeno-hito Feb 20, 2021
90d659c
feat: exhibition show
Takeno-hito Feb 22, 2021
6728172
feat: exhibition enter
Takeno-hito Feb 22, 2021
5bb84ff
feat: exhibition exit
Takeno-hito Feb 23, 2021
f5a5685
feat: activity_log resource
Takeno-hito Feb 23, 2021
59e13a3
fix: pass through resource in guest/exit, showlog
Takeno-hito Feb 23, 2021
069e95c
feat: 404 in guest/show_log
Takeno-hito Feb 23, 2021
8e4d314
fix: exhroom/exit: remove duplicate validation
Takeno-hito Feb 23, 2021
581418c
feat: exhibition/log
Takeno-hito Feb 23, 2021
e2a88bb
fix: set permission to general
Takeno-hito Feb 24, 2021
010ba50
feat: set permission to online/exhibition
Takeno-hito Feb 26, 2021
05b7ab1
feat: term controller
Takeno-hito Feb 27, 2021
4efd4d7
refactor: remove unused implements
Takeno-hito Feb 28, 2021
8fd4f14
refactor: remove unused import
Takeno-hito Feb 28, 2021
26fb005
fix: remove message arg in Httpexception_with_error_code
Takeno-hito Feb 28, 2021
387c44b
style: make the if expression one line
Takeno-hito Feb 28, 2021
49f69f3
style: remove unnessesary ()
Takeno-hito Feb 28, 2021
895dcc8
refactor: rename reserv to reservation
Takeno-hito Feb 28, 2021
0eeebeb
refactor: use strpos instead of regex
Takeno-hito Feb 28, 2021
720a5bd
fix: stop quitting writing php with adding = in !=
Takeno-hito Feb 28, 2021
90fb815
fix: remove unused expression
Takeno-hito Feb 28, 2021
7d57f3a
fix: rename to clarify method usage
Takeno-hito Feb 28, 2021
3c46658
refactor: use do-while in generating reservation-id
Takeno-hito Feb 28, 2021
9939319
fix: remove unused method in guest resource
Takeno-hito Feb 28, 2021
ac29262
fix: to accept enter when the time as same as enter_scheduled_time
Takeno-hito Feb 28, 2021
9b78368
refactor: rename config/manage to config/onsite
Takeno-hito Feb 28, 2021
b6c0a33
refactor: use group in router
Takeno-hito Feb 28, 2021
e777fe3
Merge branch 'develop' into feature/#85_afes_manage
Takeno-hito Mar 1, 2021
d4fade3
refactor: fix by phpcbf / phpcs
Takeno-hito Mar 1, 2021
b4c8b72
feat: exhibition room controller index
Takeno-hito Mar 2, 2021
669926e
fix: use getErrorCode
Takeno-hito Mar 4, 2021
6a226ad
fix: use correct controller
Takeno-hito Mar 4, 2021
f006c59
feat: term index
Takeno-hito Mar 5, 2021
06950fb
Merge branch 'develop' into feature/#85_afes_manage
Takeno-hito Mar 6, 2021
cf7ecc1
feat: return term object
Takeno-hito Mar 7, 2021
f097e8a
fix: return prefix in term info
Takeno-hito Mar 7, 2021
0ef0ab6
fix: rename violet color to purple
Takeno-hito Mar 7, 2021
2e77fc2
fix: rename color_id to guest_type
Takeno-hito Mar 8, 2021
2a847d3
test: create onsite factories
Takeno-hito Mar 8, 2021
d574548
test: fix model factory
Takeno-hito Mar 8, 2021
de1d62e
test: create guest entrance enter
Takeno-hito Mar 8, 2021
e459ac7
test: move "generalEntranceTest" to "general/EntranceTest"
Takeno-hito Mar 9, 2021
c96b8cc
test: create InvalidGuestCodeCheck
Takeno-hito Mar 9, 2021
d932bbd
fix: use term instead of term_id
Takeno-hito Mar 10, 2021
d14b2f9
fix: return term in reservation/check
Takeno-hito Mar 11, 2021
967120f
test: fix: flip args of assertEquals
Takeno-hito Mar 13, 2021
9a0b80f
test: generl/enter/alreadyUsedGuestCode
Takeno-hito Mar 13, 2021
68ae7b9
test: generl/enter/notFoundReservation
Takeno-hito Mar 13, 2021
6900aec
test: generl/enter/AlreadyEnteredReservation
Takeno-hito Mar 13, 2021
1cafa15
test: generl/enter/OutOfReservationTime
Takeno-hito Mar 13, 2021
c8f9baf
test: generl/enter/WrongWristBandColor
Takeno-hito Mar 13, 2021
10ff4ab
feat: EXHIBITION_NOT_FOUND
Takeno-hito Mar 13, 2021
0905444
fix: return status code instead of 404/409
Takeno-hito Mar 13, 2021
fdece4e
Merge branch 'develop' into feature/#85_afes_manage
Takeno-hito Mar 13, 2021
306a7ef
style: auto fix by phpcbf
Takeno-hito Mar 13, 2021
f2513d0
test: test when entertime is over
Takeno-hito Mar 13, 2021
ef826fb
Merge branch 'develop' into feature/#85_afes_manage
Takeno-hito Mar 13, 2021
8edbdad
test: general/exit
Takeno-hito Mar 13, 2021
bfabdb0
test: general/exit/GuestNotFound
Takeno-hito Mar 13, 2021
cd61c8c
test: general/exit/GuestAlreadyExited
Takeno-hito Mar 13, 2021
8de13a9
style: fix by phpcs
Takeno-hito Mar 16, 2021
67b7513
test: entrance forbidden
Takeno-hito Mar 16, 2021
167e6ea
test: entrance guest
Takeno-hito Mar 16, 2021
658417b
test: create GuestTest
Takeno-hito Mar 16, 2021
c92422c
test: add path description
Takeno-hito Mar 16, 2021
b025de9
test: guest/All
Takeno-hito Mar 16, 2021
acbb0fe
fix: remove unnessesary "/" from path
Takeno-hito Mar 15, 2021
068b7f5
fix: onsite/general/exh/status
Takeno-hito Mar 19, 2021
2289510
fix: exhibition cannot use term get
Takeno-hito Mar 19, 2021
602023e
feat/refactor: term resource
Takeno-hito Mar 19, 2021
ac0030b
fix: return guest type
Takeno-hito Mar 19, 2021
8291970
fix: return term obj
Takeno-hito Mar 19, 2021
0aba8a9
fix: rename GuestGray to StudentGray
Takeno-hito Mar 19, 2021
cead771
fix: return guest_type in term/all
Takeno-hito Mar 19, 2021
10fc133
fix: return guest_type OBJ in term/all
Takeno-hito Mar 19, 2021
88953ba
fix: return all guest counts
Takeno-hito Mar 19, 2021
0fd4e3c
fix: pass ExhRoom/log through activitylog resource
Takeno-hito Mar 19, 2021
714f1a9
fix: use ActivityLogResource instead of ExhibitionRoom....
Takeno-hito Mar 19, 2021
2a7daba
feat: thumbnail and name column migration
Takeno-hito Mar 21, 2021
72eaf38
feat: return thumbnail_id, name data in exhroom
Takeno-hito Mar 21, 2021
943cfb4
feat: activity log path
Takeno-hito Mar 21, 2021
dc8feca
fix: controller name
Takeno-hito Mar 21, 2021
e3f5077
fix: set dates attribute
Takeno-hito Mar 22, 2021
7d5d640
fix: count only who have not exited
Takeno-hito Mar 24, 2021
44c4f3f
feat: check valid character
Takeno-hito Mar 25, 2021
b39ada9
feat: use only valid reservation Id
Takeno-hito Mar 25, 2021
237e4ce
test: Guest/Show
Takeno-hito Mar 25, 2021
8deb84c
fix: timestamp format in term resource
Takeno-hito Mar 27, 2021
bbb21f4
test: use Iso8601Zulu Format
Takeno-hito Mar 27, 2021
ae718db
test-feat: general/GuestNotFound
Takeno-hito Mar 27, 2021
3cb3fe5
test-docs: remove guest/$id/log
Takeno-hito Mar 27, 2021
7a25b8d
fix: allow reservation to get log
Takeno-hito Mar 27, 2021
12b343c
test: log/permission test
Takeno-hito Mar 27, 2021
3b268b2
test: remove id factory from activityLog
Takeno-hito Mar 27, 2021
d79a24f
fix: set modelLog increments true
Takeno-hito Mar 27, 2021
8dbe2db
test: use faker in factory
Takeno-hito Mar 27, 2021
414a5a6
test: ActivityLog/testData
Takeno-hito Mar 27, 2021
f20d3d9
fix: add useCurrent in term timestamps
Takeno-hito Mar 31, 2021
34a86f8
Merge branch 'develop' into HEAD
Takeno-hito Mar 31, 2021
e07ae66
feat: log search
Takeno-hito Apr 8, 2021
28996a8
fix: validate "if string" instead "if int"
Takeno-hito Apr 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ public function report(Exception $exception) {
*/
public function render($request, Exception $exception) {
$request->headers->set('Accept', 'application/json');
if ($exception instanceof HttpExceptionWithErrorCode) {
return response([
'code'=>$exception->getStatusCode(),
'error_code'=>$exception->getErrorCode()
], $exception->getStatusCode());
}
if ($exception instanceof HttpException) {
return response([
'code'=>$exception->getStatusCode(),
'message'=>$exception->getMessage(),
], $exception->getStatusCode(), $exception->getHeaders());
'message'=>$exception->getMessage()
], $exception->getStatusCode());
}
if ($exception instanceof ValidationException) {
return response(['code'=>400, 'message'=> $exception->getMessage()], 400);
Expand Down
20 changes: 20 additions & 0 deletions app/Exceptions/HttpExceptionWithErrorCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php


namespace App\Exceptions;

use Symfony\Component\HttpKernel\Exception\HttpException;

class HttpExceptionWithErrorCode extends HttpException {
private $errorCode;

public function __construct($httpCode, $errorCode) {
$this->errorCode = $errorCode;

parent::__construct($httpCode);
}

public function getErrorCode() {
return $this->errorCode;
}
}
42 changes: 42 additions & 0 deletions app/Http/Controllers/ActivityLogController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Http\Controllers;

use App\Http\Resources\ActivityLogResource;
use App\Http\Resources\ArticleResource;
use App\Models\ActivityLog;
use App\Models\Article;
use App\Models\Reservation;
use App\Models\Revision;
use Illuminate\Http\Request;
use Laravel\Lumen\Routing\Controller as BaseController;
use Carbon\Carbon;

class ActivityLogController extends BaseController {

public function index(Request $request) {
$query = $this->validate($request, [
'id' => ['string'],
'timestamp' => ['string'],
'guest_id' => ['string'],
'exh_id' => ['string'],
'log_type' => ['string'],
'reservation_id' => ['string'],
]);
$log = ActivityLog::query();

foreach ($query as $i => $value) {
if ($i == 'reservation_id') {
if (!$request->user()->hasPermission('reservation')) {
abort(403);
}
if ($reservation = Reservation::find($value)) {
$log->where('guest_id', $reservation->guest->id);
} else return response([]);
}
$log->where($i, $value);
}

return response()->json(ActivityLogResource::collection($log->get()));
}
}
120 changes: 120 additions & 0 deletions app/Http/Controllers/ExhibitionRoomController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

namespace App\Http\Controllers;

use App\Exceptions\HttpExceptionWithErrorCode;
use App\Http\Resources\ActivityLogResource;
use App\Http\Resources\ExhibitionRoomResource;
use App\Http\Resources\GuestResource;
use App\Models\ExhibitionRoom;
use App\Models\Guest;
use App\Models\Term;
use Illuminate\Http\Request;
use Carbon\Carbon;
use App\Models\ActivityLog;

class ExhibitionRoomController extends Controller {
public function index() {
$exh_status = [];
$all_limit = 0;
foreach (ExhibitionRoom::all() as $exh) {
$all_limit += $exh->capacity;
$exh_status[$exh->id] = new ExhibitionRoomResource($exh);
}

$all_counts = [];
foreach (Term::all() as $term) {
$cnt = Guest::query()->whereNull('exited_at')->where('term_id', $term->id)->count();
if ($cnt !== 0) $all_counts[$term->id] = $cnt;
}
return response()->json([
'exh' => $exh_status,
'all' => [
'count' => $all_counts,
'limit' => $all_limit
]
]);
}

public function show(Request $request, $id) {
$exhibition = ExhibitionRoom::find($id);
if (!$exhibition) {
abort(404);
}

return response()->json(new ExhibitionRoomResource($exhibition));
}

public function enter(Request $request) {
$this->validate($request, [
'guest_id' => ['string', 'required']
]);

$user_id = $request->user()->id;
$guest = Guest::find($request->guest_id);
$exh = ExhibitionRoom::find($user_id);
$current = Carbon::now();

if (!$exh) throw new HttpExceptionWithErrorCode(400, 'EXHIBITION_NOT_FOUND');
if (!$guest) throw new HttpExceptionWithErrorCode(400, 'GUEST_NOT_FOUND');

if ($guest->exh_id === $user_id)
throw new HttpExceptionWithErrorCode(400, 'GUEST_ALREADY_ENTERED');

if ($exh->capacity === $exh->guest_count)
throw new HttpExceptionWithErrorCode(400, 'PEOPLE_LIMIT_EXCEEDED');

if ($guest->exited_at !== null)
throw new HttpExceptionWithErrorCode(400, 'GUEST_ALREADY_EXITED');

if (new Carbon($guest->term->exit_scheduled_time) < $current)
throw new HttpExceptionWithErrorCode(400, 'EXIT_TIME_EXCEEDED');


$guest->update(['exh_id' => $exh->id]);

ActivityLog::create([
'exh_id' => $exh->id,
'log_type' => 'enter',
'guest_id' => $guest->id
]);

return response()->json(new GuestResource($guest));
}

public function exit(Request $request) {
$this->validate($request, [
'guest_id' => ['string', 'required']
]);

$user_id = $request->user()->id;
$guest = Guest::find($request->guest_id);
$exh = ExhibitionRoom::find($user_id);

if (!$exh) throw new HttpExceptionWithErrorCode(400, 'EXHIBITION_NOT_FOUND');
if (!$guest) throw new HttpExceptionWithErrorCode(400, 'GUEST_NOT_FOUND');

if ($guest->exited_at !== null)
throw new HttpExceptionWithErrorCode(400, 'GUEST_ALREADY_EXITED');

$guest->update(['exh_id' => null]);

ActivityLog::create([
'exh_id' => $exh->id,
'log_type' => 'exit',
'guest_id' => $guest->id
]);

return response()->json(new GuestResource($guest));
}

public function showLog(Request $request) {
$id = $request->user()->id;
$guest = ExhibitionRoom::find($id);
if (!$guest) {
abort(500, 'ExhibitionRoom Not found');
}
$logs = ActivityLog::query()->where('exh_id', $id)->get();
return response()->json(ActivityLogResource::collection($logs));
}
}
101 changes: 101 additions & 0 deletions app/Http/Controllers/GuestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

namespace App\Http\Controllers;

use App\Exceptions\HttpExceptionWithErrorCode;
use App\Http\Resources\ActivityLogResource;
use App\Http\Resources\GuestResource;
use App\Models\Guest;
use App\Models\Reservation;
use Illuminate\Http\Request;
use Carbon\Carbon;
use App\Models\ActivityLog;

class GuestController extends Controller {
public function show(Request $request, $id) {
$guest = Guest::find($id);
if (!$guest) {
abort(404);
}

return response()->json(new GuestResource($guest));
}

public function index() {
return response()->json(GuestResource::collection(Guest::all()));
}

public function enter(Request $request) {
$this->validate($request, [
'reservation_id' => ['string', 'required'],
'guest_id' => ['string', 'required']
]);

if (!preg_match('/^[A-Z]{2,3}-[2-578ac-kmnpr-z]{5}$/', $request->guest_id)) {
throw new HttpExceptionWithErrorCode(400, 'INVALID_WRISTBAND_CODE');
}

$reservation = Reservation::find($request->reservation_id);

if (!$reservation) throw new HttpExceptionWithErrorCode(400, 'RESERVATION_NOT_FOUND');

$reservation_error_code = $reservation->getErrorCode();

if ($reservation_error_code !== null) {
throw new HttpExceptionWithErrorCode(400, $reservation_error_code);
}

if (Guest::find($request->guest_id)) {
throw new HttpExceptionWithErrorCode(400, 'ALREADY_USED_WRISTBAND');
}

$term = $reservation->term;

if (strpos($request->guest_id, config('onsite.guest_types')[$term->guest_type]['prefix']) !== 0
) {
throw new HttpExceptionWithErrorCode(400, 'WRONG_WRISTBAND_COLOR');
}


$guest = Guest::create(
[
'id' => $request->guest_id,
'term_id' => $term->id,
'reservation_id' => $request->reservation_id
]
);

// TODO: 複数人で処理するときの扱いを考える (docsの編集待ち)
$reservation->update(['guest_id' => $guest->id]);

return response()->json(new GuestResource($guest));
}

public function exit(Request $request) {
$this->validate($request, [
'guest_id' => ['string', 'required']
]);

$guest = Guest::find($request->guest_id);
if (!$guest) {
throw new HttpExceptionWithErrorCode(400, 'GUEST_NOT_FOUND');
}

if ($guest->exited_at !== null) {
throw new HttpExceptionWithErrorCode(400, 'GUEST_ALREADY_EXITED');
}

$guest->update(['exited_at' => Carbon::now()]);

return response()->json(new GuestResource($guest));
}

public function showLog(Request $request, $id) {
$guest = Guest::find($id);
if (!$guest) {
abort(404);
}
$logs = ActivityLog::query()->where('guest_id', $id)->get();
return response()->json(ActivityLogResource::collection($logs));
}
}
81 changes: 81 additions & 0 deletions app/Http/Controllers/ReservationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace App\Http\Controllers;

use App\Http\Resources\ReservationResource;
use App\Http\Resources\ReservationWithPrivateResource;
use App\Models\Reservation;
use Illuminate\Http\Request;
use \Illuminate\Support\Str;

class ReservationController extends Controller {

public function index(Request $request) {
$query = $this->validate($request, [
'email' => ['string', 'email:rfc,dns'],
'term_id' => ['string'],
'people_count' => ['integer', 'gte:1'],
'name' => ['string'],
'address' => ['string'],
'cellphone' => ['string', 'regex:/0\d{9,10}$/']
]);

$response = Reservation::query();

foreach ($query as $i => $value) $response->where($i, $value);


return response(ReservationResource::collection($response->get()));
}
public function create(Request $request) {
$body = $this->validate($request, [
'email' => ['required', 'string', 'email:rfc,dns'],
'term_id' => ['required', 'string'],
'people_count' => ['required', 'integer', 'gte:1'],
'name' => ['required', 'string'],
'address' => ['required', 'string'],
'cellphone' => ['required', 'string', 'regex:/0\d{9,10}$/']
]);

$salt = "234578acdefghijkmnprstuvwxyz";
do {
$reservation_id = 'R-';
while (strlen($reservation_id) < 10) {
$reservation_id .= $salt[mt_rand(0, strlen($salt) - 1)];
}
} while (Reservation::where('id', $reservation_id)->exists());

$reservation = Reservation::create(
array_merge($body, ['id' => $reservation_id])
);

return response($reservation, 201);
}

public function show($id) {
$reservation = Reservation::find($id);
if (!$reservation) abort(404);

return response()->json(new ReservationWithPrivateResource($reservation));
}

public function check($id) {
$reservation = Reservation::find($id);
if (!$reservation) abort(404);

$status_code = $reservation->getErrorCode();
if ($status_code !== null) {
$valid = false;
} else {
$valid = true;
}

$res = [
'valid' => $valid,
'status_code' => $status_code,
'term' => $reservation->term
];

return response()->json($res);
}
}
Loading