diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile
new file mode 100644
index 000000000..bea40f0e4
--- /dev/null
+++ b/.gitpod.Dockerfile
@@ -0,0 +1,10 @@
+FROM gitpod/workspace-full
+
+USER gitpod
+
+# Install custom tools, runtime, etc. using apt-get
+# For example, the command below would install "bastet" - a command line tetris clone:
+#
+# RUN sudo apt-get -q update && # sudo apt-get install -yq bastet && # sudo rm -rf /var/lib/apt/lists/*
+#
+# More information: https://www.gitpod.io/docs/config-docker/
diff --git a/.gitpod.yml b/.gitpod.yml
new file mode 100644
index 000000000..1c8664098
--- /dev/null
+++ b/.gitpod.yml
@@ -0,0 +1,6 @@
+tasks:
+ - init: echo "Replace me with a build script for the project."
+ command: echo "Replace me with omething that should run on every start, or just
+ remove me entirely."
+image:
+ file: .gitpod.Dockerfile
diff --git a/Gemfile b/Gemfile
index 60c8169ed..20095d03b 100755
--- a/Gemfile
+++ b/Gemfile
@@ -1,9 +1,7 @@
-# A sample Gemfile
source "https://rubygems.org"
gem 'rake'
gem 'activesupport'
-gem 'activerecord', '~> 4.2.0'
gem 'sinatra'
gem 'sinatra-contrib'
@@ -11,9 +9,14 @@ gem 'sinatra-activerecord'
gem 'puma'
gem 'tux'
+gem 'pry'
group :development, :test do
- gem 'pry'
gem 'shotgun'
- gem 'sqlite3', '~> 1.3.6'
+ gem 'sqlite3'
end
+
+group :production do
+ gem 'pg'
+ gem 'rails_12factor'
+end
\ No newline at end of file
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 000000000..8003b8e00
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,102 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ activemodel (4.2.11.1)
+ activesupport (= 4.2.11.1)
+ builder (~> 3.1)
+ activerecord (4.2.11.1)
+ activemodel (= 4.2.11.1)
+ activesupport (= 4.2.11.1)
+ arel (~> 6.0)
+ activesupport (4.2.11.1)
+ i18n (~> 0.7)
+ minitest (~> 5.1)
+ thread_safe (~> 0.3, >= 0.3.4)
+ tzinfo (~> 1.1)
+ arel (6.0.4)
+ backports (3.16.1)
+ bond (0.5.1)
+ builder (3.2.4)
+ coderay (1.1.2)
+ concurrent-ruby (1.1.6)
+ i18n (0.9.5)
+ concurrent-ruby (~> 1.0)
+ method_source (0.9.2)
+ minitest (5.14.0)
+ multi_json (1.14.1)
+ mustermann (1.1.1)
+ ruby2_keywords (~> 0.0.1)
+ nio4r (2.5.2)
+ pg (1.2.3)
+ pry (0.12.2)
+ coderay (~> 1.1.0)
+ method_source (~> 0.9.0)
+ puma (4.3.2)
+ nio4r (~> 2.0)
+ rack (2.2.2)
+ rack-protection (2.0.8.1)
+ rack
+ rack-test (0.6.3)
+ rack (>= 1.0)
+ rails_12factor (0.0.3)
+ rails_serve_static_assets
+ rails_stdout_logging
+ rails_serve_static_assets (0.0.5)
+ rails_stdout_logging (0.0.5)
+ rake (13.0.1)
+ ripl (0.7.1)
+ bond (~> 0.5.1)
+ ripl-multi_line (0.3.1)
+ ripl (>= 0.3.6)
+ ripl-rack (0.2.1)
+ rack (>= 1.0)
+ rack-test (~> 0.6.2)
+ ripl (>= 0.7.0)
+ ruby2_keywords (0.0.2)
+ shotgun (0.9.2)
+ rack (>= 1.0)
+ sinatra (2.0.8.1)
+ mustermann (~> 1.0)
+ rack (~> 2.0)
+ rack-protection (= 2.0.8.1)
+ tilt (~> 2.0)
+ sinatra-activerecord (2.0.14)
+ activerecord (>= 3.2)
+ sinatra (>= 1.0)
+ sinatra-contrib (2.0.8.1)
+ backports (>= 2.8.2)
+ multi_json
+ mustermann (~> 1.0)
+ rack-protection (= 2.0.8.1)
+ sinatra (= 2.0.8.1)
+ tilt (~> 2.0)
+ sqlite3 (1.3.13)
+ thread_safe (0.3.6)
+ tilt (2.0.10)
+ tux (0.3.0)
+ ripl (>= 0.3.5)
+ ripl-multi_line (>= 0.2.4)
+ ripl-rack (>= 0.2.0)
+ sinatra (>= 1.2.1)
+ tzinfo (1.2.6)
+ thread_safe (~> 0.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activesupport
+ pg
+ pry
+ puma
+ rails_12factor
+ rake
+ shotgun
+ sinatra
+ sinatra-activerecord
+ sinatra-contrib
+ sqlite3
+ tux
+
+BUNDLED WITH
+ 2.1.4
diff --git a/README.md b/README.md
index 2577b6932..e39db7627 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
+[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/lighthouse-labs/finstagram)
+
# finstagram
diff --git a/app/actions.rb b/app/actions.rb
index e69de29bb..f15b091e9 100755
--- a/app/actions.rb
+++ b/app/actions.rb
@@ -0,0 +1,91 @@
+helpers do
+ def current_user
+ User.find_by(id: session[:user_id])
+ end
+end
+
+get '/' do
+ @finstagram_posts = FinstagramPost.order(created_at: :desc)
+ erb(:index)
+end
+
+get '/signup' do
+ @user = User.new
+ erb(:signup)
+end
+
+post '/signup' do
+ email = params[:email]
+ avatar_url = params[:avatar_url]
+ username = params[:username]
+ password = params[:password]
+
+ @user = User.new({ email: email, avatar_url: avatar_url, username: username, password: password })
+
+ if @user.save
+ redirect to('/login')
+ else
+ erb(:signup)
+ end
+end
+
+get '/login' do # when a GET request comes into /login
+ erb(:login) # render app/views/login.erb
+end
+
+post '/login' do
+ username = params[:username]
+ password = params[:password]
+
+ user = User.find_by(username: username)
+
+ if user && user.password == password
+ session[:user_id] = user.id
+ redirect to('/')
+ else
+ @error_message = "Login failed."
+ erb(:login)
+ end
+end
+
+get '/logout' do
+ session[:user_id] = nil
+ redirect to('/')
+end
+
+get '/finstagram_posts/new' do
+ @finstagram_post = FinstagramPost.new
+ erb(:"finstagram_posts/new")
+end
+
+post '/finstagram_posts' do
+ photo_url = params[:photo_url]
+
+ @finstagram_post = FinstagramPost.new({ photo_url: photo_url, user_id: current_user.id })
+
+ if @finstagram_post.save
+ redirect(to('/'))
+ else
+ erb(:"finstagram_posts/new")
+ end
+end
+
+get '/finstagram_posts/:id' do
+ @finstagram_post = FinstagramPost.find(params[:id]) # find the finstagram post with the ID from the URL
+ erb(:"finstagram_posts/show") # render app/views/finstagram_posts/show.erb
+end
+
+post '/comments' do
+ # point values from params to variables
+ text = params[:text]
+ finstagram_post_id = params[:finstagram_post_id]
+
+ # instantiate a comment with those values & assign the comment to the `current_user`
+ comment = Comment.new({ text: text, finstagram_post_id: finstagram_post_id, user_id: current_user.id })
+
+ # save the comment
+ comment.save
+
+ # `redirect` back to wherever we came from
+ redirect(back)
+end
\ No newline at end of file
diff --git a/app/models/comment.rb b/app/models/comment.rb
new file mode 100644
index 000000000..a6dd513a5
--- /dev/null
+++ b/app/models/comment.rb
@@ -0,0 +1,10 @@
+class Comment < ActiveRecord::Base
+
+ # Associations from a previous exercise
+ belongs_to :user
+ belongs_to :finstagram_post
+
+ # New validation code
+ validates_presence_of :text, :user, :finstagram_post
+
+end
\ No newline at end of file
diff --git a/app/models/finstagram_post.rb b/app/models/finstagram_post.rb
new file mode 100644
index 000000000..d3c42aaa6
--- /dev/null
+++ b/app/models/finstagram_post.rb
@@ -0,0 +1,28 @@
+class FinstagramPost < ActiveRecord::Base
+
+ belongs_to :user
+ has_many :comments
+ has_many :likes
+
+ validates :photo_url, :user, presence: true
+
+ def humanized_time_ago
+ time_ago_in_seconds = Time.now - self.created_at
+ time_ago_in_minutes = time_ago_in_seconds / 60
+
+ if time_ago_in_minutes >= 60
+ "#{(time_ago_in_minutes / 60).to_i} hours ago"
+ else
+ "#{time_ago_in_minutes.to_i} minutes ago"
+ end
+ end
+
+ def like_count
+ self.likes.size
+ end
+
+ def comment_count
+ self.comments.size
+ end
+
+end
\ No newline at end of file
diff --git a/app/models/like.rb b/app/models/like.rb
new file mode 100644
index 000000000..89a3af999
--- /dev/null
+++ b/app/models/like.rb
@@ -0,0 +1,6 @@
+class Like < ActiveRecord::Base
+
+ belongs_to :user
+ belongs_to :finstagram_post
+
+end
\ No newline at end of file
diff --git a/app/models/user.rb b/app/models/user.rb
new file mode 100644
index 000000000..ebb85e2e4
--- /dev/null
+++ b/app/models/user.rb
@@ -0,0 +1,8 @@
+class User < ActiveRecord::Base
+
+ has_many :finstagram_posts
+ has_many :comments
+ has_many :likes
+ validates :email, :username, uniqueness: true
+ validates :email, :avatar_url, :username, :password, presence: true
+end
diff --git a/app/views/HTML_class.html b/app/views/HTML_class.html
new file mode 100644
index 000000000..80a14712b
--- /dev/null
+++ b/app/views/HTML_class.html
@@ -0,0 +1,31 @@
+
+
+
+ My Very First Site
+
+
+
+
+
Welcome Welcome!
+
Ramen
+
+
+
+
+
+
Some Aricle
+
+
+ We all think that celebrities are rich and famous. Take one look at their social media or see them walk a red carpet, and you’ll quickly realize that they’re loaded. But no one seems to really know exactly how much money a celebrity is worth.
+
+Yes, we know that Maria Sharapova has won a bunch of tennis tournaments and has a ton of ad partnerships, but exactly how much money has she made from that? And what about Dolly Parton, the Queen of Country? Check out the list below to be blown away by some of the insane net worths of the biggest celebrities in the world.
+
+
+ Take me to Hongkong!
+
+ alt="Hey!">
+
+
+
+
+
\ No newline at end of file
diff --git a/app/views/Practice_2d1.html b/app/views/Practice_2d1.html
new file mode 100644
index 000000000..af48364c7
--- /dev/null
+++ b/app/views/Practice_2d1.html
@@ -0,0 +1,13 @@
+
+
+
+
+ Document
+
+
+
+
+ Mark Completed
+
+
+
\ No newline at end of file
diff --git a/app/views/index.html b/app/views/Untitled.html
similarity index 100%
rename from app/views/index.html
rename to app/views/Untitled.html
diff --git a/app/views/finstagram_posts/new.erb b/app/views/finstagram_posts/new.erb
new file mode 100644
index 000000000..5abec7542
--- /dev/null
+++ b/app/views/finstagram_posts/new.erb
@@ -0,0 +1,32 @@
+
New Post
+
+ <% @finstagram_post.errors.full_messages.each do |message| %>
+
<%= message %>
+ <% end %>
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/views/finstagram_posts/show.erb b/app/views/finstagram_posts/show.erb
new file mode 100644
index 000000000..446bc098e
--- /dev/null
+++ b/app/views/finstagram_posts/show.erb
@@ -0,0 +1 @@
+<%= erb(:"shared/finstagram_post", { locals: { finstagram_post: @finstagram_post, allow_new_comment: true }}) %>
\ No newline at end of file
diff --git a/app/views/index.erb b/app/views/index.erb
new file mode 100644
index 000000000..bf1332260
--- /dev/null
+++ b/app/views/index.erb
@@ -0,0 +1,8 @@
+<% if current_user %>
+
+
+
+ <%= yield %>
+
+
+
+
\ No newline at end of file
diff --git a/app/views/login.erb b/app/views/login.erb
new file mode 100644
index 000000000..afa0e31bb
--- /dev/null
+++ b/app/views/login.erb
@@ -0,0 +1,15 @@
+
Login to Finstagram
+
+<%= @error_message if @error_message %>
\ No newline at end of file
diff --git a/app/views/shared/finstagram_post.erb b/app/views/shared/finstagram_post.erb
new file mode 100644
index 000000000..30a67794a
--- /dev/null
+++ b/app/views/shared/finstagram_post.erb
@@ -0,0 +1,24 @@
+
+
+
\ No newline at end of file
diff --git a/app/views/shared/new_comment.erb b/app/views/shared/new_comment.erb
new file mode 100644
index 000000000..39497469d
--- /dev/null
+++ b/app/views/shared/new_comment.erb
@@ -0,0 +1,13 @@
+
+
+<% if current_user && allow_new_comment %>
+ <%= erb(:"shared/new_comment", { locals: { finstagram_post: finstagram_post }}) %>
+<% end %>
\ No newline at end of file
diff --git a/app/views/signup.erb b/app/views/signup.erb
new file mode 100644
index 000000000..94f135983
--- /dev/null
+++ b/app/views/signup.erb
@@ -0,0 +1,28 @@
+
Join Finstagram!
+
+ <% @user.errors.full_messages.each do |message| %>
+
<%= message %>
+ <% end %>
+
+
+
\ No newline at end of file
diff --git a/config/database.rb b/config/database.rb
index e8c8eab1c..1b5b88861 100755
--- a/config/database.rb
+++ b/config/database.rb
@@ -1,14 +1,23 @@
configure do
# Log queries to STDOUT in development
- if Sinatra::Application.development?
+ if Sinatra::Application.development?
ActiveRecord::Base.logger = Logger.new(STDOUT)
+ set :database, {
+ adapter: "sqlite3",
+ database: "db/db.sqlite3"
+ }
+ else
+ db = URI.parse(ENV['DATABASE_URL'])
+ set :database, {
+ adapter: "postgresql",
+ host: db.host,
+ username: db.user,
+ password: db.password,
+ database: db.path[1..-1],
+ encoding: "utf8"
+ }
end
- set :database, {
- adapter: "sqlite3",
- database: "db/db.sqlite3"
- }
-
# Load all models from app/models, using autoload instead of require
# See http://www.rubyinside.com/ruby-techniques-revealed-autoload-1652.html
Dir[APP_ROOT.join('app', 'models', '*.rb')].each do |model_file|
diff --git a/db/migrate/0_create_base_tables.rb b/db/migrate/0_create_base_tables.rb
index aecd605d1..b0bd2ac15 100644
--- a/db/migrate/0_create_base_tables.rb
+++ b/db/migrate/0_create_base_tables.rb
@@ -1,6 +1,6 @@
-class CreateBaseTables < ActiveRecord::Migration
+class CreateBaseTables < ActiveRecord::Migration[5.2]
- def change
+ def change
create_table :users do |t|
t.string :username
t.string :avatar_url
@@ -17,17 +17,17 @@ def change
create_table :comments do |t|
t.references :user
- t.references :finstagram_post
+ t.references :post
t.text :text
t.timestamps
end
create_table :likes do |t|
t.references :user
- t.references :finstagram_post
+ t.references :post
t.timestamps
end
end
-end
+end
\ No newline at end of file
diff --git a/db/schema.rb b/db/schema.rb
new file mode 100644
index 000000000..c2f2d7cd9
--- /dev/null
+++ b/db/schema.rb
@@ -0,0 +1,47 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended that you check this file into your version control system.
+
+ActiveRecord::Schema.define(version: 0) do
+
+ create_table "comments", force: :cascade do |t|
+ t.integer "user_id"
+ t.integer "finstagram_post_id"
+ t.text "text"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "finstagram_posts", force: :cascade do |t|
+ t.integer "user_id"
+ t.string "photo_url"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "likes", force: :cascade do |t|
+ t.integer "user_id"
+ t.integer "finstagram_post_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "users", force: :cascade do |t|
+ t.string "username"
+ t.string "avatar_url"
+ t.string "email"
+ t.string "password"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+end
diff --git a/public/stylesheets/Styles.css b/public/stylesheets/Styles.css
new file mode 100644
index 000000000..e69de29bb
diff --git a/public/stylesheets/app.css b/public/stylesheets/app.css
index e69de29bb..fead7ac1f 100755
--- a/public/stylesheets/app.css
+++ b/public/stylesheets/app.css
@@ -0,0 +1,42 @@
+a.photo{
+ transition: padding 0.5s;
+}
+
+a.photo:hover{
+ padding: 10px
+}
+
+
+
+body{
+ font-family: 'Trade Winds', cursive;
+}
+
+
+
+.finstagram-post .user-info img{
+ border-radius: 50%;
+}
+
+
+
+.finstagram-post{
+ margin-bottom: 48px;
+}
+
+
+main{
+ background-color: white;
+ padding: 16px;
+}
+
+
+body{
+ background-color: whitesmoke;
+}
+
+
+header{
+ background-color: #244751;
+ color: #E8FDFF;
+}
\ No newline at end of file
+ <%= comment.user.username %>: <%= comment.text %> +
+