github.com/s7techlab/cckit@v0.10.5/examples/fabcar/README.md (about)

     1  # Fabcar CCkit Chaincode
     2  
     3  Fabcar CCkit is modification of Hyperledger fabric-samples [fabcar chaincode](https://github.com/hyperledger/fabric-samples/blob/main/chaincode/fabcar/go/fabcar.go)
     4  
     5  Fabcar Hyperledger Fabric Chaincode (FHF) short description:
     6  1) FHF is made without code generating
     7  2) At FHF you can create cat at once with method 'CreateCar'. Payload example:
     8  ```json
     9  {
    10    "car_number": "CAR1",
    11    "make": "Toyota",
    12    "model": "Prius",
    13    "colour": "blue",
    14    "owner": "Tomoko"
    15  }
    16  ```
    17  
    18  2) Then you can get car with method 'QueryCar'. Payload example:
    19  ```json
    20  {
    21    "car_number": "CAR1"
    22  }
    23  ```
    24  
    25  3) Or get all cars with method 'QueryAllCars' without payload
    26  
    27  4) Last method is 'ChangeCarOwner' to change car owner. Payload example:
    28  ```json
    29  {
    30    "car_number": "CAR1",
    31    "new_owner": "Brad"
    32  }
    33  ```
    34  
    35  
    36  
    37  Fabcar CCkit Chaincode (FCk) has four entities: Maker, Car, Owner and Detail.
    38  FCk has some difference from FHF:
    39  1) FCk gateway was generated with [proto](./fabcar.proto)
    40  2) You can not create car at once, because before car's maker have to be created and put at BC state. Chaincode state stored as serialized protobuf
    41     Use method 'CreateMaker', payload example:
    42  ```json
    43  {
    44    "name": "Toyota",
    45    "country": "Japan",
    46    "foundation_year,omitempty": "1937" // it must be more than 1886, because this year was founded the oldest automaker - Mercedes-Benz
    47  }
    48  ```
    49  
    50  2) You can get (method 'GetMaker') or delete (method 'DeleteMaker') maker by its name. For example:
    51  ```json
    52  {
    53    "name": "Toyota"
    54  }
    55  ```
    56  
    57  3) And get all cars with method 'ListMakers' without payload
    58  
    59  4) Now your car can be created with 'CreateCar' method, for example:
    60  ```json
    61  {
    62    "make": "Toyota", // if maker is not created programm will return error
    63    "model": "Prius",
    64    "colour": "blue",
    65    "number": 111111,
    66    "owners": [
    67      {
    68        "first_name": "Tomoko",
    69        "second_name": "Uemura",
    70        "vehicle_passport": "bbb222"
    71      }
    72    ],
    73    "details": [
    74      {
    75        "type": WHEELS,
    76        "make": "Michelin"
    77      },
    78      {
    79        "type": BATTERY,
    80        "make": "BYD"
    81      }
    82    ]
    83  }
    84  ```
    85  
    86  The response is:
    87  ```json
    88  {
    89    "car": {
    90      "id": ["Toyota", "Prius", "111111"],
    91      "make": "",
    92      "model": "Prius",
    93      "colour": "blue",
    94      "number": 111111,
    95      "owners_quantity": 1
    96    },
    97    "owners": {
    98      "items": [
    99        {
   100          "car_id": ["Toyota", "Prius", "111111"],
   101          "first_name": "Tomoko",
   102          "second_name": "Uemura",
   103          "vehicle_passport": "bbb222"
   104        }
   105      ]
   106    },
   107    "details": {
   108      "items": [
   109        {
   110          "car_id": ["Toyota", "Prius", "111111"],
   111          "type": WHEELS,
   112          "make": "Michelin"
   113        },
   114        {
   115          "car_id": ["Toyota", "Prius", "111111"],
   116          "type": BATTERY,
   117          "make": "BYD"
   118        }
   119      ]
   120    }
   121  }
   122  ```
   123  
   124  5) Car updating makes with 'UpdateCar', payload:
   125  ```json
   126  {
   127    "id": ["Toyota", "Prius", "111111"],
   128    "color": "red",
   129    "owners": [
   130      {
   131        "car_id": ["Toyota", "Prius", "111111"],
   132        "first_name": "Tomoko",
   133        "second_name": "Uemura",
   134        "vehicle_passport": "ccc333"
   135      },
   136      {
   137        "car_id": ["Toyota", "Prius", "111111"],
   138        "first_name": "Michel",
   139        "second_name": "Uemura",
   140        "vehicle_passport": "ddd444"
   141      }
   142    ],
   143    "details": [
   144      {
   145        "car_id": ["Toyota", "Prius", "111111"],
   146        "type": BATTERY,
   147        "make": "Panasonic"
   148      }
   149    ]
   150  }
   151  ```
   152  
   153  The response is:
   154  ```json
   155  {
   156    "car": {
   157      "id": ["Toyota", "Prius", "111111"],
   158      "make": "",
   159      "model": "Prius",
   160      "colour": "red", // it was 'blue'
   161      "number": 111111,
   162      "owners_quantity": 2 // become more
   163    },
   164    "owners": {
   165      "items": [ // become more
   166        {
   167          "car_id": ["Toyota", "Prius", "111111"],
   168          "first_name": "Tomoko",
   169          "second_name": "Uemura",
   170          "vehicle_passport": "ccc333" // it was 'bbb222'
   171        },
   172        { // it was added
   173          "car_id": ["Toyota", "Prius", "111111"],
   174          "first_name": "Michel",
   175          "second_name": "Tailor",
   176          "vehicle_passport": "ddd444"
   177        }
   178      ]
   179    },
   180    "details": {
   181      "items": [
   182        {
   183          "car_id": ["Toyota", "Prius", "111111"],
   184          "type": WHEELS,
   185          "make": "Michelin"
   186        },
   187        {
   188          "car_id": ["Toyota", "Prius", "111111"],
   189          "type": BATTERY,
   190          "make": "Panasonic" // it was 'BYD'
   191        }
   192      ]
   193    }
   194  }
   195  ```
   196  
   197  6) Also, you can delete car with 'DeleteCar', the response is like from 'UpdateCar' method (point 5)
   198  
   199  7) If you would like to get car, use 'GetCar' to get it without owners and details or 'GetCarView' with them. Request:
   200  ```json
   201  {
   202    "id": ["Toyota", "Prius", "111111"]
   203  }
   204  ```
   205  
   206  8) To get all cars use 'ListCars' without payload
   207  
   208  9) Also, car owner can be updated without car changing ('UpdateCarOwners' method):
   209  ```json
   210  {
   211    "car_id": ["Toyota", "Prius", "111111"],
   212    "owners": [
   213      {
   214        "first_name": "Tomoko",
   215        "second_name": "Uemura",
   216        "vehicle_passport": "eee555"
   217      },
   218      {
   219        "first_name": "Adriana",
   220        "second_name": "Grande",
   221        "vehicle_passport": "fff666"
   222      }
   223    ]
   224  }
   225  ```
   226  
   227  The response:
   228  ```json
   229  {
   230    "items": [
   231      {
   232        "car_id": ["Toyota", "Prius", "111111"],
   233        "first_name": "Tomoko",
   234        "second_name": "Uemura",
   235        "vehicle_passport": "eee555" // it was 'ccc333'
   236      },
   237      { // without changes
   238        "car_id": ["Toyota", "Prius", "111111"],
   239        "first_name": "Michel",
   240        "second_name": "Uemura",
   241        "vehicle_passport": "ddd444"
   242      },
   243      { // was added
   244        "car_id": ["Toyota", "Prius", "111111"],
   245        "first_name": "Adriana",
   246        "second_name": "Grande",
   247        "vehicle_passport": "fff666"
   248      }
   249    ]
   250  }
   251  ```
   252  
   253  10) To delete ('DeleteCarOwner') or get ('GetCarOwner') car owner use the same payload:
   254  ```json
   255  {
   256    "car_id": ["Toyota", "Prius", "111111"],
   257    "first_name": "Tomoko",
   258    "second_name": "Uemura"
   259  }
   260  ```
   261  
   262  11) Also, you can update car detail ('UpdateCarDetails') without car changes, for example:
   263  ```json
   264  {
   265    "car_id": ["Toyota", "Prius", "111111"],
   266    "details": [
   267       {
   268          "type": WHEELS, 
   269          "make": "Michelin"
   270       },
   271       {
   272          "type": BATTERY,
   273          "make": "Contemporary Amperex Technology"
   274       }
   275    ]
   276  }
   277  ```
   278  
   279  The response:
   280  ```json
   281  {
   282     "items": [
   283        { // without changes
   284           "car_id": ["Toyota", "Prius", "111111"],
   285           "type": WHEELS,
   286           "make": "Michelin"
   287        },
   288        {
   289           "car_id": ["Toyota", "Prius", "111111"],
   290           "type": BATTERY,
   291           "make": "Contemporary Amperex Technology" // it was 'Panasonic'
   292        }
   293     ]
   294  }
   295  ```
   296  
   297  12) To delete ('DeleteCarDetail') or get ('GetCarDetail') car owner use the same payload:
   298  ```json
   299  {
   300    "car_id": ["Toyota", "Prius", "111111"],
   301    "type": BATTERY
   302  }
   303  ``` 
   304  
   305  13) And, of course, you can get list of car owners (method 'ListCarOwners') or list of car details (method 'ListCarDetails')
   306      by car id. Use payload:
   307  ```json
   308  {
   309     "id": ["Toyota", "Prius", "111111"] 
   310  }
   311  ```