commit 82de95b4b774d837dcab22b5fc1d00eb28f5cbb2 Author: Sambo Chea Date: Sat Sep 4 19:07:29 2021 +0700 Task: Add sample client sdk diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c8a157 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# Files and directories created by pub. +.dart_tool/ +.packages + +# Conventional directory for build output. +build/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..effe43c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a307539 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +A simple command-line application. diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..18b40b8 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,16 @@ +# Defines a default set of lint rules enforced for projects at Google. For +# details and rationale, see +# https://github.com/dart-lang/pedantic#enabled-lints. + +include: package:pedantic/analysis_options.yaml + +# For lint rules and documentation, see http://dart-lang.github.io/linter/lints. + +# Uncomment to specify additional rules. +# linter: +# rules: +# - camel_case_types + +# analyzer: +# exclude: +# - path/to/excluded/files/** diff --git a/bin/sample_dart_dsdk.dart b/bin/sample_dart_dsdk.dart new file mode 100644 index 0000000..d721de6 --- /dev/null +++ b/bin/sample_dart_dsdk.dart @@ -0,0 +1,3 @@ +void main(List arguments) { + print('Hello world!'); +} diff --git a/lib/sdk/ClientSDK.dart b/lib/sdk/ClientSDK.dart new file mode 100644 index 0000000..e93a240 --- /dev/null +++ b/lib/sdk/ClientSDK.dart @@ -0,0 +1,20 @@ +import 'package:sample_dart_dsdk/sdk/services/CategoryService.dart'; +import 'package:sample_dart_dsdk/sdk/services/ProductService.dart'; + +class ClientSDK { + static var _instance; + + static ClientSDK getInstance() { + if (_instance == null) { + ClientSDK(); + } + + return _instance; + } + + ProductService getProductService() { + return ProductService(); + } + + CategoryService getCategoryService() => CategoryService(); +} diff --git a/lib/sdk/models/CategoryModel.dart b/lib/sdk/models/CategoryModel.dart new file mode 100644 index 0000000..9e68eb1 --- /dev/null +++ b/lib/sdk/models/CategoryModel.dart @@ -0,0 +1,6 @@ +class Category { + int id; + String name; + + Category(this.id, this.name); +} diff --git a/lib/sdk/models/ProductModel.dart b/lib/sdk/models/ProductModel.dart new file mode 100644 index 0000000..d559fea --- /dev/null +++ b/lib/sdk/models/ProductModel.dart @@ -0,0 +1,20 @@ +class Product { + int id; + String name; + double price; + + Product(this.id, this.name, this.price); + + static Product fromJson(dynamic json) => Product( + json['id'], + json['name'], + json['price'], + ); +} + +class ProductRequest { + String name; + double price; + + ProductRequest(this.name, this.price); +} diff --git a/lib/sdk/services/CategoryService.dart b/lib/sdk/services/CategoryService.dart new file mode 100644 index 0000000..c9cfacc --- /dev/null +++ b/lib/sdk/services/CategoryService.dart @@ -0,0 +1,7 @@ +import 'package:sample_dart_dsdk/sdk/models/CategoryModel.dart'; + +class CategoryService { + List getAll() { + return List.empty(); + } +} diff --git a/lib/sdk/services/ProductService.dart b/lib/sdk/services/ProductService.dart new file mode 100644 index 0000000..8b39da7 --- /dev/null +++ b/lib/sdk/services/ProductService.dart @@ -0,0 +1,15 @@ +import 'package:sample_dart_dsdk/sdk/models/ProductModel.dart'; + +class ProductService { + List getAll() { + return List.empty(); + } + + Product getOne() { + return Product.fromJson(null); + } + + Product create() { + return Product.fromJson(null); + } +} diff --git a/lib/test.dart b/lib/test.dart new file mode 100644 index 0000000..638da64 --- /dev/null +++ b/lib/test.dart @@ -0,0 +1,13 @@ +import 'package:sample_dart_dsdk/sdk/ClientSDK.dart'; + +void main(List args) { + var client = ClientSDK.getInstance(); + var productService = client.getProductService(); + var products = productService.getAll(); + + print(products); + + var categoryService = client.getCategoryService(); + var categories = categoryService.getAll(); + print(categories); +} diff --git a/pubspec.lock b/pubspec.lock new file mode 100644 index 0000000..07e0c32 --- /dev/null +++ b/pubspec.lock @@ -0,0 +1,12 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + pedantic: + dependency: "direct dev" + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.11.1" +sdks: + dart: ">=2.12.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..b0eb8f0 --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,13 @@ +name: sample_dart_dsdk +description: A simple command-line application. +version: 1.0.0 +# homepage: https://www.example.com + +environment: + sdk: '>=2.12.0 <3.0.0' + +# dependencies: +# path: ^1.8.0 + +dev_dependencies: + pedantic: ^1.10.0