* Fix bugs of product api.

This commit is contained in:
zhujinyong
2021-09-10 08:35:03 +08:00
parent 90839a8c94
commit d2b43d2a2f
6 changed files with 27 additions and 12 deletions

View File

@@ -18,9 +18,10 @@ class productsEntry extends entry
* @access public
* @return void
*/
public function get()
public function get($programID = 0)
{
$programID = $this->param('program', 0);
if(!$programID) $programID = $this->param('program', 0);
if($programID)
{
$control = $this->loadController('program', 'product');
@@ -67,16 +68,16 @@ class productsEntry extends entry
*/
public function post()
{
$fields = 'program,line,name,PO,QD,RD,type,desc,whitelist';
$fields = 'program,code,line,name,PO,QD,RD,type,desc,whitelist';
$this->batchSetPost($fields);
$this->setPost('acl', $this->request('acl', 'private'));
$this->setPost('whitelist', $this->request('whitelist', array()));
$control = $this->loadController('product', 'create');
$this->requireFields('name,program');
$this->requireFields('name,code');
$control->create($this->request('program'));
$control->create($this->request('program', 0));
$data = $this->getData();
if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);

View File

@@ -29,7 +29,7 @@ class ProgramsEntry extends Entry
$result = array();
foreach($programs as $program)
{
$result[] = $this->format($program, 'openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time');
$result[] = $this->format($program, 'begin:date,end:date,realBegan:date,realEnd:date,openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time,deleted:bool');
}
return $this->send(200, array('programs' => $result));
}

View File

@@ -31,7 +31,7 @@ class userEntry extends Entry
$user = $data->data->user;
unset($user->password);
$this->send(200, $this->format($user, 'last:time,locked:time'));
$this->send(200, $user);
}
/**
@@ -46,8 +46,10 @@ class userEntry extends Entry
{
$info = new stdclass();
$info->profile = $this->loadModel('user')->getById($this->app->user->account);
unset($info->profile->password);
$profile = $this->loadModel('user')->getById($this->app->user->account);
unset($profile->password);
$info->profile = $this->format($profile, 'last:time,locked:time,birthday:date,join:date');
if(!$fields) return $this->send(200, $info);

View File

@@ -9,8 +9,9 @@ $routes['/tokens'] = 'tokens';
$routes['/configurations'] = 'configs';
$routes['/configurations/:name'] = 'config';
$routes['/products'] = 'products';
$routes['/products/:id'] = 'product';
$routes['/programs/:id/products'] = 'products';
$routes['/products'] = 'products';
$routes['/products/:id'] = 'product';
$routes['/productlines'] = 'productLines';
$routes['/productlines/:id'] = 'productLine';

View File

@@ -529,6 +529,9 @@ class baseEntry
return gmdate("Y-m-d\TH:i:s\Z", strtotime($value));
}
return $value;
case 'date':
if(!$value or $value == '0000-00-00') return null;
return $value;
case 'bool':
return boolval($value) ? true : false;
default:

View File

@@ -97,7 +97,15 @@ class program extends control
*/
public function product($programID = 0, $browseType = 'noclosed', $orderBy = 'order_desc', $recTotal = 0, $recPerPage = 15, $pageID = 1)
{
$programID = $this->program->saveState($programID, $this->program->getPairs());
$programPairs = $this->program->getPairs();
if(defined('RUN_MODE') && RUN_MODE == 'api' && !isset($programPairs[$programID]))
{
return $this->send(array('status' => 'fail', 'code' => 404, 'message' => '404 Not found'));
}
$programID = $this->program->saveState($programID, $programPairs);
setCookie("lastProgram", $programID, $this->config->cookieLife, $this->config->webRoot, '', false, true);
$this->program->setMenu($programID);