-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create and update a metric. #40
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,32 @@ | ||
<?php | ||
|
||
class Metric extends Eloquent { | ||
use \Watson\Validating\ValidatingTrait; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No leading slash is required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found whilst working on Hippo that if you start namespacing things, it's good to prefix it with a slash as to make it "fully qualified". We had issues before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still not required for imports. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fully qualified names don't have the leading slashes by definition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But that's exactly where the problem lay last time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okey dokey, we can get them removed, but I'm still 100% sure that there was a reason we ended up having to do that (not for traits, since we don't use them). |
||
|
||
class Metric extends Eloquent implements \Dingo\Api\Transformer\TransformableInterface { | ||
use ValidatingTrait; | ||
|
||
protected $rules = [ | ||
'name' => 'required', | ||
'suffix' => 'required', | ||
'display_chart' => 'boolean', | ||
]; | ||
|
||
protected $fillable = ['name', 'suffix', 'description', 'display_chart']; | ||
|
||
/** | ||
* Determines whether a chart should be shown. | ||
* @return bool | ||
*/ | ||
public function getShouldDisplayAttribute() { | ||
return $this->display_chart === 1; | ||
} | ||
|
||
/** | ||
* Get the transformer instance. | ||
* | ||
* @return ComponentTransformer | ||
*/ | ||
public function getTransformer() { | ||
return new MetricTransformer(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
class MetricTransformer extends \League\Fractal\TransformerAbstract { | ||
public function transform(Metric $metric) { | ||
return [ | ||
'id' => (int) $component->id, | ||
'name' => $component->name, | ||
'description' => $component->description, | ||
'suffix' => $component->suffix, | ||
'display' => $component->shouldDisplay, | ||
'created_at' => $component->created_at->timestamp, | ||
'updated_at' => $component->updated_at->timestamp, | ||
]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy paste error? Should be
postMetrics
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah.