Skip to content

Commit 9cf17e9

Browse files
authored
Merge pull request #45 from kwood6319/SeedUpdateMayFromFrancis
Seed update may from francis
2 parents 992a7d2 + 19eaade commit 9cf17e9

4 files changed

Lines changed: 218 additions & 54 deletions

File tree

app/controllers/requests_controller.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ def index
1717
end
1818

1919
# 2. Category Filter
20-
if params[:category].present?
21-
@requests = @requests.where(category: params[:category])
22-
end
20+
@requests = @requests.where(category: params[:category]) if params[:category].present?
2321

2422
# 3. Prefecture Filter
2523
if params[:prefecture].present?
@@ -39,6 +37,7 @@ def index
3937

4038
def show
4139
authorize @request
40+
@offers = @request.offers
4241
end
4342

4443
def new

app/models/request.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ class Request < ApplicationRecord
1616
]
1717

1818
CATEGORIES = %w[
19-
Food
20-
Stationery
21-
Hygiene
22-
Clothes
23-
Baby
24-
Cooking
25-
Cleaning
26-
Seasonal
27-
Other
19+
food
20+
stationery
21+
hygiene
22+
clothes
23+
baby
24+
cooking
25+
cleaning
26+
seasonal
27+
other
2828
]
2929

3030
UNITS = %w[
@@ -46,14 +46,14 @@ class Request < ApplicationRecord
4646

4747
REGIONS_AND_PREFECTURES = {
4848
"Hokkaido" => %w[Hokkaido],
49-
"Tohoku" => %w[Aomori Iwate Miyagi Akita Yamagata Fukushima],
50-
"Kanto" => %w[Ibaraki Tochigi Gunma Saitama Chiba Tokyo Kanagawa],
51-
"Chubu" => %w[Niigata Toyama Ishikawa Fukui Yamanashi Nagano Gifu Shizuoka Aichi],
52-
"Kansai" => %w[Mie Shiga Kyoto Osaka Hyogo Nara Wakayama],
53-
"Chugoku" => %w[Tottori Shimane Okayama Hiroshima Yamaguchi],
54-
"Shikoku" => %w[Tokushima Kagawa Ehime Kochi],
55-
"Kyushu" => %w[Fukuoka Saga Nagasaki Kumamoto Oita Miyazaki Kagoshima],
56-
"Okinawa" => %w[Okinawa]
49+
"Tohoku" => %w[Aomori Iwate Miyagi Akita Yamagata Fukushima],
50+
"Kanto" => %w[Ibaraki Tochigi Gunma Saitama Chiba Tokyo Kanagawa],
51+
"Chubu" => %w[Niigata Toyama Ishikawa Fukui Yamanashi Nagano Gifu Shizuoka Aichi],
52+
"Kansai" => %w[Mie Shiga Kyoto Osaka Hyogo Nara Wakayama],
53+
"Chugoku" => %w[Tottori Shimane Okayama Hiroshima Yamaguchi],
54+
"Shikoku" => %w[Tokushima Kagawa Ehime Kochi],
55+
"Kyushu" => %w[Fukuoka Saga Nagasaki Kumamoto Oita Miyazaki Kagoshima],
56+
"Okinawa" => %w[Okinawa]
5757
}.freeze # Freeze makes this object immutable
5858

5959
REGIONS = REGIONS_AND_PREFECTURES.keys

app/views/requests/show.html.erb

Lines changed: 86 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,87 @@
1-
<div class="container-fluid">
2-
<h2>Request</h2>
3-
Title: <%= @request.title %><br>
4-
Category: <%= @request.category %><br>
5-
Quantity Needed: <%= @request.quantity_needed %><br>
6-
Quantity Remaining: <%= @request.quantity_remaining %><br>
7-
Condition: <%= @request.condition %><br>
8-
Description: <%= @request.description %><br>
9-
Region: <%= @request.charity.region %><br>
10-
Prefecture: <%= @request.charity.prefecture %><br>
11-
Status: <%= @request.status %><br>
12-
</div>
13-
<!--Links-->
14-
<%= link_to "Back to Requests", requests_path %><br>
15-
<%= link_to "View Offers", request_offers_path(@request) %><br>
16-
<% if policy(@request).edit? %>
17-
<%= link_to "Edit Request", edit_request_path(@request) %>
18-
<% end %>
19-
<% if policy(Offer.new(request: @request)).new? %>
20-
<%= link_to "Make an Offer", new_request_offer_path(@request) %>
21-
<% end %><br>
22-
<!--Offers-->
23-
<div class="container-fluid">
24-
<% @request.offers.each do |offer| %>
25-
<h4>Offer from: <%= offer.donor.display_name %></h4>
26-
Condition: <%= offer.condition %><br>
27-
Can be sent: <%= offer.can_ship_by %><br>
28-
Message: <%= offer.message %><br>
29-
Quantity Offered: <%= offer.quantity_offered %><br>
30-
Status: <%= offer.status %><br>
31-
Tracking Number: <%= offer.tracking_number %><br>
32-
<% end %>
1+
<div class="container mt-5 mb-4">
2+
<div class="mb-3">
3+
<%= link_to requests_path, class: "btn btn-outline-secondary" do %>
4+
← Back to Requests
5+
<% end %>
6+
</div>
7+
<div class="row align-items-stretch g-4">
8+
<div class="col-lg-5">
9+
<div class="tall-card p-3 h-100">
10+
<div class="row pt-2">
11+
<div class="col-lg-7">
12+
<h2> <%=@request.title %> </h2>
13+
</div>
14+
<div class="col-lg-4">
15+
<h3> <%= @request.quantity_remaining - @request.quantity_needed %> / <%= @request.quantity_needed %> </h3>
16+
<%= @request.urgency %>
17+
</div>
18+
</div>
19+
<div>
20+
<h4> Region: </h4>
21+
<p> <%= @request.charity.prefecture %> - <%= @request.charity.region %> </p>
22+
</div>
23+
<div>
24+
<h4> Condition: </h4>
25+
<p> <%= @request.condition %> </p>
26+
</div>
27+
<div>
28+
<h4> Description: </h4>
29+
<p> <%= @request.description %> </p>
30+
</div>
31+
<div>
32+
<p> <%= @request.status %> </p>
33+
</div>
34+
<% if policy(@request).edit? %>
35+
<%= link_to "Edit Request", edit_request_path(@request), class: "btn btn-outline-secondary" %>
36+
<% end %>
37+
</div>
38+
</div>
39+
<div class="col-lg-6 mx-3">
40+
<% if current_user.charity? && current_user.charity == @request.charity %>
41+
<h2> Offers </h2>
42+
<% if @offers.empty? %>
43+
No offers yet
44+
<% else %>
45+
<% @offers.each do |offer| %>
46+
<div class="small-card offer-card p-2 mb-3
47+
<%= 'approved-offer' if offer.status == 'approved' %>
48+
<%= 'rejected-offer' if offer.status == 'rejected' %>">
49+
<div class="row">
50+
<div class="col-lg-9">
51+
<h3> <%= offer.donor.display_name %> </h3>
52+
</div>
53+
<div class="col-lg-3">
54+
<h3> <%= offer.quantity_offered %> </h3>
55+
</div>
56+
<p> <%= offer.donor.region if offer.donor.region %> </p>
57+
<p> Condition: <%= offer.condition %> </p>
58+
<p> Can be sent: <%= offer.can_ship_by.strftime("%b %e") %> </p>
59+
<p> Message: <%= offer.message %> </p>
60+
<p> Status: <%= offer.status %> </p>
61+
<p> Tracking Number: <%= offer.tracking_number %> </p>
62+
</div>
63+
<% if offer.status == "submitted" %>
64+
<div class="row">
65+
<div class="col-lg-6">
66+
<% if policy(offer).approve? %>
67+
<%= button_to "Approve Offer", approve_offer_path(offer), method: :patch, class: "btn btn-success" %>
68+
<% end %>
69+
</div>
70+
<div class="col-lg-6">
71+
<% if policy(offer).reject? %>
72+
<%=button_to "Reject Offer", reject_offer_path(offer), method: :patch, class: "btn btn-danger" %>
73+
<% end %>
74+
</div>
75+
</div>
76+
<% end %>
77+
</div>
78+
<% end %>
79+
<% end %>
80+
<% else %>
81+
<% if policy(Offer.new(request: @request)).new? %>
82+
<%= link_to "Make an Offer", new_request_offer_path(@request), class: "small-card offer-card p-2 mb-3" %>
83+
<% end %>
84+
<% end %>
85+
</div>
86+
</div>
3387
</div>

db/seeds.rb

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,30 @@
5757
password: "123456"
5858
)
5959

60+
user8 = User.create!(
61+
role: 0,
62+
email: "lewagon@donor.com",
63+
password: "123456"
64+
)
65+
66+
user9 = User.create!(
67+
role: 1,
68+
email: "youmewe@charity.com",
69+
password: "123456"
70+
)
71+
72+
user10 = User.create!(
73+
role: 1,
74+
email: "refugeechildren@charity.com",
75+
password: "123456"
76+
)
77+
78+
user11 = User.create!(
79+
role: 0,
80+
email: "childrens@donor.com",
81+
password: "123456"
82+
)
83+
6084
puts "#{User.count} users created!"
6185

6286
puts "----------------------------------------------"
@@ -96,6 +120,30 @@
96120

97121
puts "Charity #{charity3.org_name} created."
98122

123+
charity4 = Charity.create!(
124+
user: user9,
125+
prefecture: "Tokyo",
126+
description: "Looking for laptops",
127+
org_name: "YouWeMe",
128+
region: "Kanto",
129+
shipping_address: "123 Tokyo"
130+
)
131+
132+
puts "Charity #{charity4.org_name} created."
133+
134+
charity5 = Charity.create!(
135+
user: user10,
136+
prefecture: "Tokyo",
137+
description: "A charity supporting refugee children",
138+
org_name: "Refugee Children",
139+
region: "Kanto",
140+
shipping_address: "456 Tokyo"
141+
)
142+
143+
puts "Charity #{charity5.org_name} created."
144+
145+
puts "#{Charity.count} charities created!"
146+
99147
puts "----------------------------------------------"
100148

101149
puts "Creating donors..."
@@ -130,6 +178,28 @@
130178

131179
puts "Donor #{donor3.display_name} created."
132180

181+
donor4 = Donor.create!(
182+
user: user8,
183+
prefecture: "Tokyo",
184+
display_name: "Le Wagon Tokyo",
185+
donor_type: "company",
186+
region: "Kanto"
187+
)
188+
189+
puts "Donor #{donor4.display_name} created."
190+
191+
donor5 = Donor.create!(
192+
user: user11,
193+
prefecture: "Tokyo",
194+
display_name: "Toy Donor",
195+
donor_type: "individual",
196+
region: "Kanto"
197+
)
198+
199+
puts "Donor #{donor5.display_name} created."
200+
201+
puts "#{Donor.count} donors created!"
202+
133203
puts "----------------------------------------------"
134204

135205
puts "Creating requests..."
@@ -285,11 +355,26 @@
285355

286356
puts "Created request for #{request10.quantity_needed} #{request10.title}."
287357

358+
request11 = Request.create!(
359+
category: "electronics",
360+
charity: charity4,
361+
condition: "Used - Good",
362+
description: "Laptops needed",
363+
quantity_needed: 2,
364+
quantity_remaining: 2,
365+
status: "submitted",
366+
title: "Laptops",
367+
units: "units",
368+
urgency: "high"
369+
)
370+
371+
puts "Created request for #{request11.quantity_needed} #{request11.title}."
372+
288373
puts "----------------------------------------------"
289374

290375
puts "Creating offers..."
291376

292-
offer1 = Offer.create!(
377+
offer1a = Offer.create!(
293378
can_ship_by: Date.today + 7.days,
294379
condition: "Used - Good",
295380
donor: donor1,
@@ -300,7 +385,20 @@
300385
tracking_number: ""
301386
)
302387

303-
puts "Created offer for #{offer1.quantity_offered} for #{offer1.request.title} by #{offer1.donor.display_name}"
388+
puts "Created offer for #{offer1a.quantity_offered} for #{offer1a.request.title} by #{offer1a.donor.display_name}"
389+
390+
offer1b = Offer.create!(
391+
can_ship_by: Date.today + 7.days,
392+
condition: "Used - New",
393+
donor: donor2,
394+
message: "Can ship next week",
395+
quantity_offered: 1,
396+
request: request1,
397+
status: "submitted",
398+
tracking_number: ""
399+
)
400+
401+
puts "Created offer for #{offer1b.quantity_offered} for #{offer1b.request.title} by #{offer1b.donor.display_name}"
304402

305403
offer2 = Offer.create!(
306404
can_ship_by: Date.today,
@@ -354,4 +452,17 @@
354452

355453
puts "Created offer for #{offer5.quantity_offered} for #{offer5.request.title} by #{offer5.donor.display_name}"
356454

455+
offer6 = Offer.create!(
456+
can_ship_by: Date.today - 3.days,
457+
condition: "Used - Like New",
458+
donor: donor4,
459+
message: "Laptops like new",
460+
quantity_offered: 2,
461+
request: request11,
462+
status: "accepted",
463+
tracking_number: "XXXXXX"
464+
)
465+
466+
puts "Created offer for #{offer6.quantity_offered} for #{offer6.request.title} by #{offer6.donor.display_name}"
467+
357468
puts "Seed finished!"

0 commit comments

Comments
 (0)