-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
476 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,7 @@ def home | |
def courses | ||
@active_nav_item = 'courses' | ||
end | ||
def about | ||
@active_nav_item = 'about' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module ArticlesHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.array! @articles, partial: "articles/article", as: :article |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial! "articles/article", article: @article |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.