Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ace Nassri committed Jun 22, 2018
1 parent a1b141d commit 28a6fbb
Show file tree
Hide file tree
Showing 9 changed files with 1,260 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/currencyservice/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
1 change: 1 addition & 0 deletions src/currencyservice/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
7 changes: 7 additions & 0 deletions src/currencyservice/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --only=production
COPY . .
EXPOSE 31337
CMD [ "node", "server.js" ]
47 changes: 47 additions & 0 deletions src/currencyservice/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

const path = require('path');
const grpc = require('grpc');

const PROTO_PATH = path.join(__dirname, './proto/currency_service.proto');
const PORT = 31337;

const shopProto = grpc.load(PROTO_PATH).hipstershop;
const client = new shopProto.CurrencyService(`localhost:${PORT}`,
grpc.credentials.createInsecure());

const request = {
from: {
currency_code: 'USD',
amount: {
decimal: 300,
fractional: 0
}
},
to_code: 'CHF'
};

client.convert(request, function (err, response) {
if (err) {
console.error(err);
} else {
const amount = response.amount;
console.log(`OUTPUT: ${amount.decimal}.${amount.fractional}`);
}
});
29 changes: 29 additions & 0 deletions src/currencyservice/currency_service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
syntax = "proto3";
package hipstershop;

message Empty {}

service CurrencyService {
rpc GetSupportedCurrencies(Empty) returns (GetSupportedCurrenciesResponse) {}
rpc Convert(CurrencyConversionRequest) returns (Money) {}
}
// Describes a money amount without currency. For example, decimal=2 and
// fractional=500 (or fractional=5) makes up 2.5 units.
message MoneyAmount {
uint32 decimal = 1;
uint32 fractional = 2;
}
message Money {
// The 3-letter currency code defined in ISO 4217.
string currency_code = 1;
MoneyAmount amount = 2;
}
message GetSupportedCurrenciesResponse {
// The 3-letter currency code defined in ISO 4217.
repeated string currency_codes = 1;
}
message CurrencyConversionRequest {
Money from = 1;
// The 3-letter currency code defined in ISO 4217.
string to_code = 2;
}
Loading

0 comments on commit 28a6fbb

Please sign in to comment.