[BUGFIX] improve database access
This commit is contained in:
parent
4ba6bfa009
commit
16b11662ed
|
@ -28,7 +28,7 @@ func listGoods(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
log = log.WithField("productid", id)
|
||||
var list []*models.Good
|
||||
result := &models.Good.FilterAvailable(database.Read).Where("product_id = ?", id).Find(&list)
|
||||
result := (&models.Good{}).FilterAvailable(database.Read).Where("product_id = ?", id).Find(&list)
|
||||
if result.RowsAffected == 0 {
|
||||
log.Warn("no goods found")
|
||||
http.Error(w, "no goods found for this product", http.StatusNotFound)
|
||||
|
@ -60,7 +60,7 @@ func getGoodAvailablityCount(w http.ResponseWriter, r *http.Request) (int, *logr
|
|||
return -1, log
|
||||
}
|
||||
var count float64
|
||||
&models.Good.FilterAvailable(database.Read).Where("product_id = ?", id).Count(&count)
|
||||
(&models.Good{}).FilterAvailable(database.Read).Where("product_id = ?", id).Count(&count)
|
||||
return int(count), log
|
||||
}
|
||||
|
||||
|
|
|
@ -13,10 +13,9 @@ import (
|
|||
// Function to get the status of the microservice, the database and the goods
|
||||
func status(w http.ResponseWriter, r *http.Request) {
|
||||
log := logger.HTTP(r)
|
||||
var good models.Good
|
||||
var count int64
|
||||
var avg float64
|
||||
&models.Good.FilterAvailable(database.Read).Count(&count)
|
||||
(&models.Good{}).FilterAvailable(database.Read).Count(&count)
|
||||
database.Read.Raw("SELECT avg(g.gcount) as avg FROM (select count(*) as gcount FROM good g WHERE deleted_at is NULL GROUP BY g.product_id) g").Row().Scan(&avg)
|
||||
lib.Write(w, map[string]interface{}{
|
||||
"status": "running",
|
||||
|
|
|
@ -15,8 +15,12 @@ angular.module('microStock')
|
|||
$http.post(config.store.goods.productById.replace("%d",$stateParams.productid)+'?count='+$scope.count,$scope.obj).then(function(){
|
||||
$scope.obj = {};
|
||||
$scope.msg = {type:'success',text:'Saved '+$scope.count+' good(s) from product '+$scope.product.title+'.'};
|
||||
}, function(){
|
||||
$scope.msg = {type:'error',text:'An error occurred while saving good(s) from product '+$scope.product.title+'.'};
|
||||
}, function(e){
|
||||
if(e.status == 403){
|
||||
$scope.msg = {type:'error',text:'You are not allowed to add goods, maybe you should login!'};
|
||||
}else{
|
||||
$scope.msg = {type:'error',text:'An error occurred while saving good(s): '+e.data};
|
||||
}
|
||||
});
|
||||
};
|
||||
}]);
|
||||
|
|
|
@ -17,6 +17,12 @@ angular.module('microStock')
|
|||
}
|
||||
load();
|
||||
$scope.delete = function(id){
|
||||
$http.delete(config.store.goods.productById.replace("%d",id)).then(load);
|
||||
$http.delete(config.store.goods.productById.replace("%d",id)).then(load,function(e){
|
||||
if(e.status == 403) {
|
||||
alert("You are not allowed to delete manuelle goods, maybe you should login!");
|
||||
}else{
|
||||
alert("A error occurred during deleting this good: "+e.data);
|
||||
}
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
|
Reference in New Issue