IBM / FoodTrackerBackend

This tutorial teaches how to create a Kitura Swift backend for the FoodTracker iOS app tutorial from Apple. This project contains a version of the tutorial code that has been updated to use Codable rather than NSCoder.
109 stars 38 forks source link

Fixed README for Web and ORM #22

Closed dokun1 closed 6 years ago

dokun1 commented 6 years ago

Now that the ORM instructions are live and required for the tutorial, the web frontend templating tutorial includes the use of the ORM.

Andrew-Lees11 commented 6 years ago

This is the change I made in the completed food Tracker for my comment:

router.get("/foodtracker") { request, response, next in
    defer {
        next()
    }
}
  1. Build a JSON string description of the FoodTracker meal store. Add the following code inside your “/foodtracker" route below the defer closure:
    Meal.findAll { (result: [Meal]?, error: RequestError?) in
    guard let meals = result else {
        return
    }
    var allMeals: [String: [[String:Any]]] = ["meals" :[]]
    for meal in meals {
        allMeals["meals"]?.append(["name": meal.name, "rating": meal.rating])
    }
    }
  2. Render the template and add it to your response. Add the following line after the for meal in meals loop:
dokun1 commented 6 years ago

Ok, I'll make a change in a little bit - handling expenses and admin stuff now that I'm back from Tokyo.