Commit 6289346c authored by Daniel Ravi Negi's avatar Daniel Ravi Negi 🤙🏼
Browse files

Change names

parent 47d7bd56
......@@ -15,3 +15,4 @@ Dart_Packages.xml
client.html
config.yaml
migrations/*
.dart_tool
\ No newline at end of file
......@@ -25,6 +25,23 @@ class AccessCodeController extends ResourceController {
return Response.ok(accessCode);
}
@Scope(['admin'])
@Operation.put('id')
Future<Response> updateAccesscode(@Bind.path('id') int id,
@Bind.body(ignore: ['id', 'code']) AccessCode accesscode) async {
final updateQuery = Query<AccessCode>(context)
..where((v) => v.id).equalTo(id)
..values = accesscode;
final update = updateQuery.updateOne();
if (update == null) {
return Response.notFound();
}
return Response.ok(update);
}
@Scope(['admin'])
@Operation.post()
Future<Response> postAccessCode() async {
......
import 'package:aqueduct/aqueduct.dart';
import '../coupons_backend.dart';
import '../model/coupon.dart';
import '../model/coupon_code.dart';
import '../model/metadata.dart';
import '../model/user.dart';
class CouponCodeController extends ResourceController {
CouponCodeController(this.context);
final ManagedContext context;
@Scope(['admin'])
@Operation.delete('vendorID', 'couponID', 'id')
Future<Response> deleteCouponCodeByIDByCoupon(
@Bind.path('vendorID') int vendorID,
@Bind.path('couponID') int couponID,
@Bind.path('id') int id) async {
final deleteQuery = Query<CouponCode>(context)
..where((c) => c.id).equalTo(id)
..where((c) => c.coupon.id).equalTo(couponID)
..where((c) => c.coupon.vendor.id).equalTo(vendorID);
final delete = deleteQuery.delete();
if (delete == null) {
return Response.notFound();
}
return Response.accepted();
}
@override
APIRequestBody documentOperationRequestBody(
APIDocumentContext context, Operation operation) {
if (operation.method == "POST") {
return APIRequestBody.schema(context.schema['CouponCode']);
}
return null;
}
@override
Map<String, APIResponse> documentOperationResponses(
APIDocumentContext context, Operation operation) {
if (operation.method == "GET") {
return {
"200": APIResponse.schema(
"Get a coupon code", context.schema["CouponCode"]),
"404": APIResponse("Could not find any redeemable couponcode!")
};
} else if (operation.method == "POST") {
return {
"200":
APIResponse.schema("Add a couponcode", context.schema["CouponCode"])
};
}
return {"400": APIResponse("Unkown error")};
}
@Scope(['user'])
@Operation.get('vendorID', 'couponID')
Future<Response> getCodeByCouponIDByVendorID(
......@@ -122,68 +169,11 @@ class CouponCodeController extends ResourceController {
if (update == null) {
return Response.serverError();
}
return Response.ok(couponCode);
}
return Response.notFound();
}
@Scope(['admin'])
@Operation.put('vendorID', 'couponID', 'id')
Future<Response> putCouponCodeByIDByCouponIDByVendorID(
@Bind.path('vendorID')
int vendorID,
@Bind.path('couponID')
int couponID,
@Bind.path('id')
int id,
@Bind.body(ignore: ['metadataCouponCode', 'coupon', 'id'])
CouponCode couponCode) async {
final updateQuery = Query<CouponCode>(context)
..where((c) => c.id).equalTo(id)
..where((c) => c.coupon.id).equalTo(couponID)
..where((c) => c.coupon.vendor.id).equalTo(vendorID)
..values = couponCode;
final update = updateQuery.updateOne();
if (update == null) {
return Response.notFound();
}
final now = DateTime.now().toUtc();
final updateMetadataQuery = Query<MetadataCouponCode>(context)
..where((x) => x.couponCode.id).equalTo(couponID)
..values.changedAt = now;
final updateMetadata = updateMetadataQuery.updateOne();
if (updateMetadata == null) {
return Response.serverError();
}
return Response.ok(update);
}
@Scope(['admin'])
@Operation.delete('vendorID', 'couponID', 'id')
Future<Response> deleteCouponCodeByIDByCoupon(
@Bind.path('vendorID') int vendorID,
@Bind.path('couponID') int couponID,
@Bind.path('id') int id) async {
final deleteQuery = Query<CouponCode>(context)
..where((c) => c.id).equalTo(id)
..where((c) => c.coupon.id).equalTo(couponID)
..where((c) => c.coupon.vendor.id).equalTo(vendorID);
final delete = deleteQuery.delete();
if (delete == null) {
return Response.notFound();
}
return Response.accepted();
}
@Scope(['admin'])
@Operation.post('vendorID', 'couponID')
Future<Response> postCouponCodeByCouponIDByVendorID(
......@@ -219,7 +209,7 @@ class CouponCodeController extends ResourceController {
if (insertedCouponCode == null) {
return Response.badRequest();
}
final metadata = Query<MetadataCouponCode>(context)
final metadata = Query<CouponCodeMetadata>(context)
..values.changedAt = now
..values.createdAt = now
..values.couponCode = insertedCouponCode;
......@@ -231,30 +221,38 @@ class CouponCodeController extends ResourceController {
return Response.ok(insertedCouponCode);
}
@override
APIRequestBody documentOperationRequestBody(
APIDocumentContext context, Operation operation) {
if (operation.method == "POST") {
return APIRequestBody.schema(context.schema['CouponCode']);
@Scope(['admin'])
@Operation.put('vendorID', 'couponID', 'id')
Future<Response> putCouponCodeByIDByCouponIDByVendorID(
@Bind.path('vendorID')
int vendorID,
@Bind.path('couponID')
int couponID,
@Bind.path('id')
int id,
@Bind.body(ignore: ['metadataCouponCode', 'coupon', 'id'])
CouponCode couponCode) async {
final updateQuery = Query<CouponCode>(context)
..where((c) => c.id).equalTo(id)
..where((c) => c.coupon.id).equalTo(couponID)
..where((c) => c.coupon.vendor.id).equalTo(vendorID)
..values = couponCode;
final update = updateQuery.updateOne();
if (update == null) {
return Response.notFound();
}
return null;
}
@override
Map<String, APIResponse> documentOperationResponses(
APIDocumentContext context, Operation operation) {
if (operation.method == "GET") {
return {
"200": APIResponse.schema(
"Get a coupon code", context.schema["CouponCode"]),
"404": APIResponse("Could not find any redeemable couponcode!")
};
} else if (operation.method == "POST") {
return {
"200":
APIResponse.schema("Add a couponcode", context.schema["CouponCode"])
};
final now = DateTime.now().toUtc();
final updateMetadataQuery = Query<CouponCodeMetadata>(context)
..where((x) => x.couponCode.id).equalTo(couponID)
..values.changedAt = now;
final updateMetadata = updateMetadataQuery.updateOne();
if (updateMetadata == null) {
return Response.serverError();
}
return {"400": APIResponse("Unkown error")};
return Response.ok(update);
}
}
import 'package:aqueduct/aqueduct.dart';
import '../coupons_backend.dart';
import '../model/metadata.dart';
import '../model/coupon.dart';
import '../model/metadata.dart';
import '../model/vendor.dart';
class CouponController extends ResourceController {
......@@ -19,7 +20,6 @@ class CouponController extends ResourceController {
if (coupons == null || coupons.isEmpty) {
return Response.notFound();
}
return Response.ok(coupons);
}
......@@ -27,18 +27,55 @@ class CouponController extends ResourceController {
@Operation.get('vendorID', 'id')
Future<Response> getCouponByIDByVendorID(
@Bind.path('vendorID') int vendorID, @Bind.path('id') int id) async {
final couponQuery = Query<Coupon>(context);
couponQuery
final couponQuery = Query<Coupon>(context)
..where((c) => c.vendor.id).equalTo(vendorID)
..where((c) => c.id).equalTo(id);
final coupon = await couponQuery.fetchOne();
if (coupon == null) {
return Response.notFound();
}
return Response.ok(coupon);
}
@Scope(['admin'])
@Operation.post('vendorID')
Future<Response> insertCouponByIDByVendorID(
@Bind.path('vendorID') int vendorID) async {
if (request.body.isEmpty) {
return Response.badRequest();
}
final now = DateTime.now();
final vendorQuery = Query<Vendor>(context)
..where((v) => v.id).equalTo(vendorID);
final vendor = await vendorQuery.fetchOne();
if (vendor == null) {
return Response.badRequest();
}
final coupon = Coupon()
..read(await request.body.decode(), ignore: ['id', 'vendor'])
..vendor = vendor;
final query = Query<Coupon>(context)..values = coupon;
final insertedCoupon = await query.insert();
if (insertedCoupon == null) {
return Response.serverError();
}
final metadata = Query<CouponMetadata>(context)
..values.changedAt = now
..values.createdAt = now
..values.coupon = insertedCoupon;
final insertedMetadata = metadata.insert();
if (insertedMetadata == null) {
return Response.serverError();
}
return Response.ok(insertedCoupon);
}
@Scope(['admin'])
@Operation.put('vendorID', 'id')
Future<Response> updateCouponByIDByVendorID(
......@@ -60,7 +97,7 @@ class CouponController extends ResourceController {
}
final now = DateTime.now().toUtc();
final updateMetadata = Query<MetadataCoupon>(context)
final updateMetadata = Query<CouponMetadata>(context)
..where((x) => x.coupon.id).equalTo(id)
..values.changedAt = now;
......@@ -87,53 +124,14 @@ class CouponController extends ResourceController {
return Response.accepted();
}
@Scope(['admin'])
@Operation.post('vendorID')
Future<Response> insertCouponByIDByVendorID(
@Bind.path('vendorID') int vendorID) async {
if (request.body.isEmpty) {
return Response.badRequest();
}
final now = DateTime.now();
final vendorQuery = Query<Vendor>(context)
..where((v) => v.id).equalTo(vendorID);
final vendor = await vendorQuery.fetchOne();
if (vendor == null) {
return Response.badRequest();
}
final coupon = Coupon()
..read(await request.body.decode(), ignore: ['id', 'vendor'])
..vendor = vendor;
final query = Query<Coupon>(context)..values = coupon;
final insertedCoupon = await query.insert();
if (insertedCoupon == null) {
return Response.serverError();
}
final metadata = Query<MetadataCoupon>(context)
..values.changedAt = now
..values.createdAt = now
..values.coupon = insertedCoupon;
final insertedMetadata = metadata.insert();
if (insertedMetadata == null) {
return Response.serverError();
}
return Response.ok(insertedCoupon);
}
@override
APIRequestBody documentOperationRequestBody(
APIDocumentContext context, Operation operation) {
if (operation.method == "POST" || operation.method == "PUT") {
return APIRequestBody.schema(context.schema['Coupon']);
} else {
return null;
}
return null;
}
@override
......
......@@ -13,8 +13,8 @@ class StoreController extends ResourceController {
@Operation.get('vendorID')
Future<Response> getAllStoresByVendorID(@Bind.path('vendorID') int vendorid,
{@Bind.query('name') String name}) async {
final storeQuery = Query<Store>(context);
storeQuery.where((s) => s.vendor.id).equalTo(vendorid);
final storeQuery = Query<Store>(context)
..where((s) => s.vendor.id).equalTo(vendorid);
if (name != null) {
storeQuery.where((s) => s.name).contains(name, caseSensitive: false);
}
......@@ -29,11 +29,11 @@ class StoreController extends ResourceController {
@Operation.get('vendorID', 'id')
Future<Response> getStoresByIDByVendorID(
@Bind.path('vendorID') int vendorID, @Bind.path('id') int id) async {
final storeQuery = Query<Store>(context);
storeQuery
final query = Query<Store>(context)
..where((s) => s.vendor.id).equalTo(vendorID)
..where((s) => s.id).equalTo(id);
final store = await storeQuery.fetch();
final store = await query.fetch();
if (store == null) {
return Response.notFound();
}
......@@ -48,18 +48,18 @@ class StoreController extends ResourceController {
@Bind.body(ignore: ['id', 'metadataStore', 'vendor']) Store store) async {
final now = DateTime.now().toUtc();
final updateQuery = Query<Store>(context)
final query = Query<Store>(context)
..values = store
..where((x) => x.id).equalTo(id)
..where((x) => x.vendor.id).equalTo(vendorID);
final updateStore = await updateQuery.updateOne();
final updateStore = await query.updateOne();
if (updateStore == null) {
return Response.notFound();
}
final updateMetadataQuery = Query<MetadataStore>(context)
final updateMetadataQuery = Query<StoreMetadata>(context)
..where((x) => x.store.id).equalTo(id)
..values.changedAt = now;
......@@ -116,7 +116,7 @@ class StoreController extends ResourceController {
final insertedStore = await query.insert();
final now = DateTime.now().toUtc();
final accessMetaDataStore = Query<MetadataStore>(context)
final accessMetaDataStore = Query<StoreMetadata>(context)
..values.changedAt = now
..values.createdAt = now
..values.store = insertedStore;
......@@ -133,12 +133,11 @@ class StoreController extends ResourceController {
@override
APIRequestBody documentOperationRequestBody(
APIDocumentContext context, Operation operation) {
if (operation.method == "POST") {
return APIRequestBody.schema(context.schema['Store']);
} else if (operation.method == 'PUT') {
if (operation.method == 'POST' || operation.method == 'POST') {
return APIRequestBody.schema(context.schema['Store']);
} else {
return null;
}
return null;
}
@override
......
......@@ -24,7 +24,6 @@ class VendorController extends ResourceController {
@Operation.get('id')
Future<Response> getVenodorByID(@Bind.path('id') int id) async {
final vendorQuery = Query<Vendor>(context)..where((v) => v.id).equalTo(id);
vendorQuery.join(object: (x) => x.metadataVendor);
final vendor = await vendorQuery.fetch();
if (vendor == null) {
return Response.notFound();
......@@ -48,7 +47,7 @@ class VendorController extends ResourceController {
final now = DateTime.now().toUtc();
final updateMetadataQuery = Query<MetadataVendor>(context)
final updateMetadataQuery = Query<VendorMetadata>(context)
..where((m) => m.vendor.id).equalTo(id)
..values.changedAt = now;
......@@ -88,7 +87,7 @@ class VendorController extends ResourceController {
final insertedVendor = await vendorQuery.insert();
final now = DateTime.now().toUtc();
final accessMetaDataVendorQuery = Query<MetadataVendor>(context)
final accessMetaDataVendorQuery = Query<VendorMetadata>(context)
..values.changedAt = now
..values.createdAt = now
..values.vendor = insertedVendor;
......@@ -112,7 +111,7 @@ class VendorController extends ResourceController {
}
return null;
}
@override
Map<String, APIResponse> documentOperationResponses(
APIDocumentContext context, Operation operation) {
......
......@@ -30,11 +30,17 @@ class _Coupon {
@Relate(#coupons, onDelete: DeleteRule.cascade)
Vendor vendor;
@Column(indexed: true)
DateTime startDate;
@Column(indexed: true)
DateTime expirationDate;
ManagedSet<RedeemedCoupon> usedBy;
ManagedSet<CouponCode> codes;
MetadataCoupon metadataCoupon;
CouponMetadata couponMetadata;
}
class RedeemedCoupon extends ManagedObject<_RedeemedCoupon>
......
......@@ -16,5 +16,5 @@ class _CouponCode {
@Relate(#codes, onDelete: DeleteRule.cascade)
Coupon coupon;
MetadataCouponCode metadataCouponCode;
CouponCodeMetadata couponCodeMetadata;
}
......@@ -5,19 +5,19 @@ import 'coupon_code.dart';
import 'store.dart';
import 'vendor.dart';
class MetadataCouponCode extends ManagedObject<_MetadataCouponCode>
implements _MetadataCouponCode {}
class CouponCodeMetadata extends ManagedObject<_CouponCodeMetadata>
implements _CouponCodeMetadata {}
class _MetadataCouponCode extends _Metadata {
@Relate(#metadataCouponCode, onDelete: DeleteRule.cascade)
class _CouponCodeMetadata extends _Metadata {
@Relate(#couponCodeMetadata, onDelete: DeleteRule.cascade)
CouponCode couponCode;
}
class MetadataCoupon extends ManagedObject<_MetadataCoupon>
implements _MetadataCoupon {}
class CouponMetadata extends ManagedObject<_CouponMetadata>
implements _CouponMetadata {}
class _MetadataCoupon extends _Metadata {
@Relate(#metadataCoupon, onDelete: DeleteRule.cascade)
class _CouponMetadata extends _Metadata {
@Relate(#couponMetadata, onDelete: DeleteRule.cascade)
Coupon coupon;
@Column(indexed: true)
......@@ -27,19 +27,19 @@ class _MetadataCoupon extends _Metadata {
DateTime expirationDate;
}
class MetadataStore extends ManagedObject<StoreMetadata>
implements StoreMetadata {}
class StoreMetadata extends ManagedObject<_StoreMetadata>
implements _StoreMetadata {}
class StoreMetadata extends _Metadata {
@Relate(#metadataStore, onDelete: DeleteRule.cascade)
class _StoreMetadata extends _Metadata {
@Relate(#storeMetadata, onDelete: DeleteRule.cascade)
Store store;
}
class MetadataVendor extends ManagedObject<_MetadataVendor>
implements _MetadataVendor {}
class VendorMetadata extends ManagedObject<_VendorMetadata>
implements _VendorMetadata {}
class _MetadataVendor extends _Metadata {
@Relate(#metadataVendor, onDelete: DeleteRule.cascade)
class _VendorMetadata extends _Metadata {
@Relate(#vendorMetadata, onDelete: DeleteRule.cascade)
Vendor vendor;
}
......
......@@ -16,5 +16,5 @@ class _Store {
@Column(nullable: true)
Document properties;
MetadataStore metadataStore;
StoreMetadata storeMetadata;
}
......@@ -19,5 +19,5 @@ class _Vendor {
ManagedSet<Store> stores;
MetadataVendor metadataVendor;
VendorMetadata vendorMetadata;
}
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment