1

Work in progress

This commit is contained in:
Alex Yatskov 2015-03-25 19:10:34 +09:00
parent 8aaf32c866
commit 5dad43ce55
2 changed files with 50 additions and 30 deletions

View File

@ -203,42 +203,52 @@ func removeCategory(rw http.ResponseWriter, req *http.Request) {
} }
func accessReview(rw http.ResponseWriter, req *http.Request) { func accessReview(rw http.ResponseWriter, req *http.Request) {
// function accessReview(query, callback) { var request jsonAccessRequest
// query.profile = fixupProfile(query.profile); if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError)
return
}
// pool.query('SELECT url FROM reviews WHERE id = (?) LIMIT 1', [query.id], function(err, rows) { reviewRows := db.QueryRow("SELECT url FROM reviews WHERE id = (?) LIMIT 1", request.Id)
// if (err) {
// throw err;
// }
// var results = { var reply jsonAccessReply
// success: rows.length > 0 if err := reviewRows.Scan(&reply.Url); err == nil {
// }; reply.Url = "http://www.tripadvisor.com" + reply.Url
reply.Success = true
}
// if (results.success) { if reply.Success {
// results.url = 'http://www.tripadvisor.com' + rows[0].url; _, err := db.Exec("UPDATE reviews SET accessCount = accessCount + 1 WHERE id = (?)", request.Id)
if err != nil {
log.Fatal(err)
}
// pool.query('UPDATE reviews SET accessCount = accessCount + 1 WHERE id = (?)', [query.id], function(err, info) { if len(request.Profile) > 0 {
// if (_.keys(query.profile).length > 0) { result, err := db.Exec("INSERT INTO history(date, reviewId) VALUES(NOW(), ?)", request.Id)
// pool.query('INSERT INTO history(date, reviewId) VALUES(NOW(), ?)', [query.id], function(err, info) { if err != nil {
// if (err) { log.Fatal(err)
// throw err; }
// }
// for (var categoryId in query.profile) { insertId, err := result.LastInsertId()
// pool.query( if err != nil {
// 'INSERT INTO historyGroups(categoryId, categoryValue, historyId) VALUES(?, ?, ?)', log.Fatal(err)
// [categoryId, query.profile[categoryId], info.insertId] }
// );
// }
// });
// }
// });
// }
// callback(results); for id, value := range request.Profile {
// }); if _, err := db.Exec("INSERT INTO historyGroups(categoryId, categoryValue, historyId) VALUES(?, ?, ?)", id, value, insertId); err != nil {
// } log.Fatal(err)
}
}
}
}
js, err := json.Marshal(reply)
if err != nil {
log.Fatal(err)
}
rw.Header().Set("Content-Type", "application/json")
rw.Write(js)
} }
func staticPath() (string, error) { func staticPath() (string, error) {

View File

@ -24,6 +24,16 @@ package main
type featureMap map[string]float64 type featureMap map[string]float64
type jsonAccessRequest struct {
Id int `json:"id"`
Profile featureMap `json:"profile"`
}
type jsonAccessReply struct {
Success bool `json:"success"`
Url string `json:"url"`
}
type jsonRange struct { type jsonRange struct {
Max float64 `json:"max"` Max float64 `json:"max"`
Min float64 `json:"min"` Min float64 `json:"min"`