Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ ruby "3.2.1"
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.1.3", ">= 7.1.3.2"

gem "devise"

# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
gem "sprockets-rails"

Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class ApplicationController < ActionController::Base
before_action :authenticate_user!
end
71 changes: 71 additions & 0 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
class CommentsController < ApplicationController
before_action :set_comment, only: %i[ show edit update destroy ]

# GET /comments or /comments.json
def index
@comments = Comment.all
end

# GET /comments/1 or /comments/1.json
def show
end

# GET /comments/new
def new
@comment = Comment.new
end

# GET /comments/1/edit
def edit
end

# POST /comments or /comments.json
def create
@comment = Comment.new(comment_params)
@comment.author = current_user

respond_to do |format|
if @comment.save
format.html { redirect_back fallback_location: root_path, notice: "Comment was successfully created." }
format.json { render :show, status: :created, location: @comment }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @comment.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /comments/1 or /comments/1.json
def update
respond_to do |format|
if @comment.update(comment_params)
format.html { redirect_to comment_url(@comment), notice: "Comment was successfully updated." }
format.json { render :show, status: :ok, location: @comment }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @comment.errors, status: :unprocessable_entity }
end
end
end

# DELETE /comments/1 or /comments/1.json
def destroy
@comment.destroy!

respond_to do |format|
format.html { redirect_to comments_url, notice: "Comment was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_comment
@comment = Comment.find(params[:id])
end

# Only allow a list of trusted parameters through.
def comment_params
params.require(:comment).permit(:id, :body, :author_id, :photo_id)
end
end
70 changes: 70 additions & 0 deletions app/controllers/follow_requests_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class FollowRequestsController < ApplicationController
before_action :set_follow_request, only: %i[ show edit update destroy ]

# GET /follow_requests or /follow_requests.json
def index
@follow_requests = FollowRequest.all
end

# GET /follow_requests/1 or /follow_requests/1.json
def show
end

# GET /follow_requests/new
def new
@follow_request = FollowRequest.new
end

# GET /follow_requests/1/edit
def edit
end

# POST /follow_requests or /follow_requests.json
def create
@follow_request = FollowRequest.new(follow_request_params)

respond_to do |format|
if @follow_request.save
format.html { redirect_to follow_request_url(@follow_request), notice: "Follow request was successfully created." }
format.json { render :show, status: :created, location: @follow_request }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @follow_request.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /follow_requests/1 or /follow_requests/1.json
def update
respond_to do |format|
if @follow_request.update(follow_request_params)
format.html { redirect_to follow_request_url(@follow_request), notice: "Follow request was successfully updated." }
format.json { render :show, status: :ok, location: @follow_request }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @follow_request.errors, status: :unprocessable_entity }
end
end
end

# DELETE /follow_requests/1 or /follow_requests/1.json
def destroy
@follow_request.destroy!

respond_to do |format|
format.html { redirect_to follow_requests_url, notice: "Follow request was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_follow_request
@follow_request = FollowRequest.find(params[:id])
end

# Only allow a list of trusted parameters through.
def follow_request_params
params.require(:follow_request).permit(:id, :status, :recipient_id, :sender_id)
end
end
70 changes: 70 additions & 0 deletions app/controllers/likes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class LikesController < ApplicationController
before_action :set_like, only: %i[ show edit update destroy ]

# GET /likes or /likes.json
def index
@likes = Like.all
end

# GET /likes/1 or /likes/1.json
def show
end

# GET /likes/new
def new
@like = Like.new
end

# GET /likes/1/edit
def edit
end

# POST /likes or /likes.json
def create
@like = Like.new(like_params)

respond_to do |format|
if @like.save
format.html { redirect_to like_url(@like), notice: "Like was successfully created." }
format.json { render :show, status: :created, location: @like }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @like.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /likes/1 or /likes/1.json
def update
respond_to do |format|
if @like.update(like_params)
format.html { redirect_to like_url(@like), notice: "Like was successfully updated." }
format.json { render :show, status: :ok, location: @like }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @like.errors, status: :unprocessable_entity }
end
end
end

# DELETE /likes/1 or /likes/1.json
def destroy
@like.destroy!

respond_to do |format|
format.html { redirect_to likes_url, notice: "Like was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_like
@like = Like.find(params[:id])
end

# Only allow a list of trusted parameters through.
def like_params
params.require(:like).permit(:id, :fan_id, :photo_id)
end
end
71 changes: 71 additions & 0 deletions app/controllers/photos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
class PhotosController < ApplicationController
before_action :authenticate_user!
before_action :set_photo, only: %i[ show edit update destroy ]

# GET /photos or /photos.json
def index
@photos = Photo.all
end

# GET /photos/1 or /photos/1.json
def show
end

# GET /photos/new
def new
@photo = Photo.new
end

# GET /photos/1/edit
def edit
end

# POST /photos or /photos.json
def create
@photo = Photo.new(photo_params)

respond_to do |format|
if @photo.save
format.html { redirect_to photo_url(@photo), notice: "Photo was successfully created." }
format.json { render :show, status: :created, location: @photo }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @photo.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /photos/1 or /photos/1.json
def update
respond_to do |format|
if @photo.update(photo_params)
format.html { redirect_to photo_url(@photo), notice: "Photo was successfully updated." }
format.json { render :show, status: :ok, location: @photo }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @photo.errors, status: :unprocessable_entity }
end
end
end

# DELETE /photos/1 or /photos/1.json
def destroy
@photo.destroy!

respond_to do |format|
format.html { redirect_to photos_url, notice: "Photo was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_photo
@photo = Photo.find(params[:id])
end

# Only allow a list of trusted parameters through.
def photo_params
params.require(:photo).permit(:image, :comments_count, :likes_count, :caption, :owner_id)
end
end
21 changes: 21 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class UsersController < ApplicationController
def show
@user = User.find_by!(username: params.fetch(:username))
end

def liked
@user = User.find_by!(username: params.fetch(:username))
end

def feed
@user = User.find_by!(username: params.fetch(:username))
end

def followers
@user = User.find_by!(username: params.fetch(:username))
end

def following
@user = User.find_by!(username: params.fetch(:username))
end
end
18 changes: 18 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# == Schema Information
#
# Table name: comments
#
# id :bigint not null, primary key
# body :text
# created_at :datetime not null
# updated_at :datetime not null
# author_id :bigint
# photo_id :bigint
#
class Comment < ApplicationRecord
belongs_to :author, class_name: "User", counter_cache: true
belongs_to :photo, counter_cache: true


validates :body, presence: true
end
18 changes: 18 additions & 0 deletions app/models/follow_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# == Schema Information
#
# Table name: follow_requests
#
# id :bigint not null, primary key
# status :string
# created_at :datetime not null
# updated_at :datetime not null
# recipient_id :bigint
# sender_id :bigint
#
class FollowRequest < ApplicationRecord
belongs_to :recipient, class_name: "User"
belongs_to :sender, class_name: "User"


enum status: { pending: "pending", rejected: "rejected", accepted: "accepted" }
end
16 changes: 16 additions & 0 deletions app/models/like.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# == Schema Information
#
# Table name: likes
#
# id :bigint not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
# fan_id :bigint
# photo_id :bigint
#
class Like < ApplicationRecord
belongs_to :fan, class_name: "User", counter_cache: true
belongs_to :photo, counter_cache: true


end
Loading