-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Products can now be tagged with things like `Gluten Free` or `Vegan`, and will show up as such under Product listings
- Loading branch information
Showing
18 changed files
with
157 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,3 +136,8 @@ en: | |
payment_settings: | ||
index: | ||
link_to: "Payment Settings" | ||
tags: | ||
index: | ||
link_to: "Tags" | ||
new: | ||
link_to: "Add Tag" |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
<h3><%= name %></h3> | ||
<p class="text-sm">Serves <%= servings %></p> | ||
<p class="text-sm"> | ||
Serves <%= servings %> | ||
<%- if product.tags.present? %> | ||
(<%= product.tags.pluck(:label).join(", ") %>) | ||
<%- end %> | ||
</p> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Marketplace | ||
class ProductTag < Record | ||
self.table_name = :marketplace_product_tags | ||
|
||
belongs_to :product, inverse_of: :product_tags | ||
belongs_to :tag, inverse_of: :product_tags | ||
end | ||
end |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Marketplace | ||
class Tag < Record | ||
self.table_name = "marketplace_tags" | ||
|
||
belongs_to :bazaar, inverse_of: :tags | ||
has_many :product_tags, inverse_of: :tag, dependent: :destroy | ||
has_many :products, through: :product_tags, inverse_of: :tags | ||
|
||
attr_accessor :marketplace | ||
location(parent: :marketplace) | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
class Marketplace | ||
class TagPolicy < Policy | ||
alias_method :tag, :object | ||
def space | ||
tag.bazaar | ||
end | ||
|
||
def permitted_attributes(_params = nil) | ||
%i[label] | ||
end | ||
|
||
def update? | ||
return false unless current_person.authenticated? | ||
|
||
super | ||
end | ||
|
||
alias_method :create?, :update? | ||
|
||
def show? | ||
true | ||
end | ||
|
||
class Scope < ApplicationScope | ||
def resolve | ||
scope.all | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
class Marketplace | ||
class TagsController < Controller | ||
# Apparently, `tag` is used inside of `turbo_frame_tag`, so if we define a | ||
# helper_method named `tag` our method gets called when it really shouldn't | ||
# be... so `mtag` it is. For now. | ||
expose :mtag, scope: -> { tags }, model: Tag | ||
expose :tags, -> { policy_scope(bazaar.tags.create_with(marketplace: marketplace)) } | ||
|
||
def new | ||
authorize(mtag) | ||
end | ||
|
||
def create | ||
if authorize(mtag).save | ||
redirect_to marketplace.location(child: :tags) | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def index | ||
skip_authorization | ||
end | ||
|
||
def mtag_params | ||
policy(Tag).permit(params.require(:tag)) | ||
end | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
db/migrate/20240208025354_create_marketplace_product_tags.rb
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class CreateMarketplaceProductTags < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :marketplace_tags, id: :uuid do |t| | ||
t.references :bazaar, type: :uuid | ||
t.string :label | ||
|
||
t.timestamps | ||
end | ||
|
||
create_table :marketplace_product_tags, id: :uuid do |t| | ||
t.references :product, type: :uuid, foreign_key: {to_table: :marketplace_products} | ||
t.references :tag, type: :uuid, foreign_key: {to_table: :marketplace_tags} | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
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
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