Skip to content

Commit

Permalink
refactor: Format cds files
Browse files Browse the repository at this point in the history
  • Loading branch information
alahyaoui committed Feb 12, 2024
1 parent 637601e commit 535ee4f
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 97 deletions.
55 changes: 28 additions & 27 deletions db/common.cds
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
namespace company.project.common;

using {
sap,
cuid,
managed,
temporal,
Currency,
Language,
Country,
sap.common.CodeList as CodeList,
sap,
cuid,
managed,
temporal,
Currency,
Language,
Country,
sap.common.CodeList as CodeList,
} from '@sap/cds/common';

/**
* Entities are structured types with named and typed elements, representing sets of (persisted) data that can be read and manipulated using usual CRUD operations.
* Entities are structured types with named and typed elements, representing sets of (persisted) data that can be read and manipulated using usual CRUD operations.
* They usually contain one or more designated primary key elements.
*
*
* source: https://cap.cloud.sap/docs/cds/cdl#entity-definitions-%E2%80%94-define-entity
*/

// ------------------------------------------------------------------------------------
// Entities
// ------------------------------------------------------------------------------------

entity SampleCommonEntity: cuid, managed, temporal {
propertyString: String;
entity SampleCommonEntity : cuid, managed, temporal {
propertyString : String;
}

/**
* CDS's aspects allow to flexibly extend definitions by new elements as well as overriding properties and annotations.
* They're based on a mixin approach as known from Aspect-oriented Programming methods.
*
*
* source: https://cap.cloud.sap/docs/cds/cdl#aspects
*/

Expand All @@ -38,44 +38,45 @@ entity SampleCommonEntity: cuid, managed, temporal {
// ------------------------------------------------------------------------------------

aspect SampleAspect1 {
propertyString: String;
propertyInteger: Integer;
propertyString : String;
propertyInteger : Integer;
}

aspect SampleAspect2: managed, temporal {
propertyString: String;
propertyInteger: Integer;
aspect SampleAspect2 : managed, temporal {
propertyString : String;
propertyInteger : Integer;
}

/**
* You can declare custom types to reuse later on, for example, for elements in entity definitions.
* You can declare custom types to reuse later on, for example, for elements in entity definitions.
* Custom-defined types can be simple, that is derived from one of the predefined types, structure types or Associations.
*
*
* source: https://cap.cloud.sap/docs/cds/cdl#type-definitions-%E2%80%94-define-type
*/

// ------------------------------------------------------------------------------------
// Types
// ------------------------------------------------------------------------------------

type SampleStringType : String(255);

type SampleStringType : String(255);
type SampleAssociationType : Association to SampleCommonEntity;

type SampleStructuredType {
decimalProperty : Decimal(10,3);
currencyProperty : Currency;
decimalProperty : Decimal(10, 3);
currencyProperty : Currency;
}

type SampleArrayedType : array of { property: String; }
type SampleArrayedType : array of {
property : String;
}

type SampleCodeListType : Association to SampleCodeList;
type SampleCodeListType : Association to SampleCodeList;

// ------------------------------------------------------------------------------------
// Code Lists
// ------------------------------------------------------------------------------------

@cds.odata.valuelist
entity SampleCodeList : CodeList {
key code : String(20);
key code : String(20);
}
74 changes: 37 additions & 37 deletions db/schema.cds
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
namespace company.project.db;

using {
sap,
cuid
sap,
cuid
} from '@sap/cds/common';

using {
company.project.common.SampleAspect1,
company.project.common.SampleAspect2,
company.project.common.SampleCommonEntity,
company.project.common.SampleAssociationType,
company.project.common.SampleArrayedType,
company.project.common.SampleCodeListType,
company.project.common.SampleAspect1,
company.project.common.SampleAspect2,
company.project.common.SampleCommonEntity,
company.project.common.SampleAssociationType,
company.project.common.SampleArrayedType,
company.project.common.SampleCodeListType,
} from '../db/common';


entity SampleEntity : cuid, SampleAspect1 {

//======================================================================//
// Built-in Types (https://cap.cloud.sap/docs/cds/types#built-in-types) //
//======================================================================//
//======================================================================//
// Built-in Types (https://cap.cloud.sap/docs/cds/types#built-in-types) //
//======================================================================//

sampleUUID : UUID; // an opaque string | example: 'be071623-8699-4106-...' | sql: NVARCHAR(36)
sampleUUID : UUID; // an opaque string | example: 'be071623-8699-4106-...' | sql: NVARCHAR(36)

sampleBoolean : Boolean; // a boolean | example: true or false | sql: BOOLEAN
sampleBoolean : Boolean; // a boolean | example: true or false | sql: BOOLEAN

sampleUInt8 : UInt8; // an unsigned integer number stored with 8 bit | example: 0 to 255 | sql: TINYINT
sampleUInt8 : UInt8; // an unsigned integer number stored with 8 bit | example: 0 to 255 | sql: TINYINT

sampleInt16 : Int16; // an integer number stored with 16 bit | example: -32768 to 32767 | sql: SMALLINT
sampleInt16 : Int16; // an integer number stored with 16 bit | example: -32768 to 32767 | sql: SMALLINT

sampleInt32 : Int32; // an integer number stored with 32 bit | example: -2,147,483,648 to 2,147,483,647 | sql: INTEGER
sampleInt32 : Int32; // an integer number stored with 32 bit | example: -2,147,483,648 to 2,147,483,647 | sql: INTEGER

sampleInteger : Integer; // same as previous
sampleInteger : Integer; // same as previous

sampleInt64 : Int64; // an integer number stored with 64 bit | example: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | sql: BIGINT
sampleInt64 : Int64; // an integer number stored with 64 bit | example: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | sql: BIGINT

sampleInteger64 : Integer64; // same as previous
sampleInteger64 : Integer64; // same as previous

sampleDecimal : Decimal(10, 2); // a decimal number, usage -> 'Decimal(precision, scale)' | example: 15.2 | sql: DECIMAL
sampleDecimal : Decimal(10, 2); // a decimal number, usage -> 'Decimal(precision, scale)' | example: 15.2 | sql: DECIMAL

sampleDouble : Double; // a double number | example: DOUBLE 2.2250738585072014E-308 to 1.79769313486231570e+308d | sql: DOUBLE
sampleDouble : Double; // a double number | example: DOUBLE 2.2250738585072014E-308 to 1.79769313486231570e+308d | sql: DOUBLE

sampleDate : Date; // a date | example: '2021-06-27' | sql: DATE
sampleDate : Date; // a date | example: '2021-06-27' | sql: DATE

sampleTime : Time; // a time | example: '07:59:59' | sql: TIME
sampleTime : Time; // a time | example: '07:59:59' | sql: TIME

sampleDateTime : DateTime; // a Timestamp with second precision | example: '2021-06-27T14:52:23Z' | sql: TIMESTAMP
sampleDateTime : DateTime; // a Timestamp with second precision | example: '2021-06-27T14:52:23Z' | sql: TIMESTAMP

sampleTimestamp : Timestamp; // a Timestamp with µs precision | example: '2021-06-27T14:52:23.123Z' | sql: TIMESTAMP
sampleTimestamp : Timestamp; // a Timestamp with µs precision | example: '2021-06-27T14:52:23.123Z' | sql: TIMESTAMP

sampleString : String; // a String, usage -> 'String(length)' or 'String' for default length of 5000 (HANA) or 255 (Others) | example: 'hello world' | sql: NVARCHAR
sampleString : String; // a String, usage -> 'String(length)' or 'String' for default length of 5000 (HANA) or 255 (Others) | example: 'hello world' | sql: NVARCHAR

sampleBinary : Binary; // a String used to store binary data, usage | example: '0001 1100 1011 0101...' | sql: VARBINARY
sampleBinary : Binary; // a String used to store binary data, usage | example: '0001 1100 1011 0101...' | sql: VARBINARY

sampleLargeBinary : LargeBinary; // a String used to store BLOBs | example: '0001 1100 1011 0101...' | sql: BLOB
sampleLargeBinary : LargeBinary; // a String used to store BLOBs | example: '0001 1100 1011 0101...' | sql: BLOB

sampleLargeString : LargeString; // a Large String | example: 'Lorem Ipsum...' | sql: NCLOB
sampleLargeString : LargeString; // a Large String | example: 'Lorem Ipsum...' | sql: NCLOB

//=====================================================//
// My own defined entities, aspects, types, code lists //
//=====================================================//
//=====================================================//
// My own defined entities, aspects, types, code lists //
//=====================================================//

sampleCommonEntity : Association to one SampleCommonEntity;
SampleAspect2 : Composition of one SampleAspect2;
sampleAssociationType : SampleAssociationType;
sampleArrayedType : SampleArrayedType;
sampleCodeList : SampleCodeListType;
sampleCommonEntity : Association to one SampleCommonEntity;
SampleAspect2 : Composition of one SampleAspect2;
sampleAssociationType : SampleAssociationType;
sampleArrayedType : SampleArrayedType;
sampleCodeList : SampleCodeListType;
}
16 changes: 8 additions & 8 deletions srv/sample-service-auth.cds
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ using {company.project.service.SampleService} from './sample-service';

annotate SampleService with @(requires: 'authenticated-user');

annotate SampleService.SampleView with
@restrict: [{grant: [
'READ',
'CREATE',
'UPDATE'
]}];
annotate SampleService.SampleView with
@restrict: [{grant: [
'READ',
'CREATE',
'UPDATE'
]}];

annotate SampleService.SampleReadOnlyView with
@(restrict: [{grant: ['READ']}]);
annotate SampleService.SampleReadOnlyView with
@(restrict: [{grant: ['READ']}]);
16 changes: 8 additions & 8 deletions srv/sample-service-capabilities.cds
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using {company.project.service.SampleService} from './sample-service';

annotate SampleService.SampleView with {
sampleBinary @readonly;
sampleLargeBinary @readonly;
sampleLargeString @readonly;
sampleBinary @readonly;
sampleLargeBinary @readonly;
sampleLargeString @readonly;
};

annotate SampleService.SampleView with @Capabilities : {
InsertRestrictions.Insertable : true,
UpdateRestrictions.Updatable : true,
DeleteRestrictions.Deletable : false
};
annotate SampleService.SampleView with @Capabilities: {
InsertRestrictions.Insertable: true,
UpdateRestrictions.Updatable : true,
DeleteRestrictions.Deletable : false
};
43 changes: 26 additions & 17 deletions srv/sample-service.cds
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,35 @@ namespace company.project.service;

using {company.project.db as db} from '../db/schema';

@impl : './handlers/sample-service-handler'
@impl: './handlers/sample-service-handler'
service SampleService @(path: 'sample') {

entity SampleView as projection on db.SampleEntity {
*
} excluding {
sampleUUID,
entity SampleView as
projection on db.SampleEntity {
*
}
excluding {
sampleUUID,
} actions {
action sampleAction ( id: UUID, bool: Boolean );
action sampleAction(id : UUID, bool : Boolean);
}

@readonly
entity SampleReadOnlyView as projection on db.SampleEntity {
sampleUUID,
sampleUInt8,
sampleBoolean
}
where sampleBoolean = true
group by sampleUUID
order By sampleUInt8
@readonly
entity SampleReadOnlyView as
projection on db.SampleEntity {
sampleUUID,
sampleUInt8,
sampleBoolean
}
where
sampleBoolean = true
group by
sampleUUID
order by
sampleUInt8

event SampleEvent: { id: UUID; bool: Boolean };
}
event SampleEvent : {
id : UUID;
bool : Boolean
};
}

0 comments on commit 535ee4f

Please sign in to comment.