diff --git a/Gemfile b/Gemfile index 211a4a7..93e3b88 100644 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,6 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '2.7.0' -# gem 'nokogiri', require: false - # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '6.0.2.1' # Use sqlite3 as the database for Active Record @@ -39,6 +37,9 @@ gem 'devise-encryptable', '0.2.0' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.4.2', require: false +# for composite primary keys +gem 'composite_primary_keys' + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index 17ac9f4..3f376de 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -73,6 +73,8 @@ GEM regexp_parser (~> 1.5) xpath (~> 3.2) childprocess (3.0.0) + composite_primary_keys (12.0.2) + activerecord (~> 6.0.0) concurrent-ruby (1.1.6) crass (1.0.6) devise (4.7.1) @@ -84,7 +86,7 @@ GEM devise-encryptable (0.2.0) devise (>= 2.1.0) erubi (1.9.0) - ffi (1.12.2) + ffi (1.12.2-x64-mingw32) globalid (0.4.2) activesupport (>= 4.2.0) httparty (0.18.0) @@ -105,11 +107,11 @@ GEM mime-types (3.3.1) mime-types-data (~> 3.2015) mime-types-data (3.2019.1009) - mimemagic (0.3.4) + mimemagic (0.3.5) mini_mime (1.0.2) mini_portile2 (2.4.0) minitest (5.14.0) - msgpack (1.3.3) + msgpack (1.3.3-x64-mingw32) multi_xml (0.6.0) nio4r (2.5.2) nokogiri (1.10.9) @@ -157,7 +159,7 @@ GEM rubyzip (2.3.0) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) - sassc (2.2.1) + sassc (2.2.1-x64-mingw32) ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0) @@ -184,6 +186,8 @@ GEM turbolinks-source (5.2.0) tzinfo (1.2.7) thread_safe (~> 0.1) + tzinfo-data (1.2019.3) + tzinfo (>= 1.0.0) warden (1.2.8) rack (>= 2.0.6) web-console (4.0.1) @@ -199,20 +203,21 @@ GEM activesupport (>= 4.2) rack-proxy (>= 0.6.1) railties (>= 4.2) - websocket-driver (0.7.1) + websocket-driver (0.7.2) websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.4) + websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) zeitwerk (2.3.0) PLATFORMS - ruby + x64-mingw32 DEPENDENCIES bootsnap (>= 1.4.2) byebug capybara (>= 2.15) + composite_primary_keys devise (= 4.7.1) devise-encryptable (= 0.2.0) httparty (= 0.18.0) @@ -232,4 +237,4 @@ RUBY VERSION ruby 2.7.0p0 BUNDLED WITH - 2.1.2 + 2.1.4 diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index b8595d5..cd97425 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -118,4 +118,19 @@ input[type=text], input[type=url], input[type=email], input[type=password], inpu line-height: 25px; font-size: 16px; border: 1px solid #bbb; +} + +input { + background-color: white; + border: solid #3F51B5; + border-width: 1px; + color: #3F51B5; + padding: 3px 3px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 16px; + margin-right: 0.1em; + font-weight: bolder; + border-radius: 4px; } \ No newline at end of file diff --git a/app/assets/stylesheets/favorites.scss b/app/assets/stylesheets/favorites.scss index a780c04..2197538 100644 --- a/app/assets/stylesheets/favorites.scss +++ b/app/assets/stylesheets/favorites.scss @@ -40,7 +40,10 @@ display: flex; :nth-child(2) { - color: darkred; + -webkit-text-fill-color: #ffffff; + background-color: #ff1919; + border-radius: 4px; + border-color: #ff1919; } } diff --git a/app/assets/stylesheets/print.css b/app/assets/stylesheets/print.css new file mode 100644 index 0000000..7fada74 --- /dev/null +++ b/app/assets/stylesheets/print.css @@ -0,0 +1,17 @@ +@media print { + nav, input, button, .favNav { + display: none; + } + + @page { + size: A4; + } + + body { + counter-reset: chapternum figurenum; + font-family: "Trebuchet MS", "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Tahoma, sans-serif; + line-height: 1.5; + font-size: 11pt; + } +} + diff --git a/app/assets/stylesheets/tiss_crawler.scss b/app/assets/stylesheets/tiss_crawler.scss index 00b82ff..dfc467c 100644 --- a/app/assets/stylesheets/tiss_crawler.scss +++ b/app/assets/stylesheets/tiss_crawler.scss @@ -1,3 +1,8 @@ // Place all the styles related to the tiss_crawler controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: https://sass-lang.com/ + +.annotationField { + width: 99.5%; + height: 8em; +} \ No newline at end of file diff --git a/app/controllers/crawlers/courses_crawler_controller.rb b/app/controllers/crawlers/courses_crawler_controller.rb index dc41553..e000079 100644 --- a/app/controllers/crawlers/courses_crawler_controller.rb +++ b/app/controllers/crawlers/courses_crawler_controller.rb @@ -26,6 +26,8 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController params[:semester] = regex[:semester] end + @personal_annotation = get_stored_annotation FavoriteCourse, {number: params[:number]} + puts params # TissCrawler fetches the course's detail information @@ -82,4 +84,8 @@ class Crawlers::CoursesCrawlerController < Crawlers::TissCrawlerController redirect_back(fallback_location: search) end + def add_annotation + store_annotation FavoriteCourse, 'Course', {number: params[:id]} + end + end diff --git a/app/controllers/crawlers/people_crawler_controller.rb b/app/controllers/crawlers/people_crawler_controller.rb index ffb605d..beed2ee 100644 --- a/app/controllers/crawlers/people_crawler_controller.rb +++ b/app/controllers/crawlers/people_crawler_controller.rb @@ -22,6 +22,8 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController params[:api] = '/api/person/v22/id/' params[:tiss_id] = params[:tiss_id] + @personal_annotation = get_stored_annotation FavoritePerson, {tiss_id: params[:tiss_id]} + puts params # TissCrawler fetches the person's detail information @person = TissCrawler.get_details(params) @@ -35,12 +37,12 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController @person = TissCrawler.get_details(params) # create stores the object to the db after creation - favorite_hash = { tiss_id: @person['tiss_id'], - # the user who is currently active - user_id: current_user.id, - first_name: @person['first_name'], - last_name: @person['last_name'], - picture_uri: @person['picture_uri'] } + favorite_hash = {tiss_id: @person['tiss_id'], + # the user who is currently active + user_id: current_user.id, + first_name: @person['first_name'], + last_name: @person['last_name'], + picture_uri: @person['picture_uri']} if FavoritePerson.create(favorite_hash).valid? FavoritePerson.create(favorite_hash) flash[:alert] = 'Person added to your favorites!' @@ -50,4 +52,8 @@ class Crawlers::PeopleCrawlerController < Crawlers::TissCrawlerController redirect_back(fallback_location: crawlers_tiss_crawler_search_path) end + def add_annotation + store_annotation FavoritePerson, 'Person', {tiss_id: params[:id]} + end + end diff --git a/app/controllers/crawlers/projects_crawler_controller.rb b/app/controllers/crawlers/projects_crawler_controller.rb index 605efe2..c25cb31 100644 --- a/app/controllers/crawlers/projects_crawler_controller.rb +++ b/app/controllers/crawlers/projects_crawler_controller.rb @@ -21,6 +21,8 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController @id = params[:id] + @personal_annotation = get_stored_annotation FavoriteProject, {id: @id} + puts params # TissCrawler fetches the project's detail information @project = TissCrawler.get_project_details(params) @@ -34,9 +36,9 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController @project = TissCrawler.get_project_details(params) # create stores the object to the db after creation - favorite_hash = {id: params[:id], + favorite_hash = {id: [params[:id], current_user.id], # the user who is currently active - user_id: current_user.id, + # user_id: current_user.id, title: @project['titleDe']} if FavoriteProject.create(favorite_hash).valid? FavoriteProject.create(favorite_hash) @@ -46,4 +48,8 @@ class Crawlers::ProjectsCrawlerController < Crawlers::TissCrawlerController end redirect_back(fallback_location: search) end + + def add_annotation + store_annotation FavoriteProject, 'Project', {id: params[:id]} + end end diff --git a/app/controllers/crawlers/theses_crawler_controller.rb b/app/controllers/crawlers/theses_crawler_controller.rb index 711b1a0..97c8e65 100644 --- a/app/controllers/crawlers/theses_crawler_controller.rb +++ b/app/controllers/crawlers/theses_crawler_controller.rb @@ -21,6 +21,8 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController @id = params[:id] + @personal_annotation = get_stored_annotation FavoriteThesis, {id: @id} + puts params # TissCrawler fetches the thesis' detail information @thesis = TissCrawler.get_thesis_details(params) @@ -34,9 +36,9 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController @thesis = TissCrawler.get_thesis_details(params) # create stores the object to the db after creation - favorite_hash = {id: params[:id], + favorite_hash = {id: [params[:id], current_user.id], # the user who is currently active - user_id: current_user.id, + # user_id: current_user.id, title: @thesis['title']['de']} if FavoriteThesis.create(favorite_hash).valid? FavoriteThesis.create(favorite_hash) @@ -46,4 +48,8 @@ class Crawlers::ThesesCrawlerController < Crawlers::TissCrawlerController end redirect_back(fallback_location: search) end + + def add_annotation + store_annotation FavoriteThesis, 'Thesis', {id: params[:id]} + end end diff --git a/app/controllers/crawlers/tiss_crawler_controller.rb b/app/controllers/crawlers/tiss_crawler_controller.rb index aae78e3..0a9a39d 100644 --- a/app/controllers/crawlers/tiss_crawler_controller.rb +++ b/app/controllers/crawlers/tiss_crawler_controller.rb @@ -34,4 +34,31 @@ class Crawlers::TissCrawlerController < ApplicationController def add_to_fav end + def add_annotation + + end + + private + def get_stored_annotation(object, id_hash) + id_hash['user_id'] = current_user + if object.exists?(id_hash) + object.where(id_hash)[0]['personal_annotation'] + else + "" + end + end + + def store_annotation(object, object_name, id_hash) + id_hash['user_id'] = current_user + + # Allow storing empty strings as a way of "clearing" the stored val + if object.exists?(id_hash) + object.where(id_hash)[0].update(:personal_annotation => params[:body]) + flash[:alert] = 'Annotation stored!' + else + flash[:alert] = object_name + ' has to be favorited first!' + end + redirect_back(fallback_location: crawlers_tiss_crawler_search_path) + end + end diff --git a/app/helpers/crawlers/tiss_crawler_helper.rb b/app/helpers/crawlers/tiss_crawler_helper.rb index b730a09..ec3bcc2 100644 --- a/app/helpers/crawlers/tiss_crawler_helper.rb +++ b/app/helpers/crawlers/tiss_crawler_helper.rb @@ -1,2 +1,9 @@ module Crawlers::TissCrawlerHelper + def render_personal_annotations(id, personal_annotation) + render :partial => "crawlers/personal_annotations", + :locals => { + :cur_id => id, + :personal_annotation => personal_annotation + } + end end diff --git a/app/models/favorite_course.rb b/app/models/favorite_course.rb index 60d0d1f..7bac3e6 100644 --- a/app/models/favorite_course.rb +++ b/app/models/favorite_course.rb @@ -1,4 +1,6 @@ class FavoriteCourse < ApplicationRecord + self.primary_keys = :id, :user_id + validates :title, :semester, :number, presence: true - validates :semester, :number, uniqueness: {scope: [:semester, :number]} + validates :semester, :number, uniqueness: {scope: [:semester, :number, :user_id]} end diff --git a/app/models/favorite_person.rb b/app/models/favorite_person.rb index 9d1e8b8..e5d4186 100644 --- a/app/models/favorite_person.rb +++ b/app/models/favorite_person.rb @@ -1,5 +1,5 @@ class FavoritePerson < ApplicationRecord - self.primary_key = 'tiss_id' + self.primary_keys = :tiss_id, :user_id - validates :tiss_id, uniqueness: true + validates :tiss_id, uniqueness: { scope: [:user_id] } end diff --git a/app/models/favorite_project.rb b/app/models/favorite_project.rb index f7482c4..ca4e37e 100644 --- a/app/models/favorite_project.rb +++ b/app/models/favorite_project.rb @@ -1,5 +1,5 @@ class FavoriteProject < ApplicationRecord - self.primary_key = 'id' + self.primary_keys = :id, :user_id - validates :id, uniqueness: true + validates :id, :user_id, uniqueness: {scope: [:id, :user_id]} end diff --git a/app/models/favorite_thesis.rb b/app/models/favorite_thesis.rb index f1618f9..23f5238 100644 --- a/app/models/favorite_thesis.rb +++ b/app/models/favorite_thesis.rb @@ -1,5 +1,5 @@ class FavoriteThesis < ApplicationRecord - self.primary_key = 'id' + self.primary_keys = :id, :user_id - validates :id, uniqueness: true + validates :id, :user_id, uniqueness: {scope: [:id, :user_id]} end diff --git a/app/views/crawlers/_personal_annotations.html.erb b/app/views/crawlers/_personal_annotations.html.erb new file mode 100644 index 0000000..d28329b --- /dev/null +++ b/app/views/crawlers/_personal_annotations.html.erb @@ -0,0 +1,13 @@ +<%= form_tag "add_annotation", :id => "id" do -%> + <%= hidden_field_tag :authenticity_token, form_authenticity_token %> +

+ Add an annotation: +

+

+ <%= text_area_tag 'body', personal_annotation, class: 'annotationField' %> + <%= hidden_field_tag :id , cur_id %> +

+

+ <%= submit_tag "Save annotation" %> +

+<% end -%> \ No newline at end of file diff --git a/app/views/crawlers/courses_crawler/show_detail.html.erb b/app/views/crawlers/courses_crawler/show_detail.html.erb index 23c85ba..d8ad360 100644 --- a/app/views/crawlers/courses_crawler/show_detail.html.erb +++ b/app/views/crawlers/courses_crawler/show_detail.html.erb @@ -1,6 +1,8 @@ <% if @course != nil %> <%-# TODO parse more fields and style them appropriately -%> -

<%= @course['title']['de'] %>

+

Course: <%= @course['title']['de'] %>

+ <%= button_to "PRINT", '#', onclick: "print()" %> +
<%= @course['courseType'] %> <%= @course['semesterCode'] %>, <%= @course['weeklyHours'] %> SWS, <%= @course['instituteCode'] %> <%= @course['instituteName']['de'] %>
<%= button_to 'Add to favorites', action: :add_to_fav, number: @course['courseNumber'], semester: @course['semesterCode'] %> <% if @lecturers_names != nil %> @@ -13,4 +15,6 @@

Inhalt

<%= raw @course['objective']['de'] %> <% end %> + + <%= render_personal_annotations @course['courseNumber'], @personal_annotation %> <% end %> diff --git a/app/views/crawlers/people_crawler/show_detail.html.erb b/app/views/crawlers/people_crawler/show_detail.html.erb index ce54c90..6767af0 100644 --- a/app/views/crawlers/people_crawler/show_detail.html.erb +++ b/app/views/crawlers/people_crawler/show_detail.html.erb @@ -1,5 +1,7 @@ <% if @person != nil %> -

<%= @person['first_name'] %> <%= @person['last_name'] %>

+

Person: <%= @person['first_name'] %> <%= @person['last_name'] %>

+ <%= button_to "PRINT", '#', onclick: "print()" %> +
<% if @person['picture_uri'] != nil %> <%= image_tag @host + @person['picture_uri'] %> @@ -14,8 +16,12 @@

Other E-Mails: <%= @person['other_emails'] %>

<% end %> <% if @person['main_addresses'] != nil %> -

Address: <%= @person['main_addresses'][0]['street'] %>, <%= @person['main_addresses'][0]['zip_code'] %> <%= @person['main_addresses'][0]['city'] %>

+

Address: <%= @person['main_addresses'][0]['street'] %> + , <%= @person['main_addresses'][0]['zip_code'] %> <%= @person['main_addresses'][0]['city'] %>

<% end %> - - <%= button_to 'Add to favorites', action: :add_to_fav, tiss_id: @person['tiss_id'] %> + + <%= button_to 'Add to favorites', action: :add_to_fav, tiss_id: @person['tiss_id'], class: 'button' %> + + <%= render_personal_annotations @person['tiss_id'], @personal_annotation %> + <% end %> \ No newline at end of file diff --git a/app/views/crawlers/projects_crawler/show_detail.html.erb b/app/views/crawlers/projects_crawler/show_detail.html.erb index 7321c2c..92be9e7 100644 --- a/app/views/crawlers/projects_crawler/show_detail.html.erb +++ b/app/views/crawlers/projects_crawler/show_detail.html.erb @@ -1,5 +1,7 @@ <% if @project != nil %> -

<%= @project['titleDe'] %>

+

Project: <%= @project['titleDe'] %>

+ <%= button_to "PRINT", '#', onclick: "print()" %> +
<%= @project['contractBegin'] %> - <%= @project['contractEnd'] %>
<%= button_to 'Add to favorites', action: :add_to_fav, id: @id, title: @project['titleDe'] %> <% if @project['abstractDe'] != nil %> @@ -11,4 +13,7 @@

<%= raw @project['abstractEn'] %>

<% end %> <% end %> + + <%= render_personal_annotations @id, @personal_annotation %> + <% end %> diff --git a/app/views/crawlers/theses_crawler/show_detail.html.erb b/app/views/crawlers/theses_crawler/show_detail.html.erb index 24f1a83..54cc904 100644 --- a/app/views/crawlers/theses_crawler/show_detail.html.erb +++ b/app/views/crawlers/theses_crawler/show_detail.html.erb @@ -1,5 +1,7 @@ <% if @thesis != nil %> -

<%= @thesis['title']['de'] %>

+

Thesis: <%= @thesis['title']['de'] %>

+ <%= button_to "PRINT", '#', onclick: "print()" %> +
<%= @thesis['thesisType'] %>, <%= @thesis['instituteCode'] %> <%= @thesis['instituteName']['de'] %>
<%= button_to 'Add to favorites', action: :add_to_fav, id: @id, title: @thesis['title']['de'] %> <% if @thesis['advisor'] != nil %> @@ -10,4 +12,6 @@

Assistant

<%= @thesis['assistant']['familyName'] %> <%= @thesis['assistant']['givenName'] %>

<% end %> + + <%= render_personal_annotations @id, @personal_annotation %> <% end %> diff --git a/app/views/favorites/_nav.html.erb b/app/views/favorites/_nav.html.erb index 00728b8..4a9c8e7 100644 --- a/app/views/favorites/_nav.html.erb +++ b/app/views/favorites/_nav.html.erb @@ -3,4 +3,6 @@ <%= link_to 'Courses', favorites_courses_url %> <%= link_to 'Theses', favorites_theses_url %> <%= link_to 'Projects', favorites_projects_url %> -
\ No newline at end of file + + <%= link_to "PRINT", '#', onclick: "print()" %> + diff --git a/app/views/favorites/people.html.erb b/app/views/favorites/people.html.erb index b8d9782..7fcd78d 100644 --- a/app/views/favorites/people.html.erb +++ b/app/views/favorites/people.html.erb @@ -43,6 +43,7 @@ + <% end %> diff --git a/app/views/favorites/projects.html.erb b/app/views/favorites/projects.html.erb index 0af93e5..d458f9a 100644 --- a/app/views/favorites/projects.html.erb +++ b/app/views/favorites/projects.html.erb @@ -25,6 +25,7 @@ <%= button_to 'Delete', {:action => "delete_project", :id => project['id']}, :method => 'delete' %> + <% end %> diff --git a/app/views/favorites/theses.html.erb b/app/views/favorites/theses.html.erb index 4d2deac..bc14c31 100644 --- a/app/views/favorites/theses.html.erb +++ b/app/views/favorites/theses.html.erb @@ -26,6 +26,7 @@ <%= button_to 'Delete', {:action => "delete_thesis", :id => thesis['id']}, :method => 'delete' %> + <% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e48e0f0..37c8872 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,7 +5,9 @@ <%= csrf_meta_tags %> <%= csp_meta_tag %> + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= stylesheet_link_tag 'print', media: 'print' %> <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> @@ -43,4 +45,5 @@ + diff --git a/config/routes.rb b/config/routes.rb index 5469c54..8f7d967 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,6 +13,7 @@ Rails.application.routes.draw do post 'show_detail' get 'add_to_fav' post 'add_to_fav' + post 'add_annotation' end namespace :courses_crawler do @@ -21,6 +22,7 @@ Rails.application.routes.draw do post 'show_detail' get 'add_to_fav' post 'add_to_fav' + post 'add_annotation' end namespace :theses_crawler do @@ -29,6 +31,7 @@ Rails.application.routes.draw do post 'show_detail' get 'add_to_fav' post 'add_to_fav' + post 'add_annotation' end namespace :projects_crawler do @@ -37,6 +40,7 @@ Rails.application.routes.draw do post 'show_detail' get 'add_to_fav' post 'add_to_fav' + post 'add_annotation' end end diff --git a/db/migrate/20200421152314_create_favorite_people.rb b/db/migrate/20200421152314_create_favorite_people.rb index d1a00b0..e412e40 100644 --- a/db/migrate/20200421152314_create_favorite_people.rb +++ b/db/migrate/20200421152314_create_favorite_people.rb @@ -1,14 +1,13 @@ class CreateFavoritePeople < ActiveRecord::Migration[6.0] def change - create_table :favorite_people, id: false do |t| + create_table :favorite_people, primary_key: [:tiss_id, :user_id] do |t| t.integer :tiss_id, null: false - t.integer :user_id, null: false + t.belongs_to :user t.string :first_name t.string :last_name t.string :picture_uri - + t.string :personal_annotation t.timestamps end - add_index :favorite_people, :tiss_id, unique: true end end diff --git a/db/migrate/20200521091231_create_favorite_courses.rb b/db/migrate/20200521091231_create_favorite_courses.rb index 4937ab0..45b675e 100644 --- a/db/migrate/20200521091231_create_favorite_courses.rb +++ b/db/migrate/20200521091231_create_favorite_courses.rb @@ -1,13 +1,14 @@ class CreateFavoriteCourses < ActiveRecord::Migration[6.0] def change - create_table :favorite_courses do |t| + create_table :favorite_courses , primary_key: [:id, :user_id] do |t| + t.integer :id + t.belongs_to :user t.string :number, null: false t.string :semester, null: false t.string :title, null: false - t.integer :user_id, null: false + t.string :personal_annotation t.timestamps end - add_index :favorite_courses, [:number, :semester], unique: true end end diff --git a/db/migrate/20200525132942_create_favorite_theses.rb b/db/migrate/20200525132942_create_favorite_theses.rb index 64c63db..4292946 100644 --- a/db/migrate/20200525132942_create_favorite_theses.rb +++ b/db/migrate/20200525132942_create_favorite_theses.rb @@ -1,12 +1,12 @@ class CreateFavoriteTheses < ActiveRecord::Migration[6.0] def change - create_table :favorite_theses, id: false do |t| + create_table :favorite_theses, primary_key: [:id, :user_id] do |t| t.integer :id, null: false - t.integer :user_id, null: false + t.belongs_to :user t.string :title + t.string :personal_annotation t.timestamps end - add_index :favorite_theses, :id, unique: true end end diff --git a/db/migrate/20200529081537_create_favorite_projects.rb b/db/migrate/20200529081537_create_favorite_projects.rb index c5195f8..90dc787 100644 --- a/db/migrate/20200529081537_create_favorite_projects.rb +++ b/db/migrate/20200529081537_create_favorite_projects.rb @@ -1,12 +1,12 @@ class CreateFavoriteProjects < ActiveRecord::Migration[6.0] def change - create_table :favorite_projects, id: false do |t| + create_table :favorite_projects, primary_key: [:id, :user_id] do |t| t.integer :id, null: false - t.integer :user_id, null: false + t.belongs_to :user t.string :title + t.string :personal_annotation t.timestamps end - add_index :favorite_projects, :id, unique: true end end diff --git a/db/schema.rb b/db/schema.rb index 846a44a..88fe6f3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,43 +12,48 @@ ActiveRecord::Schema.define(version: 2020_05_29_081537) do - create_table "favorite_courses", force: :cascade do |t| + create_table "favorite_courses", primary_key: ["id", "user_id"], force: :cascade do |t| + t.integer "id" + t.integer "user_id" t.string "number", null: false t.string "semester", null: false t.string "title", null: false - t.integer "user_id", null: false + t.string "personal_annotation" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false - t.index ["number", "semester"], name: "index_favorite_courses_on_number_and_semester", unique: true + t.index ["user_id"], name: "index_favorite_courses_on_user_id" end - create_table "favorite_people", id: false, force: :cascade do |t| + create_table "favorite_people", primary_key: ["tiss_id", "user_id"], force: :cascade do |t| t.integer "tiss_id", null: false - t.integer "user_id", null: false + t.integer "user_id" t.string "first_name" t.string "last_name" t.string "picture_uri" + t.string "personal_annotation" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false - t.index ["tiss_id"], name: "index_favorite_people_on_tiss_id", unique: true + t.index ["user_id"], name: "index_favorite_people_on_user_id" end - create_table "favorite_projects", id: false, force: :cascade do |t| + create_table "favorite_projects", primary_key: ["id", "user_id"], force: :cascade do |t| t.integer "id", null: false - t.integer "user_id", null: false + t.integer "user_id" t.string "title" + t.string "personal_annotation" 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 + t.index ["user_id"], name: "index_favorite_projects_on_user_id" end - create_table "favorite_theses", id: false, force: :cascade do |t| + create_table "favorite_theses", primary_key: ["id", "user_id"], force: :cascade do |t| t.integer "id", null: false - t.integer "user_id", null: false + t.integer "user_id" t.string "title" + t.string "personal_annotation" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false - t.index ["id"], name: "index_favorite_theses_on_id", unique: true + t.index ["user_id"], name: "index_favorite_theses_on_user_id" end create_table "users", force: :cascade do |t|