2023-05-01 - Food Delivery App
main topics
- MVC
- Router
- CSV
- Inheritance
My Mental Model for MVC
MVC is not only Model-View-Controller, it also has a router (and an app.rb
to instantiate and run the router
.
app.rb
: instantiates and run therouter
router
needs acontroller
(one or more)controller
- needs a
repository
- instantiates a
view
- needs a
repository
needs a file (to act as a database)
Food Delivery - Day 2
Note
Common question: why are we spreading our software across several different files?
The answer is: software MUST be easy to change.
That's what the term soft in soft-ware means. As opposed to hard-ware.
So, we are creating all this different files so we can make our software easier to change, even if sacrificing the easiness to write. Of course we want easier ways to write software, but making it easier to change is a priority.
- create
employee
model- @id
- @username
- @password
- @role (manager or driver)
- test in
app/test.rb
- create
employee_repository
- @csv_file
- load_csv
- create fake data in
employees.csv
(a manager and a driver) - test in
app/test.rb
- create a
sessions_controller
- login
- ask username
- ask password
- login
- create a
sessions_view
- ask_for
- in the
router
, addsessions_controller
- in
#run
, call@sessions_controller.login
beforeprint_menu
- in
- adjust
app.rb
- test the login calling the
app.rb
- back to
sessions_controller
- login
employee = @employee_repository.find_by_username
- check employee for username/password match
- success:
@view.signed_in
and returns theemployee
- failure:
@view.wrong_credentials
and callslogin
again
- success:
- login
- back to
router
- after login, display
manager
ordriver
menu
- after login, display
- back to
employee
model- create
#manager?
- create
- back to
router
- create
manager_menu
- create
driver_menu
- create
manager_action
- create
driver_action
- create a
logout!
method - call
logout!
in the#quit!
- create
Recommended flow
- code the model
- test it in
test.rb
- test it in
- code the repository
- test it in
test.rb
- test it in
- code the controller and the view
- test using the
router
- test using the