Code Monkey home page Code Monkey logo

ergodnc's Introduction

About This Project

ergodnc (Ergonomic Desk & Coffee) is an open source Laravel project that's being built live on the official Laravel YouTube Channel (Check Here).

You can contribute by asking questions, helping others, reporting issues, or opening pull requests.

Learning Laravel

Laravel has the most extensive and thorough documentation and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.

If you don't feel like reading, Laracasts can help. Laracasts contains over 1500 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.

Laravel Sponsors

We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel Patreon page.

Laravel Premium Partners

ergodnc's People

Contributors

justsanjit avatar krisell avatar omar-ehab avatar raynirola avatar themsaid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ergodnc's Issues

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)

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.

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

Email verification

Should the User model implements MustVerifyEmail to ensure email verification?

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"

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 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.

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

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

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"]

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);
}

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
    );
}

Image Path

in OfficeImageControllerTest after changing the imageResource to return the full path the Storage::assertExists($response->json('data.path')); return an error

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.

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

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.

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!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.