1
0
mirror of https://github.com/ManyakRus/crud_generator.git synced 2025-01-20 09:09:22 +02:00

сделал uuid

This commit is contained in:
Nikitin Aleksandr 2024-04-24 16:19:05 +03:00
parent 2a4202cfce
commit 10df6325f7
4 changed files with 61 additions and 32 deletions

View File

@ -24,4 +24,4 @@ func initCrudTransport_manual_GRPC() {
// initCrudTransport_manual_NRPC - заполняет объекты crud для работы с БД через протокол NRPC
func initCrudTransport_manual_NRPC() {
crud_starter_attachament.SetCrudManualInterface(grpc_attachament.Crud_GRPC{})
}
}

View File

@ -30,15 +30,15 @@ func (s *ServerGRPC) LawsuitStatusType_Read(ctx context.Context, Request *grpc_p
//запрос в БД
db := postgres_gorm.GetConnection()
Model := &lawsuit_status_types.LawsuitStatusType{}
Model.ID = Request.ID
err = crud_lawsuit_status_types.Read_ctx(ctx, db, Model)
m := &lawsuit_status_types.LawsuitStatusType{}
m.ID = Request.ID
err = crud_lawsuit_status_types.Read_ctx(ctx, db, m)
if err != nil {
return &Otvet, err
}
//заполяем ответ
ModelString, err := Model.GetJSON()
ModelString, err := m.GetJSON()
if err != nil {
return &Otvet, err
}
@ -68,15 +68,15 @@ func (s *ServerGRPC) LawsuitStatusType_Delete(ctx context.Context, Request *grpc
//запрос в БД
db := postgres_gorm.GetConnection()
Model := &lawsuit_status_types.LawsuitStatusType{}
Model.ID = Request.ID
err = crud_lawsuit_status_types.Delete_ctx(ctx, db, Model)
m := &lawsuit_status_types.LawsuitStatusType{}
m.ID = Request.ID
err = crud_lawsuit_status_types.Delete_ctx(ctx, db, m)
if err != nil {
return &Otvet, err
}
//заполяем ответ
ModelString, err := Model.GetJSON()
ModelString, err := m.GetJSON()
if err != nil {
return &Otvet, err
}
@ -106,15 +106,15 @@ func (s *ServerGRPC) LawsuitStatusType_Restore(ctx context.Context, Request *grp
//запрос в БД
db := postgres_gorm.GetConnection()
Model := &lawsuit_status_types.LawsuitStatusType{}
Model.ID = Request.ID
err = crud_lawsuit_status_types.Restore_ctx(ctx, db, Model)
m := &lawsuit_status_types.LawsuitStatusType{}
m.ID = Request.ID
err = crud_lawsuit_status_types.Restore_ctx(ctx, db, m)
if err != nil {
return &Otvet, err
}
//заполяем ответ
ModelString, err := Model.GetJSON()
ModelString, err := m.GetJSON()
if err != nil {
return &Otvet, err
}
@ -143,21 +143,21 @@ func (s *ServerGRPC) LawsuitStatusType_Create(ctx context.Context, Request *grpc
}
//получим модель из строки JSON
Model := &lawsuit_status_types.LawsuitStatusType{}
err = Model.GetModelFromJSON(Request.ModelString)
m := &lawsuit_status_types.LawsuitStatusType{}
err = m.GetModelFromJSON(Request.ModelString)
if err != nil {
return &Otvet, err
}
//запрос в БД
db := postgres_gorm.GetConnection()
err = crud_lawsuit_status_types.Create_ctx(ctx, db, Model)
err = crud_lawsuit_status_types.Create_ctx(ctx, db, m)
if err != nil {
return &Otvet, err
}
//заполяем ответ
ModelString, err := Model.GetJSON()
ModelString, err := m.GetJSON()
if err != nil {
return &Otvet, err
}
@ -186,21 +186,21 @@ func (s *ServerGRPC) LawsuitStatusType_Update(ctx context.Context, Request *grpc
}
//получим модель из строки JSON
Model := &lawsuit_status_types.LawsuitStatusType{}
err = Model.GetModelFromJSON(Request.ModelString)
m := &lawsuit_status_types.LawsuitStatusType{}
err = m.GetModelFromJSON(Request.ModelString)
if err != nil {
return &Otvet, err
}
//запрос в БД
db := postgres_gorm.GetConnection()
err = crud_lawsuit_status_types.Update_ctx(ctx, db, Model)
err = crud_lawsuit_status_types.Update_ctx(ctx, db, m)
if err != nil {
return &Otvet, err
}
//заполяем ответ
ModelString, err := Model.GetJSON()
ModelString, err := m.GetJSON()
if err != nil {
return &Otvet, err
}
@ -229,21 +229,21 @@ func (s *ServerGRPC) LawsuitStatusType_Save(ctx context.Context, Request *grpc_p
}
//получим модель из строки JSON
Model := lawsuit_status_types.LawsuitStatusType{}
err = Model.GetModelFromJSON(Request.ModelString)
m := lawsuit_status_types.LawsuitStatusType{}
err = m.GetModelFromJSON(Request.ModelString)
if err != nil {
return &Otvet, err
}
//запрос в БД
db := postgres_gorm.GetConnection()
err = crud_lawsuit_status_types.Save_ctx(ctx, db, &Model)
err = crud_lawsuit_status_types.Save_ctx(ctx, db, &m)
if err != nil {
return &Otvet, err
}
//заполяем ответ
ModelString, err := Model.GetJSON()
ModelString, err := m.GetJSON()
if err != nil {
return &Otvet, err
}
@ -273,16 +273,16 @@ func (s *ServerGRPC) LawsuitStatusType_FindByExtID(ctx context.Context, Request
//запрос в БД
db := postgres_gorm.GetConnection()
Model := &lawsuit_status_types.LawsuitStatusType{}
Model.ExtID = Request.ExtID
Model.ConnectionID = Request.ConnectionId
err = crud_lawsuit_status_types.Find_ByExtID_ctx(ctx, db, Model)
m := &lawsuit_status_types.LawsuitStatusType{}
m.ExtID = Request.ExtID
m.ConnectionID = Request.ConnectionId
err = crud_lawsuit_status_types.Find_ByExtID_ctx(ctx, db, m)
if err != nil {
return &Otvet, err
}
//заполяем ответ
ModelString, err := Model.GetJSON()
ModelString, err := m.GetJSON()
if err != nil {
return &Otvet, err
}

View File

@ -1244,6 +1244,7 @@ func FindTextProtobufRequest(Table1 *types.Table, TypeGo string) (string, string
func FindTextProtobufRequestPrimaryKey(Table1 *types.Table, TypeGo string) (string, string) {
Otvet := "RequestId"
TextRequestFieldName := "ID"
TextRequest := "Request"
switch TypeGo {
@ -1514,6 +1515,9 @@ func FindTextConvertProtobufTypeToGolangType(Table1 *types.Table, Column1 *types
TableName := Table1.Name
IDName := Column1.Name
RequestColumnName := Column1.NameGo
RequestColumnName = FindRequestColumnName(Table1, Column1)
//alias в Int64
TextConvert, ok := types.MapConvertID[TableName+"."+IDName]
if ok == true {
@ -1530,7 +1534,7 @@ func FindTextConvertProtobufTypeToGolangType(Table1 *types.Table, Column1 *types
}
case "uuid.UUID":
{
Otvet = "uuid.FromBytes([]byte(" + VariableName + Column1.NameGo + "))"
Otvet = "uuid.FromBytes([]byte(" + VariableName + RequestColumnName + "))"
return Otvet
}
}
@ -1701,7 +1705,11 @@ func ReplaceTextRequestID_PrimaryKey(Text string, Table1 *types.Table) string {
TextRequestID, TextID := FindTextProtobufRequestPrimaryKey(Table1, TypeGo)
Otvet = strings.ReplaceAll(Otvet, "RequestId{}", TextRequestID+"{}")
Otvet = strings.ReplaceAll(Otvet, "Request.ID", "Request."+TextID)
Otvet = strings.ReplaceAll(Otvet, "*grpc_proto.RequestId", "*grpc_proto."+TextRequestID)
//Otvet = strings.ReplaceAll(Otvet, "Request.ID", "Request."+TextID)
TextID = FindTextConvertProtobufTypeToGolangType(Table1, PrimaryKeyColumn, "Request.")
Otvet = strings.ReplaceAll(Otvet, "Request.ID", TextID)
return Otvet
}
@ -1742,3 +1750,12 @@ func FindNegativeValue(TypeGo string) string {
return Otvet
}
// FindRequestColumnName - возвращает название колонки в Request
func FindRequestColumnName(Table1 *types.Table, Column1 *types.Column) string {
Otvet := ""
_, Otvet := FindTextProtobufRequest(Table1, Column1.TypeGo)
return Otvet
}

View File

@ -127,6 +127,18 @@ func CreateFiles(Table1 *types.Table) error {
CrudTableURL := create_files.FindCrudTableURL(TableName)
TextGRPCServer = create_files.AddImport(TextGRPCServer, CrudTableURL)
//замена ID на PrimaryKey
TextGRPCServer = create_files.ReplacePrimaryKeyM_ID(TextGRPCServer, Table1)
//замена RequestId{}
TextGRPCServer = create_files.ReplaceTextRequestID_PrimaryKey(TextGRPCServer, Table1)
//замена int64(ID) на ID
TextGRPCServer = create_files.ReplaceIDtoID(TextGRPCServer, Table1)
//добавим импорт uuid
TextGRPCServer = create_files.CheckAndAddImportUUID_FromText(TextGRPCServer)
//удалим лишние функции
TextGRPCServer = DeleteFuncDelete(TextGRPCServer, Table1)
TextGRPCServer = DeleteFuncRestore(TextGRPCServer, Table1)