Skip to content

Commit

Permalink
Add Profile Page (Displays Previous Orders)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasUCSB committed Nov 15, 2024
1 parent ad9e953 commit 709734e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
4 changes: 4 additions & 0 deletions app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ def handle_register
render :register_form, status: :unprocessable_entity
end
end

def show_profile
@orders = Order.includes(:item).where(user_id: session[:user]['id'])
end
end
7 changes: 0 additions & 7 deletions app/views/item/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
<h1>Welcome, <%= @username %></h1>
<div style="position: absolute;top: 0;right: 0;">
<% if @loggedin %>
<a href="logout">Log Out</a>
<% else %>
<a href="login">Log In</a>&nbsp;&nbsp;&nbsp;<a href="register">Register</a>
<% end %>
</div>

<% if @loggedin %>
<a href="create_listing">Create a new listing</a>
Expand Down
7 changes: 7 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
</head>

<body>
<div style="position: absolute;top: 0;right: 0;">
<% if @loggedin %>
<%= link_to "Log Out", "/logout" %> <%= link_to "Profile", "/profile" %>
<% else %>
<%= link_to "Log In", "/login" %> <%= link_to "Register", "/register" %>
<% end %>
</div>
<%= yield %>
</body>
</html>
23 changes: 23 additions & 0 deletions app/views/user/show_profile.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<h1><%= @username %></h1>
<h2><strong>Your Order History:</strong></h2>

<table>
<thead>
<tr>
<th>Item Name</th>
<th>Quantity</th>
<th>Item Price</th>
<th>Total Price</th>
</tr>
</thead>
<tbody>
<% @orders.each do |order| %>
<tr>
<td><%= order.item.name %></td>
<td><%= order.quantity %></td>
<td><%= order.item.price %></td>
<td><%= order.quantity * order.item.price %></td>
</tr>
<% end %>
</tbody>
</table>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@

get "item/:id" => "item#show_listing", as: :item
post "item/:id/order" => "item#create_order", as: :create_order

get "profile" => "user#show_profile"
end

0 comments on commit 709734e

Please sign in to comment.