Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. // create new product
  2. app.post('/newproduct', upload.single('images'), function (req, res) {
  3.  
  4. if (req.body.title == '' || req.body.price == '') {
  5. res.json({success: false, msg: 'Please add title and price.'});
  6. console.log('title: ' + req.body.title);
  7. console.log('price: ' + req.body.price);
  8. } else {
  9.  
  10. var newProduct = new Product({
  11. title: req.body.title,
  12. price: req.body.price,
  13. description: req.body.description,
  14. images: req.file
  15.  
  16. });
  17.  
  18.  
  19. console.log(req.body);
  20. console.log(req.file);
  21.  
  22. // save the new product
  23. newProduct.save(function(err) {
  24. if (err) {
  25. res.json({success: false, msg: 'Listing was unsuccessful.'});
  26. } else {
  27. res.json({success: true, msg: 'Successful creating a new product!'});
  28. console.log(newProduct.createdAt);
  29. console.log(newProduct.updatedAt);
  30. }
  31.  
  32. });
  33.  
  34. }
  35.  
  36. });
  37.  
  38. { title: 'TEST', description: 'Test 2', price: '350' }
  39. { fieldname: 'images',
  40. originalname: 'fileName.png',
  41. encoding: '7bit',
  42. mimetype: 'image/png',
  43. destination: 'public/uploads/',
  44. filename: '4ce97ccc379e4c29404392417c4fbfb6',
  45. path: 'public/uploads/4ce97ccc379e4c29404392417c4fbfb6',
  46. size: 7063823 }
  47. POST /newproduct 200 72.025 ms - 51
  48.  
  49. func web() {
  50.  
  51. Alamofire.request(.GET, postEndPoint, parameters: nil, encoding:
  52. .JSON).responseJSON { (response:Response<AnyObject, NSError>) -> Void in
  53.  
  54. print(response.result.value)
  55. if (response.result.value != nil)
  56. {
  57.  
  58.  
  59. self.arr = (response.result.value) as! NSMutableArray
  60. let descriptor: NSSortDescriptor = NSSortDescriptor(key: "createdAt", ascending: false)
  61. self.arr.sortedArrayUsingDescriptors([descriptor])
  62.  
  63. }
  64.  
  65. self.homeTableView.reloadData()
  66.  
  67. self.homeCollectionView.reloadData()
  68.  
  69.  
  70. }
  71.  
  72. }
  73.  
  74. func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
  75.  
  76.  
  77. let cell: MainTableViewCell = tableView.dequeueReusableCellWithIdentifier("MainTableViewCell", forIndexPath: indexPath) as! MainTableViewCell
  78.  
  79.  
  80. let dict = arr[indexPath.row] as! NSDictionary
  81. print(dict)
  82.  
  83.  
  84. print(dict["title"])
  85. cell.productTitleLabel?.text = String (dict["title"]! )
  86. cell.productDescriptionLabel?.text = String (dict["description"]! )
  87. cell.productPriceLabel?.text = String (dict["price"]! )
  88. cell.productTimeLabel?.text = String (dict["createdAt"]!)
  89. // how can I upload image file
  90.  
  91.  
  92. cell.frame.size.width = screenWidth / 3
  93.  
  94. return cell
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement