Skip to content

Commit

Permalink
cursos
Browse files Browse the repository at this point in the history
  • Loading branch information
Jmspter committed Dec 9, 2024
1 parent 6db9fe6 commit bfd15ed
Show file tree
Hide file tree
Showing 24 changed files with 220 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/assets/images/image01.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions app/controllers/aulas_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class AulasController < ApplicationController
before_action :set_curso
before_action :set_aula, only: [:show, :update]

def show
# Define a próxima aula
@next_aula = @curso.aulas.where("id > ?", @aula.id).order(:id).first
end

def update
@aula.update(liberada: true)
redirect_to curso_aula_path(@curso, @aula), notice: "Aula liberada!"
end

private

def set_curso
@curso = Curso.find(params[:curso_id])
end

def set_aula
@aula = @curso.aulas.find(params[:id])
end
end
17 changes: 17 additions & 0 deletions app/controllers/cursos_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CursosController < ApplicationController
before_action :set_curso, only: [:show]

def index
@cursos = Curso.all
end

def show
@aulas = @curso.aulas.order(:id)
end

private

def set_curso
@curso = Curso.find(params[:id])
end
end
2 changes: 2 additions & 0 deletions app/helpers/aulas_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module AulasHelper
end
2 changes: 2 additions & 0 deletions app/helpers/cursos_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CursosHelper
end
5 changes: 5 additions & 0 deletions app/models/aula.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Aula < ApplicationRecord
belongs_to :curso

validates :titulo, :video_url, presence: true
end
5 changes: 5 additions & 0 deletions app/models/curso.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Curso < ApplicationRecord
has_many :aulas, dependent: :destroy

validates :nome, :descricao, presence: true
end
12 changes: 12 additions & 0 deletions app/views/aulas/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<h1><%= @aula.titulo %></h1>

<iframe width="560" height="315" src="https://www.youtube.com/embed/<%= @aula.video_url %>" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

<% if @aula.liberada %>
<p>Aula disponível!</p>
<% if @next_aula %>
<%= button_to "Liberar próxima aula", curso_aula_path(@curso, @next_aula), method: :patch %>
<% end %>
<% else %>
<p>Aula bloqueada.</p>
<% end %>
9 changes: 9 additions & 0 deletions app/views/cursos/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1>Cursos Disponíveis</h1>

<ul>
<% @cursos.each do |curso| %>
<li>
<%= link_to curso.nome, curso_path(curso) %> - <%= curso.descricao %>
</li>
<% end %>
</ul>
14 changes: 14 additions & 0 deletions app/views/cursos/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<h1><%= @curso.nome %></h1>
<p><%= @curso.descricao %></p>

<h2>Aulas</h2>
<ul>
<% @curso.aulas.each do |aula| %>
<li>
<%= link_to aula.titulo, curso_aula_path(@curso, aula) %>
<% unless aula.liberada %>
(Bloqueada)
<% end %>
</li>
<% end %>
</ul>
2 changes: 1 addition & 1 deletion app/views/layouts/_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<%= link_to "Home", root_path, class: nav_link_class('home') %>
</li>
<li>
<%= link_to "Cursos", courses_path, class: nav_link_class('courses') %>
<%= link_to "Cursos", cursos_path, class: nav_link_class('courses') %>
</li>
<li>
<%= link_to "Network", articles_path, class: nav_link_class('network') %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/pwa/manifest.json.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"display": "standalone",
"scope": "/",
"description": "RookieCoderNetwork.",
"theme_color": "#ffffff",
"background_color": "#ffffff"
"theme_color": "#00",
"background_color": "#00"
}
7 changes: 0 additions & 7 deletions app/views/static_pages/courses.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default: &default
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: postgres
password: <%= ENV["DATABASE_PASSWORD"] %>
password: Jam10Bi@
host: localhost

development:
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
resources :articles do
resources :comments, only: [:create, :destroy]
end
resources :cursos do
resources :aulas, only: [:show, :update]
end
devise_for :users
root "static_pages#home"
get "/courses" => "static_pages#courses"
get "/about" => "static_pages#about"

get 'quiz/question', to: 'quiz#question'
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20241208234114_create_cursos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateCursos < ActiveRecord::Migration[8.0]
def change
create_table :cursos do |t|
t.string :nome
t.text :descricao

t.timestamps
end
end
end
12 changes: 12 additions & 0 deletions db/migrate/20241208234136_create_aulas.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateAulas < ActiveRecord::Migration[8.0]
def change
create_table :aulas do |t|
t.string :titulo
t.string :video_url
t.references :curso, null: false, foreign_key: true
t.boolean :liberada

t.timestamps
end
end
end
Loading

0 comments on commit bfd15ed

Please sign in to comment.