-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.proto
107 lines (99 loc) · 3.47 KB
/
service.proto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// service
syntax = "proto3";
// Import entity proto.
import "proto/entity.proto";
// Import https://github.com/bufbuild/protoc-gen-validate.
import "validate/validate.proto";
// Import https://protobuf.dev/reference/protobuf/google.protobuf/#timestamp.
import "google/protobuf/timestamp.proto";
// Import https://github.com/googleapis/googleapis/blob/master/google/api/annotations.proto.
import "google/api/annotations.proto";
// Import https://github.com/grpc-ecosystem/grpc-gateway/blob/main/protoc-gen-openapiv2/options/annotations.proto.
import "protoc-gen-openapiv2/options/annotations.proto";
// Target of Go package.
option go_package = "github.com/moemoe89/btc/api/go/grpc";
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
info: {
title: "BTC Service";
version: "0.1";
};
host: "localhost:8081";
schemes: HTTP;
consumes: "application/json";
responses: {
key: "400";
value: {
description: "Returned when the request parameters are invalid.";
}
};
responses: {
key: "401";
value: {
description: "Returned when the request lacks valid authentication credentials.";
}
};
responses: {
key: "403";
value: {
description: "Returned when the user does not have permission to access the resource.";
}
};
responses: {
key: "500";
value: {
description: "Returned when the server encountered an unexpected condition that prevented it from fulfilling the request.";
}
};
};
// BTCService is a service that handles BTC data.
service BTCService {
// CreateTransaction creates a new record for BTC transaction.
// Only single transaction will create by this RPC for a specific User.
rpc CreateTransaction(CreateTransactionRequest) returns (e.Transaction) {
option (google.api.http) = {
post: "/v1/transaction",
body: "*",
};
}
// ListTransaction get the list of records for BTC transaction.
// The record can be filtered by specific User.
rpc ListTransaction(ListTransactionRequest) returns (ListTransactionResponse) {
option (google.api.http) = {
get: "/v1/transaction",
};
}
// GetUserBalance get the latest balance for a specific User.
rpc GetUserBalance(GetUserBalanceRequest) returns (e.UserBalance) {
option (google.api.http) = {
get: "/v1/user/balance",
};
}
}
// CreateTransactionRequest
message CreateTransactionRequest {
// (Required) The ID of User.
int64 user_id = 1 [(validate.rules).int64.gte = 1];
// (Required) The date and time of the created transaction.
google.protobuf.Timestamp datetime = 2 [(validate.rules).timestamp.required = true];
// (Required) The amount of the transaction, should not be 0.
double amount = 3 [(validate.rules).double = {gte: 0.1, lte: -0.1}];
}
// ListTransactionRequest
message ListTransactionRequest {
// (Required) The ID of User.
int64 user_id = 1 [(validate.rules).int64.gte = 1];
// (Required) The start date and time filter of the transactions.
google.protobuf.Timestamp start_datetime = 2 [(validate.rules).timestamp.required = true];
// (Required) The end date and time filter of the transactions.
google.protobuf.Timestamp end_datetime = 3 [(validate.rules).timestamp.required = true];
}
// ListTransactionResponse
message ListTransactionResponse {
// The list of Transactions.
repeated e.Transaction transactions = 1;
}
// GetUserBalanceRequest
message GetUserBalanceRequest {
// (Required) The ID of User.
int64 user_id = 1 [(validate.rules).int64.gte = 1];
}