This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
2017-03-30 18:43:18 +02:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2017-03-30 19:05:33 +02:00
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"goji.io/pat"
|
2017-03-30 18:43:18 +02:00
|
|
|
|
|
|
|
"github.com/genofire/hs_master-kss-monolith/lib/database"
|
|
|
|
lib "github.com/genofire/hs_master-kss-monolith/lib/http"
|
|
|
|
logger "github.com/genofire/hs_master-kss-monolith/lib/log"
|
|
|
|
"github.com/genofire/hs_master-kss-monolith/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
func listReview(w http.ResponseWriter, r *http.Request) {
|
|
|
|
log := logger.HTTP(r)
|
2017-03-30 19:05:33 +02:00
|
|
|
id, err := strconv.ParseInt(pat.Param(r, "productid"), 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("wrong productid format")
|
|
|
|
http.Error(w, "wrong productid", http.StatusNotAcceptable)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
log.WithField("productid", id)
|
2017-03-30 18:43:18 +02:00
|
|
|
var list []*models.Review
|
2017-03-30 19:05:33 +02:00
|
|
|
result := database.Read.Where("product_id = ?", id).Find(&list)
|
|
|
|
if result.RowsAffected == 0 {
|
|
|
|
log.Warn("no reviews found")
|
|
|
|
http.Error(w, "no reviews found", http.StatusNotFound)
|
|
|
|
return
|
|
|
|
}
|
2017-03-30 18:43:18 +02:00
|
|
|
lib.Write(w, list)
|
|
|
|
log.Info("done")
|
|
|
|
}
|