-
Notifications
You must be signed in to change notification settings - Fork 3
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
Implement edit and delete feature for products #168
Open
spaceman03
wants to merge
10
commits into
main
Choose a base branch
from
merch-products/zhixuan
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d0c3ff4
Implemented edit and delete feature for products
spaceman03 e8d372e
Fix lint issue
spaceman03 04c5484
Fix lint issue
spaceman03 9919a34
Fix lint issue
spaceman03 c8ab473
Fix lint issue
spaceman03 3bad8ee
Fix lint issue
spaceman03 955fd71
Fix lint issue
spaceman03 4ad7639
Fix lint issue
spaceman03 7cc2d64
Fix lint issue
spaceman03 86c8b93
Fix lint issue
spaceman03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export class Product { | ||
constructor( | ||
public id = '', | ||
public name = '', | ||
public colors= '', | ||
public sizes = '', | ||
public price = '', | ||
public category = '' | ||
) { } | ||
} |
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,64 +1,28 @@ | ||
import { Product } from "types"; | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/require-await */ | ||
import { Product } from "../@types/Product"; | ||
// todo turn into real api | ||
class ProductsApi { | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
async getProducts(): Promise<any> { | ||
const res: Product[] = [ | ||
{ | ||
id: "1", | ||
name: "product1", | ||
price: 1000, | ||
images: [ | ||
"https://i.kym-cdn.com/entries/icons/original/000/033/421/cover2.jpg", | ||
"https://i.pinimg.com/474x/c0/f9/f1/c0f9f10a0061a8dd1080d7d9e560579c.jpg", | ||
], | ||
sizes: ["s", "m", "l", "xl"], | ||
category: "shirt", | ||
is_available: true, | ||
colors: ["black,white,blue"], | ||
stock: { | ||
black: { S: 10, M: 15, L: 20, XL: 5 }, | ||
white: { S: 12, M: 17, L: 22, XL: 7 }, | ||
blue: { S: 8, M: 13, L: 18, XL: 3 } | ||
}, | ||
}, | ||
{ | ||
id: "2", | ||
name: "product2", | ||
price: 2000, | ||
images: [ | ||
"https://i.kym-cdn.com/photos/images/newsfeed/002/164/493/b8b.jpg", | ||
"https://i.kym-cdn.com/entries/icons/original/000/033/421/cover2.jpg", | ||
], | ||
sizes: ["s", "m"], | ||
category: "sweater", | ||
is_available: true, | ||
colors: ["blue"], | ||
stock: { | ||
blue: { S: 8, M: 13, L: 18, XL: 3 } | ||
}, | ||
}, | ||
{ | ||
id: "3", | ||
name: "product3", | ||
price: 3000, | ||
images: [ | ||
"https://i.kym-cdn.com/entries/icons/original/000/033/421/cover2.jpg", | ||
"https://i.kym-cdn.com/photos/images/newsfeed/002/164/493/b8b.jpg", | ||
"https://i.pinimg.com/474x/c0/f9/f1/c0f9f10a0061a8dd1080d7d9e560579c.jpg", | ||
], | ||
sizes: ["xs", "s", "m", "l"], | ||
category: "hat", | ||
is_available: false, | ||
colors: ["white"], | ||
stock: { | ||
white: { S: 12, M: 17, L: 22, XL: 7 } | ||
}, | ||
}, | ||
]; | ||
async getProducts(): Promise<Product[]> { | ||
const req = await fetch(`${process.env.PAYLOAD_PUBLIC_SERVER_URL}/api/products`); | ||
const products = await req.json(); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
return products?.docs as Product[]; | ||
} | ||
|
||
return res; | ||
async deleteProduct(id: string): Promise<void> { | ||
try { | ||
const response = await fetch(`${process.env.PAYLOAD_PUBLIC_SERVER_URL}/api/products/${id}`, { | ||
method: 'DELETE', | ||
}); | ||
if (!response.ok) { | ||
throw new Error('Failed to delete product'); | ||
} | ||
} catch (error) { | ||
throw new Error(error instanceof Error ? error.message : 'An unknown error occurred'); | ||
} | ||
} | ||
|
||
} | ||
|
||
export default new ProductsApi(); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Zhixuan, thanks for your work. Could you revert the changes on this file for now? The API changes for Product should addressed in a separate ticket