diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..fadd49af Binary files /dev/null and b/.DS_Store differ diff --git a/Gemfile.lock b/Gemfile.lock index 10034745..6e05e9db 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -219,6 +219,8 @@ GEM net-smtp (0.3.3) net-protocol nio4r (2.5.9) + nokogiri (1.15.5-arm64-darwin) + racc (~> 1.4) nokogiri (1.15.5-x86_64-darwin) racc (~> 1.4) nokogiri (1.15.5-x86_64-linux) @@ -347,6 +349,7 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) + sqlite3 (1.6.8-arm64-darwin) sqlite3 (1.6.8-x86_64-darwin) sqlite3 (1.6.8-x86_64-linux) stimulus-rails (1.2.2) @@ -404,6 +407,7 @@ GEM zeitwerk (2.6.12) PLATFORMS + arm64-darwin-21 x86_64-darwin-22 x86_64-linux diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 00000000..467f3545 Binary files /dev/null and b/app/.DS_Store differ diff --git a/app/controllers/deliveries_controller.rb b/app/controllers/deliveries_controller.rb new file mode 100644 index 00000000..5498dfbf --- /dev/null +++ b/app/controllers/deliveries_controller.rb @@ -0,0 +1,81 @@ +class DeliveriesController < ApplicationController + before_action :authenticate_user! + + def index + matching_deliveries = Delivery.where(:user_id => current_user.id) + @list_of_deliveries = matching_deliveries.order({ :created_at => :desc }) + @not_arrived = @list_of_deliveries.where(:actual_arrive => false) + @arrived = @list_of_deliveries.where(:actual_arrive => true) + + + render({ :template => "deliveries/index" }) + end + + def show + the_id = params.fetch("path_id") + + matching_deliveries = Delivery.where({ :id => the_id }) + + @the_delivery = matching_deliveries.at(0) + + render({ :template => "deliveries/show" }) + end + + def create + the_delivery = Delivery.new + the_delivery.description = params.fetch("query_description") + the_delivery.supposed_to_arrive = params.fetch("query_supposed_to_arrive") + the_delivery.actual_arrive = false + the_delivery.details = params.fetch("query_details") + # the_delivery.user_id = params.fetch("query_user_id") + the_delivery.user_id = current_user.id + + if the_delivery.valid? + the_delivery.save + redirect_to("/deliveries", { :notice => "Added to list." }) + else + redirect_to("/deliveries", { :alert => the_delivery.errors.full_messages.to_sentence }) + end + end + + def mark_as_received + the_id = params.fetch("path_id") + the_delivery = Delivery.where({ :id => the_id }).at(0) + + the_delivery.actual_arrive = true + + if the_delivery.valid? + the_delivery.save + redirect_to("/deliveries", { :notice => "Delivery marked received successfully." }) + else + redirect_to("/deliveries", { :alert => the_delivery.errors.full_messages.to_sentence }) + end + end + + def update + the_id = params.fetch("path_id") + the_delivery = Delivery.where({ :id => the_id }).at(0) + + the_delivery.description = params.fetch("query_description") + the_delivery.supposed_to_arrive = params.fetch("query_supposed_to_arrive") + the_delivery.actual_arrive = params.fetch("query_actual_arrive") + the_delivery.details = params.fetch("query_details") + the_delivery.user_id = params.fetch("query_user_id") + + if the_delivery.valid? + the_delivery.save + redirect_to("/deliveries/#{the_delivery.id}", { :notice => "Delivery updated successfully."} ) + else + redirect_to("/deliveries/#{the_delivery.id}", { :alert => the_delivery.errors.full_messages.to_sentence }) + end + end + + def destroy + the_id = params.fetch("path_id") + the_delivery = Delivery.where({ :id => the_id }).at(0) + + the_delivery.destroy + + redirect_to("/deliveries", { :notice => "Delivery deleted successfully."} ) + end +end diff --git a/app/models/delivery.rb b/app/models/delivery.rb new file mode 100644 index 00000000..cd693d0c --- /dev/null +++ b/app/models/delivery.rb @@ -0,0 +1,16 @@ +# == Schema Information +# +# Table name: deliveries +# +# id :integer not null, primary key +# actual_arrive :boolean +# description :string +# details :text +# supposed_to_arrive :date +# created_at :datetime not null +# updated_at :datetime not null +# user_id :integer +# +class Delivery < ApplicationRecord + belongs_to :user, class_name: "User", foreign_key: "user_id" +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 00000000..83be2da2 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,27 @@ +# == Schema Information +# +# Table name: users +# +# id :integer not null, primary key +# email :string default(""), not null +# encrypted_password :string default(""), not null +# remember_created_at :datetime +# reset_password_sent_at :datetime +# reset_password_token :string +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_users_on_email (email) UNIQUE +# index_users_on_reset_password_token (reset_password_token) UNIQUE +# +class User < ApplicationRecord + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :validatable + + has_many :deliveries, class_name: "Delivery", foreign_key: "user_id" + +end diff --git a/app/views/.DS_Store b/app/views/.DS_Store new file mode 100644 index 00000000..9a1d4b71 Binary files /dev/null and b/app/views/.DS_Store differ diff --git a/app/views/deliveries/index.html.erb b/app/views/deliveries/index.html.erb new file mode 100644 index 00000000..1464f040 --- /dev/null +++ b/app/views/deliveries/index.html.erb @@ -0,0 +1,85 @@ +
Know if something gets lost in the mail.
+