generated from VLADIMIR/template
fix signup route and add create users table migration
This commit is contained in:
+2
-1
@@ -21,6 +21,7 @@ service EveningDetectiveServer {
|
|||||||
rpc Signup(SignupReq) returns (SignupRsp) {
|
rpc Signup(SignupReq) returns (SignupRsp) {
|
||||||
option (google.api.http) = {
|
option (google.api.http) = {
|
||||||
post: "/api/signup"
|
post: "/api/signup"
|
||||||
|
body: "*"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,7 +39,7 @@ message EchoRsp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message SignupReq {
|
message SignupReq {
|
||||||
string name = 1;
|
string username = 1;
|
||||||
string email = 2;
|
string email = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,16 +87,12 @@
|
|||||||
},
|
},
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"name": "name",
|
"name": "body",
|
||||||
"in": "query",
|
"in": "body",
|
||||||
"required": false,
|
"required": true,
|
||||||
"type": "string"
|
"schema": {
|
||||||
},
|
"$ref": "#/definitions/evening_detective_serverSignupReq"
|
||||||
{
|
}
|
||||||
"name": "email",
|
|
||||||
"in": "query",
|
|
||||||
"required": false,
|
|
||||||
"type": "string"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
@@ -117,6 +113,17 @@
|
|||||||
"evening_detective_serverPingRsp": {
|
"evening_detective_serverPingRsp": {
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
|
"evening_detective_serverSignupReq": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"username": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"email": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"evening_detective_serverSignupRsp": {
|
"evening_detective_serverSignupRsp": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
-- +goose Up
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
username VARCHAR(50) NOT NULL UNIQUE,
|
||||||
|
email VARCHAR(100) NOT NULL UNIQUE,
|
||||||
|
password_hash VARCHAR(255) NOT NULL,
|
||||||
|
role VARCHAR(20) DEFAULT 'user' CHECK (role IN ('admin', 'author', 'organizer', 'user')),
|
||||||
|
is_active BOOLEAN DEFAULT TRUE,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
DROP TABLE IF EXISTS users;
|
||||||
+9
-9
@@ -184,7 +184,7 @@ func (x *EchoRsp) GetText() string {
|
|||||||
|
|
||||||
type SignupReq struct {
|
type SignupReq struct {
|
||||||
state protoimpl.MessageState `protogen:"open.v1"`
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
|
Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
|
||||||
Email string `protobuf:"bytes,2,opt,name=email,proto3" json:"email,omitempty"`
|
Email string `protobuf:"bytes,2,opt,name=email,proto3" json:"email,omitempty"`
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
@@ -220,9 +220,9 @@ func (*SignupReq) Descriptor() ([]byte, []int) {
|
|||||||
return file_main_proto_rawDescGZIP(), []int{4}
|
return file_main_proto_rawDescGZIP(), []int{4}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *SignupReq) GetName() string {
|
func (x *SignupReq) GetUsername() string {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
return x.Name
|
return x.Username
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -289,16 +289,16 @@ const file_main_proto_rawDesc = "" +
|
|||||||
"\aEchoReq\x12\x12\n" +
|
"\aEchoReq\x12\x12\n" +
|
||||||
"\x04text\x18\x01 \x01(\tR\x04text\"\x1d\n" +
|
"\x04text\x18\x01 \x01(\tR\x04text\"\x1d\n" +
|
||||||
"\aEchoRsp\x12\x12\n" +
|
"\aEchoRsp\x12\x12\n" +
|
||||||
"\x04text\x18\x01 \x01(\tR\x04text\"5\n" +
|
"\x04text\x18\x01 \x01(\tR\x04text\"=\n" +
|
||||||
"\tSignupReq\x12\x12\n" +
|
"\tSignupReq\x12\x1a\n" +
|
||||||
"\x04name\x18\x01 \x01(\tR\x04name\x12\x14\n" +
|
"\busername\x18\x01 \x01(\tR\busername\x12\x14\n" +
|
||||||
"\x05email\x18\x02 \x01(\tR\x05email\"!\n" +
|
"\x05email\x18\x02 \x01(\tR\x05email\"!\n" +
|
||||||
"\tSignupRsp\x12\x14\n" +
|
"\tSignupRsp\x12\x14\n" +
|
||||||
"\x05error\x18\x01 \x01(\tR\x05error2\xe7\x02\n" +
|
"\x05error\x18\x01 \x01(\tR\x05error2\xea\x02\n" +
|
||||||
"\x16EveningDetectiveServer\x12k\n" +
|
"\x16EveningDetectiveServer\x12k\n" +
|
||||||
"\x04Ping\x12'.crabs.evening_detective_server.PingReq\x1a'.crabs.evening_detective_server.PingRsp\"\x11\x82\xd3\xe4\x93\x02\v\x12\t/api/ping\x12k\n" +
|
"\x04Ping\x12'.crabs.evening_detective_server.PingReq\x1a'.crabs.evening_detective_server.PingRsp\"\x11\x82\xd3\xe4\x93\x02\v\x12\t/api/ping\x12k\n" +
|
||||||
"\x04Echo\x12'.crabs.evening_detective_server.EchoReq\x1a'.crabs.evening_detective_server.EchoRsp\"\x11\x82\xd3\xe4\x93\x02\v\"\t/api/echo\x12s\n" +
|
"\x04Echo\x12'.crabs.evening_detective_server.EchoReq\x1a'.crabs.evening_detective_server.EchoRsp\"\x11\x82\xd3\xe4\x93\x02\v\"\t/api/echo\x12v\n" +
|
||||||
"\x06Signup\x12).crabs.evening_detective_server.SignupReq\x1a).crabs.evening_detective_server.SignupRsp\"\x13\x82\xd3\xe4\x93\x02\r\"\v/api/signupB\vZ\tpkg/protob\x06proto3"
|
"\x06Signup\x12).crabs.evening_detective_server.SignupReq\x1a).crabs.evening_detective_server.SignupRsp\"\x16\x82\xd3\xe4\x93\x02\x10:\x01*\"\v/api/signupB\vZ\tpkg/protob\x06proto3"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
file_main_proto_rawDescOnce sync.Once
|
file_main_proto_rawDescOnce sync.Once
|
||||||
|
|||||||
+4
-12
@@ -91,22 +91,17 @@ func local_request_EveningDetectiveServer_Echo_0(ctx context.Context, marshaler
|
|||||||
return msg, metadata, err
|
return msg, metadata, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var filter_EveningDetectiveServer_Signup_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
|
||||||
|
|
||||||
func request_EveningDetectiveServer_Signup_0(ctx context.Context, marshaler runtime.Marshaler, client EveningDetectiveServerClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
func request_EveningDetectiveServer_Signup_0(ctx context.Context, marshaler runtime.Marshaler, client EveningDetectiveServerClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||||
var (
|
var (
|
||||||
protoReq SignupReq
|
protoReq SignupReq
|
||||||
metadata runtime.ServerMetadata
|
metadata runtime.ServerMetadata
|
||||||
)
|
)
|
||||||
|
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
|
||||||
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
|
}
|
||||||
if req.Body != nil {
|
if req.Body != nil {
|
||||||
_, _ = io.Copy(io.Discard, req.Body)
|
_, _ = io.Copy(io.Discard, req.Body)
|
||||||
}
|
}
|
||||||
if err := req.ParseForm(); err != nil {
|
|
||||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
|
||||||
}
|
|
||||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_EveningDetectiveServer_Signup_0); err != nil {
|
|
||||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
|
||||||
}
|
|
||||||
msg, err := client.Signup(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
msg, err := client.Signup(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||||
return msg, metadata, err
|
return msg, metadata, err
|
||||||
}
|
}
|
||||||
@@ -116,10 +111,7 @@ func local_request_EveningDetectiveServer_Signup_0(ctx context.Context, marshale
|
|||||||
protoReq SignupReq
|
protoReq SignupReq
|
||||||
metadata runtime.ServerMetadata
|
metadata runtime.ServerMetadata
|
||||||
)
|
)
|
||||||
if err := req.ParseForm(); err != nil {
|
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && !errors.Is(err, io.EOF) {
|
||||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
|
||||||
}
|
|
||||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_EveningDetectiveServer_Signup_0); err != nil {
|
|
||||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||||
}
|
}
|
||||||
msg, err := server.Signup(ctx, &protoReq)
|
msg, err := server.Signup(ctx, &protoReq)
|
||||||
|
|||||||
Reference in New Issue
Block a user