Skip to content

Commit

Permalink
criação da network
Browse files Browse the repository at this point in the history
  • Loading branch information
Jmspter committed Sep 3, 2024
1 parent 10bf7cb commit f8db67b
Show file tree
Hide file tree
Showing 36 changed files with 476 additions and 20 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/

name: Fly Deploy
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
Binary file added app/assets/images/favicon.ico
Binary file not shown.
Binary file added app/assets/images/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
class ArticlesController < ApplicationController
before_action :authenticate_user!
before_action :set_article, only: %i[ show edit update destroy ]
before_action :authorize_article, only: %i[edit update destroy]

# GET /articles or /articles.json
def index
@active_nav_item = 'network'
if params[:category]
@articles = Article.where(category: params[:category])
else
@articles = Article.all
end
end


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

# GET /articles/new
def new
@article = Article.new
end

# GET /articles/1/edit
def edit
end

# POST /articles or /articles.json
def create
@article = current_user.articles.build(article_params)

respond_to do |format|
if @article.save
format.html { redirect_to article_url(@article), notice: "O artigo foi criado com sucesso." }
format.json { render :show, status: :created, location: @article }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @article.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /articles/1 or /articles/1.json
def update
respond_to do |format|
if @article.update(article_params)
format.html { redirect_to article_url(@article), notice: "O artigo foi atualizado com sucesso." }
format.json { render :show, status: :ok, location: @article }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @article.errors, status: :unprocessable_entity }
end
end
end

# DELETE /articles/1 or /articles/1.json
def destroy
@article.destroy!

respond_to do |format|
format.html { redirect_to articles_url, notice: "O artigo foi destruído com sucesso." }
format.json { head :no_content }
end
end

def authorize_article
unless @article.user == current_user
redirect_to articles_url, notice: 'Você não tem permissão para realizar essa ação.'
end
end

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

# Only allow a list of trusted parameters through.
def article_params
params.require(:article).permit(:title, :content, :user_id, :category)
end
end
3 changes: 3 additions & 0 deletions app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ def home
def courses
@active_nav_item = 'courses'
end
def about
@active_nav_item = 'about'
end
end
2 changes: 2 additions & 0 deletions app/helpers/articles_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ArticlesHelper
end
6 changes: 6 additions & 0 deletions app/models/article.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Article < ApplicationRecord
CATEGORIES = ['Front-end', 'Back-end', 'Full-stack', 'Desenvolvimento Mobile', 'Desenvolvimento Web', 'Ciência de Dados']

belongs_to :user
validates :category, presence: true, inclusion: { in: CATEGORIES }
end
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class User < ApplicationRecord
has_many :articles
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
Expand Down
24 changes: 24 additions & 0 deletions app/views/articles/_article.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div id="<%= dom_id article %>" class="p-5 mx-2 bg-zinc-800 rounded-lg shadow-md mb-4">
<div class="flex gap-5">
<p class="my-3">
<strong class="block text-zinc-300 font-semibold mb-1">Título:</strong>
<span class="text-white"><%= article.title %></span>
</p>

<p class="my-3">
<strong class="block text-zinc-300 font-semibold mb-1">Autor:</strong>
<span class="text-zinc-400"><%= article.user.name %></span> <!-- Exibe o nome do usuário -->
</p>

<p class="my-3">
<strong class="block text-zinc-300 font-semibold mb-1">Categoria:</strong>
<span class="text-lime-400"><%= article.category %></span>
</p>
</div>
<p class="my-3">
<strong class="block text-zinc-300 font-semibold mb-1">Artigo:</strong>
<span class="text-zinc-200"><%= article.content %></span>
</p>
</div>


2 changes: 2 additions & 0 deletions app/views/articles/_article.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! article, :id, :title, :content, :user_id, :category, :created_at, :updated_at
json.url article_url(article, format: :json)
33 changes: 33 additions & 0 deletions app/views/articles/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%= form_with(model: article, local: true, class: "space-y-6 mx-2") do |form| %>
<% if article.errors.any? %>
<div id="error_explanation" class="bg-red-600 text-white p-4 rounded-md">
<h2 class="font-bold"><%= pluralize(article.errors.count, "erro") %> impediram este artigo de ser salvo:</h2>
<ul class="mt-2 list-disc list-inside">
<% article.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="my-5">
<%= form.label :title, 'Título', class: "block text-zinc-200 font-medium" %>
<%= form.text_field :title, class: "block shadow-sm rounded-md border border-zinc-600 bg-zinc-800 text-white outline-none px-3 py-2 mt-2 w-full focus:ring-2 focus:ring-lime-500" %>
</div>

<div class="my-5">
<%= form.label :content, 'Conteúdo', class: "block text-zinc-200 font-medium" %>
<%= form.text_area :content, rows: 10, class: "block shadow-sm rounded-md border border-zinc-600 bg-zinc-800 text-white outline-none px-3 py-2 mt-2 w-full focus:ring-2 focus:ring-lime-500" %>
</div>

<div class="my-5">
<%= form.label :category, 'categoria', class: "block text-zinc-200 font-medium" %>
<%= form.select :category, Article::CATEGORIES,
{ prompt: "Selecione uma categoria" },
class: "block shadow-sm rounded-md border border-zinc-600 bg-zinc-800 text-white outline-none px-3 py-2 mt-2 w-full focus:ring-2 focus:ring-lime-500 appearance-none" %>
</div>

<div class="my-5">
<%= form.submit "Postar", class: "bg-lime-600 hover:bg-lime-700 text-white font-bold py-2 px-4 rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-lime-500" %>
</div>
<% end %>
10 changes: 10 additions & 0 deletions app/views/articles/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="mx-auto md:w-2/3 w-full bg-zinc-900 text-white p-6 rounded-lg shadow-lg">
<h1 class="font-bold text-4xl mb-6">Editando Artigo</h1>

<%= render "form", article: @article %>

<div class="mt-4 flex gap-4">
<%= link_to "Mostrar este artigo", @article, class: "rounded-lg py-2 px-4 bg-blue-600 text-white inline-block font-medium hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500" %>
<%= link_to "Voltar aos artigos", articles_path, class: "rounded-lg py-2 px-4 bg-zinc-700 text-white inline-block font-medium hover:bg-zinc-600 focus:outline-none focus:ring-2 focus:ring-zinc-500" %>
</div>
</div>
31 changes: 31 additions & 0 deletions app/views/articles/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div class="w-3/4 text-white h-screen ml-5">
<% if notice.present? %>
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
<% end %>

<% content_for :title, "Articles" %>

<h1 class="font-bold text-4xl">Network</h1>

<%= form_with url: articles_path, method: :get, local: true, class: "my-5" do %>
<%= select_tag :category, options_for_select(Article::CATEGORIES, params[:category]), prompt: "Filtrar por categoria", class: "bg-zinc-700 text-white rounded-md py-2 px-4" %>
<%= submit_tag 'Filtrar', class: "ml-2 bg-lime-600 text-white rounded-md py-2 px-4" %>
<% end %>

<div id="articles" class="min-w-full">
<% @articles.each do |article| %>
<div class="my-5 p-4 bg-zinc-700 rounded-md">
<h2 class="text-2xl font-bold"><%= article.title %></h2>
<p class="text-zinc-400">Autor: <%= article.user.name %></p>
<p>
<%= link_to "Ler artigo", article, class: "my-2 rounded-lg py-2 px-4 bg-lime-600 text-white inline-block font-medium" %>
</p>
</div>
<% end %>
</div>

<%= link_to new_article_path, class: "fixed bottom-5 right-5 bg-lime-600 text-white rounded-full p-4 shadow-lg hover:bg-lime-700 focus:outline-none focus:ring-2 focus:ring-lime-500" do %>
<i class="fas fa-pencil-alt"></i>
<% end %>

</div>
1 change: 1 addition & 0 deletions app/views/articles/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @articles, partial: "articles/article", as: :article
8 changes: 8 additions & 0 deletions app/views/articles/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="mx-auto md:w-2/3 w-full bg-zinc-900 text-white p-6 rounded-lg shadow-lg">
<h1 class="font-bold text-4xl mb-6">Novo artigo</h1>

<%= render "form", article: @article %>
<div class="mt-4 flex gap-4">
<%= link_to "Voltar aos artigos", articles_path, class: "rounded-lg py-2 px-4 bg-zinc-700 text-white inline-block font-medium hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-gray-500" %>
</div>
</div>
14 changes: 14 additions & 0 deletions app/views/articles/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="mx-auto md:w-2/3 w-full bg-gray-900 text-white p-6 rounded-lg shadow-lg">


<%= render @article %>

<div class="mt-4 md:flex gap-4">
<%= link_to "Voltar aos artigos", articles_path, class: "mb-2 rounded-lg py-2 px-4 bg-gray-700 text-white inline-block font-medium hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-gray-500" %>
<% if @article.user == current_user %>
<%= link_to "Edite este artigo", edit_article_path(@article), class: "mb-2 rounded-lg py-2 px-4 bg-blue-600 text-white inline-block font-medium hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500" %>
<%= button_to "Deletar artigo", @article, method: :delete, data: { confirm: "Are you sure you want to delete this article?" }, class: "rounded-lg py-2 px-4 bg-red-600 text-white inline-block font-medium hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-500" %>
<% end %>
</div>
</div>

1 change: 1 addition & 0 deletions app/views/articles/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "articles/article", article: @article
2 changes: 1 addition & 1 deletion app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="flex min-h-full flex-col justify-center px-6 py-12 lg:px-8">
<div class="sm:mx-auto sm:w-full sm:max-w-sm">
<%= image_tag "rokie", class:"mx-auto h-10 w-auto" %>
<%= image_tag "rokie.png", class:"mx-auto h-10 w-auto" %>
<h2 class="mt-10 text-center text-2xl font-bold leading-9 tracking-tight text-gray-50">Crie uma conta</h2>
</div>

Expand Down
4 changes: 2 additions & 2 deletions app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="flex min-h-full flex-col justify-center px-6 py-12 lg:px-8">
<div class="sm:mx-auto sm:w-full sm:max-w-sm">
<%= image_tag "rokie", class:"mx-auto h-10 w-auto" %>
<%= image_tag "rokie.png", class:"mx-auto h-10 w-auto" %>
<h2 class="mt-10 text-center text-2xl font-bold leading-9 tracking-tight text-gray-50">Faça login na sua conta</h2>
</div>

Expand All @@ -17,7 +17,7 @@
<div>
<div class="flex items-center justify-between">
<%= f.label :password, 'Senha', class:"block text-sm font-medium leading-6 text-gray-50" %>
<div class="text-sm">
<div class="text-sm hidden">
<%= link_to "Esqueceu sua senha?", new_password_path(resource_name), class:"font-semibold text-lime-600 hover:text-lime-500" %>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<div class="w-full max-w-screen-xl mx-auto p-4 md:py-8">
<div class="sm:flex sm:items-center sm:justify-between">
<a href="/" class="flex items-center mb-4 sm:mb-0 space-x-3 rtl:space-x-reverse">
<%= image_tag("rokie", class:"h-8") %>
<%= image_tag("rokie.png", class:"h-8") %>
</a>
<ul class="flex flex-wrap items-center mb-6 text-sm font-medium text-gray-400 sm:mb-0">
<li>
<a href="#" class="hover:underline me-4 md:me-6">About</a>
<a href="/about" class="hover:underline me-4 md:me-6">About</a>
</li>
<li>
<a href="#" class="hover:underline me-4 md:me-6">Privacy Policy</a>
Expand Down
6 changes: 3 additions & 3 deletions app/views/layouts/_nav.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<nav class="bg-gray-900 border-gray-700 mb-4">
<div class="max-w-screen-xl flex flex-wrap items-center justify-between mx-auto p-4">
<a href="/" class="flex items-center space-x-3 rtl:space-x-reverse">
<%= image_tag("rokie", class:"h-8") %>
<%= image_tag("rokie.png", class:"h-8") %>
</a>
<button data-collapse-toggle="navbar-hamburger" type="button" class="inline-flex items-center justify-center p-2 w-10 h-10 text-sm text-gray-400 rounded-lg hover:bg-gray-700 focus:outline-none focus:ring-gray-600 focus:ring-gray-200" aria-controls="navbar-hamburger" aria-expanded="false">
<span class="sr-only">Open main menu</span>
Expand All @@ -18,10 +18,10 @@
<%= link_to "Cursos", courses_path, class: nav_link_class('courses') %>
</li>
<li>
<%= link_to "Network", courses_path, class: nav_link_class('network') %>
<%= link_to "Network", articles_path, class: nav_link_class('network') %>
</li>
<li>
<a href="#" class="block py-2 px-3 text-gray-400 rounded hover:bg-gray-700 hover:text-white">Quem Somos?</a>
<%= link_to "Sobre nós", about_path, class: nav_link_class('about') %>
</li>
<% if user_signed_in? %>
<li><%= link_to 'Sair', destroy_user_session_path, data: { "turbo-method": :delete }, class:"block py-2 px-3 text-gray-400 rounded hover:bg-gray-700 hover:text-red-500" %></li>
Expand Down
6 changes: 5 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<title><%= content_for(:title) || "Rookie Coder Network" %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<%= favicon_link_tag asset_path('favicon.ico') %>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

Expand All @@ -13,16 +14,19 @@
<link rel="icon" href="/icon.png" type="image/png">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/icon.png">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
</head>

<body class="bg-gray-950 text-white">
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<main class="bg-gray-950 text-white">
<%= render 'layouts/nav' %>
<% if notice.present? %>
<p class="py-2 px-3 bg-green-600 text-green-100 font-medium rounded-lg mb-5" id="notice"><%= notice %></p>
<% end %>
<%= yield %>
<%= render 'layouts/footer' %>
</main>
Expand Down
8 changes: 4 additions & 4 deletions app/views/pwa/manifest.json.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"name": "RookieCoderNetwork",
"icons": [
{
"src": "/icon.png",
"src": "<%= asset_path 'icon.png' %>",
"type": "image/png",
"sizes": "512x512"
},
{
"src": "/icon.png",
"src": "<%= asset_path 'icon.png' %>",
"type": "image/png",
"sizes": "512x512",
"purpose": "maskable"
Expand All @@ -17,6 +17,6 @@
"display": "standalone",
"scope": "/",
"description": "RookieCoderNetwork.",
"theme_color": "red",
"background_color": "red"
"theme_color": "#ffffff",
"background_color": "#ffffff"
}
Loading

0 comments on commit f8db67b

Please sign in to comment.