diff --git a/app/controllers/public/need_furbish_interests_controller.rb b/app/controllers/public/need_furbish_interests_controller.rb new file mode 100644 index 0000000..26aba86 --- /dev/null +++ b/app/controllers/public/need_furbish_interests_controller.rb @@ -0,0 +1,24 @@ +class Public::NeedFurbishInterestsController < ApplicationController + layout "public" + + before_filter :auth_customer + before_filter :check_enabled + + def new + @need = Need.find(params[:need_id]) + @need.need_furbish_interests.create(:customer_id => current_customer.id) + + redirect_to :back + end + + def destroy + + nfi = current_customer.need_furbish_interests.find(params[:id]) + nfi.destroy + + redirect_to :back + + + end + +end diff --git a/app/models/customer.rb b/app/models/customer.rb index 8bfb5dc..9d0b7fc 100755 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -11,7 +11,7 @@ class Customer < ActiveRecord::Base accepts_nested_attributes_for :particular_send - + has_many :need_furbish_interests has_many :thing_conversations, :as => :thing diff --git a/app/models/need.rb b/app/models/need.rb index b925c00..10ea27e 100755 --- a/app/models/need.rb +++ b/app/models/need.rb @@ -4,6 +4,8 @@ class Need < ActiveRecord::Base belongs_to :reseaux + has_many :need_furbish_interests + belongs_to :referent_technique, :class_name => "Customer" belongs_to :referent_negos, :class_name => "Customer" diff --git a/app/models/need_furbish_interest.rb b/app/models/need_furbish_interest.rb new file mode 100644 index 0000000..5110055 --- /dev/null +++ b/app/models/need_furbish_interest.rb @@ -0,0 +1,4 @@ +class NeedFurbishInterest < ActiveRecord::Base + belongs_to :need + belongs_to :customer +end diff --git a/app/views/public/needs/show.html.haml b/app/views/public/needs/show.html.haml index bc176ed..3ef90b8 100755 --- a/app/views/public/needs/show.html.haml +++ b/app/views/public/needs/show.html.haml @@ -130,6 +130,16 @@ =link_to i(:"check") + " Intéressé", edit_public_need_wish_path(@need, @wish) , :class => "btn btn-square btn-lg btn-success pull-right" -else =link_to i(:"hand-paper-o") + " Ça m'intéresse !", new_public_need_wish_path(@need) , :class => "btn btn-square btn-lg btn-primary pull-right" + %br + %br + %br + - @wish_furbish = @need.need_furbish_interests.where(customer_id: current_customer.id).first + -if @wish_furbish + =link_to i(:"check") + " Interessé en tant que fournisseur", public_need_furbish_interest_path(@wish_furbish) , :class => "btn btn-square btn-lg btn-success pull-right", :method => :delete + -else + =link_to i(:"hand-paper-o") + " Ça m'intéresse en tant que fournisseur !", new_public_need_furbish_interest_path(:need_id => @need.id) , :class => "btn btn-square btn-lg btn-primary pull-right" + + -elsif @need.negociating? -elsif @need.negociated? diff --git a/config/routes.rb b/config/routes.rb index e0599eb..73e243b 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -30,6 +30,9 @@ Rails.application.routes.draw do namespace :public do + resources :need_furbish_interests + + resources :payments do member do get :paid_by_ogone diff --git a/db/migrate/20180921093741_create_need_furbish_interests.rb b/db/migrate/20180921093741_create_need_furbish_interests.rb new file mode 100644 index 0000000..2b5a7f8 --- /dev/null +++ b/db/migrate/20180921093741_create_need_furbish_interests.rb @@ -0,0 +1,10 @@ +class CreateNeedFurbishInterests < ActiveRecord::Migration + def change + create_table :need_furbish_interests do |t| + t.references :need, index: true, foreign_key: true + t.references :customer, index: true, foreign_key: true + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 3c59b6a..2ef3b8d 100755 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180827155325) do +ActiveRecord::Schema.define(version: 20180921093741) do create_table "abonnements", force: :cascade do |t| t.integer "abonnement_type_id", limit: 4 @@ -554,6 +554,16 @@ ActiveRecord::Schema.define(version: 20180827155325) do add_index "need_categories", ["need_categories_id"], name: "index_need_categories_on_need_categories_id", using: :btree add_index "need_categories", ["parent_id"], name: "index_need_categories_on_parent_id", using: :btree + create_table "need_furbish_interests", force: :cascade do |t| + t.integer "need_id", limit: 4 + t.integer "customer_id", limit: 4 + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "need_furbish_interests", ["customer_id"], name: "index_need_furbish_interests_on_customer_id", using: :btree + add_index "need_furbish_interests", ["need_id"], name: "index_need_furbish_interests_on_need_id", using: :btree + create_table "needs", force: :cascade do |t| t.string "title", limit: 255 t.text "description", limit: 65535 @@ -1023,8 +1033,8 @@ ActiveRecord::Schema.define(version: 20180827155325) do t.string "name", limit: 255 t.text "description", limit: 65535 t.integer "chef_reseau_id", limit: 4 - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "token", limit: 255 t.integer "parent_id", limit: 4 t.integer "logo_image_file_id", limit: 4 @@ -1032,10 +1042,10 @@ ActiveRecord::Schema.define(version: 20180827155325) do t.string "title", limit: 255 t.string "baseline", limit: 255 t.string "sub_domain", limit: 255 - t.decimal "abo_price", precision: 10 - t.boolean "abo_needed", default: false - t.boolean "offres_enabled", default: false - t.boolean "needs_enabled", default: false + t.decimal "abo_price", precision: 10, scale: 2 + t.boolean "abo_needed", default: false + t.boolean "offres_enabled", default: false + t.boolean "needs_enabled", default: false end create_table "sessions", force: :cascade do |t| @@ -1143,6 +1153,8 @@ ActiveRecord::Schema.define(version: 20180827155325) do add_foreign_key "domain_need_categories", "need_categories" add_foreign_key "domain_needs", "domains" add_foreign_key "domain_needs", "needs" + add_foreign_key "need_furbish_interests", "customers" + add_foreign_key "need_furbish_interests", "needs" add_foreign_key "offer_reseauxes", "offers" add_foreign_key "offer_reseauxes", "reseauxes" add_foreign_key "product_category_langs", "product_categories" diff --git a/test/fixtures/need_furbish_interests.yml b/test/fixtures/need_furbish_interests.yml new file mode 100644 index 0000000..b09ddb4 --- /dev/null +++ b/test/fixtures/need_furbish_interests.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + need_id: + customer_id: + +two: + need_id: + customer_id: diff --git a/test/models/need_furbish_interest_test.rb b/test/models/need_furbish_interest_test.rb new file mode 100644 index 0000000..ac1ecf1 --- /dev/null +++ b/test/models/need_furbish_interest_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class NeedFurbishInterestTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end