Skip to content

Instantly share code, notes, and snippets.

@rukeba
Last active December 19, 2018 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rukeba/67812372dad5391e7a4353977312bc0d to your computer and use it in GitHub Desktop.
Save rukeba/67812372dad5391e7a4353977312bc0d to your computer and use it in GitHub Desktop.
Models/Collections vs API Service
class FormApiService {
get_form_list() {
return this.$http
.get('api/form-manager')
.then( ({body}) => body)
.then( ({data}) => ...)
}
get_form( form_id ) {
return this.$http
.get( `api/form-manager/${form_id}` )
.then( ({body}) => body)
.then( ({data}) => ...)
}
create_form( data ) {
return this.$http
.post( `api/form-manager`, data )
.then( ({body}) => body)
.then( ({data}) => ...)
}
update_form( form_id, data ) {
return this.$http
.put( `api/form-manager/${form_id}`, data )
.then( ({body}) => body)
.then( ({data}) => ...)
}
delete_form( form_id, data ) {
return this.$http
.delete( `api/form-manager/${form_id}` );
}
get_field_list( form_id ) {
return this.$http
.get( `api/form-manager/${form_id}/fields` )
.then( ({body}) => body)
.then( ({data}) => ...)
}
get_field( form_id, field_id ) {
return this.$http
.get( `api/form-manager/${form_id}/fields/${field_id}` )
.then( ({body}) => body)
.then( ({data}) => ...)
}
create_field( form_id, data ) {
return this.$http
.post( `api/form-manager/${form_id}/fields`, data )
.then( ({body}) => body)
.then( ({data}) => ...)
}
update_field( form_id, field_id, data ) {
return this.$http
.put( `api/form-manager/${form_id}/fields/${field_id}`, data )
.then( ({body}) => body)
.then( ({data}) => ...)
}
delete_field( form_id, field_id, data ) {
return this.$http
.delete( `api/form-manager/${form_id}/fields/${field_id}` );
}
create_field_sort_order( form_id, data ) {
return this.$http
.post( `api/form-manager/${form_id}/fields-sort-order`, data )
.then( ({body}) => body)
.then( ({data}) => ...)
}
get_email_list( form_id ) {
return this.$http
.get( `api/form-manager/${form_id}/emails` )
.then( ({body}) => body)
.then( ({data}) => ...)
}
create_email( form_id, data ) {
return this.$http
.post( `api/form-manager/${form_id}/emails`, data )
.then( ({body}) => body)
.then( ({data}) => ...)
}
delete_email( form_id, email_id, data ) {
return this.$http
.delete( `api/form-manager/${form_id}/emails/${email_id}` );
}
}
class Form extends Model {
constructor(attributes, options) {
super(attributes, options);
this.idAttribute = 'form_id';
}
urlRoot() {
return 'api/form-manager';
}
}
class FormField extends Model {
constructor(attributes, options) {
super(attributes, options);
this.form_id = options.form_id;
this.idAttribute = 'field_id';
}
urlRoot() {
return `api/form-manager/${this.form_id}/fields`;
}
}
class FormFieldOrder extends Model {
constructor(attributes, options) {
super(attributes, options);
this.form_id = options.form_id;
}
urlRoot() {
return `api/form-manager/${this.form_id}/fields-sort-order`;
}
}
class FormEmail extends Model {
constructor(attributes, options) {
super(attributes, options);
this.form_id = options.form_id;
}
urlRoot() {
return `api/form-manager/${this.form_id}/emails`;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment