[Catalyst] usage / example for Catalyst::Controller::DBIC::API::REST
Rajesh Kumar Mallah
mallah at redgrape.tech
Tue Feb 28 15:20:25 GMT 2017
Firstly thanks for the quick reply,
http://10.100.102.38:3000/api/rest/general/members/368
does respond with single record.
{
"data": {
"group_id": null,
"pan1": null,
"mobile2": null,
"pan2": null,
"pa_city": null,
"email": null,
"membership_no": null,
"holder1": "Sheela",
"pa_state": null,
"society_id": 30,
"dob1": null,
"nominee": null,
"password": null,
"phones": null,
"if_freehold": 0,
"if_member": 0,
"present_address": null,
"flat_no": "A104",
"mobile1": "9999912348",
"pa_country": null,
"holder2": "Jignesh",
"pan": null,
"dob2": null,
"member_id": 368,
"pa_zip": null
},
"Result": "OK",
"Record": {
"present_address": null,
"if_member": 0,
"phones": null,
"if_freehold": 0,
"pa_zip": null,
"member_id": 368,
"pan": null,
"dob2": null,
"pa_country": null,
"holder2": "Jignesh",
"mobile1": "9999912348",
"flat_no": "A104",
"pan2": null,
"mobile2": null,
"pan1": null,
"group_id": null,
"nominee": null,
"society_id": 30,
"password": null,
"dob1": null,
"pa_state": null,
"holder1": "Sheela",
"membership_no": null,
"email": null,
"pa_city": null
}
}
But
http://10.100.102.38:3000/api/rest/general/members?list_count=3&list_returns=holder1&list_returns=member_id&list_search.member_id=368
does not seems to be restricting and responding with:
{
"Result": "OK",
"Records": [
{
"member_id": 366,
"holder1": "Jinesh"
},
{
"member_id": 367,
"holder1": "Gita"
},
{
"member_id": 368,
"holder1": "Sheela"
}
]
}
pasted below is the exact package config:
I do have a ControllerBase interface.
========================================
package SmartCGHS::Controller::API::REST::Member;
use strict;
use warnings;
use JSON::XS;
use parent qw/SmartCGHS::ControllerBase::REST/;
__PACKAGE__->config(
# Define parent chain action and partpath
action => { setup => { PathPart =>
'general/members', Chained => '/api/rest/rest_base' } },
# DBIC result class
class => 'DB::Member',
# Columns required to create
create_requires => [qw/flat_no society_id/],
# Additional non-required columns that create allows
create_allows => [qw/dob1 dob2 email group_id holder1
holder2 if_freehold if_member membership_no mobile1 mobile2 nominee
pa_city pa_country pa_state pa_zip pan pan1 pan2 password phones
present_address/],
# Columns that update allows
update_allows => [qw/flat_no society_id dob1 dob2 email
group_id holder1 holder2 if_freehold if_member membership_no mobile1
mobile2 nominee pa_city pa_country pa_state pa_zip pan pan1 pan2
password phones present_address/],
# Columns that list returns
select => [qw/flat_no membership_no email pan
present_address pa_city pa_state pa_country pa_zip holder1 holder2
nominee dob1 dob2 pan1 pan2 mobile1 mobile2 phones if_member
if_freehold password society_id member_id group_id/],
# Every possible prefetch param allowed
prefetch_allows => [
[qw/member_ledgers/], { 'member_ledgers' => [qw//] },
[qw/member_meter_readings/], { 'member_meter_readings' => [qw//] },
[qw/payment_collections/], { 'payment_collections' =>
[qw/member_ledgers/] },
[qw/saved_bills/], { 'saved_bills' => [qw//] },
],
# Order of generated list
ordered_by => [qw/member_id/],
# columns that can be searched on via list
search_exposes => [
qw/flat_no membership_no email pan present_address pa_city
pa_state pa_country pa_zip holder1 holder2 nominee dob1 dob2 pan1
pan2 mobile1 mobile2 phones if_member if_freehold password
society_id member_id group_id/,
{ 'member_ledgers' => [qw/transaction_id head transaction_type
amount payment_id comments generated due_on society_id member_id/]
},
{ 'member_meter_readings' => [qw/uniq_id flat_no dated reading
reading_avg society_id member_id/] },
{ 'payment_collections' => [qw/payment_id payment_mode instrument_no
payment_status instrument_bank instrument_date payment_amount
payment_time book_no receipt_no society_id member_id/] },
{ 'saved_bills' => [qw/uniq_id month year bill_html society_id
member_id/] },
],);
More information about the Catalyst
mailing list