-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Add User Billing Page for Updating Billing Information #46
base: main
Are you sure you want to change the base?
Conversation
230f07a
to
3721249
Compare
AppMap runtime code review
🔄 API changes🔧 Non-breaking changesThese changes are backwards-compatible, according to the OpenAPI specification.
Detailed OpenAPI diff--- base/openapi.yml 2024-06-16 01:20:30.000000000 +0000
+++ head/openapi.yml 2024-06-21 21:13:29.000000000 +0000
@@ -315,6 +315,36 @@
type: string
name:
type: string
+ /users/{id}/billing:
+ get:
+ responses:
+ '200':
+ content:
+ text/html: {}
+ description: OK
+ patch:
+ responses:
+ '302':
+ content:
+ text/html: {}
+ description: Found
+ requestBody:
+ content:
+ application/x-www-form-urlencoded:
+ schema:
+ type: object
+ properties:
+ billing:
+ type: object
+ properties:
+ address:
+ type: string
+ city:
+ type: string
+ state:
+ type: string
+ zip_code:
+ type: string
/users/{id}/edit:
get:
responses: Performance problems🐌 New problems detected (1)N plus 1 SQL queryDescription
View in AppMapStack trace
🎉 Problems resolved (1)N plus 1 SQL queryDescription
View in AppMapStack trace
Code anti-patterns🚨 New problems detected (2)Data update performed in GET or HEAD requestDescription
View in AppMapRelated code changes--- app/controllers/users_controller.rb
+++ app/controllers/users_controller.rb
@@ -62,8 +62,27 @@ class UsersController < ApplicationController
render 'show_follow', status: :unprocessable_entity
end
- private
+ def billing
+ @user = User.find(params[:id])
+ @billing_address = UserBilling.find_or_initialize_by(user_id: @user.id)
+ end
+
+ def update_billing
+ @user = User.find(params[:id])
+ @billing_address = UserBilling.find_or_initialize_by(user_id: @user.id)
+ if @billing_address.update(billing_params)
+ flash[:success] = "Billing address updated"
+ redirect_to billing_user_path(@user)
+ else
+ render 'billing', status: :unprocessable_entity
+ end
+ end
+ private
+ def billing_params
+ params.require(:billing).permit(:address, :city, :state, :zip_code)
+ end
+
def user_params
params.require(:user).permit(:name, :email, :password,
:password_confirmation)
--- app/models/user.rb
+++ app/models/user.rb
@@ -38,6 +38,10 @@ class User < ApplicationRecord
remember_digest
end
+ def billing_address
+ UserBilling.find_by(user_id: self.id)
+ end
+
# Returns a session token to prevent session hijacking.
# We reuse the remember digest for convenience.
def session_token
--- app/views/layouts/_header.html.erb
+++ app/views/layouts/_header.html.erb
@@ -23,6 +23,7 @@
<ul id="dropdown-menu" class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
+ <li><%= link_to "Billing", billing_user_path(current_user) %></li>
<li class="divider"></li>
<li>
<%= link_to "Log out", logout_path,
Stack trace
Data update performed in GET or HEAD requestDescription
View in AppMapRelated code changes--- app/controllers/users_controller.rb
+++ app/controllers/users_controller.rb
@@ -62,8 +62,27 @@ class UsersController < ApplicationController
render 'show_follow', status: :unprocessable_entity
end
- private
+ def billing
+ @user = User.find(params[:id])
+ @billing_address = UserBilling.find_or_initialize_by(user_id: @user.id)
+ end
+
+ def update_billing
+ @user = User.find(params[:id])
+ @billing_address = UserBilling.find_or_initialize_by(user_id: @user.id)
+ if @billing_address.update(billing_params)
+ flash[:success] = "Billing address updated"
+ redirect_to billing_user_path(@user)
+ else
+ render 'billing', status: :unprocessable_entity
+ end
+ end
+ private
+ def billing_params
+ params.require(:billing).permit(:address, :city, :state, :zip_code)
+ end
+
def user_params
params.require(:user).permit(:name, :email, :password,
:password_confirmation)
--- app/models/user.rb
+++ app/models/user.rb
@@ -38,6 +38,10 @@ class User < ApplicationRecord
remember_digest
end
+ def billing_address
+ UserBilling.find_by(user_id: self.id)
+ end
+
# Returns a session token to prevent session hijacking.
# We reuse the remember digest for convenience.
def session_token
--- app/views/layouts/_header.html.erb
+++ app/views/layouts/_header.html.erb
@@ -23,6 +23,7 @@
<ul id="dropdown-menu" class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
+ <li><%= link_to "Billing", billing_user_path(current_user) %></li>
<li class="divider"></li>
<li>
<%= link_to "Log out", logout_path,
Stack trace
🎉 Problems resolved (2)Data update performed in GET or HEAD requestDescription
View in AppMapRelated code changes--- app/controllers/users_controller.rb
+++ app/controllers/users_controller.rb
@@ -62,8 +62,27 @@ class UsersController < ApplicationController
render 'show_follow', status: :unprocessable_entity
end
- private
+ def billing
+ @user = User.find(params[:id])
+ @billing_address = UserBilling.find_or_initialize_by(user_id: @user.id)
+ end
+
+ def update_billing
+ @user = User.find(params[:id])
+ @billing_address = UserBilling.find_or_initialize_by(user_id: @user.id)
+ if @billing_address.update(billing_params)
+ flash[:success] = "Billing address updated"
+ redirect_to billing_user_path(@user)
+ else
+ render 'billing', status: :unprocessable_entity
+ end
+ end
+ private
+ def billing_params
+ params.require(:billing).permit(:address, :city, :state, :zip_code)
+ end
+
def user_params
params.require(:user).permit(:name, :email, :password,
:password_confirmation)
--- app/models/user.rb
+++ app/models/user.rb
@@ -38,6 +38,10 @@ class User < ApplicationRecord
remember_digest
end
+ def billing_address
+ UserBilling.find_by(user_id: self.id)
+ end
+
# Returns a session token to prevent session hijacking.
# We reuse the remember digest for convenience.
def session_token
--- app/views/layouts/_header.html.erb
+++ app/views/layouts/_header.html.erb
@@ -23,6 +23,7 @@
<ul id="dropdown-menu" class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
+ <li><%= link_to "Billing", billing_user_path(current_user) %></li>
<li class="divider"></li>
<li>
<%= link_to "Log out", logout_path,
Stack traceData update performed in GET or HEAD requestDescription
View in AppMapRelated code changes--- app/controllers/users_controller.rb
+++ app/controllers/users_controller.rb
@@ -62,8 +62,27 @@ class UsersController < ApplicationController
render 'show_follow', status: :unprocessable_entity
end
- private
+ def billing
+ @user = User.find(params[:id])
+ @billing_address = UserBilling.find_or_initialize_by(user_id: @user.id)
+ end
+
+ def update_billing
+ @user = User.find(params[:id])
+ @billing_address = UserBilling.find_or_initialize_by(user_id: @user.id)
+ if @billing_address.update(billing_params)
+ flash[:success] = "Billing address updated"
+ redirect_to billing_user_path(@user)
+ else
+ render 'billing', status: :unprocessable_entity
+ end
+ end
+ private
+ def billing_params
+ params.require(:billing).permit(:address, :city, :state, :zip_code)
+ end
+
def user_params
params.require(:user).permit(:name, :email, :password,
:password_confirmation)
--- app/models/user.rb
+++ app/models/user.rb
@@ -38,6 +38,10 @@ class User < ApplicationRecord
remember_digest
end
+ def billing_address
+ UserBilling.find_by(user_id: self.id)
+ end
+
# Returns a session token to prevent session hijacking.
# We reuse the remember digest for convenience.
def session_token
--- app/views/layouts/_header.html.erb
+++ app/views/layouts/_header.html.erb
@@ -23,6 +23,7 @@
<ul id="dropdown-menu" class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
+ <li><%= link_to "Billing", billing_user_path(current_user) %></li>
<li class="divider"></li>
<li>
<%= link_to "Log out", logout_path,
Stack trace⭐ New AppMaps[minitest] Billing address create new billing address from [minitest] Billing address update existing billing address from |
d40f6a3
to
080e0fa
Compare
080e0fa
to
f21b3c3
Compare
@CodiumAI-Agent /improve |
PR Code Suggestions ✨
|
@CodiumAI-Agent /review |
PR Reviewer Guide 🔍
|
This pull request introduces a feature that allows users to manage and update their billing information via a dedicated billing page. The user can modify their billing address, including the address, city, state, and zip code.
Changes Implemented:
Controllers
billing
action.update_billing
action.billing_params
to permit billing-related parameters.Views
Models
Integration Tests
test/integration/billing_address_test.rb
:How to Test
rails test test/integration/billing_address_test.rb
Notes
Best Practices and Error Handling
find_or_initialize_by
to ensure that a user always has a billing address record even if starting from scratch.Code Files Changed
app/controllers/users_controller.rb
app/views/users/billing.html.erb
app/models/user_billing.rb
test/integration/billing_address_test.rb