[关闭]
@fuyb1986 2016-11-11T06:20:43.000000Z 字数 2789 阅读 638

商品

金色童年


创建一个商品

Method and URL Structure

Method Resource URL
POST /market/product/create/

Request Paramaters

Name Description Required Defalut
category 分类 YES
name 名称 YES
price 价格 YES
cover 封面图片 url YES
desc 描述 YES
desc_files 详情页面图片列表 YES

Request Data

  1. {
  2. 'category': category.pk,
  3. 'name':u'产品第一',
  4. 'price':99.0,
  5. 'cover': 'http://cover.example.com/cover.png',
  6. 'desc_files': 'http://img.example.com/file1.png,''http://img.example.com/fil2.jpg',
  7. }

cURL Example

  1. curl -X POST -H 'Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b'\
  2. --data '{...}' http://localhost/product/create/

Response

  1. {
  2. "pk":7,
  3. "category":24,
  4. "category_name":"P2",
  5. "name":"商品第一",
  6. "price":"99.00",
  7. "cover":"http://cover.example.com/cover.png",
  8. "file_list":[
  9. "http://img.example.com/file1.png",
  10. "http://img.example.com/file2.jpg"
  11. ]
  12. }

获取、更新、删除商品

Method and URL Structure

Method Resource URL
GET /market/product/${product pk}
PUTH /market/product/${product pk}
PATCH /market/product/${product pk}
DETEL /market/product/${product pk}

Request Paramaters

Name Description Required Defalut
category 分类 YES
name 名称 YES
price 价格 YES
cover 封面图片 url YES
desc 描述 YES
desc_files 详情页面图片列表 YES

Request Data

  1. {
  2. 'category': category.pk,
  3. 'name':u'产品第一',
  4. 'price':99.0,
  5. 'cover': 'http://cover.example.com/cover.png',
  6. 'desc_files': 'http://img.example.com/file1.png,''http://img.example.com/fil2.jpg',
  7. }

cURL Example

  1. curl -X PUT -H 'Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b'\
  2. --data '{...}' http://localhost/product/create/

Response

  1. {
  2. "pk":7,
  3. "category":24,
  4. "category_name":"P2",
  5. "name":"商品第一",
  6. "price":"99.00",
  7. "evaluation_data":{
  8. "count":0,
  9. "bad_count":0,
  10. "middle_count":0,
  11. "good_count":0
  12. },
  13. "cover":"http://cover.example.com/cover.png",
  14. "file_list":[
  15. "http://img.example.com/file1.png",
  16. "http://img.example.com/file2.jpg"
  17. ]
  18. }

获取商品列表

Method and URL Structure

Method Resource URL
GET /market/products/

Request Parameters

Name Description Required Default
category 分类 YES
page 页码 NO 1
page_size 每页数 NO 10
owner 商铺 NO

cURL Example

  1. curl -X PUT -H 'Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b'\
  2. --data '{...}' http://localhost/products/?category=124

Response

  1. {
  2. "count":3,
  3. "next":null,
  4. "previous":null,
  5. "results":[{
  6. "pk":7,
  7. "category":24,
  8. "category_name":"P2",
  9. "name":"商品第一",
  10. "price":"99.00",
  11. "use_point": true,
  12. "evaluation_data":{
  13. "count":0,
  14. "bad_count":0,
  15. "middle_count":0,
  16. "good_count":0
  17. },
  18. "cover":"http://cover.example.com/cover.png",
  19. "file_list":[
  20. "http://img.example.com/file1.png",
  21. "http://img.example.com/file2.jpg"
  22. ]
  23. }...]
  24. }

获取商品评价列表

Method and URL Structure

Method Resource URL
GET /market/product/evaluations/${product pk}

Request Parameters

No Applicated

cURL Example

  1. curl http://localhost/products/evaluations/1234/
  1. {
  2. "count":2,
  3. "next":null,
  4. "previous":null,
  5. "results":[{
  6. "product":36,
  7. "scores":5,
  8. "scores_display":"五星",
  9. "image":"http://example.com/xx.png",
  10. "content":"评价产品而不是定单",
  11. "created":"2016-10-20T17:05:20.835628",
  12. "owner":{
  13. "owner":27,
  14. "nickname":"xiaoming",
  15. "avatar_url":"http://www.example.com/xiaoming.jpg",
  16. "slogan":"xiaoming's slogan"
  17. }
  18. },... ]
  19. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注