Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[ADD] test technique #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
251 changes: 251 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
/* Styles de base pour la page */
body {
font-family: Arial, sans-serif;
background-color: #f9f9f9;
color: #333;
margin: 0;
padding: 20px;
}

.page-title {
font-size: 2.5em;
text-align: center;
margin-bottom: 30px;
color: #444;
}

/* Liste des chambres */
.room-list {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
padding: 0;
list-style: none;
}

/* Item de chaque chambre */
.room-item {
background-color: #fff;
border: 1px solid #ddd;
border-radius: 8px;
padding: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.room-item h2 {
font-size: 1.8em;
margin-bottom: 10px;
color: #2c3e50;
}

.room-description {
font-size: 1em;
margin-bottom: 15px;
color: #7f8c8d;
}

.room-price {
font-size: 1.2em;
font-weight: bold;
margin-bottom: 10px;
color: #e74c3c;
}

.room-capacity,
.room-images {
font-size: 0.9em;
color: #95a5a6;
margin-bottom: 5px;
}

/* Bouton de réservation */
.btn.btn-primary {
display: inline-block;
padding: 10px 20px;
font-size: 1em;
color: #fff;
background-color: #3498db;
border: none;
border-radius: 4px;
text-align: center;
text-decoration: none;
cursor: pointer;
transition: background-color 0.3s ease;
}

.btn.btn-primary:hover {
background-color: #2980b9;
}

/* Message d'absence de chambre */
.no-rooms {
text-align: center;
font-size: 1.2em;
color: #7f8c8d;
}


/* Style général pour la page */
.page-title {
font-size: 2.5rem;
color: #333;
text-align: center;
margin-bottom: 2rem;
}

/* Style pour la liste des rooms */
.room-list {
list-style-type: none;
padding: 0;
margin: 0;
}

.room-item {
background-color: #fff;
border: 1px solid #ddd;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
margin: 1rem 0;
padding: 1.5rem;
transition: transform 0.3s, box-shadow 0.3s;
}

.room-item:hover {
transform: translateY(-5px);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

/* Style pour le nom de la room */
.room-name {
font-size: 1.75rem;
color: #222;
margin-bottom: 0.5rem;
}

/* Style pour la description */
.room-description {
font-size: 1rem;
color: #666;
margin-bottom: 0.5rem;
}

/* Style pour le prix */
.room-price {
font-size: 1.1rem;
color: #333;
margin-bottom: 0.5rem;
}

/* Style pour la capacité */
.room-capacity {
font-size: 1rem;
color: #777;
}

/* Style pour le message lorsqu'il n'y a pas de rooms */
.no-rooms {
text-align: center;
font-size: 1.2rem;
color: #999;
}

/* Style général pour la page */
.page-title {
font-size: 2.5rem;
color: #333;
text-align: center;
margin-bottom: 2rem;
}

/* Style pour la liste des réservations */
.reservation-list {
list-style-type: none;
padding: 0;
margin: 0;
}

.reservation-item {
background-color: #fff;
border: 1px solid #ddd;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
margin: 1rem 0;
padding: 1.5rem;
transition: transform 0.3s, box-shadow 0.3s;
}

.reservation-item:hover {
transform: translateY(-5px);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

/* Style pour les informations de réservation */
.reservation-room {
font-size: 1.25rem;
color: #333;
margin-bottom: 0.5rem;
}

/* Style général pour la page */
.page-title {
font-size: 2.5rem;
color: #333;
text-align: center;
margin-bottom: 2rem;
}

/* Style pour le formulaire de création de chambre */
.room-form {
max-width: 600px;
margin: 0 auto;
padding: 2rem;
background-color: #f9f9f9;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.form-group {
margin-bottom: 1.5rem;
}

.form-label {
font-size: 1rem;
color: #333;
display: block;
margin-bottom: 0.5rem;
}

.form-control {
width: 100%;
padding: 0.75rem;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
font-size: 1rem;
color: #333;
}

.form-control:focus {
border-color: #007bff;
outline: none;
box-shadow: 0 0 0 0.2rem rgba(38, 143, 255, 0.25);
}

.btn-primary {
display: inline-block;
padding: 0.75rem 1.25rem;
font-size: 1rem;
font-weight: 500;
color: #fff;
background-color: #007bff;
border: 1px solid #007bff;
border-radius: 4px;
text-align: center;
text-decoration: none;
cursor: pointer;
}

.btn-primary:hover {
background-color: #0056b3;
border-color: #0056b3;
}
18 changes: 0 additions & 18 deletions app/assets/stylesheets/application.scss

This file was deleted.

29 changes: 29 additions & 0 deletions app/controllers/bookings_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class BookingsController < ApplicationController

before_action :authenticate_user!, only: [:my_reservations]

def new
@room = Room.find(params[:room_id])
@booking = Booking.new
end

def create
@booking = current_user.bookings.new(booking_params)
if @booking.save
redirect_to root_path, notice: I18n.t('notices.booking_created')
else
render :new
end
end

def my_reservations
@reservations = current_user.bookings
end

private

def booking_params
params.require(:booking).permit(:start_date, :end_date, :room_id)
end

end
25 changes: 24 additions & 1 deletion app/controllers/rooms_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
class RoomsController < ApplicationController

before_action :authenticate_user!

def index
@available_rooms = Room.all
end

def new
@room = Room.new
end

def create
@room = current_user.rooms.build(room_params)
if @room.save
redirect_to my_rooms_path, notice: I18n.t('notices.room_created')
else
render :new
end
end

def my_rooms
@rooms = current_user.rooms
end

def show
private

def room_params
params.require(:room).permit(:name, :description, :price_per_night, :capacity, images: [])
end

end
2 changes: 2 additions & 0 deletions app/helpers/bookings_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module BookingsHelper
end
6 changes: 6 additions & 0 deletions app/models/booking.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Booking < ApplicationRecord

belongs_to :room
belongs_to :user

end
5 changes: 5 additions & 0 deletions app/models/image.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Image < ApplicationRecord

belongs_to :room

end
17 changes: 17 additions & 0 deletions app/models/room.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# TODO: Add features to this model to implement the other TODO.
class Room < ApplicationRecord

# Associations, validations, etc.

belongs_to :user
has_many :bookings, dependent: :destroy
has_many :images, dependent: :destroy

validates :name, presence: true
validates :description, presence: true
validates :price_per_night, presence: true, numericality: { greater_than: 0 }
validates :capacity, presence: true, numericality: { only_integer: true, greater_than: 0 }

def available?(start_date, end_date)
# Logique pour vérifier si la chambre est disponible entre ces dates
bookings.where('start_date < ? AND end_date > ?', end_date, start_date).empty?
end

end
8 changes: 6 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
class User < ApplicationRecord

# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
# Associez les utilisateurs aux réservations
has_many :bookings, dependent: :destroy

has_many :rooms, dependent: :destroy

# Devise modules
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable

Expand Down
2 changes: 2 additions & 0 deletions app/views/bookings/create.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Bookings#create</h1>
<p>Find me in app/views/bookings/create.html.erb</p>
Loading