[go: up one dir, main page]

0% found this document useful (0 votes)
9 views14 pages

Code

The document outlines the user registration and various functionalities related to a plant and pet catalog application, including models, controllers, and routes for user authentication, viewing catalogs, managing wishlists, cart items, and processing orders. It details the relationships between different models such as User, Plant, Pet, and CartItem, and defines the necessary controller actions for each feature. Additionally, it includes routes for each functionality to facilitate navigation and interaction within the application.

Uploaded by

siddhu6863
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views14 pages

Code

The document outlines the user registration and various functionalities related to a plant and pet catalog application, including models, controllers, and routes for user authentication, viewing catalogs, managing wishlists, cart items, and processing orders. It details the relationships between different models such as User, Plant, Pet, and CartItem, and defines the necessary controller actions for each feature. Additionally, it includes routes for each functionality to facilitate navigation and interaction within the application.

Uploaded by

siddhu6863
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

US01 User Registration (Sign Up)

Model: User

We need a User model, which is assumed to be created using Devise for authentication.

class User < ApplicationRecord

# Devise modules: :database_authenticatable, :registerable, etc.

devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable

has_many :community_posts

has_many :contributions

end

Routes

Devise will automatically handle routes for user registration and authentication, such as:

devise_for :users

US02 View Plant Catalog

Model: Plant

class Plant < ApplicationRecord


has_many :community_posts

has_many :plant_pets

end

Controller: PlantsController

class PlantsController < ApplicationController

def index

@plants = Plant.all

end

def show

@plant = Plant.find(params[:id])

end

end

Routes;

resources :plants, only: [:index, :show]

US03 View Pet Catalog

Model: Pet
class Pet < ApplicationRecord

has_many :community_posts

has_many :plant_pets

end

Controller: PetsController

class PetsController < ApplicationController

def index

@pets = Pet.all

end

def show

@pet = Pet.find(params[:id])

end

end

Routes

resources :pets, only: [:index, :show]

US06 View Plant-Pet Pair Details


Model: PlantPet (join model for plant-pet pairs)

class PlantPet < ApplicationRecord

belongs_to :plant

belongs_to :pet

end

Controller: PlantPetsController

class PlantPetsController < ApplicationController

def show

@plant_pet = PlantPet.find(params[:id])

end

end

Routes

resources :plant_pets, only: [:show]

US08 View Wishlist


Model: WishlistItem (join model for items in wishlist)

class WishlistItem < ApplicationRecord

belongs_to :user

belongs_to :plant, optional: true

belongs_to :pet, optional: true

belongs_to :plant_pet, optional: true

end

Controller: WishlistController

class WishlistController < ApplicationController

def index

@wishlist_items = current_user.wishlist_items

end

end

Routes

resource :wishlist, only: [:index]


US09 Remove Item from Wishlist

Controller: WishlistItemsController

class WishlistItemsController < ApplicationController

def destroy

@wishlist_item = WishlistItem.find(params[:id])

@wishlist_item.destroy

redirect_to wishlist_path, notice: 'Item removed from wishlist'

end

end

Routes

resources :wishlist_items, only: [:destroy]

US10 Share Wishlist

Controller: WishlistController

This will be an extension of the `WishlistController` to allow for sharing options.

class WishlistController < ApplicationController

def share

end
end

Routes

get 'wishlist/share', to: 'wishlist#share', as: 'share_wishlist'

US11 Add Item to Cart

Model: CartItem

class CartItem < ApplicationRecord

belongs_to :user

belongs_to :plant, optional: true

belongs_to :pet, optional: true

belongs_to :plant_pet, optional: true

validates :quantity, numericality: { greater_than: 0 }

end

Controller: CartItemsController

class CartItemsController < ApplicationController

def create

@cart_item = current_user.cart_items.create(cart_item_params)

redirect_to cart_path
end

private

def cart_item_params

params.require(:cart_item).permit(:plant_id, :pet_id, :plant_pet_id, :quantity)

end

end

Routes

resources :cart_items, only: [:create]

US12 View Cart Items

Controller:

class CartsController < ApplicationController

def show

@cart_items = current_user.cart_items

end

end
Routes

resource :cart, only: [:show]

US13 Increase Item Count in Cart

Controller: CartItemsController

class CartItemsController < ApplicationController

def increase_quantity

@cart_item = CartItem.find(params[:id])

@cart_item.update(quantity: @cart_item.quantity + 1)

redirect_to cart_path

end

end

Routes

patch 'cart_items/:id/increase', to: 'cart_items#increase_quantity', as: 'increase_cart_item'

US14 Decrease Item Count in Cart

Controller: CartItemsController

class CartItemsController < ApplicationController


def decrease_quantity

@cart_item = CartItem.find(params[:id])

@cart_item.update(quantity: @cart_item.quantity - 1) if @cart_item.quantity > 1

redirect_to cart_path

end

end

Routes

patch 'cart_items/:id/decrease', to: 'cart_items#decrease_quantity', as: 'decrease_cart_item'

US15 Remove Item from Cart

Controller: CartItemsController

class CartItemsController < ApplicationController

def destroy

@cart_item = CartItem.find(params[:id])

@cart_item.destroy

redirect_to cart_path, notice: 'Item removed from cart'

end

end

Routes

resources :cart_items, only: [:destroy]


US16 Checkout - Provide Shipping Address

Controller: CheckoutController

class CheckoutController < ApplicationController

def show

@cart_items = current_user.cart_items

end

def create

@order = current_user.orders.create(order_params)

if @order.save

redirect_to payment_path(@order)

else

render :show

end

end

private

def order_params

params.require(:order).permit(:shipping_address)
end

end

Routes

resource :checkout, only: [:show, :create]

US17 Complete Payment

Controller: PaymentController

class PaymentController < ApplicationController

def show

@order = Order.find(params[:id])

end

def create

@order = Order.find(params[:id])

@order.process_payment(payment_params)

if @order.payment_successful?

redirect_to order_confirmation_path(@order)

else

render :show, alert: 'Payment failed, please try again'

end

end

private
def payment_params

params.require(:payment).permit(:payment_method, :card_number, :expiry_date)

end

end

Routes:

resource :payment, only: [:show, :create]

US18 View Purchase History

Controller: OrdersController

class OrdersController < ApplicationController

def index

@orders = current_user.orders

end

def show

@order = Order.find(params[:id])

end

end

Routes:

resources :orders, only: [:index, :show]


US19 Customer Support for Purchased Items

Controller: SupportController

class SupportController < ApplicationController

def create

@support_request = current_user.support_requests.create(support_request_params)

if @support_request.save

redirect_to support_path, notice: 'Your support request has been submitted.'

else

render :new

end

end

private

def support_request_params

params.require(:support_request).permit(:issue_type, :description)

Routes:

resource :support, only: [:create]

You might also like