Created
January 29, 2012 19:34
-
-
Save regedarek/1700289 to your computer and use it in GitHub Desktop.
System rezerwacji przedmiotów do klubu turystycznego
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
Aplikacja(w sinatrze pisana) powinna: | |
- pozwolić użytkownikowi wypozyczyć przedmiot na dany okres czasu | |
- zabronić wypożyczyć jeżeli dany przedmiot jest w tym okresie czasu wypożyczony | |
- sprawdzać w magazynie czy jest jeszcze jakiś przedmiot dostępny i wypożyczyć ostatni niewypozyczony | |
Przykład: | |
Magazyn: 2 namioty, 3 pary raków | |
Użytkownik wypożycza namiot na dany okres czasu(na początek ustalmy że wpisuje ręcznie np. "na tydzien") | |
Ilość namiotów zmniejsza się o 1 | |
Dodana zostaje rezerwacja na namiot z informacja o tym na ile jest wypozyczony. | |
model User | |
username | |
has_many :reservations | |
model Reservation | |
item_id | |
user_id | |
reservation_time | |
belongs_to :item | |
belongs_to :user | |
model Item | |
name | |
state | |
has_many :reservations | |
akcja wypozycz | |
reserv = Reservation.new | |
item = Item.find_by_name(params[:name]) | |
if item.state > 0 | |
reserv.item_id = item.id | |
reserv.user.id = current_user.id | |
reserv.reservation_time = params[:reservation_time] | |
reserv.complete = 0 | |
reserv.save | |
item.state -= 1 | |
item.save | |
else | |
flash[:error] = "Brak przedmiotów" | |
redirect '/' | |
end | |
akcja oddaj | |
reserv = Reservation.find(:id) | |
reserv.complete = 1 | |
reserv.item.state += 1 | |
reserv.save | |
akcja wyswietl | |
@borrowed_items = Item.where('complete = ?', 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment