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 @@ +
+
+

+ Delivery Tracker +

+

Know if something gets lost in the mail.

+
+
+ +
+ +
+
+

+ Expecting a package? +

+ +
+
+ + + +
+ +
+ + + +
+ +
+ + + +
+ + +
+
+
+ +
+
+
+

+ Waiting on +

+ +
+ +
+

+ Received +

+ +
+
+ +
diff --git a/app/views/deliveries/show.html.erb b/app/views/deliveries/show.html.erb new file mode 100644 index 00000000..c178c241 --- /dev/null +++ b/app/views/deliveries/show.html.erb @@ -0,0 +1,131 @@ +
+
+

+ elivery #<%= @the_delivery.id %> details +

+ +
+
+ + Go back + +
+ +
+ + Delete delivery + +
+
+ +
+
+ Description +
+
+ <%= @the_delivery.description %> +
+ +
+ Supposed to arrive +
+
+ <%= @the_delivery.supposed_to_arrive %> +
+ +
+ Actual arrive +
+
+ <%= @the_delivery.actual_arrive %> +
+ +
+ Details +
+
+ <%= @the_delivery.details %> +
+ +
+ User +
+
+ <%= @the_delivery.user_id %> +
+ +
+ Created at +
+
+ <%= time_ago_in_words(@the_delivery.created_at) %> ago +
+ +
+ Updated at +
+
+ <%= time_ago_in_words(@the_delivery.updated_at) %> ago +
+
+
+
+ +
+ + +
+
+

+ Edit delivery +

+ +
+
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ + +
+
+
+ +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index cbc2f44f..80afa0dc 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -9,8 +9,23 @@ <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> <%= javascript_importmap_tags %> - + +
+ <%if current_user == nil%> + Sign up | + Sign in + <%else%> + Delivery Tracker | + Edit profile | + Sign out + <%end%> +
+ +
+ + <%= notice%> + <%= alert%> <%= yield %> diff --git a/config/routes.rb b/config/routes.rb index 262ffd54..15d3fb42 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,31 @@ Rails.application.routes.draw do + devise_for :users + root "deliveries#index" + + # Routes for the deliverie resource: + get("/", { :controller => "deliveries", :action => "index" }) + + # CREATE + post("/insert_deliveries", { :controller => "deliveries", :action => "create" }) + + # READ + get("/deliveries", { :controller => "deliveries", :action => "index" }) + + get("/deliveries/:path_id", { :controller => "deliveries", :action => "show" }) + + # UPDATE + + post("/modify_delivery/:path_id", { :controller => "deliveries", :action => "update" }) + get("/mark_received/:path_id", { :controller => "deliveries", :action => "mark_as_received" }) + + # DELETE + get("/delete_delivery/:path_id", { :controller => "deliveries", :action => "destroy" }) + + #------------------------------ + # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html # Defines the root path route ("/") # root "articles#index" + end diff --git a/db/development.sqlite3 b/db/development.sqlite3 index 664ceb10..31acb9f0 100644 Binary files a/db/development.sqlite3 and b/db/development.sqlite3 differ diff --git a/db/migrate/20240622012201_create_deliveries.rb b/db/migrate/20240622012201_create_deliveries.rb new file mode 100644 index 00000000..8a89847e --- /dev/null +++ b/db/migrate/20240622012201_create_deliveries.rb @@ -0,0 +1,13 @@ +class CreateDeliveries < ActiveRecord::Migration[7.0] + def change + create_table :deliveries do |t| + t.string :description + t.date :supposed_to_arrive + t.date :actual_arrive + t.text :details + t.integer :user_id + + t.timestamps + end + end +end diff --git a/db/migrate/20240622012528_devise_create_users.rb b/db/migrate/20240622012528_devise_create_users.rb new file mode 100644 index 00000000..43927dbd --- /dev/null +++ b/db/migrate/20240622012528_devise_create_users.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +class DeviseCreateUsers < ActiveRecord::Migration[7.0] + def change + create_table :users do |t| + ## Database authenticatable + t.string :email, null: false, default: "" + t.string :encrypted_password, null: false, default: "" + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + # t.integer :sign_in_count, default: 0, null: false + # t.datetime :current_sign_in_at + # t.datetime :last_sign_in_at + # t.string :current_sign_in_ip + # t.string :last_sign_in_ip + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts + # t.string :unlock_token # Only if unlock strategy is :email or :both + # t.datetime :locked_at + + + t.timestamps null: false + end + + add_index :users, :email, unique: true + add_index :users, :reset_password_token, unique: true + # add_index :users, :confirmation_token, unique: true + # add_index :users, :unlock_token, unique: true + end +end diff --git a/db/migrate/20240623154546_delivery_change_column_type.rb b/db/migrate/20240623154546_delivery_change_column_type.rb new file mode 100644 index 00000000..20844382 --- /dev/null +++ b/db/migrate/20240623154546_delivery_change_column_type.rb @@ -0,0 +1,5 @@ +class DeliveryChangeColumnType < ActiveRecord::Migration[7.0] + def change + change_column(:deliveries, :actual_arrive, :boolean) + end +end diff --git a/db/schema.rb b/db/schema.rb index a3b04951..1569bfaa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,5 +10,31 @@ # # It's strongly recommended that you check this file into your version control system. +<<<<<<< HEAD +ActiveRecord::Schema[7.0].define(version: 2024_06_23_154546) do + create_table "deliveries", force: :cascade do |t| + t.string "description" + t.date "supposed_to_arrive" + t.boolean "actual_arrive" + t.text "details" + t.integer "user_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "users", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["email"], name: "index_users_on_email", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + end + +======= ActiveRecord::Schema[7.0].define(version: 0) do +>>>>>>> parent of 9579cb6 (Generated package) end diff --git a/db/test.sqlite3 b/db/test.sqlite3 index 0fb86e47..66d6db53 100644 Binary files a/db/test.sqlite3 and b/db/test.sqlite3 differ diff --git a/index.html b/index.html new file mode 100644 index 00000000..54061c9f --- /dev/null +++ b/index.html @@ -0,0 +1,65 @@ + + + + + Maya Sheriff + + + + + + + + +
+

Welcome to my page. Take a look at my projects!

+
+ +
+ + linkedin + + + + github + + + + dev + +
+ + + diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index d7c8d4f3..75f84e1b 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -16,12 +16,12 @@ task({ :sample_data => :environment}) do delivery.user_id = user.id delivery.description = Faker::Commerce.product_name delivery.details = "#{["FedEx", "UPS", "USPS"].sample} tracking ##{rand(1000000000000)}" if rand < 0.5 - delivery.supposed_to_arrive_on = Faker::Date.between(from: 1.month.ago, to: 2.weeks.from_now) + delivery.supposed_to_arrive = Faker::Date.between(from: 1.month.ago, to: 2.weeks.from_now) - if delivery.supposed_to_arrive_on < Time.now - delivery.arrived = [true, false].sample + if delivery.supposed_to_arrive < Time.now + delivery.actual_arrive = [true, false].sample else - delivery.arrived = false + delivery.actual_arrive = false end delivery.save diff --git a/render.yaml b/render.yaml new file mode 100644 index 00000000..50fad049 --- /dev/null +++ b/render.yaml @@ -0,0 +1,7 @@ +services: + - type: web + name: deliverytracker # the name of this service, eg hello-world + env: ruby # this app is written in ruby + plan: free # make sure to set this to free or you'll get billed $$$ + buildCommand: "./bin/render-build.sh" # we already created these two files for you + startCommand: "./bin/render-start.sh"