【发布时间】:2018-09-18 16:44:20
【问题描述】:
我正在制作一个简单的 API 端点,它返回事件的访问代码。
如果事件没有访问代码,则应为其分配一个。然后,它检查它当前是公共的还是私有的。如果是私有的,返回访问代码,如果是公共的,返回空字符串。
public function getAc($eventId) {
// Pull event
$event = $this->eventService->api->getEventForce($eventId);
// If no access code for the event, generate one and update event record accordingly
if ($event->access_code == null) {
$access_code = $this->generateAccessCode();
$affected = DB::update('update events set access_code = ? where id = ?', [$access_code, $eventId]);
}
// Is the event currently private? return access code
if ($event->privacy=='private') {
return $event->access_code;
}
// Is it public ? return empty string.
else {
return '';
}
}
我的问题是,对于为空的私人事件,它仅在第二次调用时返回访问代码(在邮递员上测试过)。这不是适当的 API 行为。
【问题讨论】:
-
哦,很高兴知道。最好把状态更新。
标签: php api laravel-5 endpoint