diff --git a/greataped/components/api/handlers/factory.go b/greataped/components/api/handlers/factory.go index 234e85c..2e0e280 100644 --- a/greataped/components/api/handlers/factory.go +++ b/greataped/components/api/handlers/factory.go @@ -6,10 +6,12 @@ type httpHandlerFactory struct{} func (factory *httpHandlerFactory) Handlers() []IHttpHandler { return []IHttpHandler{ - EchoHandler(), // │ P . /api/v1/echo - SignupHandler(), // │ P . /api/v1/signup - VerifyHandler(), // │ P . /api/v1/verify - LoginHandler(), // │ P . /api/v1/login + EchoHandler(), // │ P . /api/v1/echo + SignupHandler(), // │ P . /api/v1/signup + VerifyHandler(), // │ P . /api/v1/verify + LoginHandler(), // │ P . /api/v1/login + GetProfileByUserHandler(), // │ G . /api/v1/profile + UpdateProfileByUserHandler(), // │ P . /api/v1/profile } } diff --git a/greataped/components/api/handlers/get_profile_by_user_handler.go b/greataped/components/api/handlers/get_profile_by_user_handler.go new file mode 100644 index 0000000..c4a1252 --- /dev/null +++ b/greataped/components/api/handlers/get_profile_by_user_handler.go @@ -0,0 +1,44 @@ +package handlers + +import ( + "net/http" + + . "github.com/xeronith/diamante/contracts/network/http" + pipeline "github.com/xeronith/diamante/network/http" + . "rail.town/infrastructure/components/api/protobuf" + . "rail.town/infrastructure/components/contracts" +) + +type getProfileByUserHandler struct { +} + +func GetProfileByUserHandler() IHttpHandler { + return &getProfileByUserHandler{} +} + +func (handler *getProfileByUserHandler) Method() string { + return http.MethodGet +} + +func (handler *getProfileByUserHandler) Path() string { + return "/api/v1/profile" +} + +func (handler *getProfileByUserHandler) HandlerFunc() HttpHandlerFunc { + return func(x IServerDispatcher) error { + request := &GetProfileByUserRequest{} + result := &GetProfileByUserResult{} + + onRequestUnmarshalled := func(request *GetProfileByUserRequest) { + } + + return pipeline.Handle(x, + "get_profile_by_user", + GET_PROFILE_BY_USER_REQUEST, + GET_PROFILE_BY_USER_RESULT, + request, result, + onRequestUnmarshalled, + false, + ) + } +} diff --git a/greataped/components/api/handlers/update_profile_by_user_handler.go b/greataped/components/api/handlers/update_profile_by_user_handler.go new file mode 100644 index 0000000..b20e06b --- /dev/null +++ b/greataped/components/api/handlers/update_profile_by_user_handler.go @@ -0,0 +1,44 @@ +package handlers + +import ( + "net/http" + + . "github.com/xeronith/diamante/contracts/network/http" + pipeline "github.com/xeronith/diamante/network/http" + . "rail.town/infrastructure/components/api/protobuf" + . "rail.town/infrastructure/components/contracts" +) + +type updateProfileByUserHandler struct { +} + +func UpdateProfileByUserHandler() IHttpHandler { + return &updateProfileByUserHandler{} +} + +func (handler *updateProfileByUserHandler) Method() string { + return http.MethodPost +} + +func (handler *updateProfileByUserHandler) Path() string { + return "/api/v1/profile" +} + +func (handler *updateProfileByUserHandler) HandlerFunc() HttpHandlerFunc { + return func(x IServerDispatcher) error { + request := &UpdateProfileByUserRequest{} + result := &UpdateProfileByUserResult{} + + onRequestUnmarshalled := func(request *UpdateProfileByUserRequest) { + } + + return pipeline.Handle(x, + "update_profile_by_user", + UPDATE_PROFILE_BY_USER_REQUEST, + UPDATE_PROFILE_BY_USER_RESULT, + request, result, + onRequestUnmarshalled, + false, + ) + } +} diff --git a/greataped/components/api/operations/factory.go b/greataped/components/api/operations/factory.go index fc44528..fb347a2 100644 --- a/greataped/components/api/operations/factory.go +++ b/greataped/components/api/operations/factory.go @@ -11,6 +11,8 @@ func (factory *operationFactory) Operations() []IOperation { SignupOperation(), VerifyOperation(), LoginOperation(), + GetProfileByUserOperation(), + UpdateProfileByUserOperation(), } } diff --git a/greataped/components/api/operations/get_profile_by_user_operation.go b/greataped/components/api/operations/get_profile_by_user_operation.go new file mode 100644 index 0000000..a0ab001 --- /dev/null +++ b/greataped/components/api/operations/get_profile_by_user_operation.go @@ -0,0 +1,51 @@ +package operations + +import ( + . "github.com/xeronith/diamante/contracts/operation" + . "github.com/xeronith/diamante/contracts/service" + . "github.com/xeronith/diamante/contracts/system" + . "github.com/xeronith/diamante/operation" + . "rail.town/infrastructure/components/api/protobuf" + . "rail.town/infrastructure/components/api/services" + . "rail.town/infrastructure/components/contracts" +) + +type getProfileByUserOperation struct { + SecureOperation + + run func(IContext, *GetProfileByUserRequest) (*GetProfileByUserResult, error) +} + +func GetProfileByUserOperation() IOperation { + return &getProfileByUserOperation{ + run: GetProfileByUserService, + } +} + +func (operation *getProfileByUserOperation) Id() (ID, ID) { + return GET_PROFILE_BY_USER_REQUEST, GET_PROFILE_BY_USER_RESULT +} + +func (operation *getProfileByUserOperation) InputContainer() Pointer { + return new(GetProfileByUserRequest) +} + +func (operation *getProfileByUserOperation) OutputContainer() Pointer { + return new(GetProfileByUserResult) +} + +func (operation *getProfileByUserOperation) Execute(context IContext, payload Pointer) (Pointer, error) { + return operation.run(context, payload.(*GetProfileByUserRequest)) +} + +/* +func (operation *getProfileByUserOperation) ExecutionTimeLimits() (Duration, Duration, Duration) { + var ( + TIME_LIMIT_WARNING Duration = 20_000_000 + TIME_LIMIT_ALERT Duration = 35_000_000 + TIME_LIMIT_CRITICAL Duration = 50_000_000 + ) + + return TIME_LIMIT_WARNING, TIME_LIMIT_ALERT, TIME_LIMIT_CRITICAL +} +*/ diff --git a/greataped/components/api/operations/update_profile_by_user_operation.go b/greataped/components/api/operations/update_profile_by_user_operation.go new file mode 100644 index 0000000..cc42730 --- /dev/null +++ b/greataped/components/api/operations/update_profile_by_user_operation.go @@ -0,0 +1,51 @@ +package operations + +import ( + . "github.com/xeronith/diamante/contracts/operation" + . "github.com/xeronith/diamante/contracts/service" + . "github.com/xeronith/diamante/contracts/system" + . "github.com/xeronith/diamante/operation" + . "rail.town/infrastructure/components/api/protobuf" + . "rail.town/infrastructure/components/api/services" + . "rail.town/infrastructure/components/contracts" +) + +type updateProfileByUserOperation struct { + SecureOperation + + run func(IContext, *UpdateProfileByUserRequest) (*UpdateProfileByUserResult, error) +} + +func UpdateProfileByUserOperation() IOperation { + return &updateProfileByUserOperation{ + run: UpdateProfileByUserService, + } +} + +func (operation *updateProfileByUserOperation) Id() (ID, ID) { + return UPDATE_PROFILE_BY_USER_REQUEST, UPDATE_PROFILE_BY_USER_RESULT +} + +func (operation *updateProfileByUserOperation) InputContainer() Pointer { + return new(UpdateProfileByUserRequest) +} + +func (operation *updateProfileByUserOperation) OutputContainer() Pointer { + return new(UpdateProfileByUserResult) +} + +func (operation *updateProfileByUserOperation) Execute(context IContext, payload Pointer) (Pointer, error) { + return operation.run(context, payload.(*UpdateProfileByUserRequest)) +} + +/* +func (operation *updateProfileByUserOperation) ExecutionTimeLimits() (Duration, Duration, Duration) { + var ( + TIME_LIMIT_WARNING Duration = 20_000_000 + TIME_LIMIT_ALERT Duration = 35_000_000 + TIME_LIMIT_CRITICAL Duration = 50_000_000 + ) + + return TIME_LIMIT_WARNING, TIME_LIMIT_ALERT, TIME_LIMIT_CRITICAL +} +*/ diff --git a/greataped/components/api/protobuf/spis.pb.go b/greataped/components/api/protobuf/spis.pb.go index da2890c..f3bb4cc 100644 --- a/greataped/components/api/protobuf/spis.pb.go +++ b/greataped/components/api/protobuf/spis.pb.go @@ -547,6 +547,293 @@ func (x *LoginResult) GetToken() string { return "" } +// API: GetProfileByUser +// ----------------------------------------------------------- +type GetProfileByUserRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *GetProfileByUserRequest) Reset() { + *x = GetProfileByUserRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_spis_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetProfileByUserRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetProfileByUserRequest) ProtoMessage() {} + +func (x *GetProfileByUserRequest) ProtoReflect() protoreflect.Message { + mi := &file_spis_proto_msgTypes[10] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetProfileByUserRequest.ProtoReflect.Descriptor instead. +func (*GetProfileByUserRequest) Descriptor() ([]byte, []int) { + return file_spis_proto_rawDescGZIP(), []int{10} +} + +type GetProfileByUserResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` + DisplayName string `protobuf:"bytes,2,opt,name=displayName,proto3" json:"displayName,omitempty"` + Avatar string `protobuf:"bytes,3,opt,name=avatar,proto3" json:"avatar,omitempty"` + Banner string `protobuf:"bytes,4,opt,name=banner,proto3" json:"banner,omitempty"` + Summary string `protobuf:"bytes,5,opt,name=summary,proto3" json:"summary,omitempty"` + Github string `protobuf:"bytes,6,opt,name=github,proto3" json:"github,omitempty"` +} + +func (x *GetProfileByUserResult) Reset() { + *x = GetProfileByUserResult{} + if protoimpl.UnsafeEnabled { + mi := &file_spis_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetProfileByUserResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetProfileByUserResult) ProtoMessage() {} + +func (x *GetProfileByUserResult) ProtoReflect() protoreflect.Message { + mi := &file_spis_proto_msgTypes[11] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetProfileByUserResult.ProtoReflect.Descriptor instead. +func (*GetProfileByUserResult) Descriptor() ([]byte, []int) { + return file_spis_proto_rawDescGZIP(), []int{11} +} + +func (x *GetProfileByUserResult) GetUsername() string { + if x != nil { + return x.Username + } + return "" +} + +func (x *GetProfileByUserResult) GetDisplayName() string { + if x != nil { + return x.DisplayName + } + return "" +} + +func (x *GetProfileByUserResult) GetAvatar() string { + if x != nil { + return x.Avatar + } + return "" +} + +func (x *GetProfileByUserResult) GetBanner() string { + if x != nil { + return x.Banner + } + return "" +} + +func (x *GetProfileByUserResult) GetSummary() string { + if x != nil { + return x.Summary + } + return "" +} + +func (x *GetProfileByUserResult) GetGithub() string { + if x != nil { + return x.Github + } + return "" +} + +// API: UpdateProfileByUser +// ----------------------------------------------------------- +type UpdateProfileByUserRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + DisplayName string `protobuf:"bytes,1,opt,name=displayName,proto3" json:"displayName,omitempty"` + Avatar string `protobuf:"bytes,2,opt,name=avatar,proto3" json:"avatar,omitempty"` + Banner string `protobuf:"bytes,3,opt,name=banner,proto3" json:"banner,omitempty"` + Summary string `protobuf:"bytes,4,opt,name=summary,proto3" json:"summary,omitempty"` + Github string `protobuf:"bytes,5,opt,name=github,proto3" json:"github,omitempty"` +} + +func (x *UpdateProfileByUserRequest) Reset() { + *x = UpdateProfileByUserRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_spis_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateProfileByUserRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateProfileByUserRequest) ProtoMessage() {} + +func (x *UpdateProfileByUserRequest) ProtoReflect() protoreflect.Message { + mi := &file_spis_proto_msgTypes[12] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateProfileByUserRequest.ProtoReflect.Descriptor instead. +func (*UpdateProfileByUserRequest) Descriptor() ([]byte, []int) { + return file_spis_proto_rawDescGZIP(), []int{12} +} + +func (x *UpdateProfileByUserRequest) GetDisplayName() string { + if x != nil { + return x.DisplayName + } + return "" +} + +func (x *UpdateProfileByUserRequest) GetAvatar() string { + if x != nil { + return x.Avatar + } + return "" +} + +func (x *UpdateProfileByUserRequest) GetBanner() string { + if x != nil { + return x.Banner + } + return "" +} + +func (x *UpdateProfileByUserRequest) GetSummary() string { + if x != nil { + return x.Summary + } + return "" +} + +func (x *UpdateProfileByUserRequest) GetGithub() string { + if x != nil { + return x.Github + } + return "" +} + +type UpdateProfileByUserResult struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + DisplayName string `protobuf:"bytes,1,opt,name=displayName,proto3" json:"displayName,omitempty"` + Avatar string `protobuf:"bytes,2,opt,name=avatar,proto3" json:"avatar,omitempty"` + Banner string `protobuf:"bytes,3,opt,name=banner,proto3" json:"banner,omitempty"` + Summary string `protobuf:"bytes,4,opt,name=summary,proto3" json:"summary,omitempty"` + Github string `protobuf:"bytes,5,opt,name=github,proto3" json:"github,omitempty"` +} + +func (x *UpdateProfileByUserResult) Reset() { + *x = UpdateProfileByUserResult{} + if protoimpl.UnsafeEnabled { + mi := &file_spis_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *UpdateProfileByUserResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*UpdateProfileByUserResult) ProtoMessage() {} + +func (x *UpdateProfileByUserResult) ProtoReflect() protoreflect.Message { + mi := &file_spis_proto_msgTypes[13] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use UpdateProfileByUserResult.ProtoReflect.Descriptor instead. +func (*UpdateProfileByUserResult) Descriptor() ([]byte, []int) { + return file_spis_proto_rawDescGZIP(), []int{13} +} + +func (x *UpdateProfileByUserResult) GetDisplayName() string { + if x != nil { + return x.DisplayName + } + return "" +} + +func (x *UpdateProfileByUserResult) GetAvatar() string { + if x != nil { + return x.Avatar + } + return "" +} + +func (x *UpdateProfileByUserResult) GetBanner() string { + if x != nil { + return x.Banner + } + return "" +} + +func (x *UpdateProfileByUserResult) GetSummary() string { + if x != nil { + return x.Summary + } + return "" +} + +func (x *UpdateProfileByUserResult) GetGithub() string { + if x != nil { + return x.Github + } + return "" +} + var File_spis_proto protoreflect.FileDescriptor var file_spis_proto_rawDesc = []byte{ @@ -589,8 +876,42 @@ var file_spis_proto_rawDesc = []byte{ 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x42, 0x04, 0x5a, 0x02, 0x2e, 0x2f, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x19, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x50, + 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x42, 0x79, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x22, 0xb8, 0x01, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x66, 0x69, + 0x6c, 0x65, 0x42, 0x79, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x1a, + 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x69, + 0x73, 0x70, 0x6c, 0x61, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, + 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x76, + 0x61, 0x74, 0x61, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x6e, 0x6e, 0x65, 0x72, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x62, 0x61, 0x6e, 0x6e, 0x65, 0x72, 0x12, 0x18, 0x0a, 0x07, + 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, + 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, + 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x22, 0xa0, + 0x01, 0x0a, 0x1a, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, + 0x42, 0x79, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, + 0x0b, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0b, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x12, + 0x16, 0x0a, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x6e, 0x6e, 0x65, + 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x62, 0x61, 0x6e, 0x6e, 0x65, 0x72, 0x12, + 0x18, 0x0a, 0x07, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x67, 0x69, 0x74, 0x68, 0x75, + 0x62, 0x22, 0x9f, 0x01, 0x0a, 0x19, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x66, + 0x69, 0x6c, 0x65, 0x42, 0x79, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, + 0x20, 0x0a, 0x0b, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x4e, 0x61, 0x6d, + 0x65, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x61, 0x6e, + 0x6e, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x62, 0x61, 0x6e, 0x6e, 0x65, + 0x72, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x42, 0x04, 0x5a, 0x02, 0x2e, 0x2f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -605,23 +926,27 @@ func file_spis_proto_rawDescGZIP() []byte { return file_spis_proto_rawDescData } -var file_spis_proto_msgTypes = make([]protoimpl.MessageInfo, 10) +var file_spis_proto_msgTypes = make([]protoimpl.MessageInfo, 14) var file_spis_proto_goTypes = []interface{}{ - (*SystemCallRequest)(nil), // 0: protobuf.SystemCallRequest - (*SystemCallResult)(nil), // 1: protobuf.SystemCallResult - (*EchoRequest)(nil), // 2: protobuf.EchoRequest - (*EchoResult)(nil), // 3: protobuf.EchoResult - (*SignupRequest)(nil), // 4: protobuf.SignupRequest - (*SignupResult)(nil), // 5: protobuf.SignupResult - (*VerifyRequest)(nil), // 6: protobuf.VerifyRequest - (*VerifyResult)(nil), // 7: protobuf.VerifyResult - (*LoginRequest)(nil), // 8: protobuf.LoginRequest - (*LoginResult)(nil), // 9: protobuf.LoginResult - (*Document)(nil), // 10: protobuf.Document + (*SystemCallRequest)(nil), // 0: protobuf.SystemCallRequest + (*SystemCallResult)(nil), // 1: protobuf.SystemCallResult + (*EchoRequest)(nil), // 2: protobuf.EchoRequest + (*EchoResult)(nil), // 3: protobuf.EchoResult + (*SignupRequest)(nil), // 4: protobuf.SignupRequest + (*SignupResult)(nil), // 5: protobuf.SignupResult + (*VerifyRequest)(nil), // 6: protobuf.VerifyRequest + (*VerifyResult)(nil), // 7: protobuf.VerifyResult + (*LoginRequest)(nil), // 8: protobuf.LoginRequest + (*LoginResult)(nil), // 9: protobuf.LoginResult + (*GetProfileByUserRequest)(nil), // 10: protobuf.GetProfileByUserRequest + (*GetProfileByUserResult)(nil), // 11: protobuf.GetProfileByUserResult + (*UpdateProfileByUserRequest)(nil), // 12: protobuf.UpdateProfileByUserRequest + (*UpdateProfileByUserResult)(nil), // 13: protobuf.UpdateProfileByUserResult + (*Document)(nil), // 14: protobuf.Document } var file_spis_proto_depIdxs = []int32{ - 10, // 0: protobuf.EchoRequest.document:type_name -> protobuf.Document - 10, // 1: protobuf.EchoResult.document:type_name -> protobuf.Document + 14, // 0: protobuf.EchoRequest.document:type_name -> protobuf.Document + 14, // 1: protobuf.EchoResult.document:type_name -> protobuf.Document 2, // [2:2] is the sub-list for method output_type 2, // [2:2] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name @@ -756,6 +1081,54 @@ func file_spis_proto_init() { return nil } } + file_spis_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetProfileByUserRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_spis_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetProfileByUserResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_spis_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UpdateProfileByUserRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_spis_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UpdateProfileByUserResult); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -763,7 +1136,7 @@ func file_spis_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_spis_proto_rawDesc, NumEnums: 0, - NumMessages: 10, + NumMessages: 14, NumExtensions: 0, NumServices: 0, }, diff --git a/greataped/components/api/protobuf/spis.proto b/greataped/components/api/protobuf/spis.proto index 1539703..277d46c 100644 --- a/greataped/components/api/protobuf/spis.proto +++ b/greataped/components/api/protobuf/spis.proto @@ -62,4 +62,36 @@ message LoginResult { string token = 0x00000002; } +// API: GetProfileByUser +//----------------------------------------------------------- +message GetProfileByUserRequest { +} + +message GetProfileByUserResult { + string username = 0x00000001; + string displayName = 0x00000002; + string avatar = 0x00000003; + string banner = 0x00000004; + string summary = 0x00000005; + string github = 0x00000006; +} + +// API: UpdateProfileByUser +//----------------------------------------------------------- +message UpdateProfileByUserRequest { + string displayName = 0x00000001; + string avatar = 0x00000002; + string banner = 0x00000003; + string summary = 0x00000004; + string github = 0x00000005; +} + +message UpdateProfileByUserResult { + string displayName = 0x00000001; + string avatar = 0x00000002; + string banner = 0x00000003; + string summary = 0x00000004; + string github = 0x00000005; +} + //----------------------------------------------------------- diff --git a/greataped/components/api/services/get_profile_by_user_service.go b/greataped/components/api/services/get_profile_by_user_service.go new file mode 100644 index 0000000..96d72bd --- /dev/null +++ b/greataped/components/api/services/get_profile_by_user_service.go @@ -0,0 +1,34 @@ +package services + +import ( + . "github.com/xeronith/diamante/contracts/service" + . "rail.town/infrastructure/components/api/protobuf" + . "rail.town/infrastructure/components/contracts" + "rail.town/infrastructure/components/core" +) + +// noinspection GoUnusedParameter +func GetProfileByUserService(context IContext, input *GetProfileByUserRequest) (result *GetProfileByUserResult, err error) { + conductor := core.Conductor + _ = GET_PROFILE_BY_USER_REQUEST + + conductor.LogRemoteCall(context, INITIALIZE, "get_profile_by_user", input, result, err) + defer func() { conductor.LogRemoteCall(context, FINALIZE, "get_profile_by_user", input, result, err) }() + + _result, _err := conductor.GetProfileByUser(context.Identity()) + if _err != nil { + err = _err + return nil, err + } + + _ = _result + + result = context.ResultContainer().(*GetProfileByUserResult) + result.Username = _result.Username() + result.DisplayName = _result.DisplayName() + result.Avatar = _result.Avatar() + result.Banner = _result.Banner() + result.Summary = _result.Summary() + result.Github = _result.Github() + return result, nil +} diff --git a/greataped/components/api/services/update_profile_by_user_service.go b/greataped/components/api/services/update_profile_by_user_service.go new file mode 100644 index 0000000..e653b20 --- /dev/null +++ b/greataped/components/api/services/update_profile_by_user_service.go @@ -0,0 +1,33 @@ +package services + +import ( + . "github.com/xeronith/diamante/contracts/service" + . "rail.town/infrastructure/components/api/protobuf" + . "rail.town/infrastructure/components/contracts" + "rail.town/infrastructure/components/core" +) + +// noinspection GoUnusedParameter +func UpdateProfileByUserService(context IContext, input *UpdateProfileByUserRequest) (result *UpdateProfileByUserResult, err error) { + conductor := core.Conductor + _ = UPDATE_PROFILE_BY_USER_REQUEST + + conductor.LogRemoteCall(context, INITIALIZE, "update_profile_by_user", input, result, err) + defer func() { conductor.LogRemoteCall(context, FINALIZE, "update_profile_by_user", input, result, err) }() + + _result, _err := conductor.UpdateProfileByUser(input.DisplayName, input.Avatar, input.Banner, input.Summary, input.Github, context.Identity()) + if _err != nil { + err = _err + return nil, err + } + + _ = _result + + result = context.ResultContainer().(*UpdateProfileByUserResult) + result.DisplayName = _result.DisplayName() + result.Avatar = _result.Avatar() + result.Banner = _result.Banner() + result.Summary = _result.Summary() + result.Github = _result.Github() + return result, nil +} diff --git a/greataped/components/contracts/api.go b/greataped/components/contracts/api.go index 38ae60e..3a3be5d 100644 --- a/greataped/components/contracts/api.go +++ b/greataped/components/contracts/api.go @@ -11,4 +11,6 @@ type IApi interface { Signup(*SignupRequest) (*SignupResult, error) Verify(*VerifyRequest) (*VerifyResult, error) Login(*LoginRequest) (*LoginResult, error) + GetProfileByUser(*GetProfileByUserRequest) (*GetProfileByUserResult, error) + UpdateProfileByUser(*UpdateProfileByUserRequest) (*UpdateProfileByUserResult, error) } diff --git a/greataped/components/contracts/opcodes.go b/greataped/components/contracts/opcodes.go index 3781167..c51dc7b 100644 --- a/greataped/components/contracts/opcodes.go +++ b/greataped/components/contracts/opcodes.go @@ -23,6 +23,14 @@ const ( //LoginOperation LOGIN_REQUEST = 0xF480F151 LOGIN_RESULT = 0xBE819605 + + //GetProfileByUserOperation + GET_PROFILE_BY_USER_REQUEST = 0xEAB16E71 + GET_PROFILE_BY_USER_RESULT = 0x8EECDE97 + + //UpdateProfileByUserOperation + UPDATE_PROFILE_BY_USER_REQUEST = 0xC25AB0BA + UPDATE_PROFILE_BY_USER_RESULT = 0x678A8BAF ) var OPCODES = Opcodes{ @@ -35,4 +43,8 @@ var OPCODES = Opcodes{ 0x2C8A8A49: "Verify", 0xF480F151: "LOGIN", 0xBE819605: "Login", + 0xEAB16E71: "GET_PROFILE_BY_USER", + 0x8EECDE97: "GetProfileByUser", + 0xC25AB0BA: "UPDATE_PROFILE_BY_USER", + 0x678A8BAF: "UpdateProfileByUser", } diff --git a/greataped/components/contracts/spi.go b/greataped/components/contracts/spi.go index 8333609..f72230d 100644 --- a/greataped/components/contracts/spi.go +++ b/greataped/components/contracts/spi.go @@ -58,6 +58,8 @@ type ( Signup(username string, email string, password string, editor Identity) (ISignupResult, error) Verify(email string, token string, code string, editor Identity) (IVerifyResult, error) Login(email string, password string, editor Identity) (ILoginResult, error) + GetProfileByUser(editor Identity) (IGetProfileByUserResult, error) + UpdateProfileByUser(displayName string, avatar string, banner string, summary string, github string, editor Identity) (IUpdateProfileByUserResult, error) } IEchoResult interface { @@ -77,4 +79,21 @@ type ( Username() string Token() string } + + IGetProfileByUserResult interface { + Username() string + DisplayName() string + Avatar() string + Banner() string + Summary() string + Github() string + } + + IUpdateProfileByUserResult interface { + DisplayName() string + Avatar() string + Banner() string + Summary() string + Github() string + } ) diff --git a/greataped/components/contracts/system_component.go b/greataped/components/contracts/system_component.go index 15aa170..4111d29 100644 --- a/greataped/components/contracts/system_component.go +++ b/greataped/components/contracts/system_component.go @@ -261,6 +261,8 @@ type ( Signup(username string, email string, password string, editor Identity) (ISignupResult, error) Verify(email string, token string, code string, editor Identity) (IVerifyResult, error) Login(email string, password string, editor Identity) (ILoginResult, error) + GetProfileByUser(editor Identity) (IGetProfileByUserResult, error) + UpdateProfileByUser(displayName string, avatar string, banner string, summary string, github string, editor Identity) (IUpdateProfileByUserResult, error) NewDocument(id int64, content string) (IDocument, error) NewSystemSchedule(id int64, enabled bool, config string) (ISystemSchedule, error) @@ -283,6 +285,8 @@ type ( NewSignupResult(token string, code string, ignored interface{}) ISignupResult NewVerifyResult(token string, ignored interface{}) IVerifyResult NewLoginResult(username string, token string, ignored interface{}) ILoginResult + NewGetProfileByUserResult(username string, displayName string, avatar string, banner string, summary string, github string, ignored interface{}) IGetProfileByUserResult + NewUpdateProfileByUserResult(displayName string, avatar string, banner string, summary string, github string, ignored interface{}) IUpdateProfileByUserResult } ISystemComponent interface { diff --git a/greataped/components/contracts/system_dispatcher.go b/greataped/components/contracts/system_dispatcher.go index 29e25eb..23bad06 100644 --- a/greataped/components/contracts/system_dispatcher.go +++ b/greataped/components/contracts/system_dispatcher.go @@ -1035,6 +1035,8 @@ type IDispatcher interface { Signup(username string, email string, password string) (ISignupResult, error) Verify(email string, token string, code string) (IVerifyResult, error) Login(email string, password string) (ILoginResult, error) + GetProfileByUser() (IGetProfileByUserResult, error) + UpdateProfileByUser(displayName string, avatar string, banner string, summary string, github string) (IUpdateProfileByUserResult, error) // NewDocument creates a new 'Document' instance using the provided property values. NewDocument(id int64, content string) (IDocument, error) @@ -1112,6 +1114,10 @@ type IDispatcher interface { NewVerifyResult(token string) IVerifyResult // NewLoginResult creates a new result container for 'Login' system action. NewLoginResult(username string, token string) ILoginResult + // NewGetProfileByUserResult creates a new result container for 'Get Profile By User' system action. + NewGetProfileByUserResult(username string, displayName string, avatar string, banner string, summary string, github string) IGetProfileByUserResult + // NewUpdateProfileByUserResult creates a new result container for 'Update Profile By User' system action. + NewUpdateProfileByUserResult(displayName string, avatar string, banner string, summary string, github string) IUpdateProfileByUserResult // Assert asserts the provided condition and panics if the assertion is not valid. Assert(condition bool) IAssertionResult // AssertNoError panics if the provided error is not nil. diff --git a/greataped/components/core/api_methods.go b/greataped/components/core/api_methods.go index a08baf0..f99babd 100644 --- a/greataped/components/core/api_methods.go +++ b/greataped/components/core/api_methods.go @@ -55,10 +55,32 @@ func (api *api) Login(request *LoginRequest) (*LoginResult, error) { } } +func (api *api) GetProfileByUser(request *GetProfileByUserRequest) (*GetProfileByUserResult, error) { + result, err := api.call(GET_PROFILE_BY_USER_REQUEST, request) + + if err != nil { + return nil, err + } else { + return result.(*GetProfileByUserResult), nil + } +} + +func (api *api) UpdateProfileByUser(request *UpdateProfileByUserRequest) (*UpdateProfileByUserResult, error) { + result, err := api.call(UPDATE_PROFILE_BY_USER_REQUEST, request) + + if err != nil { + return nil, err + } else { + return result.(*UpdateProfileByUserResult), nil + } +} + func init() { API_RESULT[SYSTEM_CALL_RESULT] = SystemCallResult{} API_RESULT[ECHO_RESULT] = EchoResult{} API_RESULT[SIGNUP_RESULT] = SignupResult{} API_RESULT[VERIFY_RESULT] = VerifyResult{} API_RESULT[LOGIN_RESULT] = LoginResult{} + API_RESULT[GET_PROFILE_BY_USER_RESULT] = GetProfileByUserResult{} + API_RESULT[UPDATE_PROFILE_BY_USER_RESULT] = UpdateProfileByUserResult{} } diff --git a/greataped/components/core/initializer.go b/greataped/components/core/initializer.go index 837a8e5..380ca24 100644 --- a/greataped/components/core/initializer.go +++ b/greataped/components/core/initializer.go @@ -1111,6 +1111,14 @@ func (conductor *conductor) Login(email string, password string, editor Identity return conductor.spiManager.Login(email, password, editor) } +func (conductor *conductor) GetProfileByUser(editor Identity) (IGetProfileByUserResult, error) { + return conductor.spiManager.GetProfileByUser(editor) +} + +func (conductor *conductor) UpdateProfileByUser(displayName string, avatar string, banner string, summary string, github string, editor Identity) (IUpdateProfileByUserResult, error) { + return conductor.spiManager.UpdateProfileByUser(displayName, avatar, banner, summary, github, editor) +} + func (conductor *conductor) NewDocument(id int64, content string) (IDocument, error) { return NewDocument(id, content) } @@ -1195,6 +1203,14 @@ func (conductor *conductor) NewLoginResult(username string, token string, _ inte return NewLoginResult(username, token, nil) } +func (conductor *conductor) NewGetProfileByUserResult(username string, displayName string, avatar string, banner string, summary string, github string, _ interface{}) IGetProfileByUserResult { + return NewGetProfileByUserResult(username, displayName, avatar, banner, summary, github, nil) +} + +func (conductor *conductor) NewUpdateProfileByUserResult(displayName string, avatar string, banner string, summary string, github string, _ interface{}) IUpdateProfileByUserResult { + return NewUpdateProfileByUserResult(displayName, avatar, banner, summary, github, nil) +} + func (conductor *conductor) LogRemoteCall(context IContext, eventType uint32, source string, input, result interface{}, err error) { errorMessage := "" if err != nil { diff --git a/greataped/components/core/spi.go b/greataped/components/core/spi.go index b49f8e5..96ddda2 100644 --- a/greataped/components/core/spi.go +++ b/greataped/components/core/spi.go @@ -250,3 +250,11 @@ func (dispatcher *dispatcher) Verify(email string, token string, code string) (I func (dispatcher *dispatcher) Login(email string, password string) (ILoginResult, error) { return dispatcher.conductor.SpiManager().Login(email, password, dispatcher.identity) } + +func (dispatcher *dispatcher) GetProfileByUser() (IGetProfileByUserResult, error) { + return dispatcher.conductor.SpiManager().GetProfileByUser(dispatcher.identity) +} + +func (dispatcher *dispatcher) UpdateProfileByUser(displayName string, avatar string, banner string, summary string, github string) (IUpdateProfileByUserResult, error) { + return dispatcher.conductor.SpiManager().UpdateProfileByUser(displayName, avatar, banner, summary, github, dispatcher.identity) +} diff --git a/greataped/components/core/spi_manager.go b/greataped/components/core/spi_manager.go index 1c5fd92..e5654b4 100644 --- a/greataped/components/core/spi_manager.go +++ b/greataped/components/core/spi_manager.go @@ -379,3 +379,127 @@ func (manager *spiManager) Login(email string, password string, editor Identity) return result, nil } } + +//region IGetProfileByUserResult Implementation + +type getProfileByUserResult struct { + username string + displayName string + avatar string + banner string + summary string + github string +} + +func NewGetProfileByUserResult(username string, displayName string, avatar string, banner string, summary string, github string, _ interface{}) IGetProfileByUserResult { + return &getProfileByUserResult{ + username: username, + displayName: displayName, + avatar: avatar, + banner: banner, + summary: summary, + github: github, + } +} + +func (result getProfileByUserResult) Username() string { + return result.username +} + +func (result getProfileByUserResult) DisplayName() string { + return result.displayName +} + +func (result getProfileByUserResult) Avatar() string { + return result.avatar +} + +func (result getProfileByUserResult) Banner() string { + return result.banner +} + +func (result getProfileByUserResult) Summary() string { + return result.summary +} + +func (result getProfileByUserResult) Github() string { + return result.github +} + +//endregion + +func (manager *spiManager) GetProfileByUser(editor Identity) (result IGetProfileByUserResult, err error) { + defer func() { + if reason := recover(); reason != nil { + err = manager.Error(reason) + } + }() + + editor.Lock(GET_PROFILE_BY_USER_REQUEST) + defer editor.Unlock(GET_PROFILE_BY_USER_REQUEST) + + if result, err = commands.GetProfileByUser(NewDispatcher(Conductor, editor)); err != nil { + return nil, err + } else { + return result, nil + } +} + +//region IUpdateProfileByUserResult Implementation + +type updateProfileByUserResult struct { + displayName string + avatar string + banner string + summary string + github string +} + +func NewUpdateProfileByUserResult(displayName string, avatar string, banner string, summary string, github string, _ interface{}) IUpdateProfileByUserResult { + return &updateProfileByUserResult{ + displayName: displayName, + avatar: avatar, + banner: banner, + summary: summary, + github: github, + } +} + +func (result updateProfileByUserResult) DisplayName() string { + return result.displayName +} + +func (result updateProfileByUserResult) Avatar() string { + return result.avatar +} + +func (result updateProfileByUserResult) Banner() string { + return result.banner +} + +func (result updateProfileByUserResult) Summary() string { + return result.summary +} + +func (result updateProfileByUserResult) Github() string { + return result.github +} + +//endregion + +func (manager *spiManager) UpdateProfileByUser(displayName string, avatar string, banner string, summary string, github string, editor Identity) (result IUpdateProfileByUserResult, err error) { + defer func() { + if reason := recover(); reason != nil { + err = manager.Error(reason) + } + }() + + editor.Lock(UPDATE_PROFILE_BY_USER_REQUEST) + defer editor.Unlock(UPDATE_PROFILE_BY_USER_REQUEST) + + if result, err = commands.UpdateProfileByUser(NewDispatcher(Conductor, editor), displayName, avatar, banner, summary, github); err != nil { + return nil, err + } else { + return result, nil + } +} diff --git a/greataped/components/core/system_results.go b/greataped/components/core/system_results.go index 476f999..5cf6952 100644 --- a/greataped/components/core/system_results.go +++ b/greataped/components/core/system_results.go @@ -20,4 +20,12 @@ func (dispatcher *dispatcher) NewLoginResult(username string, token string) ILog return NewLoginResult(username, token, nil) } +func (dispatcher *dispatcher) NewGetProfileByUserResult(username string, displayName string, avatar string, banner string, summary string, github string) IGetProfileByUserResult { + return NewGetProfileByUserResult(username, displayName, avatar, banner, summary, github, nil) +} + +func (dispatcher *dispatcher) NewUpdateProfileByUserResult(displayName string, avatar string, banner string, summary string, github string) IUpdateProfileByUserResult { + return NewUpdateProfileByUserResult(displayName, avatar, banner, summary, github, nil) +} + //endregion