ergodnc's People
Forkers
ahmedhelalahmed haipham mtariqsajid sathivel1985 hamidafghan ali3bdalla efabriziogc haheap wysjd sktoke bakoorahnin engrhaider shaunstanislauslau biodunbamigboye justsanjit godkinmo gerp aarbi abdelhak002 mukeshtilokani agumaxwellforcode krisell boringke jomitjose hobby10 angelokezimana muffycompo aknadeem extjac anisur3036 debjit davorminchorov tulbadex bazzly thefeqy abdulwahhabkhan craigpotter khairy-pelcro watheqalshowaiter armandolazarte tijanieneye10 guccilive alhaji-aki arneetsingh ozankurt tauseefmd13 camimtoto timothykimemia yakidahan asfaqtamim reubenwedson muhammedshiffin ilijat macku99 bhagwatsingh-indianic alamriku robotvinay alons182 salah-jr garethredfern haidarzhy dcmastenbroek ag-php e277 assoft esinkuma kenmutisya waziri123 maxi032 lucaspedreira titosen testeru roneemrayhan prosolver-org anas-koraspond ashik-meher kawtarkoki panicoding bybuink mkcdeveloper rickydominado rc6886 jseparovic wdog namhoonchoe rahmanakorede442ergodnc's Issues
Error: Call to a member function getAttributes() on null -Episode 2
Tests\Feature\OfficeControllerTest > it shows the office
Expected response status code [200] but received 500.
The following exception occurred during the request:
Error: Call to a member function getAttributes() on null in /Users/os/Documents/projects/office-reservation/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Collection.php:88
Stack trace:
Code
/**
* @test
*/
public function itShowsTheOffice()
{
$user = User::factory()->create();
$tag = Tag::factory()->create();
$office = Office::factory()->for($user)->create();
$office->tags()->attach($tag);
$office->images()->create(['path' => 'image.jpg']);
Reservation::factory()->for($office)->create(['status' => Reservation::STATUS_ACTIVE]);
Reservation::factory()->for($office)->create(['status' => Reservation::STATUS_CANCELLED]);
$response = $this->get('/api/offices/'.$office->id);
$response->assertOk()
->assertJsonPath('data.reservations_count', 1)
->assertJsonCount(1, 'data.tags')
->assertJsonCount(1, 'data.images')
->assertJsonPath('data.user.id', $user->id);
}
Controller
public function show(Office $office): JsonResource
{
$office->loadCount(['reservations' => fn($builder) => $builder->where('status', Reservation::STATUS_ACTIVE)])
->load(['images', 'tags', 'user']);
return OfficeResource::make($office);
}
Returning `hidden` in the api response
We are already excluding hidden offices in the response here, so all the offices in the api response would have hidden = false.
Login endpoint returns "419 unknown status "
Hi @themsaid ,
I have cloned this repository with all settings as it is and for frontend, I am using your "nuxt-ergodnc" repository.
I have install front end using 'npm install' and backend using 'composer install && php artisan migrate && php artisan db:seed'
when, I try to login from frontend, It throws error '419 unknown status'.
I just noticed that it's not working in any of Laravel 8.x version. I tried it with Laravel 9 and it's working with Laravel 9 .
I think, there are some "cors " issues with "fruitcake/cors" package in laravel 8, Laravel 9 does not use this package. is there a way to make it work with laravel 8?
Thanks
Episode 5 observations
Your code is using 'public' disk everywhere. I know you said that you would move this to s3 maybe in production, but this means changing all public disk use to s3 but you may have other uses for the public disk.
I would prefer to create a new disk just for images which initially maps to local but can change to map to an S3 bucket later.
I find it useful to store the disk name in the images table. This allows images to migrated from one disk to another at some point in the future.
API should return the full URI of the image so that the consumer does not need to know where the images are being stored and can just use the URI directly.
Delete image when office is deleted
When an office is deleted, automatically the image should go as well
Email verification
Should the User model implements MustVerifyEmail to ensure email verification?
Date Between
What if the reservation date range is wider than the search date range !?
The search date range will be included in the reservation date range but the reservation will not be shown in the result. But the office in fact will be reserved and occupied in this date search range.
EX:
Search: "2021-02-01" to "2021-04-01"
Reservation: "2021-01-01" end "2021-05-01"
"2021-01-01" not between "2021-02-01" & "2021-04-01"
"2021-05-01" not between "2021-02-01" & "2021-04-01"
but ["2021-02-01" & "2021-04-01"] is inside ["2021-01-01" & "2021-05-01"]
Episode 5 - Image Deleting Logic
When you delete an image you validate if the image is either the only one or the only one and featured if so you are not allowing to delete it, but at the same time, you are allowing to create an office without a featured image or a normal image.
So I consider the logic above as a paradox because if you want to apply these rules on the delete image action you should also make the featured image in the create & update office as a required field in the user request.
The best scenario is to make the featured image a field in the Offices table and by that, you will skip the multiple queries on the images table just for adding a feature one.
Call to undefined method Tests\Feature\OfficeImageControllerTest::assertModelMissing()
what I am missing here
Code Consistency
- In the first, we used user_id for Hosts and visitor_id for visitors
- Is it better to use policies for user reservation authorization (not allowed to reserve its own offices)?
- Scope activeBetween should be named activeBetweenDates for consistency because for name convenience "activeBetween" can be either dates or numbers or ... so it's more efficient to rename it as "activeBetweenDates"
Date Between
Unable to find a file at path
I'm getting a weird error whenever I try to execute the tests.
It seems like the first part of the app URL is missing.
Problems comes from OfficeImageControllerTest
And here's the file OfficeImageControllerTest
Can anyone help ?
Business Logic
- What if I need an urgent reservation on the same date? the whole app will not be available for me
- If there is an available office on the today date it cannot be booked for today! so all the app will be again not available for all today booking. so the validation should be after_or_equal start-date for the end_date and we should remove the numberOfDays condition < 2
Missing validate method
Hi Mohamed
I think you forgot to call validate method on the validator helper in "UserReservationController" when you want to create a reservation
Multiple reservations
A user should have access to one reservation before another or shouldn’t be able to reserve an office until current reservation expire or the reservation must not clash whereby they can book ahead of their current reservation and not within their current reservation
Episode 4 - Notification Logic
When creating or updating an office, you are attaching or sync the tags in the database inside the transaction function, then you are sending notification to the admin outside the transaction, but if it was committed or failed you are in both situations sending the notification which is wrong, you need to use the "Manually using transactions" concept to control the transaction status.
ErrorException: Undefined array key "tags"
Tests\Feature\OfficeControllerTest::itIncludesImagesTagsAndUser
ErrorException: Undefined array key "tags"
/Users/os/Documents/projects/office-reservation/tests/Feature/OfficeControllerTest.php:121
/**
* @test
*/
public function itIncludesImagesTagsAndUser()
{
$user = User::factory()->create();
$tag = Tag::factory()->create();
$office = Office::factory()->for($user)->create();
$office->tags()->attach($tag);
$office->images()->create(['path' => 'image.jpg']);
$response = $this->get('/api/offices');
//$response->dump();
$response->assertOk();
//dd($response->json('data')[0]);
$this->assertIsArray($response->json('data')[0]['tags']);
$this->assertCount(1, $response->json('data')[0]['tags']);
$this->assertIsArray($response->json('data')[0]['images']);
$this->assertCount(1,$response->json('data')[0]['images']);
$this->assertEquals($user->id, $response->json('data')[0]['user']['id']);
//$response->dump();
}
Controller
public function index() : JsonResource
{
$offices = Office::query()//->orderBy('id','DESC')
->where('approval_status', Office::APPROVAL_APPROVED)
->where('hidden', false)
->when(request('host_id'),
fn($builder) => $builder->whereUserId(request('host_id')))
->when(request('user_id'), //user_id'
fn($builder) => $builder->whereRelation('reservations', 'user_id' , '=' , request('user_id')))
->when(
request('lat') && request('lng'),
fn($builder) => $builder->nearestTo(request('lat'),request('lng')), //Otherwise
fn($builder) => $builder->orderBy('id', 'ASC')//oldest record
)
//latest('id')
->with(['images', 'tags', 'user'])//Problem
->withCount(['reservations' => fn($builder) => $builder->where('status', Reservation::STATUS_ACTIVE)])
->paginate(20);
return OfficeResource::collection(
$offices
);
}
Create Reservation
- Missing the validate() function on validator() helper
- Changing the key messages related to the date to "date_range" instead of "office_id"
- The diffDays return a floor result so to get the real number of days you should use (int)ceil() and floatDiffInRealDays:
_$numberOfDays = (int)ceil(Carbon::parse(request('end_date'))->endOfDay()->floatDiffInRealDays(
Carbon::parse(request('start_date'))->startOfDay()
));
so now the difference between addDays(1) and addDays(40) will be 40 as you are getting the startDay of the first one and the endDate of the second one.
Note: (Change in the testing 41 to 40)
**Error:**
- the calculation between today and tomorrow is 1.99999 which is 1 for floor and 2 for ceil functions
- If you use only addition by one the calculation will be wrong
- If you want to keep the logic of a 1-day reservation not allowed remove the condition because it already exists inside the validator
when using the after:start_date for the end_date
Please add a license
Hello,
Please add a license (maybe a wtfpl), because without a license no one can use your code:
https://opensource.stackexchange.com/a/1721
Thanks.
Assigning a new office approval_status is redundant
When we created the office migration, the default approval_status
is pending (1).
Why do we also need to do the following in the controller when creating an office?
$attributes['approval_status'] = Office::APPROVAL_PENDING;
NOTE: If we remove that line in the controller, the JsonResource
response when creating an office does NOT contain the default pending status from the database. This will make the following assertion to fail:
->assertJsonPath('data.approval_status', Office::APPROVAL_PENDING)
Reservation Validation Rule
Hey Said,
I am running with some issue within validators which validate the reservation for an office which should always be greater than 1 day.
Lets say i make a reservation for an office from "2021-10-07" to "2021-10-08" on 2021-10-06 since the difference between these two dates is 1 day($numberOfDays = 1 ) and as user are allowed to stay till the last day which is 2021-10-08, technically that makes it reservation for 2 days( $numberOfDays + 1) and following validator will always pass
if($numberOfDays < 2){
throw ValidationException::withMessages([
'start_date' => 'You cannot make reservation for only one day'
]);
}
and user will be allowed to make the reservations which should not be allowed according to the validation rule.
Please let me know if i am mistaken.
Upload image
In the OfficeImageController/store function, it returns an error when uploading the image via postman "Call to a member function storePublicly() on null" it cannot read the image file posted!! But the test passed successfully!!
Image Path
in OfficeImageControllerTest after changing the imageResource to return the full path the Storage::assertExists($response->json('data.path')); return an error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.