作者 yangfu

增加 project-module

正在显示 55 个修改的文件 包含 2928 行增加3 行删除
@@ -196,7 +196,7 @@ func (clientVersionService *ClientVersionService) UpdateClientVersion(updateClie @@ -196,7 +196,7 @@ func (clientVersionService *ClientVersionService) UpdateClientVersion(updateClie
196 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 196 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
197 } 197 }
198 if clientVersion == nil { 198 if clientVersion == nil {
199 - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateClientVersionCommand.Id))) 199 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%v", updateClientVersionCommand.Id))
200 } 200 }
201 if err := clientVersion.Update(tool_funs.SimpleStructToMap(updateClientVersionCommand)); err != nil { 201 if err := clientVersion.Update(tool_funs.SimpleStructToMap(updateClientVersionCommand)); err != nil {
202 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 202 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
@@ -47,3 +47,27 @@ func CreateClientVersionRepository(options map[string]interface{}) (domain.Clien @@ -47,3 +47,27 @@ func CreateClientVersionRepository(options map[string]interface{}) (domain.Clien
47 } 47 }
48 return repository.NewClientVersionRepository(transactionContext) 48 return repository.NewClientVersionRepository(transactionContext)
49 } 49 }
  50 +
  51 +func CreateProjectModuleRepository(options map[string]interface{}) (domain.ProjectModuleRepository, error) {
  52 + var transactionContext *pg.TransactionContext
  53 + if value, ok := options["transactionContext"]; ok {
  54 + transactionContext = value.(*pg.TransactionContext)
  55 + }
  56 + return repository.NewProjectModuleRepository(transactionContext)
  57 +}
  58 +
  59 +func CreateProjectModuleVersionRepository(options map[string]interface{}) (domain.ProjectModuleVersionRepository, error) {
  60 + var transactionContext *pg.TransactionContext
  61 + if value, ok := options["transactionContext"]; ok {
  62 + transactionContext = value.(*pg.TransactionContext)
  63 + }
  64 + return repository.NewProjectModuleVersionRepository(transactionContext)
  65 +}
  66 +
  67 +func CreateProjectModuleFilesRepository(options map[string]interface{}) (domain.ProjectModuleFilesRepository, error) {
  68 + var transactionContext *pg.TransactionContext
  69 + if value, ok := options["transactionContext"]; ok {
  70 + transactionContext = value.(*pg.TransactionContext)
  71 + }
  72 + return repository.NewProjectModuleFilesRepository(transactionContext)
  73 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type CreateProjectModuleCommand struct {
  10 + // 项目名称
  11 + ProjectName string `json:"projectName" valid:"Required"`
  12 + // 项目唯一键值
  13 + ProjectKey string `json:"projectKey" valid:"Required"`
  14 + // 描述信息
  15 + Description string `json:"description" valid:"Required"`
  16 + // 状态 1:正常 2:删除
  17 + Status int `json:"status" valid:"Required"`
  18 +}
  19 +
  20 +func (createProjectModuleCommand *CreateProjectModuleCommand) Valid(validation *validation.Validation) {
  21 + validation.SetError("CustomValid", "未实现的自定义认证")
  22 +}
  23 +
  24 +func (createProjectModuleCommand *CreateProjectModuleCommand) ValidateCommand() error {
  25 + valid := validation.Validation{}
  26 + b, err := valid.Valid(createProjectModuleCommand)
  27 + if err != nil {
  28 + return err
  29 + }
  30 + if !b {
  31 + for _, validErr := range valid.Errors {
  32 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  33 + }
  34 + }
  35 + return nil
  36 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type RemoveProjectModuleCommand struct {
  10 + // 项目编号
  11 + ProjectModuleId int64 `json:"projectModuleId" valid:"Required"`
  12 +}
  13 +
  14 +func (removeProjectModuleCommand *RemoveProjectModuleCommand) Valid(validation *validation.Validation) {
  15 + validation.SetError("CustomValid", "未实现的自定义认证")
  16 +}
  17 +
  18 +func (removeProjectModuleCommand *RemoveProjectModuleCommand) ValidateCommand() error {
  19 + valid := validation.Validation{}
  20 + b, err := valid.Valid(removeProjectModuleCommand)
  21 + if err != nil {
  22 + return err
  23 + }
  24 + if !b {
  25 + for _, validErr := range valid.Errors {
  26 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  27 + }
  28 + }
  29 + return nil
  30 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type UpdateProjectModuleCommand struct {
  10 + // 项目编号
  11 + ProjectModuleId int64 `json:"projectModuleId" valid:"Required"`
  12 + // 项目名称
  13 + ProjectName string `json:"projectName" valid:"Required"`
  14 + // 项目唯一键值
  15 + ProjectKey string `json:"projectKey" valid:"Required"`
  16 + // 描述信息
  17 + Description string `json:"description" valid:"Required"`
  18 + // 状态 1:正常 2:删除
  19 + Status int `json:"status" valid:"Required"`
  20 +}
  21 +
  22 +func (updateProjectModuleCommand *UpdateProjectModuleCommand) Valid(validation *validation.Validation) {
  23 + validation.SetError("CustomValid", "未实现的自定义认证")
  24 +}
  25 +
  26 +func (updateProjectModuleCommand *UpdateProjectModuleCommand) ValidateCommand() error {
  27 + valid := validation.Validation{}
  28 + b, err := valid.Valid(updateProjectModuleCommand)
  29 + if err != nil {
  30 + return err
  31 + }
  32 + if !b {
  33 + for _, validErr := range valid.Errors {
  34 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  35 + }
  36 + }
  37 + return nil
  38 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type GetProjectModuleQuery struct {
  10 + // 项目编号
  11 + ProjectModuleId int64 `json:"projectModuleId" valid:"Required"`
  12 +}
  13 +
  14 +func (getProjectModuleQuery *GetProjectModuleQuery) Valid(validation *validation.Validation) {
  15 + validation.SetError("CustomValid", "未实现的自定义认证")
  16 +}
  17 +
  18 +func (getProjectModuleQuery *GetProjectModuleQuery) ValidateQuery() error {
  19 + valid := validation.Validation{}
  20 + b, err := valid.Valid(getProjectModuleQuery)
  21 + if err != nil {
  22 + return err
  23 + }
  24 + if !b {
  25 + for _, validErr := range valid.Errors {
  26 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  27 + }
  28 + }
  29 + return nil
  30 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type ListProjectModuleQuery struct {
  10 + // 查询偏离量
  11 + Offset int `json:"offset" valid:"Required"`
  12 + // 查询限制
  13 + Limit int `json:"limit" valid:"Required"`
  14 +}
  15 +
  16 +func (listProjectModuleQuery *ListProjectModuleQuery) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (listProjectModuleQuery *ListProjectModuleQuery) ValidateQuery() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(listProjectModuleQuery)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + for _, validErr := range valid.Errors {
  28 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  29 + }
  30 + }
  31 + return nil
  32 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "github.com/tiptok/godevp/pkg/application/factory"
  8 + "github.com/tiptok/godevp/pkg/application/projectModule/command"
  9 + "github.com/tiptok/godevp/pkg/application/projectModule/query"
  10 + "github.com/tiptok/godevp/pkg/domain"
  11 +)
  12 +
  13 +// 项目模块服务
  14 +type ProjectModuleService struct {
  15 +}
  16 +
  17 +// 创建
  18 +func (projectModuleService *ProjectModuleService) CreateProjectModule(createProjectModuleCommand *command.CreateProjectModuleCommand) (interface{}, error) {
  19 + if err := createProjectModuleCommand.ValidateCommand(); err != nil {
  20 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  21 + }
  22 + transactionContext, err := factory.CreateTransactionContext(nil)
  23 + if err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + if err := transactionContext.StartTransaction(); err != nil {
  27 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  28 + }
  29 + defer func() {
  30 + transactionContext.RollbackTransaction()
  31 + }()
  32 + newProjectModule := &domain.ProjectModule{
  33 + ProjectName: createProjectModuleCommand.ProjectName,
  34 + ProjectKey: createProjectModuleCommand.ProjectKey,
  35 + Description: createProjectModuleCommand.Description,
  36 + Status: createProjectModuleCommand.Status,
  37 + }
  38 + var projectModuleRepository domain.ProjectModuleRepository
  39 + if value, err := factory.CreateProjectModuleRepository(map[string]interface{}{
  40 + "transactionContext": transactionContext,
  41 + }); err != nil {
  42 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  43 + } else {
  44 + projectModuleRepository = value
  45 + }
  46 + if projectModule, err := projectModuleRepository.Save(newProjectModule); err != nil {
  47 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  48 + } else {
  49 + if err := transactionContext.CommitTransaction(); err != nil {
  50 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  51 + }
  52 + return projectModule, nil
  53 + }
  54 +}
  55 +
  56 +// 返回
  57 +func (projectModuleService *ProjectModuleService) GetProjectModule(getProjectModuleQuery *query.GetProjectModuleQuery) (interface{}, error) {
  58 + if err := getProjectModuleQuery.ValidateQuery(); err != nil {
  59 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  60 + }
  61 + transactionContext, err := factory.CreateTransactionContext(nil)
  62 + if err != nil {
  63 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  64 + }
  65 + if err := transactionContext.StartTransaction(); err != nil {
  66 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  67 + }
  68 + defer func() {
  69 + transactionContext.RollbackTransaction()
  70 + }()
  71 + var projectModuleRepository domain.ProjectModuleRepository
  72 + if value, err := factory.CreateProjectModuleRepository(map[string]interface{}{
  73 + "transactionContext": transactionContext,
  74 + }); err != nil {
  75 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  76 + } else {
  77 + projectModuleRepository = value
  78 + }
  79 + projectModule, err := projectModuleRepository.FindOne(map[string]interface{}{"projectModuleId": getProjectModuleQuery.ProjectModuleId})
  80 + if err != nil {
  81 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  82 + }
  83 + if projectModule == nil {
  84 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProjectModuleQuery.ProjectModuleId)))
  85 + } else {
  86 + if err := transactionContext.CommitTransaction(); err != nil {
  87 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  88 + }
  89 + return projectModule, nil
  90 + }
  91 +}
  92 +
  93 +// 返回列表
  94 +func (projectModuleService *ProjectModuleService) ListProjectModule(listProjectModuleQuery *query.ListProjectModuleQuery) (interface{}, error) {
  95 + if err := listProjectModuleQuery.ValidateQuery(); err != nil {
  96 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  97 + }
  98 + transactionContext, err := factory.CreateTransactionContext(nil)
  99 + if err != nil {
  100 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  101 + }
  102 + if err := transactionContext.StartTransaction(); err != nil {
  103 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  104 + }
  105 + defer func() {
  106 + transactionContext.RollbackTransaction()
  107 + }()
  108 + var projectModuleRepository domain.ProjectModuleRepository
  109 + if value, err := factory.CreateProjectModuleRepository(map[string]interface{}{
  110 + "transactionContext": transactionContext,
  111 + }); err != nil {
  112 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  113 + } else {
  114 + projectModuleRepository = value
  115 + }
  116 + if count, projectModules, err := projectModuleRepository.Find(tool_funs.SimpleStructToMap(listProjectModuleQuery)); err != nil {
  117 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  118 + } else {
  119 + if err := transactionContext.CommitTransaction(); err != nil {
  120 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  121 + }
  122 + return map[string]interface{}{
  123 + "count": count,
  124 + "projectModules": projectModules,
  125 + }, nil
  126 + }
  127 +}
  128 +
  129 +// 移除
  130 +func (projectModuleService *ProjectModuleService) RemoveProjectModule(removeProjectModuleCommand *command.RemoveProjectModuleCommand) (interface{}, error) {
  131 + if err := removeProjectModuleCommand.ValidateCommand(); err != nil {
  132 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  133 + }
  134 + transactionContext, err := factory.CreateTransactionContext(nil)
  135 + if err != nil {
  136 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  137 + }
  138 + if err := transactionContext.StartTransaction(); err != nil {
  139 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  140 + }
  141 + defer func() {
  142 + transactionContext.RollbackTransaction()
  143 + }()
  144 + var projectModuleRepository domain.ProjectModuleRepository
  145 + if value, err := factory.CreateProjectModuleRepository(map[string]interface{}{
  146 + "transactionContext": transactionContext,
  147 + }); err != nil {
  148 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  149 + } else {
  150 + projectModuleRepository = value
  151 + }
  152 + projectModule, err := projectModuleRepository.FindOne(map[string]interface{}{"projectModuleId": removeProjectModuleCommand.ProjectModuleId})
  153 + if err != nil {
  154 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  155 + }
  156 + if projectModule == nil {
  157 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProjectModuleCommand.ProjectModuleId)))
  158 + }
  159 + if projectModule, err := projectModuleRepository.Remove(projectModule); err != nil {
  160 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  161 + } else {
  162 + if err := transactionContext.CommitTransaction(); err != nil {
  163 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  164 + }
  165 + return projectModule, nil
  166 + }
  167 +}
  168 +
  169 +// 更新
  170 +func (projectModuleService *ProjectModuleService) UpdateProjectModule(updateProjectModuleCommand *command.UpdateProjectModuleCommand) (interface{}, error) {
  171 + if err := updateProjectModuleCommand.ValidateCommand(); err != nil {
  172 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  173 + }
  174 + transactionContext, err := factory.CreateTransactionContext(nil)
  175 + if err != nil {
  176 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  177 + }
  178 + if err := transactionContext.StartTransaction(); err != nil {
  179 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  180 + }
  181 + defer func() {
  182 + transactionContext.RollbackTransaction()
  183 + }()
  184 + var projectModuleRepository domain.ProjectModuleRepository
  185 + if value, err := factory.CreateProjectModuleRepository(map[string]interface{}{
  186 + "transactionContext": transactionContext,
  187 + }); err != nil {
  188 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  189 + } else {
  190 + projectModuleRepository = value
  191 + }
  192 + projectModule, err := projectModuleRepository.FindOne(map[string]interface{}{"projectModuleId": updateProjectModuleCommand.ProjectModuleId})
  193 + if err != nil {
  194 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  195 + }
  196 + if projectModule == nil {
  197 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProjectModuleCommand.ProjectModuleId)))
  198 + }
  199 + if err := projectModule.Update(tool_funs.SimpleStructToMap(updateProjectModuleCommand)); err != nil {
  200 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  201 + }
  202 + if projectModule, err := projectModuleRepository.Save(projectModule); err != nil {
  203 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  204 + } else {
  205 + if err := transactionContext.CommitTransaction(); err != nil {
  206 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  207 + }
  208 + return projectModule, nil
  209 + }
  210 +}
  211 +
  212 +func NewProjectModuleService(options map[string]interface{}) *ProjectModuleService {
  213 + newProjectModuleService := &ProjectModuleService{}
  214 + return newProjectModuleService
  215 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type CreateProjectModuleFilesCommand struct {
  10 + // 项目编号
  11 + ProjectModuleId int64 `json:"projectModuleId" valid:"Required"`
  12 + // 项目版本编号
  13 + ProjectModuleVersion int64 `json:"projectModuleVersion" valid:"Required"`
  14 + // 文件类型 1:文件夹 2:文件
  15 + FileType int `json:"fileType" valid:"Required"`
  16 + // 代码块
  17 + CodeBlock string `json:"codeBlock" valid:"Required"`
  18 + // 父级Id
  19 + ParentId int64 `json:"parentId" valid:"Required"`
  20 + // 排序
  21 + Sort int `json:"sort" valid:"Required"`
  22 + // 备注信息
  23 + Remark string `json:"remark,omitempty"`
  24 +}
  25 +
  26 +func (createProjectModuleFilesCommand *CreateProjectModuleFilesCommand) Valid(validation *validation.Validation) {
  27 + validation.SetError("CustomValid", "未实现的自定义认证")
  28 +}
  29 +
  30 +func (createProjectModuleFilesCommand *CreateProjectModuleFilesCommand) ValidateCommand() error {
  31 + valid := validation.Validation{}
  32 + b, err := valid.Valid(createProjectModuleFilesCommand)
  33 + if err != nil {
  34 + return err
  35 + }
  36 + if !b {
  37 + for _, validErr := range valid.Errors {
  38 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  39 + }
  40 + }
  41 + return nil
  42 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type RemoveProjectModuleFilesCommand struct {
  10 + // 项目文件编号
  11 + ProjectModuleFilesId int64 `json:"projectModuleFilesId" valid:"Required"`
  12 +}
  13 +
  14 +func (removeProjectModuleFilesCommand *RemoveProjectModuleFilesCommand) Valid(validation *validation.Validation) {
  15 + validation.SetError("CustomValid", "未实现的自定义认证")
  16 +}
  17 +
  18 +func (removeProjectModuleFilesCommand *RemoveProjectModuleFilesCommand) ValidateCommand() error {
  19 + valid := validation.Validation{}
  20 + b, err := valid.Valid(removeProjectModuleFilesCommand)
  21 + if err != nil {
  22 + return err
  23 + }
  24 + if !b {
  25 + for _, validErr := range valid.Errors {
  26 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  27 + }
  28 + }
  29 + return nil
  30 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type UpdateProjectModuleFilesCommand struct {
  10 + // 项目文件编号
  11 + ProjectModuleFilesId int64 `json:"projectModuleFilesId" valid:"Required"`
  12 + // 代码块
  13 + CodeBlock string `json:"codeBlock" valid:"Required"`
  14 + // 备注信息
  15 + Remark string `json:"remark,omitempty"`
  16 +}
  17 +
  18 +func (updateProjectModuleFilesCommand *UpdateProjectModuleFilesCommand) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (updateProjectModuleFilesCommand *UpdateProjectModuleFilesCommand) ValidateCommand() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(updateProjectModuleFilesCommand)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + for _, validErr := range valid.Errors {
  30 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  31 + }
  32 + }
  33 + return nil
  34 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type GetProjectModuleFilesQuery struct {
  10 + // 项目文件编号
  11 + ProjectModuleFilesId int64 `json:"projectModuleFilesId" valid:"Required"`
  12 +}
  13 +
  14 +func (getProjectModuleFilesQuery *GetProjectModuleFilesQuery) Valid(validation *validation.Validation) {
  15 + validation.SetError("CustomValid", "未实现的自定义认证")
  16 +}
  17 +
  18 +func (getProjectModuleFilesQuery *GetProjectModuleFilesQuery) ValidateQuery() error {
  19 + valid := validation.Validation{}
  20 + b, err := valid.Valid(getProjectModuleFilesQuery)
  21 + if err != nil {
  22 + return err
  23 + }
  24 + if !b {
  25 + for _, validErr := range valid.Errors {
  26 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  27 + }
  28 + }
  29 + return nil
  30 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type ListProjectModuleFilesQuery struct {
  10 + // 查询偏离量
  11 + Offset int `json:"offset" valid:"Required"`
  12 + // 查询限制
  13 + Limit int `json:"limit" valid:"Required"`
  14 +}
  15 +
  16 +func (listProjectModuleFilesQuery *ListProjectModuleFilesQuery) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (listProjectModuleFilesQuery *ListProjectModuleFilesQuery) ValidateQuery() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(listProjectModuleFilesQuery)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + for _, validErr := range valid.Errors {
  28 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  29 + }
  30 + }
  31 + return nil
  32 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "github.com/tiptok/godevp/pkg/application/factory"
  8 + "github.com/tiptok/godevp/pkg/application/projectModuleFiles/command"
  9 + "github.com/tiptok/godevp/pkg/application/projectModuleFiles/query"
  10 + "github.com/tiptok/godevp/pkg/domain"
  11 +)
  12 +
  13 +// 项目模块文件
  14 +type ProjectModuleFilesService struct {
  15 +}
  16 +
  17 +// 创建
  18 +func (projectModuleFilesService *ProjectModuleFilesService) CreateProjectModuleFiles(createProjectModuleFilesCommand *command.CreateProjectModuleFilesCommand) (interface{}, error) {
  19 + if err := createProjectModuleFilesCommand.ValidateCommand(); err != nil {
  20 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  21 + }
  22 + transactionContext, err := factory.CreateTransactionContext(nil)
  23 + if err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + if err := transactionContext.StartTransaction(); err != nil {
  27 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  28 + }
  29 + defer func() {
  30 + transactionContext.RollbackTransaction()
  31 + }()
  32 + newProjectModuleFiles := &domain.ProjectModuleFiles{
  33 + ProjectModuleId: createProjectModuleFilesCommand.ProjectModuleId,
  34 + ProjectModuleVersion: createProjectModuleFilesCommand.ProjectModuleVersion,
  35 + FileType: createProjectModuleFilesCommand.FileType,
  36 + CodeBlock: createProjectModuleFilesCommand.CodeBlock,
  37 + ParentId: createProjectModuleFilesCommand.ParentId,
  38 + Sort: createProjectModuleFilesCommand.Sort,
  39 + Remark: createProjectModuleFilesCommand.Remark,
  40 + }
  41 + var projectModuleFilesRepository domain.ProjectModuleFilesRepository
  42 + if value, err := factory.CreateProjectModuleFilesRepository(map[string]interface{}{
  43 + "transactionContext": transactionContext,
  44 + }); err != nil {
  45 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  46 + } else {
  47 + projectModuleFilesRepository = value
  48 + }
  49 + if projectModuleFiles, err := projectModuleFilesRepository.Save(newProjectModuleFiles); err != nil {
  50 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  51 + } else {
  52 + if err := transactionContext.CommitTransaction(); err != nil {
  53 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  54 + }
  55 + return projectModuleFiles, nil
  56 + }
  57 +}
  58 +
  59 +// 返回
  60 +func (projectModuleFilesService *ProjectModuleFilesService) GetProjectModuleFiles(getProjectModuleFilesQuery *query.GetProjectModuleFilesQuery) (interface{}, error) {
  61 + if err := getProjectModuleFilesQuery.ValidateQuery(); err != nil {
  62 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  63 + }
  64 + transactionContext, err := factory.CreateTransactionContext(nil)
  65 + if err != nil {
  66 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  67 + }
  68 + if err := transactionContext.StartTransaction(); err != nil {
  69 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  70 + }
  71 + defer func() {
  72 + transactionContext.RollbackTransaction()
  73 + }()
  74 + var projectModuleFilesRepository domain.ProjectModuleFilesRepository
  75 + if value, err := factory.CreateProjectModuleFilesRepository(map[string]interface{}{
  76 + "transactionContext": transactionContext,
  77 + }); err != nil {
  78 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  79 + } else {
  80 + projectModuleFilesRepository = value
  81 + }
  82 + projectModuleFiles, err := projectModuleFilesRepository.FindOne(map[string]interface{}{"projectModuleFilesId": getProjectModuleFilesQuery.ProjectModuleFilesId})
  83 + if err != nil {
  84 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  85 + }
  86 + if projectModuleFiles == nil {
  87 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProjectModuleFilesQuery.ProjectModuleFilesId)))
  88 + } else {
  89 + if err := transactionContext.CommitTransaction(); err != nil {
  90 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  91 + }
  92 + return projectModuleFiles, nil
  93 + }
  94 +}
  95 +
  96 +// 返回列表
  97 +func (projectModuleFilesService *ProjectModuleFilesService) ListProjectModuleFiles(listProjectModuleFilesQuery *query.ListProjectModuleFilesQuery) (interface{}, error) {
  98 + if err := listProjectModuleFilesQuery.ValidateQuery(); err != nil {
  99 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  100 + }
  101 + transactionContext, err := factory.CreateTransactionContext(nil)
  102 + if err != nil {
  103 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  104 + }
  105 + if err := transactionContext.StartTransaction(); err != nil {
  106 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  107 + }
  108 + defer func() {
  109 + transactionContext.RollbackTransaction()
  110 + }()
  111 + var projectModuleFilesRepository domain.ProjectModuleFilesRepository
  112 + if value, err := factory.CreateProjectModuleFilesRepository(map[string]interface{}{
  113 + "transactionContext": transactionContext,
  114 + }); err != nil {
  115 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  116 + } else {
  117 + projectModuleFilesRepository = value
  118 + }
  119 + if count, projectModuleFiless, err := projectModuleFilesRepository.Find(tool_funs.SimpleStructToMap(listProjectModuleFilesQuery)); err != nil {
  120 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  121 + } else {
  122 + if err := transactionContext.CommitTransaction(); err != nil {
  123 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  124 + }
  125 + return map[string]interface{}{
  126 + "count": count,
  127 + "projectModuleFiless": projectModuleFiless,
  128 + }, nil
  129 + }
  130 +}
  131 +
  132 +// 移除
  133 +func (projectModuleFilesService *ProjectModuleFilesService) RemoveProjectModuleFiles(removeProjectModuleFilesCommand *command.RemoveProjectModuleFilesCommand) (interface{}, error) {
  134 + if err := removeProjectModuleFilesCommand.ValidateCommand(); err != nil {
  135 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  136 + }
  137 + transactionContext, err := factory.CreateTransactionContext(nil)
  138 + if err != nil {
  139 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  140 + }
  141 + if err := transactionContext.StartTransaction(); err != nil {
  142 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  143 + }
  144 + defer func() {
  145 + transactionContext.RollbackTransaction()
  146 + }()
  147 + var projectModuleFilesRepository domain.ProjectModuleFilesRepository
  148 + if value, err := factory.CreateProjectModuleFilesRepository(map[string]interface{}{
  149 + "transactionContext": transactionContext,
  150 + }); err != nil {
  151 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  152 + } else {
  153 + projectModuleFilesRepository = value
  154 + }
  155 + projectModuleFiles, err := projectModuleFilesRepository.FindOne(map[string]interface{}{"projectModuleFilesId": removeProjectModuleFilesCommand.ProjectModuleFilesId})
  156 + if err != nil {
  157 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  158 + }
  159 + if projectModuleFiles == nil {
  160 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProjectModuleFilesCommand.ProjectModuleFilesId)))
  161 + }
  162 + if projectModuleFiles, err := projectModuleFilesRepository.Remove(projectModuleFiles); err != nil {
  163 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  164 + } else {
  165 + if err := transactionContext.CommitTransaction(); err != nil {
  166 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  167 + }
  168 + return projectModuleFiles, nil
  169 + }
  170 +}
  171 +
  172 +// 更新
  173 +func (projectModuleFilesService *ProjectModuleFilesService) UpdateProjectModuleFiles(updateProjectModuleFilesCommand *command.UpdateProjectModuleFilesCommand) (interface{}, error) {
  174 + if err := updateProjectModuleFilesCommand.ValidateCommand(); err != nil {
  175 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  176 + }
  177 + transactionContext, err := factory.CreateTransactionContext(nil)
  178 + if err != nil {
  179 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  180 + }
  181 + if err := transactionContext.StartTransaction(); err != nil {
  182 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  183 + }
  184 + defer func() {
  185 + transactionContext.RollbackTransaction()
  186 + }()
  187 + var projectModuleFilesRepository domain.ProjectModuleFilesRepository
  188 + if value, err := factory.CreateProjectModuleFilesRepository(map[string]interface{}{
  189 + "transactionContext": transactionContext,
  190 + }); err != nil {
  191 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  192 + } else {
  193 + projectModuleFilesRepository = value
  194 + }
  195 + projectModuleFiles, err := projectModuleFilesRepository.FindOne(map[string]interface{}{"projectModuleFilesId": updateProjectModuleFilesCommand.ProjectModuleFilesId})
  196 + if err != nil {
  197 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  198 + }
  199 + if projectModuleFiles == nil {
  200 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProjectModuleFilesCommand.ProjectModuleFilesId)))
  201 + }
  202 + if err := projectModuleFiles.Update(tool_funs.SimpleStructToMap(updateProjectModuleFilesCommand)); err != nil {
  203 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  204 + }
  205 + if projectModuleFiles, err := projectModuleFilesRepository.Save(projectModuleFiles); err != nil {
  206 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  207 + } else {
  208 + if err := transactionContext.CommitTransaction(); err != nil {
  209 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  210 + }
  211 + return projectModuleFiles, nil
  212 + }
  213 +}
  214 +
  215 +func NewProjectModuleFilesService(options map[string]interface{}) *ProjectModuleFilesService {
  216 + newProjectModuleFilesService := &ProjectModuleFilesService{}
  217 + return newProjectModuleFilesService
  218 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type CreateProjectModuleVersionCommand struct {
  10 + // 项目编号
  11 + ProjectModuleId int64 `json:"projectModuleId" valid:"Required"`
  12 + // 唯一标识
  13 + Version int64 `json:"version" valid:"Required"`
  14 + // 描述信息
  15 + Description string `json:"description" valid:"Required"`
  16 +}
  17 +
  18 +func (createProjectModuleVersionCommand *CreateProjectModuleVersionCommand) Valid(validation *validation.Validation) {
  19 + validation.SetError("CustomValid", "未实现的自定义认证")
  20 +}
  21 +
  22 +func (createProjectModuleVersionCommand *CreateProjectModuleVersionCommand) ValidateCommand() error {
  23 + valid := validation.Validation{}
  24 + b, err := valid.Valid(createProjectModuleVersionCommand)
  25 + if err != nil {
  26 + return err
  27 + }
  28 + if !b {
  29 + for _, validErr := range valid.Errors {
  30 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  31 + }
  32 + }
  33 + return nil
  34 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type RemoveProjectModuleVersionCommand struct {
  10 + ProjectModuleVersionId int64 `json:"projectModuleVersionId" valid:"Required"`
  11 + // 项目版本编号
  12 + ProjectModuleVersion int64 `json:"projectModuleVersion" valid:"Required"`
  13 +}
  14 +
  15 +func (removeProjectModuleVersionCommand *RemoveProjectModuleVersionCommand) Valid(validation *validation.Validation) {
  16 + validation.SetError("CustomValid", "未实现的自定义认证")
  17 +}
  18 +
  19 +func (removeProjectModuleVersionCommand *RemoveProjectModuleVersionCommand) ValidateCommand() error {
  20 + valid := validation.Validation{}
  21 + b, err := valid.Valid(removeProjectModuleVersionCommand)
  22 + if err != nil {
  23 + return err
  24 + }
  25 + if !b {
  26 + for _, validErr := range valid.Errors {
  27 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  28 + }
  29 + }
  30 + return nil
  31 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type UpdateProjectModuleVersionCommand struct {
  10 + ProjectModuleVersionId int64 `json:"projectModuleVersionId" valid:"Required"`
  11 + // 项目版本编号
  12 + ProjectModuleVersion int64 `json:"projectModuleVersion" valid:"Required"`
  13 + // 项目编号
  14 + ProjectModuleId int64 `json:"projectModuleId" valid:"Required"`
  15 + // 唯一标识
  16 + Version int64 `json:"version" valid:"Required"`
  17 + // 描述信息
  18 + Description string `json:"description" valid:"Required"`
  19 + // 状态 1:正常 2:删除
  20 + Status int `json:"status" valid:"Required"`
  21 +}
  22 +
  23 +func (updateProjectModuleVersionCommand *UpdateProjectModuleVersionCommand) Valid(validation *validation.Validation) {
  24 + validation.SetError("CustomValid", "未实现的自定义认证")
  25 +}
  26 +
  27 +func (updateProjectModuleVersionCommand *UpdateProjectModuleVersionCommand) ValidateCommand() error {
  28 + valid := validation.Validation{}
  29 + b, err := valid.Valid(updateProjectModuleVersionCommand)
  30 + if err != nil {
  31 + return err
  32 + }
  33 + if !b {
  34 + for _, validErr := range valid.Errors {
  35 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  36 + }
  37 + }
  38 + return nil
  39 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type GetProjectModuleVersionQuery struct {
  10 + ProjectModuleVersionId int64 `json:"projectModuleVersionId" valid:"Required"`
  11 + // 项目版本编号
  12 + ProjectModuleVersion int64 `json:"projectModuleVersion" valid:"Required"`
  13 +}
  14 +
  15 +func (getProjectModuleVersionQuery *GetProjectModuleVersionQuery) Valid(validation *validation.Validation) {
  16 + validation.SetError("CustomValid", "未实现的自定义认证")
  17 +}
  18 +
  19 +func (getProjectModuleVersionQuery *GetProjectModuleVersionQuery) ValidateQuery() error {
  20 + valid := validation.Validation{}
  21 + b, err := valid.Valid(getProjectModuleVersionQuery)
  22 + if err != nil {
  23 + return err
  24 + }
  25 + if !b {
  26 + for _, validErr := range valid.Errors {
  27 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  28 + }
  29 + }
  30 + return nil
  31 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/astaxie/beego/validation"
  7 +)
  8 +
  9 +type ListProjectModuleVersionQuery struct {
  10 + // 查询偏离量
  11 + Offset int `json:"offset" valid:"Required"`
  12 + // 查询限制
  13 + Limit int `json:"limit" valid:"Required"`
  14 +}
  15 +
  16 +func (listProjectModuleVersionQuery *ListProjectModuleVersionQuery) Valid(validation *validation.Validation) {
  17 + validation.SetError("CustomValid", "未实现的自定义认证")
  18 +}
  19 +
  20 +func (listProjectModuleVersionQuery *ListProjectModuleVersionQuery) ValidateQuery() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(listProjectModuleVersionQuery)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + for _, validErr := range valid.Errors {
  28 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  29 + }
  30 + }
  31 + return nil
  32 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "github.com/tiptok/godevp/pkg/application/factory"
  8 + "github.com/tiptok/godevp/pkg/application/projectModuleVersion/command"
  9 + "github.com/tiptok/godevp/pkg/application/projectModuleVersion/query"
  10 + "github.com/tiptok/godevp/pkg/domain"
  11 +)
  12 +
  13 +// 项目模板版本
  14 +type ProjectModuleVersionService struct {
  15 +}
  16 +
  17 +// 创建
  18 +func (projectModuleVersionService *ProjectModuleVersionService) CreateProjectModuleVersion(createProjectModuleVersionCommand *command.CreateProjectModuleVersionCommand) (interface{}, error) {
  19 + if err := createProjectModuleVersionCommand.ValidateCommand(); err != nil {
  20 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  21 + }
  22 + transactionContext, err := factory.CreateTransactionContext(nil)
  23 + if err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + if err := transactionContext.StartTransaction(); err != nil {
  27 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  28 + }
  29 + defer func() {
  30 + transactionContext.RollbackTransaction()
  31 + }()
  32 + newProjectModuleVersion := &domain.ProjectModuleVersion{
  33 + ProjectModuleId: createProjectModuleVersionCommand.ProjectModuleId,
  34 + Version: createProjectModuleVersionCommand.Version,
  35 + Description: createProjectModuleVersionCommand.Description,
  36 + }
  37 + var projectModuleVersionRepository domain.ProjectModuleVersionRepository
  38 + if value, err := factory.CreateProjectModuleVersionRepository(map[string]interface{}{
  39 + "transactionContext": transactionContext,
  40 + }); err != nil {
  41 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  42 + } else {
  43 + projectModuleVersionRepository = value
  44 + }
  45 + if projectModuleVersion, err := projectModuleVersionRepository.Save(newProjectModuleVersion); err != nil {
  46 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  47 + } else {
  48 + if err := transactionContext.CommitTransaction(); err != nil {
  49 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  50 + }
  51 + return projectModuleVersion, nil
  52 + }
  53 +}
  54 +
  55 +// 返回
  56 +func (projectModuleVersionService *ProjectModuleVersionService) GetProjectModuleVersion(getProjectModuleVersionQuery *query.GetProjectModuleVersionQuery) (interface{}, error) {
  57 + if err := getProjectModuleVersionQuery.ValidateQuery(); err != nil {
  58 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  59 + }
  60 + transactionContext, err := factory.CreateTransactionContext(nil)
  61 + if err != nil {
  62 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  63 + }
  64 + if err := transactionContext.StartTransaction(); err != nil {
  65 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  66 + }
  67 + defer func() {
  68 + transactionContext.RollbackTransaction()
  69 + }()
  70 + var projectModuleVersionRepository domain.ProjectModuleVersionRepository
  71 + if value, err := factory.CreateProjectModuleVersionRepository(map[string]interface{}{
  72 + "transactionContext": transactionContext,
  73 + }); err != nil {
  74 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  75 + } else {
  76 + projectModuleVersionRepository = value
  77 + }
  78 + projectModuleVersion, err := projectModuleVersionRepository.FindOne(map[string]interface{}{"projectModuleVersionId": getProjectModuleVersionQuery.ProjectModuleVersionId})
  79 + if err != nil {
  80 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  81 + }
  82 + if projectModuleVersion == nil {
  83 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProjectModuleVersionQuery.ProjectModuleVersionId)))
  84 + } else {
  85 + if err := transactionContext.CommitTransaction(); err != nil {
  86 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  87 + }
  88 + return projectModuleVersion, nil
  89 + }
  90 +}
  91 +
  92 +// 返回列表
  93 +func (projectModuleVersionService *ProjectModuleVersionService) ListProjectModuleVersion(listProjectModuleVersionQuery *query.ListProjectModuleVersionQuery) (interface{}, error) {
  94 + if err := listProjectModuleVersionQuery.ValidateQuery(); err != nil {
  95 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  96 + }
  97 + transactionContext, err := factory.CreateTransactionContext(nil)
  98 + if err != nil {
  99 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  100 + }
  101 + if err := transactionContext.StartTransaction(); err != nil {
  102 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  103 + }
  104 + defer func() {
  105 + transactionContext.RollbackTransaction()
  106 + }()
  107 + var projectModuleVersionRepository domain.ProjectModuleVersionRepository
  108 + if value, err := factory.CreateProjectModuleVersionRepository(map[string]interface{}{
  109 + "transactionContext": transactionContext,
  110 + }); err != nil {
  111 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  112 + } else {
  113 + projectModuleVersionRepository = value
  114 + }
  115 + if count, projectModuleVersions, err := projectModuleVersionRepository.Find(tool_funs.SimpleStructToMap(listProjectModuleVersionQuery)); err != nil {
  116 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  117 + } else {
  118 + if err := transactionContext.CommitTransaction(); err != nil {
  119 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  120 + }
  121 + return map[string]interface{}{
  122 + "count": count,
  123 + "projectModuleVersions": projectModuleVersions,
  124 + }, nil
  125 + }
  126 +}
  127 +
  128 +// 移除
  129 +func (projectModuleVersionService *ProjectModuleVersionService) RemoveProjectModuleVersion(removeProjectModuleVersionCommand *command.RemoveProjectModuleVersionCommand) (interface{}, error) {
  130 + if err := removeProjectModuleVersionCommand.ValidateCommand(); err != nil {
  131 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  132 + }
  133 + transactionContext, err := factory.CreateTransactionContext(nil)
  134 + if err != nil {
  135 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  136 + }
  137 + if err := transactionContext.StartTransaction(); err != nil {
  138 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  139 + }
  140 + defer func() {
  141 + transactionContext.RollbackTransaction()
  142 + }()
  143 + var projectModuleVersionRepository domain.ProjectModuleVersionRepository
  144 + if value, err := factory.CreateProjectModuleVersionRepository(map[string]interface{}{
  145 + "transactionContext": transactionContext,
  146 + }); err != nil {
  147 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  148 + } else {
  149 + projectModuleVersionRepository = value
  150 + }
  151 + projectModuleVersion, err := projectModuleVersionRepository.FindOne(map[string]interface{}{"projectModuleVersionId": removeProjectModuleVersionCommand.ProjectModuleVersionId})
  152 + if err != nil {
  153 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  154 + }
  155 + if projectModuleVersion == nil {
  156 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProjectModuleVersionCommand.ProjectModuleVersionId)))
  157 + }
  158 + if projectModuleVersion, err := projectModuleVersionRepository.Remove(projectModuleVersion); err != nil {
  159 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  160 + } else {
  161 + if err := transactionContext.CommitTransaction(); err != nil {
  162 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  163 + }
  164 + return projectModuleVersion, nil
  165 + }
  166 +}
  167 +
  168 +// 更新
  169 +func (projectModuleVersionService *ProjectModuleVersionService) UpdateProjectModuleVersion(updateProjectModuleVersionCommand *command.UpdateProjectModuleVersionCommand) (interface{}, error) {
  170 + if err := updateProjectModuleVersionCommand.ValidateCommand(); err != nil {
  171 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  172 + }
  173 + transactionContext, err := factory.CreateTransactionContext(nil)
  174 + if err != nil {
  175 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  176 + }
  177 + if err := transactionContext.StartTransaction(); err != nil {
  178 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  179 + }
  180 + defer func() {
  181 + transactionContext.RollbackTransaction()
  182 + }()
  183 + var projectModuleVersionRepository domain.ProjectModuleVersionRepository
  184 + if value, err := factory.CreateProjectModuleVersionRepository(map[string]interface{}{
  185 + "transactionContext": transactionContext,
  186 + }); err != nil {
  187 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  188 + } else {
  189 + projectModuleVersionRepository = value
  190 + }
  191 + projectModuleVersion, err := projectModuleVersionRepository.FindOne(map[string]interface{}{"projectModuleVersionId": updateProjectModuleVersionCommand.ProjectModuleVersionId})
  192 + if err != nil {
  193 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  194 + }
  195 + if projectModuleVersion == nil {
  196 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProjectModuleVersionCommand.ProjectModuleVersionId)))
  197 + }
  198 + if err := projectModuleVersion.Update(tool_funs.SimpleStructToMap(updateProjectModuleVersionCommand)); err != nil {
  199 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  200 + }
  201 + if projectModuleVersion, err := projectModuleVersionRepository.Save(projectModuleVersion); err != nil {
  202 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  203 + } else {
  204 + if err := transactionContext.CommitTransaction(); err != nil {
  205 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  206 + }
  207 + return projectModuleVersion, nil
  208 + }
  209 +}
  210 +
  211 +func NewProjectModuleVersionService(options map[string]interface{}) *ProjectModuleVersionService {
  212 + newProjectModuleVersionService := &ProjectModuleVersionService{}
  213 + return newProjectModuleVersionService
  214 +}
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +// 项目模块
  6 +type ProjectModule struct {
  7 + // 唯一标识
  8 + Id int64 `json:"id"`
  9 + // 项目名称
  10 + ProjectName string `json:"projectName"`
  11 + // 项目唯一键值
  12 + ProjectKey string `json:"projectKey"`
  13 + // 描述信息
  14 + Description string `json:"description"`
  15 + // 状态 1:正常 2:删除
  16 + Status int `json:"status"`
  17 + // 创建时间
  18 + CreateTime time.Time `json:"createTime"`
  19 + // 更新时间
  20 + UpdateTime time.Time `json:"updateTime"`
  21 + // 项目模板版本信息
  22 + ProjectModuleVersion *ProjectModuleVersion `json:"projectModuleVersion"`
  23 +}
  24 +
  25 +type ProjectModuleRepository interface {
  26 + Save(projectModule *ProjectModule) (*ProjectModule, error)
  27 + Remove(projectModule *ProjectModule) (*ProjectModule, error)
  28 + FindOne(queryOptions map[string]interface{}) (*ProjectModule, error)
  29 + Find(queryOptions map[string]interface{}) (int64, []*ProjectModule, error)
  30 +}
  31 +
  32 +func (projectModule *ProjectModule) Identify() interface{} {
  33 + if projectModule.Id == 0 {
  34 + return nil
  35 + }
  36 + return projectModule.Id
  37 +}
  38 +
  39 +func (projectModule *ProjectModule) Update(data map[string]interface{}) error {
  40 + if projectName, ok := data["projectName"]; ok {
  41 + projectModule.ProjectName = projectName.(string)
  42 + }
  43 + if projectKey, ok := data["projectKey"]; ok {
  44 + projectModule.ProjectKey = projectKey.(string)
  45 + }
  46 + if description, ok := data["description"]; ok {
  47 + projectModule.Description = description.(string)
  48 + }
  49 + if status, ok := data["status"]; ok {
  50 + projectModule.Status = status.(int)
  51 + }
  52 + if CreateTime, ok := data["CreateTime"]; ok {
  53 + projectModule.CreateTime = CreateTime.(time.Time)
  54 + }
  55 + if UpdateTime, ok := data["UpdateTime"]; ok {
  56 + projectModule.UpdateTime = UpdateTime.(time.Time)
  57 + }
  58 + //if id, ok := data["id"]; ok {
  59 + // projectModule.ProjectModuleVersion.Id = id.(int64)
  60 + //}
  61 + //if projectModuleId, ok := data["projectModuleId"]; ok {
  62 + // projectModule.ProjectModuleVersion.ProjectModuleId = projectModuleId.(int64)
  63 + //}
  64 + //if version, ok := data["version"]; ok {
  65 + // projectModule.ProjectModuleVersion.Version = version.(int64)
  66 + //}
  67 + //if description, ok := data["description"]; ok {
  68 + // projectModule.ProjectModuleVersion.Description = description.(string)
  69 + //}
  70 + //if status, ok := data["status"]; ok {
  71 + // projectModule.ProjectModuleVersion.Status = status.(int)
  72 + //}
  73 + //if CreateTime, ok := data["CreateTime"]; ok {
  74 + // projectModule.ProjectModuleVersion.CreateTime = CreateTime.(datetime)
  75 + //}
  76 + //if UpdateTime, ok := data["UpdateTime"]; ok {
  77 + // projectModule.ProjectModuleVersion.UpdateTime = UpdateTime.(datetime)
  78 + //}
  79 + return nil
  80 +}
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +// 项目模板文件
  6 +type ProjectModuleFiles struct {
  7 + // 唯一标识
  8 + Id int64 `json:"id"`
  9 + // 项目编号
  10 + ProjectModuleId int64 `json:"projectModuleId"`
  11 + // 项目版本编号
  12 + ProjectModuleVersion int64 `json:"projectModuleVersion"`
  13 + // 文件类型 1:文件夹 2:文件
  14 + FileType int `json:"fileType"`
  15 + // 代码块
  16 + CodeBlock string `json:"codeBlock"`
  17 + // 父级Id
  18 + ParentId int64 `json:"parentId"`
  19 + // 排序
  20 + Sort int `json:"sort"`
  21 + // 备注信息
  22 + Remark string `json:"remark"`
  23 + // 创建时间
  24 + CreateTime time.Time `json:"createTime"`
  25 + // 更新时间
  26 + UpdateTime time.Time `json:"updateTime"`
  27 + // 当前文件相对路径 a/b/c
  28 + Path string `json:"path"`
  29 + // 标签
  30 + Tag string `json:"tag"`
  31 +}
  32 +
  33 +type ProjectModuleFilesRepository interface {
  34 + Save(projectModuleFiles *ProjectModuleFiles) (*ProjectModuleFiles, error)
  35 + Remove(projectModuleFiles *ProjectModuleFiles) (*ProjectModuleFiles, error)
  36 + FindOne(queryOptions map[string]interface{}) (*ProjectModuleFiles, error)
  37 + Find(queryOptions map[string]interface{}) (int64, []*ProjectModuleFiles, error)
  38 +}
  39 +
  40 +func (projectModuleFiles *ProjectModuleFiles) Identify() interface{} {
  41 + if projectModuleFiles.Id == 0 {
  42 + return nil
  43 + }
  44 + return projectModuleFiles.Id
  45 +}
  46 +
  47 +func (projectModuleFiles *ProjectModuleFiles) Update(data map[string]interface{}) error {
  48 + if id, ok := data["id"]; ok {
  49 + projectModuleFiles.Id = id.(int64)
  50 + }
  51 + if projectModuleId, ok := data["projectModuleId"]; ok {
  52 + projectModuleFiles.ProjectModuleId = projectModuleId.(int64)
  53 + }
  54 + if projectModuleVersion, ok := data["projectModuleVersion"]; ok {
  55 + projectModuleFiles.ProjectModuleVersion = projectModuleVersion.(int64)
  56 + }
  57 + if fileType, ok := data["fileType"]; ok {
  58 + projectModuleFiles.FileType = fileType.(int)
  59 + }
  60 + if codeBlock, ok := data["codeBlock"]; ok {
  61 + projectModuleFiles.CodeBlock = codeBlock.(string)
  62 + }
  63 + if ParentId, ok := data["ParentId"]; ok {
  64 + projectModuleFiles.ParentId = ParentId.(int64)
  65 + }
  66 + if Sort, ok := data["Sort"]; ok {
  67 + projectModuleFiles.Sort = Sort.(int)
  68 + }
  69 + if remark, ok := data["remark"]; ok {
  70 + projectModuleFiles.Remark = remark.(string)
  71 + }
  72 + if CreateTime, ok := data["CreateTime"]; ok {
  73 + projectModuleFiles.CreateTime = CreateTime.(time.Time)
  74 + }
  75 + if UpdateTime, ok := data["UpdateTime"]; ok {
  76 + projectModuleFiles.UpdateTime = UpdateTime.(time.Time)
  77 + }
  78 + if path, ok := data["path"]; ok {
  79 + projectModuleFiles.Path = path.(string)
  80 + }
  81 + if tag, ok := data["tag"]; ok {
  82 + projectModuleFiles.Tag = tag.(string)
  83 + }
  84 + return nil
  85 +}
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +// 项目模块版本
  6 +type ProjectModuleVersion struct {
  7 + // 唯一标识
  8 + Id int64 `json:"id"`
  9 + // 项目编号
  10 + ProjectModuleId int64 `json:"projectModuleId"`
  11 + // 唯一标识
  12 + Version int64 `json:"version"`
  13 + // 描述信息
  14 + Description string `json:"description"`
  15 + // 状态 1:正常 2:删除
  16 + Status int `json:"status"`
  17 + // 创建时间
  18 + CreateTime time.Time `json:"createTime"`
  19 + // 更新时间
  20 + UpdateTime time.Time `json:"updateTime"`
  21 +}
  22 +
  23 +type ProjectModuleVersionRepository interface {
  24 + Save(projectModuleVersion *ProjectModuleVersion) (*ProjectModuleVersion, error)
  25 + Remove(projectModuleVersion *ProjectModuleVersion) (*ProjectModuleVersion, error)
  26 + FindOne(queryOptions map[string]interface{}) (*ProjectModuleVersion, error)
  27 + Find(queryOptions map[string]interface{}) (int64, []*ProjectModuleVersion, error)
  28 +}
  29 +
  30 +func (projectModuleVersion *ProjectModuleVersion) Identify() interface{} {
  31 + if projectModuleVersion.Id == 0 {
  32 + return nil
  33 + }
  34 + return projectModuleVersion.Id
  35 +}
  36 +
  37 +func (projectModuleVersion *ProjectModuleVersion) Update(data map[string]interface{}) error {
  38 + if id, ok := data["id"]; ok {
  39 + projectModuleVersion.Id = id.(int64)
  40 + }
  41 + if projectModuleId, ok := data["projectModuleId"]; ok {
  42 + projectModuleVersion.ProjectModuleId = projectModuleId.(int64)
  43 + }
  44 + if version, ok := data["version"]; ok {
  45 + projectModuleVersion.Version = version.(int64)
  46 + }
  47 + if description, ok := data["description"]; ok {
  48 + projectModuleVersion.Description = description.(string)
  49 + }
  50 + if status, ok := data["status"]; ok {
  51 + projectModuleVersion.Status = status.(int)
  52 + }
  53 + if CreateTime, ok := data["CreateTime"]; ok {
  54 + projectModuleVersion.CreateTime = CreateTime.(time.Time)
  55 + }
  56 + if UpdateTime, ok := data["UpdateTime"]; ok {
  57 + projectModuleVersion.UpdateTime = UpdateTime.(time.Time)
  58 + }
  59 + return nil
  60 +}
@@ -6,7 +6,7 @@ import ( @@ -6,7 +6,7 @@ import (
6 ) 6 )
7 7
8 type ClientVersion struct { 8 type ClientVersion struct {
9 - TableName string `pg:"client_versions,alias:client_version"` 9 + tableName struct{} `pg:"client_version,alias:client_version"`
10 // dcc 10 // dcc
11 Id int64 11 Id int64
12 // 提交人 12 // 提交人
  1 +package models
  2 +
  3 +import "time"
  4 +
  5 +type ProjectModule struct {
  6 + tableName struct{} `pg:"project_module,alias:project_module"`
  7 + // 唯一标识
  8 + Id int64 `pg:"pk"`
  9 + // 项目名称
  10 + ProjectName string
  11 + // 项目唯一键值
  12 + ProjectKey string
  13 + // 描述信息
  14 + Description string
  15 + // 状态 1:正常 2:删除
  16 + Status int
  17 + // 创建时间
  18 + CreateTime time.Time
  19 + // 更新时间
  20 + UpdateTime time.Time
  21 + // 项目模板版本信息
  22 + ProjectModuleVersion *ProjectModuleVersion
  23 +}
  1 +package models
  2 +
  3 +import "time"
  4 +
  5 +type ProjectModuleFiles struct {
  6 + tableName struct{} `pg:"project_module_files,alias:project_module_files"`
  7 + // 唯一标识
  8 + Id int64 `pg:"pk"`
  9 + // 项目编号
  10 + ProjectModuleId int64
  11 + // 项目版本编号
  12 + ProjectModuleVersion int64
  13 + // 文件类型 1:文件夹 2:文件
  14 + FileType int
  15 + // 代码块
  16 + CodeBlock string
  17 + // 父级Id
  18 + ParentId int64
  19 + // 排序
  20 + Sort int
  21 + // 备注信息
  22 + Remark string
  23 + // 创建时间
  24 + CreateTime time.Time
  25 + // 更新时间
  26 + UpdateTime time.Time
  27 + // 当前文件相对路径 a/b/c
  28 + Path string
  29 + // 标签
  30 + Tag string
  31 +}
  1 +package models
  2 +
  3 +import "time"
  4 +
  5 +type ProjectModuleVersion struct {
  6 + tableName struct{} `pg:"project_module_version,alias:project_module_version"`
  7 + // 唯一标识
  8 + Id int64 `pg:"pk"`
  9 + // 项目编号
  10 + ProjectModuleId int64
  11 + // 唯一标识
  12 + Version int64
  13 + // 描述信息
  14 + Description string
  15 + // 状态 1:正常 2:删除
  16 + Status int
  17 + // 创建时间
  18 + CreateTime time.Time
  19 + // 更新时间
  20 + UpdateTime time.Time
  21 +}
1 package models 1 package models
2 2
3 type RoleAccess struct { 3 type RoleAccess struct {
4 - TableName string `pg:"role_access,alias:role_access"` 4 + tableName struct{} `pg:"role_access,alias:role_access"`
5 // dcc 5 // dcc
6 Id int64 6 Id int64
7 // 角色id 7 // 角色id
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/go-pg/pg/v10"
  7 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  8 + "github.com/tiptok/godevp/pkg/domain"
  9 + "github.com/tiptok/godevp/pkg/infrastructure/pg/models"
  10 +)
  11 +
  12 +type ProjectModuleFilesRepository struct {
  13 + transactionContext *pgTransaction.TransactionContext
  14 +}
  15 +
  16 +func (repository *ProjectModuleFilesRepository) nextIdentify() (int64, error) {
  17 + return 0, nil
  18 +}
  19 +func (repository *ProjectModuleFilesRepository) Save(projectModuleFiles *domain.ProjectModuleFiles) (*domain.ProjectModuleFiles, error) {
  20 + tx := repository.transactionContext.PgTx
  21 + if projectModuleFiles.Identify() == nil {
  22 + _, err := repository.nextIdentify()
  23 + if err != nil {
  24 + return projectModuleFiles, err
  25 + }
  26 + if _, err := tx.QueryOne(
  27 + pg.Scan(&projectModuleFiles.Id, &projectModuleFiles.ProjectModuleId, &projectModuleFiles.ProjectModuleVersion, &projectModuleFiles.FileType, &projectModuleFiles.CodeBlock, &projectModuleFiles.ParentId, &projectModuleFiles.Sort, &projectModuleFiles.Remark, &projectModuleFiles.CreateTime, &projectModuleFiles.UpdateTime, &projectModuleFiles.Path, &projectModuleFiles.Tag),
  28 + "INSERT INTO project_module_filess (id, project_module_id, project_module_version, file_type, code_block, parent_id, sort, remark, create_time, update_time, path, tag) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, project_module_id, project_module_version, file_type, code_block, parent_id, sort, remark, create_time, update_time, path, tag",
  29 + projectModuleFiles.ProjectModuleId, projectModuleFiles.ProjectModuleVersion, projectModuleFiles.FileType, projectModuleFiles.CodeBlock, projectModuleFiles.ParentId, projectModuleFiles.Sort, projectModuleFiles.Remark, projectModuleFiles.CreateTime, projectModuleFiles.UpdateTime, projectModuleFiles.Path, projectModuleFiles.Tag); err != nil {
  30 + return projectModuleFiles, err
  31 + }
  32 + } else {
  33 + if _, err := tx.QueryOne(
  34 + pg.Scan(&projectModuleFiles.ProjectModuleId, &projectModuleFiles.ProjectModuleVersion, &projectModuleFiles.FileType, &projectModuleFiles.CodeBlock, &projectModuleFiles.ParentId, &projectModuleFiles.Sort, &projectModuleFiles.Remark, &projectModuleFiles.CreateTime, &projectModuleFiles.UpdateTime, &projectModuleFiles.Path, &projectModuleFiles.Tag),
  35 + "UPDATE project_module_filess SET project_module_id=?, project_module_version=?, file_type=?, code_block=?, parent_id=?, sort=?, remark=?, create_time=?, update_time=?, path=?, tag=? WHERE id=? RETURNING project_module_id, project_module_version, file_type, code_block, parent_id, sort, remark, create_time, update_time, path, tag",
  36 + projectModuleFiles.ProjectModuleId, projectModuleFiles.ProjectModuleVersion, projectModuleFiles.FileType, projectModuleFiles.CodeBlock, projectModuleFiles.ParentId, projectModuleFiles.Sort, projectModuleFiles.Remark, projectModuleFiles.CreateTime, projectModuleFiles.UpdateTime, projectModuleFiles.Path, projectModuleFiles.Tag, projectModuleFiles.Identify()); err != nil {
  37 + return projectModuleFiles, err
  38 + }
  39 + }
  40 + return projectModuleFiles, nil
  41 +}
  42 +func (repository *ProjectModuleFilesRepository) Remove(projectModuleFiles *domain.ProjectModuleFiles) (*domain.ProjectModuleFiles, error) {
  43 + tx := repository.transactionContext.PgTx
  44 + projectModuleFilesModel := new(models.ProjectModuleFiles)
  45 + projectModuleFilesModel.Id = projectModuleFiles.Identify().(int64)
  46 + if _, err := tx.Model(projectModuleFilesModel).WherePK().Delete(); err != nil {
  47 + return projectModuleFiles, err
  48 + }
  49 + return projectModuleFiles, nil
  50 +}
  51 +func (repository *ProjectModuleFilesRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProjectModuleFiles, error) {
  52 + tx := repository.transactionContext.PgTx
  53 + projectModuleFilesModel := new(models.ProjectModuleFiles)
  54 + query := tx.Model(projectModuleFilesModel)
  55 + if projectModuleFilesId, ok := queryOptions["projectModuleFilesId"]; ok {
  56 + query = query.Where("project_module_files.id = ?", projectModuleFilesId)
  57 + }
  58 + if err := query.First(); err != nil {
  59 + if err.Error() == "pg: no rows in result set" {
  60 + return nil, fmt.Errorf("没有此资源")
  61 + } else {
  62 + return nil, err
  63 + }
  64 + }
  65 + if projectModuleFilesModel.Id == 0 {
  66 + return nil, nil
  67 + } else {
  68 + return repository.transformPgModelToDomainModel(projectModuleFilesModel)
  69 + }
  70 +}
  71 +func (repository *ProjectModuleFilesRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProjectModuleFiles, error) {
  72 + tx := repository.transactionContext.PgTx
  73 + var projectModuleFilesModels []*models.ProjectModuleFiles
  74 + projectModuleFiless := make([]*domain.ProjectModuleFiles, 0)
  75 + query := tx.Model(&projectModuleFilesModels)
  76 + if offset, ok := queryOptions["offset"]; ok {
  77 + offset := offset.(int)
  78 + if offset > -1 {
  79 + query = query.Offset(offset)
  80 + }
  81 + } else {
  82 + query = query.Offset(0)
  83 + }
  84 + if limit, ok := queryOptions["limit"]; ok {
  85 + limit := limit.(int)
  86 + if limit > -1 {
  87 + query = query.Limit(limit)
  88 + }
  89 + } else {
  90 + query = query.Limit(20)
  91 + }
  92 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  93 + return 0, projectModuleFiless, err
  94 + } else {
  95 + for _, projectModuleFilesModel := range projectModuleFilesModels {
  96 + if projectModuleFiles, err := repository.transformPgModelToDomainModel(projectModuleFilesModel); err != nil {
  97 + return 0, projectModuleFiless, err
  98 + } else {
  99 + projectModuleFiless = append(projectModuleFiless, projectModuleFiles)
  100 + }
  101 + }
  102 + return int64(count), projectModuleFiless, nil
  103 + }
  104 +}
  105 +func (repository *ProjectModuleFilesRepository) transformPgModelToDomainModel(projectModuleFilesModel *models.ProjectModuleFiles) (*domain.ProjectModuleFiles, error) {
  106 + return &domain.ProjectModuleFiles{
  107 + Id: projectModuleFilesModel.Id,
  108 + ProjectModuleId: projectModuleFilesModel.ProjectModuleId,
  109 + ProjectModuleVersion: projectModuleFilesModel.ProjectModuleVersion,
  110 + FileType: projectModuleFilesModel.FileType,
  111 + CodeBlock: projectModuleFilesModel.CodeBlock,
  112 + ParentId: projectModuleFilesModel.ParentId,
  113 + Sort: projectModuleFilesModel.Sort,
  114 + Remark: projectModuleFilesModel.Remark,
  115 + CreateTime: projectModuleFilesModel.CreateTime,
  116 + UpdateTime: projectModuleFilesModel.UpdateTime,
  117 + Path: projectModuleFilesModel.Path,
  118 + Tag: projectModuleFilesModel.Tag,
  119 + }, nil
  120 +}
  121 +func NewProjectModuleFilesRepository(transactionContext *pgTransaction.TransactionContext) (*ProjectModuleFilesRepository, error) {
  122 + if transactionContext == nil {
  123 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  124 + } else {
  125 + return &ProjectModuleFilesRepository{
  126 + transactionContext: transactionContext,
  127 + }, nil
  128 + }
  129 +}
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/go-pg/pg/v10"
  7 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  8 + "github.com/tiptok/godevp/pkg/domain"
  9 + "github.com/tiptok/godevp/pkg/infrastructure/pg/models"
  10 +)
  11 +
  12 +type ProjectModuleRepository struct {
  13 + transactionContext *pgTransaction.TransactionContext
  14 +}
  15 +
  16 +func (repository *ProjectModuleRepository) nextIdentify() (int64, error) {
  17 + return 0, nil
  18 +}
  19 +func (repository *ProjectModuleRepository) Save(projectModule *domain.ProjectModule) (*domain.ProjectModule, error) {
  20 + tx := repository.transactionContext.PgTx
  21 + if projectModule.Identify() == nil {
  22 + _, err := repository.nextIdentify()
  23 + if err != nil {
  24 + return projectModule, err
  25 + }
  26 + if _, err := tx.QueryOne(
  27 + pg.Scan(&projectModule.Id, &projectModule.ProjectName, &projectModule.ProjectKey, &projectModule.Description, &projectModule.Status, &projectModule.CreateTime, &projectModule.UpdateTime, &projectModule.ProjectModuleVersion),
  28 + "INSERT INTO project_module (id, project_name, project_key, description, status, create_time, update_time, project_module_version) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?) RETURNING id, project_name, project_key, description, status, create_time, update_time, project_module_version",
  29 + projectModule.ProjectName, projectModule.ProjectKey, projectModule.Description, projectModule.Status, projectModule.CreateTime, projectModule.UpdateTime, projectModule.ProjectModuleVersion); err != nil {
  30 + return projectModule, err
  31 + }
  32 + } else {
  33 + if _, err := tx.QueryOne(
  34 + pg.Scan(&projectModule.ProjectName, &projectModule.ProjectKey, &projectModule.Description, &projectModule.Status, &projectModule.CreateTime, &projectModule.UpdateTime, &projectModule.ProjectModuleVersion),
  35 + "UPDATE project_module SET project_name=?, project_key=?, description=?, status=?, create_time=?, update_time=?, project_module_version=? WHERE id=? RETURNING project_name, project_key, description, status, create_time, update_time, project_module_version",
  36 + projectModule.ProjectName, projectModule.ProjectKey, projectModule.Description, projectModule.Status, projectModule.CreateTime, projectModule.UpdateTime, projectModule.ProjectModuleVersion, projectModule.Identify()); err != nil {
  37 + return projectModule, err
  38 + }
  39 + }
  40 + return projectModule, nil
  41 +}
  42 +func (repository *ProjectModuleRepository) Remove(projectModule *domain.ProjectModule) (*domain.ProjectModule, error) {
  43 + tx := repository.transactionContext.PgTx
  44 + projectModuleModel := new(models.ProjectModule)
  45 + projectModuleModel.Id = projectModule.Identify().(int64)
  46 + if _, err := tx.Model(projectModuleModel).WherePK().Delete(); err != nil {
  47 + return projectModule, err
  48 + }
  49 + return projectModule, nil
  50 +}
  51 +func (repository *ProjectModuleRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProjectModule, error) {
  52 + tx := repository.transactionContext.PgTx
  53 + projectModuleModel := new(models.ProjectModule)
  54 + query := tx.Model(projectModuleModel)
  55 + if projectModuleId, ok := queryOptions["projectModuleId"]; ok {
  56 + query = query.Where("project_module.id = ?", projectModuleId)
  57 + }
  58 + if err := query.First(); err != nil {
  59 + if err.Error() == "pg: no rows in result set" {
  60 + return nil, fmt.Errorf("没有此资源")
  61 + } else {
  62 + return nil, err
  63 + }
  64 + }
  65 + if projectModuleModel.Id == 0 {
  66 + return nil, nil
  67 + } else {
  68 + return repository.transformPgModelToDomainModel(projectModuleModel)
  69 + }
  70 +}
  71 +func (repository *ProjectModuleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProjectModule, error) {
  72 + tx := repository.transactionContext.PgTx
  73 + var projectModuleModels []*models.ProjectModule
  74 + projectModules := make([]*domain.ProjectModule, 0)
  75 + query := tx.Model(&projectModuleModels)
  76 + if offset, ok := queryOptions["offset"]; ok {
  77 + offset := offset.(int)
  78 + if offset > -1 {
  79 + query = query.Offset(offset)
  80 + }
  81 + } else {
  82 + query = query.Offset(0)
  83 + }
  84 + if limit, ok := queryOptions["limit"]; ok {
  85 + limit := limit.(int)
  86 + if limit > -1 {
  87 + query = query.Limit(limit)
  88 + }
  89 + } else {
  90 + query = query.Limit(20)
  91 + }
  92 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  93 + return 0, projectModules, err
  94 + } else {
  95 + for _, projectModuleModel := range projectModuleModels {
  96 + if projectModule, err := repository.transformPgModelToDomainModel(projectModuleModel); err != nil {
  97 + return 0, projectModules, err
  98 + } else {
  99 + projectModules = append(projectModules, projectModule)
  100 + }
  101 + }
  102 + return int64(count), projectModules, nil
  103 + }
  104 +}
  105 +func (repository *ProjectModuleRepository) transformPgModelToDomainModel(projectModuleModel *models.ProjectModule) (*domain.ProjectModule, error) {
  106 + return &domain.ProjectModule{
  107 + Id: projectModuleModel.Id,
  108 + ProjectName: projectModuleModel.ProjectName,
  109 + ProjectKey: projectModuleModel.ProjectKey,
  110 + Description: projectModuleModel.Description,
  111 + Status: projectModuleModel.Status,
  112 + CreateTime: projectModuleModel.CreateTime,
  113 + UpdateTime: projectModuleModel.UpdateTime,
  114 + //ProjectModuleVersion: projectModuleModel.ProjectModuleVersion,
  115 + }, nil
  116 +}
  117 +func NewProjectModuleRepository(transactionContext *pgTransaction.TransactionContext) (*ProjectModuleRepository, error) {
  118 + if transactionContext == nil {
  119 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  120 + } else {
  121 + return &ProjectModuleRepository{
  122 + transactionContext: transactionContext,
  123 + }, nil
  124 + }
  125 +}
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/go-pg/pg/v10"
  7 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  8 + "github.com/tiptok/godevp/pkg/domain"
  9 + "github.com/tiptok/godevp/pkg/infrastructure/pg/models"
  10 +)
  11 +
  12 +type ProjectModuleVersionRepository struct {
  13 + transactionContext *pgTransaction.TransactionContext
  14 +}
  15 +
  16 +func (repository *ProjectModuleVersionRepository) nextIdentify() (int64, error) {
  17 + return 0, nil
  18 +}
  19 +func (repository *ProjectModuleVersionRepository) Save(projectModuleVersion *domain.ProjectModuleVersion) (*domain.ProjectModuleVersion, error) {
  20 + tx := repository.transactionContext.PgTx
  21 + if projectModuleVersion.Identify() == nil {
  22 + _, err := repository.nextIdentify()
  23 + if err != nil {
  24 + return projectModuleVersion, err
  25 + }
  26 + if _, err := tx.QueryOne(
  27 + pg.Scan(&projectModuleVersion.Id, &projectModuleVersion.ProjectModuleId, &projectModuleVersion.Version, &projectModuleVersion.Description, &projectModuleVersion.Status, &projectModuleVersion.CreateTime, &projectModuleVersion.UpdateTime),
  28 + "INSERT INTO project_module_versions (project_module_version.id, project_module_version.project_module_id, project_module_version.version, project_module_version.description, project_module_version.status, project_module_version._create_time, project_module_version._update_time, id, project_module_id, version, description, status, create_time, update_time) VALUES (?, ?, ?, ?, ?, ?, ?, DEFAULT, ?, ?, ?, ?, ?, ?) RETURNING project_module_version.id, project_module_version.project_module_id, project_module_version.version, project_module_version.description, project_module_version.status, project_module_version._create_time, project_module_version._update_time, id, project_module_id, version, description, status, create_time, update_time",
  29 + projectModuleVersion.ProjectModuleId, projectModuleVersion.Version, projectModuleVersion.Description, projectModuleVersion.Status, projectModuleVersion.CreateTime, projectModuleVersion.UpdateTime); err != nil {
  30 + return projectModuleVersion, err
  31 + }
  32 + } else {
  33 + if _, err := tx.QueryOne(
  34 + pg.Scan(&projectModuleVersion.ProjectModuleId, &projectModuleVersion.Version, &projectModuleVersion.Description, &projectModuleVersion.Status, &projectModuleVersion.CreateTime, &projectModuleVersion.UpdateTime),
  35 + "UPDATE project_module_versions SET project_module_version.id=?, project_module_version.project_module_id=?, project_module_version.version=?, project_module_version.description=?, project_module_version.status=?, project_module_version._create_time=?, project_module_version._update_time=?, project_module_id=?, version=?, description=?, status=?, create_time=?, update_time=? WHERE id=? RETURNING project_module_version.id, project_module_version.project_module_id, project_module_version.version, project_module_version.description, project_module_version.status, project_module_version._create_time, project_module_version._update_time, project_module_id, version, description, status, create_time, update_time",
  36 + projectModuleVersion.ProjectModuleId, projectModuleVersion.Version, projectModuleVersion.Description, projectModuleVersion.Status, projectModuleVersion.CreateTime, projectModuleVersion.UpdateTime, projectModuleVersion.Identify()); err != nil {
  37 + return projectModuleVersion, err
  38 + }
  39 + }
  40 + return projectModuleVersion, nil
  41 +}
  42 +func (repository *ProjectModuleVersionRepository) Remove(projectModuleVersion *domain.ProjectModuleVersion) (*domain.ProjectModuleVersion, error) {
  43 + tx := repository.transactionContext.PgTx
  44 + projectModuleVersionModel := new(models.ProjectModuleVersion)
  45 + projectModuleVersionModel.Id = projectModuleVersion.Identify().(int64)
  46 + if _, err := tx.Model(projectModuleVersionModel).WherePK().Delete(); err != nil {
  47 + return projectModuleVersion, err
  48 + }
  49 + return projectModuleVersion, nil
  50 +}
  51 +func (repository *ProjectModuleVersionRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProjectModuleVersion, error) {
  52 + tx := repository.transactionContext.PgTx
  53 + projectModuleVersionModel := new(models.ProjectModuleVersion)
  54 + query := tx.Model(projectModuleVersionModel)
  55 + if projectModuleVersionId, ok := queryOptions["projectModuleVersionId"]; ok {
  56 + query = query.Where("project_module_version.id = ?", projectModuleVersionId)
  57 + }
  58 + if err := query.First(); err != nil {
  59 + if err.Error() == "pg: no rows in result set" {
  60 + return nil, fmt.Errorf("没有此资源")
  61 + } else {
  62 + return nil, err
  63 + }
  64 + }
  65 + if projectModuleVersionModel.Id == 0 {
  66 + return nil, nil
  67 + } else {
  68 + return repository.transformPgModelToDomainModel(projectModuleVersionModel)
  69 + }
  70 +}
  71 +func (repository *ProjectModuleVersionRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProjectModuleVersion, error) {
  72 + tx := repository.transactionContext.PgTx
  73 + var projectModuleVersionModels []*models.ProjectModuleVersion
  74 + projectModuleVersions := make([]*domain.ProjectModuleVersion, 0)
  75 + query := tx.Model(&projectModuleVersionModels)
  76 + if offset, ok := queryOptions["offset"]; ok {
  77 + offset := offset.(int)
  78 + if offset > -1 {
  79 + query = query.Offset(offset)
  80 + }
  81 + } else {
  82 + query = query.Offset(0)
  83 + }
  84 + if limit, ok := queryOptions["limit"]; ok {
  85 + limit := limit.(int)
  86 + if limit > -1 {
  87 + query = query.Limit(limit)
  88 + }
  89 + } else {
  90 + query = query.Limit(20)
  91 + }
  92 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  93 + return 0, projectModuleVersions, err
  94 + } else {
  95 + for _, projectModuleVersionModel := range projectModuleVersionModels {
  96 + if projectModuleVersion, err := repository.transformPgModelToDomainModel(projectModuleVersionModel); err != nil {
  97 + return 0, projectModuleVersions, err
  98 + } else {
  99 + projectModuleVersions = append(projectModuleVersions, projectModuleVersion)
  100 + }
  101 + }
  102 + return int64(count), projectModuleVersions, nil
  103 + }
  104 +}
  105 +func (repository *ProjectModuleVersionRepository) transformPgModelToDomainModel(projectModuleVersionModel *models.ProjectModuleVersion) (*domain.ProjectModuleVersion, error) {
  106 + return &domain.ProjectModuleVersion{
  107 + Id: projectModuleVersionModel.Id,
  108 + ProjectModuleId: projectModuleVersionModel.ProjectModuleId,
  109 + Version: projectModuleVersionModel.Version,
  110 + Description: projectModuleVersionModel.Description,
  111 + Status: projectModuleVersionModel.Status,
  112 + CreateTime: projectModuleVersionModel.CreateTime,
  113 + UpdateTime: projectModuleVersionModel.UpdateTime,
  114 + }, nil
  115 +}
  116 +func NewProjectModuleVersionRepository(transactionContext *pgTransaction.TransactionContext) (*ProjectModuleVersionRepository, error) {
  117 + if transactionContext == nil {
  118 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  119 + } else {
  120 + return &ProjectModuleVersionRepository{
  121 + transactionContext: transactionContext,
  122 + }, nil
  123 + }
  124 +}
  1 +package controllers
  2 +
  3 +import (
  4 + "encoding/json"
  5 +
  6 + "github.com/astaxie/beego"
  7 + "github.com/linmadan/egglib-go/web/beego/utils"
  8 + "github.com/tiptok/godevp/pkg/application/projectModule/command"
  9 + "github.com/tiptok/godevp/pkg/application/projectModule/query"
  10 + "github.com/tiptok/godevp/pkg/application/projectModule/service"
  11 +)
  12 +
  13 +type ProjectModuleController struct {
  14 + beego.Controller
  15 +}
  16 +
  17 +func (controller *ProjectModuleController) CreateProjectModule() {
  18 + projectModuleService := service.NewProjectModuleService(nil)
  19 + createProjectModuleCommand := &command.CreateProjectModuleCommand{}
  20 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createProjectModuleCommand)
  21 + data, err := projectModuleService.CreateProjectModule(createProjectModuleCommand)
  22 + var response utils.JsonResponse
  23 + if err != nil {
  24 + response = utils.ResponseError(controller.Ctx, err)
  25 + } else {
  26 + response = utils.ResponseData(controller.Ctx, data)
  27 + }
  28 + controller.Data["json"] = response
  29 + controller.ServeJSON()
  30 +}
  31 +
  32 +func (controller *ProjectModuleController) UpdateProjectModule() {
  33 + projectModuleService := service.NewProjectModuleService(nil)
  34 + updateProjectModuleCommand := &command.UpdateProjectModuleCommand{}
  35 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateProjectModuleCommand)
  36 + projectModuleId, _ := controller.GetInt64(":projectModuleId")
  37 + updateProjectModuleCommand.ProjectModuleId = projectModuleId
  38 + data, err := projectModuleService.UpdateProjectModule(updateProjectModuleCommand)
  39 + var response utils.JsonResponse
  40 + if err != nil {
  41 + response = utils.ResponseError(controller.Ctx, err)
  42 + } else {
  43 + response = utils.ResponseData(controller.Ctx, data)
  44 + }
  45 + controller.Data["json"] = response
  46 + controller.ServeJSON()
  47 +}
  48 +
  49 +func (controller *ProjectModuleController) GetProjectModule() {
  50 + projectModuleService := service.NewProjectModuleService(nil)
  51 + getProjectModuleQuery := &query.GetProjectModuleQuery{}
  52 + projectModuleId, _ := controller.GetInt64(":projectModuleId")
  53 + getProjectModuleQuery.ProjectModuleId = projectModuleId
  54 + data, err := projectModuleService.GetProjectModule(getProjectModuleQuery)
  55 + var response utils.JsonResponse
  56 + if err != nil {
  57 + response = utils.ResponseError(controller.Ctx, err)
  58 + } else {
  59 + response = utils.ResponseData(controller.Ctx, data)
  60 + }
  61 + controller.Data["json"] = response
  62 + controller.ServeJSON()
  63 +}
  64 +
  65 +func (controller *ProjectModuleController) RemoveProjectModule() {
  66 + projectModuleService := service.NewProjectModuleService(nil)
  67 + removeProjectModuleCommand := &command.RemoveProjectModuleCommand{}
  68 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), removeProjectModuleCommand)
  69 + projectModuleId, _ := controller.GetInt64(":projectModuleId")
  70 + removeProjectModuleCommand.ProjectModuleId = projectModuleId
  71 + data, err := projectModuleService.RemoveProjectModule(removeProjectModuleCommand)
  72 + var response utils.JsonResponse
  73 + if err != nil {
  74 + response = utils.ResponseError(controller.Ctx, err)
  75 + } else {
  76 + response = utils.ResponseData(controller.Ctx, data)
  77 + }
  78 + controller.Data["json"] = response
  79 + controller.ServeJSON()
  80 +}
  81 +
  82 +func (controller *ProjectModuleController) ListProjectModule() {
  83 + projectModuleService := service.NewProjectModuleService(nil)
  84 + listProjectModuleQuery := &query.ListProjectModuleQuery{}
  85 + offset, _ := controller.GetInt("offset")
  86 + listProjectModuleQuery.Offset = offset
  87 + limit, _ := controller.GetInt("limit")
  88 + listProjectModuleQuery.Limit = limit
  89 + data, err := projectModuleService.ListProjectModule(listProjectModuleQuery)
  90 + var response utils.JsonResponse
  91 + if err != nil {
  92 + response = utils.ResponseError(controller.Ctx, err)
  93 + } else {
  94 + response = utils.ResponseData(controller.Ctx, data)
  95 + }
  96 + controller.Data["json"] = response
  97 + controller.ServeJSON()
  98 +}
  1 +package controllers
  2 +
  3 +import (
  4 + "encoding/json"
  5 +
  6 + "github.com/astaxie/beego"
  7 + "github.com/linmadan/egglib-go/web/beego/utils"
  8 + "github.com/tiptok/godevp/pkg/application/projectModuleFiles/command"
  9 + "github.com/tiptok/godevp/pkg/application/projectModuleFiles/query"
  10 + "github.com/tiptok/godevp/pkg/application/projectModuleFiles/service"
  11 +)
  12 +
  13 +type ProjectModuleFilesController struct {
  14 + beego.Controller
  15 +}
  16 +
  17 +func (controller *ProjectModuleFilesController) CreateProjectModuleFiles() {
  18 + projectModuleFilesService := service.NewProjectModuleFilesService(nil)
  19 + createProjectModuleFilesCommand := &command.CreateProjectModuleFilesCommand{}
  20 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createProjectModuleFilesCommand)
  21 + data, err := projectModuleFilesService.CreateProjectModuleFiles(createProjectModuleFilesCommand)
  22 + var response utils.JsonResponse
  23 + if err != nil {
  24 + response = utils.ResponseError(controller.Ctx, err)
  25 + } else {
  26 + response = utils.ResponseData(controller.Ctx, data)
  27 + }
  28 + controller.Data["json"] = response
  29 + controller.ServeJSON()
  30 +}
  31 +
  32 +func (controller *ProjectModuleFilesController) UpdateProjectModuleFiles() {
  33 + projectModuleFilesService := service.NewProjectModuleFilesService(nil)
  34 + updateProjectModuleFilesCommand := &command.UpdateProjectModuleFilesCommand{}
  35 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateProjectModuleFilesCommand)
  36 + projectModuleFilesId, _ := controller.GetInt64(":projectModuleFilesId")
  37 + updateProjectModuleFilesCommand.ProjectModuleFilesId = projectModuleFilesId
  38 + data, err := projectModuleFilesService.UpdateProjectModuleFiles(updateProjectModuleFilesCommand)
  39 + var response utils.JsonResponse
  40 + if err != nil {
  41 + response = utils.ResponseError(controller.Ctx, err)
  42 + } else {
  43 + response = utils.ResponseData(controller.Ctx, data)
  44 + }
  45 + controller.Data["json"] = response
  46 + controller.ServeJSON()
  47 +}
  48 +
  49 +func (controller *ProjectModuleFilesController) GetProjectModuleFiles() {
  50 + projectModuleFilesService := service.NewProjectModuleFilesService(nil)
  51 + getProjectModuleFilesQuery := &query.GetProjectModuleFilesQuery{}
  52 + projectModuleFilesId, _ := controller.GetInt64(":projectModuleFilesId")
  53 + getProjectModuleFilesQuery.ProjectModuleFilesId = projectModuleFilesId
  54 + data, err := projectModuleFilesService.GetProjectModuleFiles(getProjectModuleFilesQuery)
  55 + var response utils.JsonResponse
  56 + if err != nil {
  57 + response = utils.ResponseError(controller.Ctx, err)
  58 + } else {
  59 + response = utils.ResponseData(controller.Ctx, data)
  60 + }
  61 + controller.Data["json"] = response
  62 + controller.ServeJSON()
  63 +}
  64 +
  65 +func (controller *ProjectModuleFilesController) RemoveProjectModuleFiles() {
  66 + projectModuleFilesService := service.NewProjectModuleFilesService(nil)
  67 + removeProjectModuleFilesCommand := &command.RemoveProjectModuleFilesCommand{}
  68 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), removeProjectModuleFilesCommand)
  69 + projectModuleFilesId, _ := controller.GetInt64(":projectModuleFilesId")
  70 + removeProjectModuleFilesCommand.ProjectModuleFilesId = projectModuleFilesId
  71 + data, err := projectModuleFilesService.RemoveProjectModuleFiles(removeProjectModuleFilesCommand)
  72 + var response utils.JsonResponse
  73 + if err != nil {
  74 + response = utils.ResponseError(controller.Ctx, err)
  75 + } else {
  76 + response = utils.ResponseData(controller.Ctx, data)
  77 + }
  78 + controller.Data["json"] = response
  79 + controller.ServeJSON()
  80 +}
  81 +
  82 +func (controller *ProjectModuleFilesController) ListProjectModuleFiles() {
  83 + projectModuleFilesService := service.NewProjectModuleFilesService(nil)
  84 + listProjectModuleFilesQuery := &query.ListProjectModuleFilesQuery{}
  85 + offset, _ := controller.GetInt("offset")
  86 + listProjectModuleFilesQuery.Offset = offset
  87 + limit, _ := controller.GetInt("limit")
  88 + listProjectModuleFilesQuery.Limit = limit
  89 + data, err := projectModuleFilesService.ListProjectModuleFiles(listProjectModuleFilesQuery)
  90 + var response utils.JsonResponse
  91 + if err != nil {
  92 + response = utils.ResponseError(controller.Ctx, err)
  93 + } else {
  94 + response = utils.ResponseData(controller.Ctx, data)
  95 + }
  96 + controller.Data["json"] = response
  97 + controller.ServeJSON()
  98 +}
  1 +package controllers
  2 +
  3 +import (
  4 + "encoding/json"
  5 +
  6 + "github.com/astaxie/beego"
  7 + "github.com/linmadan/egglib-go/web/beego/utils"
  8 + "github.com/tiptok/godevp/pkg/application/projectModuleVersion/command"
  9 + "github.com/tiptok/godevp/pkg/application/projectModuleVersion/query"
  10 + "github.com/tiptok/godevp/pkg/application/projectModuleVersion/service"
  11 +)
  12 +
  13 +type ProjectModuleVersionController struct {
  14 + beego.Controller
  15 +}
  16 +
  17 +func (controller *ProjectModuleVersionController) CreateProjectModuleVersion() {
  18 + projectModuleVersionService := service.NewProjectModuleVersionService(nil)
  19 + createProjectModuleVersionCommand := &command.CreateProjectModuleVersionCommand{}
  20 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createProjectModuleVersionCommand)
  21 + data, err := projectModuleVersionService.CreateProjectModuleVersion(createProjectModuleVersionCommand)
  22 + var response utils.JsonResponse
  23 + if err != nil {
  24 + response = utils.ResponseError(controller.Ctx, err)
  25 + } else {
  26 + response = utils.ResponseData(controller.Ctx, data)
  27 + }
  28 + controller.Data["json"] = response
  29 + controller.ServeJSON()
  30 +}
  31 +
  32 +func (controller *ProjectModuleVersionController) UpdateProjectModuleVersion() {
  33 + projectModuleVersionService := service.NewProjectModuleVersionService(nil)
  34 + updateProjectModuleVersionCommand := &command.UpdateProjectModuleVersionCommand{}
  35 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateProjectModuleVersionCommand)
  36 + projectModuleVersionId, _ := controller.GetInt64(":projectModuleVersionId")
  37 + updateProjectModuleVersionCommand.ProjectModuleVersionId = projectModuleVersionId
  38 + data, err := projectModuleVersionService.UpdateProjectModuleVersion(updateProjectModuleVersionCommand)
  39 + var response utils.JsonResponse
  40 + if err != nil {
  41 + response = utils.ResponseError(controller.Ctx, err)
  42 + } else {
  43 + response = utils.ResponseData(controller.Ctx, data)
  44 + }
  45 + controller.Data["json"] = response
  46 + controller.ServeJSON()
  47 +}
  48 +
  49 +func (controller *ProjectModuleVersionController) GetProjectModuleVersion() {
  50 + projectModuleVersionService := service.NewProjectModuleVersionService(nil)
  51 + getProjectModuleVersionQuery := &query.GetProjectModuleVersionQuery{}
  52 + projectModuleVersionId, _ := controller.GetInt64(":projectModuleVersionId")
  53 + getProjectModuleVersionQuery.ProjectModuleVersionId = projectModuleVersionId
  54 + data, err := projectModuleVersionService.GetProjectModuleVersion(getProjectModuleVersionQuery)
  55 + var response utils.JsonResponse
  56 + if err != nil {
  57 + response = utils.ResponseError(controller.Ctx, err)
  58 + } else {
  59 + response = utils.ResponseData(controller.Ctx, data)
  60 + }
  61 + controller.Data["json"] = response
  62 + controller.ServeJSON()
  63 +}
  64 +
  65 +func (controller *ProjectModuleVersionController) RemoveProjectModuleVersion() {
  66 + projectModuleVersionService := service.NewProjectModuleVersionService(nil)
  67 + removeProjectModuleVersionCommand := &command.RemoveProjectModuleVersionCommand{}
  68 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), removeProjectModuleVersionCommand)
  69 + projectModuleVersionId, _ := controller.GetInt64(":projectModuleVersionId")
  70 + removeProjectModuleVersionCommand.ProjectModuleVersionId = projectModuleVersionId
  71 + data, err := projectModuleVersionService.RemoveProjectModuleVersion(removeProjectModuleVersionCommand)
  72 + var response utils.JsonResponse
  73 + if err != nil {
  74 + response = utils.ResponseError(controller.Ctx, err)
  75 + } else {
  76 + response = utils.ResponseData(controller.Ctx, data)
  77 + }
  78 + controller.Data["json"] = response
  79 + controller.ServeJSON()
  80 +}
  81 +
  82 +func (controller *ProjectModuleVersionController) ListProjectModuleVersion() {
  83 + projectModuleVersionService := service.NewProjectModuleVersionService(nil)
  84 + listProjectModuleVersionQuery := &query.ListProjectModuleVersionQuery{}
  85 + offset, _ := controller.GetInt("offset")
  86 + listProjectModuleVersionQuery.Offset = offset
  87 + limit, _ := controller.GetInt("limit")
  88 + listProjectModuleVersionQuery.Limit = limit
  89 + data, err := projectModuleVersionService.ListProjectModuleVersion(listProjectModuleVersionQuery)
  90 + var response utils.JsonResponse
  91 + if err != nil {
  92 + response = utils.ResponseError(controller.Ctx, err)
  93 + } else {
  94 + response = utils.ResponseData(controller.Ctx, data)
  95 + }
  96 + controller.Data["json"] = response
  97 + controller.ServeJSON()
  98 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "github.com/tiptok/godevp/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + beego.Router("/project-module-filess/", &controllers.ProjectModuleFilesController{}, "Post:CreateProjectModuleFiles")
  10 + beego.Router("/project-module-filess/:projectModuleFilesId", &controllers.ProjectModuleFilesController{}, "Put:UpdateProjectModuleFiles")
  11 + beego.Router("/project-module-filess/:projectModuleFilesId", &controllers.ProjectModuleFilesController{}, "Get:GetProjectModuleFiles")
  12 + beego.Router("/project-module-filess/:projectModuleFilesId", &controllers.ProjectModuleFilesController{}, "Delete:RemoveProjectModuleFiles")
  13 + beego.Router("/project-module-filess/", &controllers.ProjectModuleFilesController{}, "Get:ListProjectModuleFiles")
  14 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "github.com/tiptok/godevp/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + beego.Router("/project-modules/", &controllers.ProjectModuleController{}, "Post:CreateProjectModule")
  10 + beego.Router("/project-modules/:projectModuleId", &controllers.ProjectModuleController{}, "Put:UpdateProjectModule")
  11 + beego.Router("/project-modules/:projectModuleId", &controllers.ProjectModuleController{}, "Get:GetProjectModule")
  12 + beego.Router("/project-modules/:projectModuleId", &controllers.ProjectModuleController{}, "Delete:RemoveProjectModule")
  13 + beego.Router("/project-modules/", &controllers.ProjectModuleController{}, "Get:ListProjectModule")
  14 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "github.com/tiptok/godevp/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + beego.Router("/project-module-versions/", &controllers.ProjectModuleVersionController{}, "Post:CreateProjectModuleVersion")
  10 + beego.Router("/project-module-versions/:projectModuleVersionId", &controllers.ProjectModuleVersionController{}, "Put:UpdateProjectModuleVersion")
  11 + beego.Router("/project-module-versions/:projectModuleVersionId", &controllers.ProjectModuleVersionController{}, "Get:GetProjectModuleVersion")
  12 + beego.Router("/project-module-versions/:projectModuleVersionId", &controllers.ProjectModuleVersionController{}, "Delete:RemoveProjectModuleVersion")
  13 + beego.Router("/project-module-versions/", &controllers.ProjectModuleVersionController{}, "Get:ListProjectModuleVersion")
  14 +}
  1 +package project_module
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + . "github.com/onsi/ginkgo"
  8 + . "github.com/onsi/gomega"
  9 + pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
  10 +)
  11 +
  12 +var _ = Describe("创建", func() {
  13 + Describe("提交数据创建", func() {
  14 + Context("提交正确的新项目模块数据", func() {
  15 + It("返回项目模块数据", func() {
  16 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  17 + body := map[string]interface{}{
  18 + "projectName": "string",
  19 + "projectKey": "string",
  20 + "description": "string",
  21 + "status": "int",
  22 + }
  23 + httpExpect.POST("/project-modules/").
  24 + WithJSON(body).
  25 + Expect().
  26 + Status(http.StatusOK).
  27 + JSON().
  28 + Object().
  29 + ContainsKey("code").ValueEqual("code", 0).
  30 + ContainsKey("msg").ValueEqual("msg", "ok").
  31 + ContainsKey("data").Value("data").Object().
  32 + ContainsKey("id").ValueNotEqual("id", BeZero())
  33 + })
  34 + })
  35 + })
  36 + AfterEach(func() {
  37 + _, err := pG.DB.Exec("DELETE FROM project_modules WHERE true")
  38 + Expect(err).NotTo(HaveOccurred())
  39 + })
  40 +})
  1 +package project_module
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg/v10"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("返回", func() {
  14 + var projectModuleId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&projectModuleId),
  18 + "INSERT INTO project_modules (id, project_name, project_key, description, status, create_time, update_time, project_module_version) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
  19 + "testProjectName", "testProjectKey", "testDescription", "testStatus", "testCreateTime", "testUpdateTime", "testProjectModuleVersion")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据projectModuleId参数返回项目模块", func() {
  23 + Context("传入有效的projectModuleId", func() {
  24 + It("返回项目模块数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.GET("/project-modules/{projectModuleId}").
  27 + Expect().
  28 + Status(http.StatusOK).
  29 + JSON().
  30 + Object().
  31 + ContainsKey("code").ValueEqual("code", 0).
  32 + ContainsKey("msg").ValueEqual("msg", "ok").
  33 + ContainsKey("data").Value("data").Object()
  34 + })
  35 + })
  36 + })
  37 + AfterEach(func() {
  38 + _, err := pG.DB.Exec("DELETE FROM project_modules WHERE true")
  39 + Expect(err).NotTo(HaveOccurred())
  40 + })
  41 +})
  1 +package project_module
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg/v10"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("返回列表", func() {
  14 + var projectModuleId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&projectModuleId),
  18 + "INSERT INTO project_modules (id, project_name, project_key, description, status, create_time, update_time, project_module_version) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
  19 + "testProjectName", "testProjectKey", "testDescription", "testStatus", "testCreateTime", "testUpdateTime", "testProjectModuleVersion")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据参数返回项目模块列表", func() {
  23 + Context("传入有效的参数", func() {
  24 + It("返回项目模块数据列表", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.GET("/project-modules/").
  27 + WithQuery("offset", "int").
  28 + WithQuery("limit", "int").
  29 + Expect().
  30 + Status(http.StatusOK).
  31 + JSON().
  32 + Object().
  33 + ContainsKey("code").ValueEqual("code", 0).
  34 + ContainsKey("msg").ValueEqual("msg", "ok").
  35 + ContainsKey("data").Value("data").Object().
  36 + ContainsKey("count").ValueEqual("count", 1).
  37 + ContainsKey("projectModules").Value("projectModules").Array()
  38 + })
  39 + })
  40 + })
  41 + AfterEach(func() {
  42 + _, err := pG.DB.Exec("DELETE FROM project_modules WHERE true")
  43 + Expect(err).NotTo(HaveOccurred())
  44 + })
  45 +})
  1 +package project_module
  2 +
  3 +import (
  4 + "net/http"
  5 + "net/http/httptest"
  6 + "testing"
  7 +
  8 + "github.com/astaxie/beego"
  9 + . "github.com/onsi/ginkgo"
  10 + . "github.com/onsi/gomega"
  11 + _ "github.com/tiptok/godevp/pkg/infrastructure/pg"
  12 + _ "github.com/tiptok/godevp/pkg/port/beego"
  13 +)
  14 +
  15 +func TestProjectModule(t *testing.T) {
  16 + RegisterFailHandler(Fail)
  17 + RunSpecs(t, "Beego Port ProjectModule Correlations Test Case Suite")
  18 +}
  19 +
  20 +var handler http.Handler
  21 +var server *httptest.Server
  22 +
  23 +var _ = BeforeSuite(func() {
  24 + handler = beego.BeeApp.Handlers
  25 + server = httptest.NewServer(handler)
  26 +})
  27 +
  28 +var _ = AfterSuite(func() {
  29 + server.Close()
  30 +})
  1 +package project_module
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg/v10"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("移除", func() {
  14 + var projectModuleId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&projectModuleId),
  18 + "INSERT INTO project_modules (id, project_name, project_key, description, status, create_time, update_time, project_module_version) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
  19 + "testProjectName", "testProjectKey", "testDescription", "testStatus", "testCreateTime", "testUpdateTime", "testProjectModuleVersion")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据参数移除", func() {
  23 + Context("传入有效的projectModuleId", func() {
  24 + It("返回被移除项目模块的数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.DELETE("/project-modules/{projectModuleId}").
  27 + Expect().
  28 + Status(http.StatusOK).
  29 + JSON().
  30 + Object().
  31 + ContainsKey("code").ValueEqual("code", 0).
  32 + ContainsKey("msg").ValueEqual("msg", "ok").
  33 + ContainsKey("data").Value("data").Object()
  34 + })
  35 + })
  36 + })
  37 + AfterEach(func() {
  38 + _, err := pG.DB.Exec("DELETE FROM project_modules WHERE true")
  39 + Expect(err).NotTo(HaveOccurred())
  40 + })
  41 +})
  1 +package project_module
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg/v10"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("更新", func() {
  14 + var projectModuleId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&projectModuleId),
  18 + "INSERT INTO project_modules (id, project_name, project_key, description, status, create_time, update_time, project_module_version) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
  19 + "testProjectName", "testProjectKey", "testDescription", "testStatus", "testCreateTime", "testUpdateTime", "testProjectModuleVersion")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("提交数据更新", func() {
  23 + Context("提交正确的项目模块数据", func() {
  24 + It("返回更新后的项目模块数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + body := map[string]interface{}{
  27 + "projectName": "string",
  28 + "projectKey": "string",
  29 + "description": "string",
  30 + "status": "int",
  31 + }
  32 + httpExpect.PUT("/project-modules/{projectModuleId}").
  33 + WithJSON(body).
  34 + Expect().
  35 + Status(http.StatusOK).
  36 + JSON().
  37 + Object().
  38 + ContainsKey("code").ValueEqual("code", 0).
  39 + ContainsKey("msg").ValueEqual("msg", "ok").
  40 + ContainsKey("data").Value("data").Object().
  41 + ContainsKey("id").ValueEqual("id", projectModuleId)
  42 + })
  43 + })
  44 + })
  45 + AfterEach(func() {
  46 + _, err := pG.DB.Exec("DELETE FROM project_modules WHERE true")
  47 + Expect(err).NotTo(HaveOccurred())
  48 + })
  49 +})
  1 +package project_module_files
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + . "github.com/onsi/ginkgo"
  8 + . "github.com/onsi/gomega"
  9 + pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
  10 +)
  11 +
  12 +var _ = Describe("创建", func() {
  13 + Describe("提交数据创建", func() {
  14 + Context("提交正确的新项目模板文件数据", func() {
  15 + It("返回项目模板文件数据", func() {
  16 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  17 + body := map[string]interface{}{
  18 + "projectModuleId": "int64",
  19 + "projectModuleVersion": "int64",
  20 + "fileType": "int",
  21 + "codeBlock": "string",
  22 + "ParentId": "int64",
  23 + "Sort": "int",
  24 + "remark": "string",
  25 + }
  26 + httpExpect.POST("/project-module-filess/").
  27 + WithJSON(body).
  28 + Expect().
  29 + Status(http.StatusOK).
  30 + JSON().
  31 + Object().
  32 + ContainsKey("code").ValueEqual("code", 0).
  33 + ContainsKey("msg").ValueEqual("msg", "ok").
  34 + ContainsKey("data").Value("data").Object().
  35 + ContainsKey("id").ValueNotEqual("id", BeZero())
  36 + })
  37 + })
  38 + })
  39 + AfterEach(func() {
  40 + _, err := pG.DB.Exec("DELETE FROM project_module_filess WHERE true")
  41 + Expect(err).NotTo(HaveOccurred())
  42 + })
  43 +})
  1 +package project_module_files
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg/v10"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("返回", func() {
  14 + var projectModuleFilesId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&projectModuleFilesId),
  18 + "INSERT INTO project_module_filess (id, project_module_id, project_module_version, file_type, code_block, parent_id, sort, remark, create_time, update_time, path, tag) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
  19 + "testProjectModuleId", "testProjectModuleVersion", "testFileType", "testCodeBlock", "testParentId", "testSort", "testRemark", "testCreateTime", "testUpdateTime", "testPath", "testTag")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据projectModuleFilesId参数返回项目模板文件", func() {
  23 + Context("传入有效的projectModuleFilesId", func() {
  24 + It("返回项目模板文件数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.GET("/project-module-filess/{projectModuleFilesId}").
  27 + Expect().
  28 + Status(http.StatusOK).
  29 + JSON().
  30 + Object().
  31 + ContainsKey("code").ValueEqual("code", 0).
  32 + ContainsKey("msg").ValueEqual("msg", "ok").
  33 + ContainsKey("data").Value("data").Object()
  34 + })
  35 + })
  36 + })
  37 + AfterEach(func() {
  38 + _, err := pG.DB.Exec("DELETE FROM project_module_filess WHERE true")
  39 + Expect(err).NotTo(HaveOccurred())
  40 + })
  41 +})
  1 +package project_module_files
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg/v10"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("返回列表", func() {
  14 + var projectModuleFilesId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&projectModuleFilesId),
  18 + "INSERT INTO project_module_filess (id, project_module_id, project_module_version, file_type, code_block, parent_id, sort, remark, create_time, update_time, path, tag) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
  19 + "testProjectModuleId", "testProjectModuleVersion", "testFileType", "testCodeBlock", "testParentId", "testSort", "testRemark", "testCreateTime", "testUpdateTime", "testPath", "testTag")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据参数返回项目模板文件列表", func() {
  23 + Context("传入有效的参数", func() {
  24 + It("返回项目模板文件数据列表", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.GET("/project-module-filess/").
  27 + WithQuery("offset", "int").
  28 + WithQuery("limit", "int").
  29 + Expect().
  30 + Status(http.StatusOK).
  31 + JSON().
  32 + Object().
  33 + ContainsKey("code").ValueEqual("code", 0).
  34 + ContainsKey("msg").ValueEqual("msg", "ok").
  35 + ContainsKey("data").Value("data").Object().
  36 + ContainsKey("count").ValueEqual("count", 1).
  37 + ContainsKey("projectModuleFiless").Value("projectModuleFiless").Array()
  38 + })
  39 + })
  40 + })
  41 + AfterEach(func() {
  42 + _, err := pG.DB.Exec("DELETE FROM project_module_filess WHERE true")
  43 + Expect(err).NotTo(HaveOccurred())
  44 + })
  45 +})
  1 +package project_module_files
  2 +
  3 +import (
  4 + "net/http"
  5 + "net/http/httptest"
  6 + "testing"
  7 +
  8 + "github.com/astaxie/beego"
  9 + . "github.com/onsi/ginkgo"
  10 + . "github.com/onsi/gomega"
  11 + _ "github.com/tiptok/godevp/pkg/infrastructure/pg"
  12 + _ "github.com/tiptok/godevp/pkg/port/beego"
  13 +)
  14 +
  15 +func TestProjectModuleFiles(t *testing.T) {
  16 + RegisterFailHandler(Fail)
  17 + RunSpecs(t, "Beego Port ProjectModuleFiles Correlations Test Case Suite")
  18 +}
  19 +
  20 +var handler http.Handler
  21 +var server *httptest.Server
  22 +
  23 +var _ = BeforeSuite(func() {
  24 + handler = beego.BeeApp.Handlers
  25 + server = httptest.NewServer(handler)
  26 +})
  27 +
  28 +var _ = AfterSuite(func() {
  29 + server.Close()
  30 +})
  1 +package project_module_files
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg/v10"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("移除", func() {
  14 + var projectModuleFilesId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&projectModuleFilesId),
  18 + "INSERT INTO project_module_filess (id, project_module_id, project_module_version, file_type, code_block, parent_id, sort, remark, create_time, update_time, path, tag) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
  19 + "testProjectModuleId", "testProjectModuleVersion", "testFileType", "testCodeBlock", "testParentId", "testSort", "testRemark", "testCreateTime", "testUpdateTime", "testPath", "testTag")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据参数移除", func() {
  23 + Context("传入有效的projectModuleFilesId", func() {
  24 + It("返回被移除项目模板文件的数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.DELETE("/project-module-filess/{projectModuleFilesId}").
  27 + Expect().
  28 + Status(http.StatusOK).
  29 + JSON().
  30 + Object().
  31 + ContainsKey("code").ValueEqual("code", 0).
  32 + ContainsKey("msg").ValueEqual("msg", "ok").
  33 + ContainsKey("data").Value("data").Object()
  34 + })
  35 + })
  36 + })
  37 + AfterEach(func() {
  38 + _, err := pG.DB.Exec("DELETE FROM project_module_filess WHERE true")
  39 + Expect(err).NotTo(HaveOccurred())
  40 + })
  41 +})
  1 +package project_module_files
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg/v10"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("更新", func() {
  14 + var projectModuleFilesId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&projectModuleFilesId),
  18 + "INSERT INTO project_module_filess (id, project_module_id, project_module_version, file_type, code_block, parent_id, sort, remark, create_time, update_time, path, tag) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
  19 + "testProjectModuleId", "testProjectModuleVersion", "testFileType", "testCodeBlock", "testParentId", "testSort", "testRemark", "testCreateTime", "testUpdateTime", "testPath", "testTag")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("提交数据更新", func() {
  23 + Context("提交正确的项目模板文件数据", func() {
  24 + It("返回更新后的项目模板文件数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + body := map[string]interface{}{
  27 + "codeBlock": "string",
  28 + "remark": "string",
  29 + }
  30 + httpExpect.PUT("/project-module-filess/{projectModuleFilesId}").
  31 + WithJSON(body).
  32 + Expect().
  33 + Status(http.StatusOK).
  34 + JSON().
  35 + Object().
  36 + ContainsKey("code").ValueEqual("code", 0).
  37 + ContainsKey("msg").ValueEqual("msg", "ok").
  38 + ContainsKey("data").Value("data").Object().
  39 + ContainsKey("id").ValueEqual("id", projectModuleFilesId)
  40 + })
  41 + })
  42 + })
  43 + AfterEach(func() {
  44 + _, err := pG.DB.Exec("DELETE FROM project_module_filess WHERE true")
  45 + Expect(err).NotTo(HaveOccurred())
  46 + })
  47 +})
  1 +package project_module_version
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + . "github.com/onsi/ginkgo"
  8 + . "github.com/onsi/gomega"
  9 + pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
  10 +)
  11 +
  12 +var _ = Describe("创建", func() {
  13 + Describe("提交数据创建", func() {
  14 + Context("提交正确的新项目模块版本数据", func() {
  15 + It("返回项目模块版本数据", func() {
  16 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  17 + body := map[string]interface{}{
  18 + "projectModuleId": "int64",
  19 + "version": "int64",
  20 + "description": "string",
  21 + }
  22 + httpExpect.POST("/project-module-versions/").
  23 + WithJSON(body).
  24 + Expect().
  25 + Status(http.StatusOK).
  26 + JSON().
  27 + Object().
  28 + ContainsKey("code").ValueEqual("code", 0).
  29 + ContainsKey("msg").ValueEqual("msg", "ok").
  30 + ContainsKey("data").Value("data").Object().
  31 + ContainsKey("id").ValueNotEqual("id", BeZero())
  32 + })
  33 + })
  34 + })
  35 + AfterEach(func() {
  36 + _, err := pG.DB.Exec("DELETE FROM project_module_versions WHERE true")
  37 + Expect(err).NotTo(HaveOccurred())
  38 + })
  39 +})
  1 +package project_module_version
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg/v10"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("返回", func() {
  14 + var projectModuleVersionId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&projectModuleVersionId),
  18 + "INSERT INTO project_module_versions (project_module_version.id, project_module_version.project_module_id, project_module_version.version, project_module_version.description, project_module_version.status, project_module_version._create_time, project_module_version._update_time, id, project_module_id, version, description, status, create_time, update_time) VALUES (?, ?, ?, ?, ?, ?, ?, DEFAULT, ?, ?, ?, ?, ?, ?) RETURNING id",
  19 + "testProjectModuleVersionId", "testProjectModuleVersionProjectModuleId", "testProjectModuleVersionVersion", "testProjectModuleVersionDescription", "testProjectModuleVersionStatus", "testProjectModuleVersionCreateTime", "testProjectModuleVersionUpdateTime", "testProjectModuleId", "testVersion", "testDescription", "testStatus", "testCreateTime", "testUpdateTime")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据projectModuleVersionId参数返回项目模块版本", func() {
  23 + Context("传入有效的projectModuleVersionId", func() {
  24 + It("返回项目模块版本数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.GET("/project-module-versions/{projectModuleVersionId}").
  27 + Expect().
  28 + Status(http.StatusOK).
  29 + JSON().
  30 + Object().
  31 + ContainsKey("code").ValueEqual("code", 0).
  32 + ContainsKey("msg").ValueEqual("msg", "ok").
  33 + ContainsKey("data").Value("data").Object()
  34 + })
  35 + })
  36 + })
  37 + AfterEach(func() {
  38 + _, err := pG.DB.Exec("DELETE FROM project_module_versions WHERE true")
  39 + Expect(err).NotTo(HaveOccurred())
  40 + })
  41 +})
  1 +package project_module_version
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg/v10"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("返回列表", func() {
  14 + var projectModuleVersionId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&projectModuleVersionId),
  18 + "INSERT INTO project_module_versions (project_module_version.id, project_module_version.project_module_id, project_module_version.version, project_module_version.description, project_module_version.status, project_module_version._create_time, project_module_version._update_time, id, project_module_id, version, description, status, create_time, update_time) VALUES (?, ?, ?, ?, ?, ?, ?, DEFAULT, ?, ?, ?, ?, ?, ?) RETURNING id",
  19 + "testProjectModuleVersionId", "testProjectModuleVersionProjectModuleId", "testProjectModuleVersionVersion", "testProjectModuleVersionDescription", "testProjectModuleVersionStatus", "testProjectModuleVersionCreateTime", "testProjectModuleVersionUpdateTime", "testProjectModuleId", "testVersion", "testDescription", "testStatus", "testCreateTime", "testUpdateTime")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据参数返回项目模块版本列表", func() {
  23 + Context("传入有效的参数", func() {
  24 + It("返回项目模块版本数据列表", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.GET("/project-module-versions/").
  27 + WithQuery("offset", "int").
  28 + WithQuery("limit", "int").
  29 + Expect().
  30 + Status(http.StatusOK).
  31 + JSON().
  32 + Object().
  33 + ContainsKey("code").ValueEqual("code", 0).
  34 + ContainsKey("msg").ValueEqual("msg", "ok").
  35 + ContainsKey("data").Value("data").Object().
  36 + ContainsKey("count").ValueEqual("count", 1).
  37 + ContainsKey("projectModuleVersions").Value("projectModuleVersions").Array()
  38 + })
  39 + })
  40 + })
  41 + AfterEach(func() {
  42 + _, err := pG.DB.Exec("DELETE FROM project_module_versions WHERE true")
  43 + Expect(err).NotTo(HaveOccurred())
  44 + })
  45 +})
  1 +package project_module_version
  2 +
  3 +import (
  4 + "net/http"
  5 + "net/http/httptest"
  6 + "testing"
  7 +
  8 + "github.com/astaxie/beego"
  9 + . "github.com/onsi/ginkgo"
  10 + . "github.com/onsi/gomega"
  11 + _ "github.com/tiptok/godevp/pkg/infrastructure/pg"
  12 + _ "github.com/tiptok/godevp/pkg/port/beego"
  13 +)
  14 +
  15 +func TestProjectModuleVersion(t *testing.T) {
  16 + RegisterFailHandler(Fail)
  17 + RunSpecs(t, "Beego Port ProjectModuleVersion Correlations Test Case Suite")
  18 +}
  19 +
  20 +var handler http.Handler
  21 +var server *httptest.Server
  22 +
  23 +var _ = BeforeSuite(func() {
  24 + handler = beego.BeeApp.Handlers
  25 + server = httptest.NewServer(handler)
  26 +})
  27 +
  28 +var _ = AfterSuite(func() {
  29 + server.Close()
  30 +})
  1 +package project_module_version
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg/v10"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("移除", func() {
  14 + var projectModuleVersionId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&projectModuleVersionId),
  18 + "INSERT INTO project_module_versions (project_module_version.id, project_module_version.project_module_id, project_module_version.version, project_module_version.description, project_module_version.status, project_module_version._create_time, project_module_version._update_time, id, project_module_id, version, description, status, create_time, update_time) VALUES (?, ?, ?, ?, ?, ?, ?, DEFAULT, ?, ?, ?, ?, ?, ?) RETURNING id",
  19 + "testProjectModuleVersionId", "testProjectModuleVersionProjectModuleId", "testProjectModuleVersionVersion", "testProjectModuleVersionDescription", "testProjectModuleVersionStatus", "testProjectModuleVersionCreateTime", "testProjectModuleVersionUpdateTime", "testProjectModuleId", "testVersion", "testDescription", "testStatus", "testCreateTime", "testUpdateTime")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据参数移除", func() {
  23 + Context("传入有效的projectModuleVersionId", func() {
  24 + It("返回被移除项目模块版本的数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.DELETE("/project-module-versions/{projectModuleVersionId}").
  27 + Expect().
  28 + Status(http.StatusOK).
  29 + JSON().
  30 + Object().
  31 + ContainsKey("code").ValueEqual("code", 0).
  32 + ContainsKey("msg").ValueEqual("msg", "ok").
  33 + ContainsKey("data").Value("data").Object()
  34 + })
  35 + })
  36 + })
  37 + AfterEach(func() {
  38 + _, err := pG.DB.Exec("DELETE FROM project_module_versions WHERE true")
  39 + Expect(err).NotTo(HaveOccurred())
  40 + })
  41 +})
  1 +package project_module_version
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg/v10"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("更新", func() {
  14 + var projectModuleVersionId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&projectModuleVersionId),
  18 + "INSERT INTO project_module_versions (project_module_version.id, project_module_version.project_module_id, project_module_version.version, project_module_version.description, project_module_version.status, project_module_version._create_time, project_module_version._update_time, id, project_module_id, version, description, status, create_time, update_time) VALUES (?, ?, ?, ?, ?, ?, ?, DEFAULT, ?, ?, ?, ?, ?, ?) RETURNING id",
  19 + "testProjectModuleVersionId", "testProjectModuleVersionProjectModuleId", "testProjectModuleVersionVersion", "testProjectModuleVersionDescription", "testProjectModuleVersionStatus", "testProjectModuleVersionCreateTime", "testProjectModuleVersionUpdateTime", "testProjectModuleId", "testVersion", "testDescription", "testStatus", "testCreateTime", "testUpdateTime")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("提交数据更新", func() {
  23 + Context("提交正确的项目模块版本数据", func() {
  24 + It("返回更新后的项目模块版本数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + body := map[string]interface{}{
  27 + "projectModuleVersion": "int64",
  28 + "projectModuleId": "int64",
  29 + "version": "int64",
  30 + "description": "string",
  31 + "status": "int",
  32 + }
  33 + httpExpect.PUT("/project-module-versions/{projectModuleVersionId}").
  34 + WithJSON(body).
  35 + Expect().
  36 + Status(http.StatusOK).
  37 + JSON().
  38 + Object().
  39 + ContainsKey("code").ValueEqual("code", 0).
  40 + ContainsKey("msg").ValueEqual("msg", "ok").
  41 + ContainsKey("data").Value("data").Object().
  42 + ContainsKey("id").ValueEqual("id", projectModuleVersionId)
  43 + })
  44 + })
  45 + })
  46 + AfterEach(func() {
  47 + _, err := pG.DB.Exec("DELETE FROM project_module_versions WHERE true")
  48 + Expect(err).NotTo(HaveOccurred())
  49 + })
  50 +})