Skip to content

Commit

Permalink
Add server support for round descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
loriswit committed Nov 15, 2019
1 parent 7647d58 commit a5737ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions server/src/Binch/Controller/RoundController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public function post(Request $request, Response $response, String $path)
$params->validate([
"price" => ["required" => true, "type" => "int"],
"payer" => ["required" => true, "type" => "string"],
"consumers" => ["required" => true, "array" => "int"]
"consumers" => ["required" => true, "array" => "int"],
"description" => ["required" => false, "type" => "string"]
]);

$price = $params->price;
Expand Down Expand Up @@ -82,7 +83,9 @@ public function post(Request $request, Response $response, String $path)
if(count($consumers) == 0)
throw new HttpError(422, "Round must have at least one consumer");

$round = Round::create($group, $price, $payer, $consumers);
$description = $params->description ?? "";

$round = Round::create($group, $price, $payer, $consumers, $description);
$round->save();

$url = $this->container->get("router")->pathFor("rounds", ["path" => $path]);
Expand Down
7 changes: 6 additions & 1 deletion server/src/Binch/Entity/Round.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class Round extends Entity
* @param int $price The price of a single drink
* @param Member $payer The member that payed
* @param array $consumers A list of the members that consumed
* @param String $description The description of the round
* @return Round The created round
*/
public static function create(Group $group, int $price, Member $payer, array $consumers)
public static function create(Group $group, int $price, Member $payer, array $consumers, String $description)
{
$round = new self();
$round->bean = R::dispense("round");
Expand All @@ -29,6 +30,9 @@ public static function create(Group $group, int $price, Member $payer, array $co
$round->bean->date = R::isoDateTime();
$round->bean->deleted = false;

if(!empty($description))
$round->bean->description = self::format($description);

$amount = 0;
foreach($consumers as $consumer)
{
Expand Down Expand Up @@ -123,6 +127,7 @@ public function export()
"date" => $this->bean->date,
"price" => intval($this->bean->price),
"payer" => $this->bean->payer->name,
"description" => $this->bean->description,
"deleted" => boolval($this->bean->deleted)
];

Expand Down

0 comments on commit a5737ea

Please sign in to comment.