0.0.1 • Published 5 years ago

@bounder/scg-ng-data-service v0.0.1

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

ScgNgDataService

This library consist of a couple of base classes which makes it easy to create data services for Django Rest Framework. This library is used internally by scgvisual.com for their web applications.

The following classes can be extended to create functional rest service classes:

BaseDataService

This is the base class for all DataService classes. It add the methods getByKey, create, delete, update, partialUpdate and getFields to a data service. The end points for the methods are constructed based on the entityName and the type of method. You can add custom UrlParams to the methods which are inserted into the end point path. Finally you can override makeUrl to add custom logic for forming Urls

ListDataService

This class extends BaseDataService and adds the getAll and getWithQuery in methods to any class extending it.

PaginatedDataService

This class extends BaseDataService and adds the getPage and getWithQuery methods to any class extending it.

Configuration

You have to configure the data service classes using the injectable config token. The following is an example of a minimum configuration:

// This is an example configuration
const MY_CONFIG: ScgDsConfig = {
  baseUrl: 'https://api.test.sctvisual.com/'
};

// This is an example implementation of a derrived data service.
@Injectable(
  {providedIn: 'root'}
)
class TestDataService extends BaseDataService<TestEntity> {
  constructor(dataServiceFactory: ScgDataServiceFactory) {
    super('Test', dataServiceFactory);
  }
}

// Add the following providers to your module configuration
providers: [
  {provide: SCG_DATA_SERVICE_CONFIG, useValue: MY_CONFIG}, // Configuration injection token
  ScgDataServiceFactory, // ServiceFactory including the config and HttpClient
]