-
Notifications
You must be signed in to change notification settings - Fork 14
Initial implementation #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Initial implementation #3
Conversation
| } | ||
|
|
||
| public Booking createBooking(Car car, User user) { | ||
| Booking booking = new Booking(UUID.randomUUID(), car, user, LocalDateTime.now(), false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expand capacity when full
|
The other code comments seem to have disappeared. |
| private BookingDao bookingDao; | ||
| private UserDao userDao; | ||
| private CarDao carDao; | ||
| private CarService carService; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it bad practice to mix and match dao and services in a service class?
… input immediately
…creating booking and only display available cars when trying to book a car
| return this.bookingDao.getBookings(); | ||
| } | ||
|
|
||
| public Booking[] getBookingsByUserId(String userId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UUID instead of String
| if (booking == null) { | ||
| break; | ||
| } | ||
| if (booking.getUser().getUserId().toString().equals(userId)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (booking.getUser().getUserId().toString().equals(userId)) { | |
| if (booking.getUser().getUserId().equals(userId)) { |
| Booking[] bookings = getBookings(); | ||
|
|
||
| for (Booking booking : bookings) { | ||
| if (booking == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this if check.
| if (booking == null) { | ||
| break; | ||
| } | ||
| if (booking.getUser().getUserId().toString().equals(userId)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (booking.getUser().getUserId().toString().equals(userId)) { | |
| if (booking != null && booking.getUser().getUserId().toString().equals(userId)) { |
| int curUserBookingIdx = 0; | ||
| // 3. iterate second time to populate userBookings | ||
| for (Booking booking : bookings) { | ||
| if (booking == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get rid of this
|
|
||
|
|
||
| public Car[] getCarsByUserId(String userId) { | ||
| if (bookingDao.getCurBookingIdx() == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove initial if. so change logic to get all bookings if size is 0 then return empty array otherwise perform your current logic.
| return userCars; | ||
| } | ||
|
|
||
| public void createBooking(String carRegNumber, String userId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public void createBooking(String carRegNumber, String userId) { | |
| public void createBooking(String carRegNumber, UUID userId) { |
|
|
||
| public void createBooking(String carRegNumber, String userId) { | ||
| // Do I need to robustly handle invalid car reg number and/or user ids for now? | ||
| Car[] cars = carDao.getCars(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need available cars. i.e cars which are not part of a booking.
| public void createBooking(String carRegNumber, String userId) { | ||
| // Do I need to robustly handle invalid car reg number and/or user ids for now? | ||
| Car[] cars = carDao.getCars(); | ||
| boolean isCarFound = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can go. because if car is null when you finish loop it means not found
| return; | ||
| } | ||
|
|
||
| Booking booking = bookingDao.createBooking(foundCar, foundUser); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Booking booking = bookingDao.createBooking(foundCar, foundUser); | |
| return bookingDao.createBooking(foundCar, foundUser); |
This is my first attempt at the initial CLI build.