diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb
index 1ea293a..af83806 100644
--- a/app/controllers/favorites_controller.rb
+++ b/app/controllers/favorites_controller.rb
@@ -35,7 +35,14 @@ class FavoritesController < ApplicationController
end
def projects
+ @favorite_projects = FavoriteProject.where('user_id': current_user.id)
+ .order(sort_column + " " + sort_direction)
+ @host = 'https://tiss.tuwien.ac.at'
+ end
+ def delete_project
+ FavoriteProject.find_by(id: params[:id]).destroy
+ redirect_back(fallback_location: projects)
end
private
diff --git a/app/models/favorite_project.rb b/app/models/favorite_project.rb
new file mode 100644
index 0000000..f7482c4
--- /dev/null
+++ b/app/models/favorite_project.rb
@@ -0,0 +1,5 @@
+class FavoriteProject < ApplicationRecord
+ self.primary_key = 'id'
+
+ validates :id, uniqueness: true
+end
diff --git a/app/views/favorites/projects.html.erb b/app/views/favorites/projects.html.erb
index 88f6087..61868b2 100644
--- a/app/views/favorites/projects.html.erb
+++ b/app/views/favorites/projects.html.erb
@@ -1,3 +1,34 @@
-<%= render(:partial => "nav")%>
+<%= render(:partial => "nav") %>
-
Fav Projects
\ No newline at end of file
+Favorite Projects
+
+<% if !@favorite_projects[0].blank? %>
+
+
+
+ | <%= sortable "Title", "title" %> |
+ <%= sortable "Registration Date", "created_at" %> |
+ |
+ |
+
+ <% for project in @favorite_projects %>
+
+ |
+ <%= project['title'] %>
+ |
+
+ <%= project['created_at'] %>
+ |
+
+ <%= button_to 'Details', crawlers_projects_crawler_show_detail_url(:id => project['id']) %>
+ |
+
+ <%= button_to 'Delete', {:action => "delete_project", :id => project['id']}, :method => 'delete' %>
+ |
+
+ <% end %>
+
+
+<% else %>
+ No favorite projects added yet!
+<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 9b741ff..5469c54 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -48,7 +48,7 @@ Rails.application.routes.draw do
get 'theses'
delete 'delete_thesis'
get 'projects'
- delete 'delete_projects'
+ delete 'delete_project'
end
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
diff --git a/db/migrate/20200529081537_create_favorite_projects.rb b/db/migrate/20200529081537_create_favorite_projects.rb
new file mode 100644
index 0000000..c5195f8
--- /dev/null
+++ b/db/migrate/20200529081537_create_favorite_projects.rb
@@ -0,0 +1,12 @@
+class CreateFavoriteProjects < ActiveRecord::Migration[6.0]
+ def change
+ create_table :favorite_projects, id: false do |t|
+ t.integer :id, null: false
+ t.integer :user_id, null: false
+ t.string :title
+
+ t.timestamps
+ end
+ add_index :favorite_projects, :id, unique: true
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index c1cc81e..846a44a 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2020_05_25_132942) do
+ActiveRecord::Schema.define(version: 2020_05_29_081537) do
create_table "favorite_courses", force: :cascade do |t|
t.string "number", null: false
@@ -33,6 +33,15 @@ ActiveRecord::Schema.define(version: 2020_05_25_132942) do
t.index ["tiss_id"], name: "index_favorite_people_on_tiss_id", unique: true
end
+ create_table "favorite_projects", id: false, force: :cascade do |t|
+ t.integer "id", null: false
+ t.integer "user_id", null: false
+ t.string "title"
+ t.datetime "created_at", precision: 6, null: false
+ t.datetime "updated_at", precision: 6, null: false
+ t.index ["id"], name: "index_favorite_projects_on_id", unique: true
+ end
+
create_table "favorite_theses", id: false, force: :cascade do |t|
t.integer "id", null: false
t.integer "user_id", null: false
diff --git a/test/fixtures/favorite_projects.yml b/test/fixtures/favorite_projects.yml
new file mode 100644
index 0000000..5181636
--- /dev/null
+++ b/test/fixtures/favorite_projects.yml
@@ -0,0 +1,11 @@
+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+# This model initially had no columns defined. If you add columns to the
+# model remove the '{}' from the fixture names and add the columns immediately
+# below each fixture, per the syntax in the comments below
+#
+one: {}
+# column: value
+#
+two: {}
+# column: value
diff --git a/test/models/favorite_project_test.rb b/test/models/favorite_project_test.rb
new file mode 100644
index 0000000..953fa61
--- /dev/null
+++ b/test/models/favorite_project_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class FavoriteProjectTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end