diff --git a/db/migrations/0004_add_license_comments_table.rb b/db/migrations/0004_add_license_comments_table.rb new file mode 100644 index 0000000..32e6687 --- /dev/null +++ b/db/migrations/0004_add_license_comments_table.rb @@ -0,0 +1,20 @@ +Sequel.migration do + + up do + create_table(:license_comments) do + primary_key :id + String :body, null: false + DateTime :created_at + DateTime :updated_at + end + + alter_table(:license_comments) do + add_foreign_key :license_id, :items + end + end + + down do + drop_table(:license_comments) + end + +end diff --git a/lib/models/license.rb b/lib/models/license.rb index 35cbd16..5f959fa 100644 --- a/lib/models/license.rb +++ b/lib/models/license.rb @@ -1,5 +1,5 @@ class License < Sequel::Model - + one_to_many :license_comments end diff --git a/lib/models/license_comment.rb b/lib/models/license_comment.rb new file mode 100644 index 0000000..1873421 --- /dev/null +++ b/lib/models/license_comment.rb @@ -0,0 +1,5 @@ +class LicenseComment < Sequel::Model + + many_to_one :licenses + +end diff --git a/lib/routes.rb b/lib/routes.rb index 974e816..e402b1c 100644 --- a/lib/routes.rb +++ b/lib/routes.rb @@ -92,3 +92,12 @@ get '/license/:license_id' do :license => license } end + +post '/license/:license_id/comment' do + license = License.first(id: params[:license_id]) + + comment = LicenseComment.create(body: params[:comment_body]) + license.add_license_comment(comment) + + redirect "/license/#{license.id}" +end diff --git a/raven.rb b/raven.rb index c39306a..d62ab7b 100644 --- a/raven.rb +++ b/raven.rb @@ -24,6 +24,7 @@ DB = Sequel.connect(adapter: conf.get('database.adapter'), database: conf.get('d require_relative 'lib/models/item.rb' require_relative 'lib/models/item_comment.rb' require_relative 'lib/models/license.rb' +require_relative 'lib/models/license_comment.rb' # Load helper functions require_relative 'lib/helpers.rb' diff --git a/views/item/list.erb b/views/item/list.erb index 1bb7839..7d4a7c0 100644 --- a/views/item/list.erb +++ b/views/item/list.erb @@ -11,7 +11,7 @@ <% if items.length > 0 %> <% else %> diff --git a/views/license/view.erb b/views/license/view.erb index 86b2e7b..deab559 100644 --- a/views/license/view.erb +++ b/views/license/view.erb @@ -34,3 +34,28 @@ + +
+
+ <% if license.license_comments.length > 0 %> + + <% else %> +

There are no comments to display at this time.

+ <% end %> +
+
+ +
+
+
+ + + + +
+
+