作者 yangfu

增加 project-module

正在显示 55 个修改的文件 包含 2928 行增加3 行删除
... ... @@ -196,7 +196,7 @@ func (clientVersionService *ClientVersionService) UpdateClientVersion(updateClie
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if clientVersion == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateClientVersionCommand.Id)))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%v", updateClientVersionCommand.Id))
}
if err := clientVersion.Update(tool_funs.SimpleStructToMap(updateClientVersionCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ...
... ... @@ -47,3 +47,27 @@ func CreateClientVersionRepository(options map[string]interface{}) (domain.Clien
}
return repository.NewClientVersionRepository(transactionContext)
}
func CreateProjectModuleRepository(options map[string]interface{}) (domain.ProjectModuleRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewProjectModuleRepository(transactionContext)
}
func CreateProjectModuleVersionRepository(options map[string]interface{}) (domain.ProjectModuleVersionRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewProjectModuleVersionRepository(transactionContext)
}
func CreateProjectModuleFilesRepository(options map[string]interface{}) (domain.ProjectModuleFilesRepository, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewProjectModuleFilesRepository(transactionContext)
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type CreateProjectModuleCommand struct {
// 项目名称
ProjectName string `json:"projectName" valid:"Required"`
// 项目唯一键值
ProjectKey string `json:"projectKey" valid:"Required"`
// 描述信息
Description string `json:"description" valid:"Required"`
// 状态 1:正常 2:删除
Status int `json:"status" valid:"Required"`
}
func (createProjectModuleCommand *CreateProjectModuleCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createProjectModuleCommand *CreateProjectModuleCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createProjectModuleCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type RemoveProjectModuleCommand struct {
// 项目编号
ProjectModuleId int64 `json:"projectModuleId" valid:"Required"`
}
func (removeProjectModuleCommand *RemoveProjectModuleCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProjectModuleCommand *RemoveProjectModuleCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeProjectModuleCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type UpdateProjectModuleCommand struct {
// 项目编号
ProjectModuleId int64 `json:"projectModuleId" valid:"Required"`
// 项目名称
ProjectName string `json:"projectName" valid:"Required"`
// 项目唯一键值
ProjectKey string `json:"projectKey" valid:"Required"`
// 描述信息
Description string `json:"description" valid:"Required"`
// 状态 1:正常 2:删除
Status int `json:"status" valid:"Required"`
}
func (updateProjectModuleCommand *UpdateProjectModuleCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateProjectModuleCommand *UpdateProjectModuleCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateProjectModuleCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type GetProjectModuleQuery struct {
// 项目编号
ProjectModuleId int64 `json:"projectModuleId" valid:"Required"`
}
func (getProjectModuleQuery *GetProjectModuleQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getProjectModuleQuery *GetProjectModuleQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getProjectModuleQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ListProjectModuleQuery struct {
// 查询偏离量
Offset int `json:"offset" valid:"Required"`
// 查询限制
Limit int `json:"limit" valid:"Required"`
}
func (listProjectModuleQuery *ListProjectModuleQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProjectModuleQuery *ListProjectModuleQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listProjectModuleQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"github.com/tiptok/godevp/pkg/application/factory"
"github.com/tiptok/godevp/pkg/application/projectModule/command"
"github.com/tiptok/godevp/pkg/application/projectModule/query"
"github.com/tiptok/godevp/pkg/domain"
)
// 项目模块服务
type ProjectModuleService struct {
}
// 创建
func (projectModuleService *ProjectModuleService) CreateProjectModule(createProjectModuleCommand *command.CreateProjectModuleCommand) (interface{}, error) {
if err := createProjectModuleCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
newProjectModule := &domain.ProjectModule{
ProjectName: createProjectModuleCommand.ProjectName,
ProjectKey: createProjectModuleCommand.ProjectKey,
Description: createProjectModuleCommand.Description,
Status: createProjectModuleCommand.Status,
}
var projectModuleRepository domain.ProjectModuleRepository
if value, err := factory.CreateProjectModuleRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectModuleRepository = value
}
if projectModule, err := projectModuleRepository.Save(newProjectModule); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return projectModule, nil
}
}
// 返回
func (projectModuleService *ProjectModuleService) GetProjectModule(getProjectModuleQuery *query.GetProjectModuleQuery) (interface{}, error) {
if err := getProjectModuleQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var projectModuleRepository domain.ProjectModuleRepository
if value, err := factory.CreateProjectModuleRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectModuleRepository = value
}
projectModule, err := projectModuleRepository.FindOne(map[string]interface{}{"projectModuleId": getProjectModuleQuery.ProjectModuleId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if projectModule == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProjectModuleQuery.ProjectModuleId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return projectModule, nil
}
}
// 返回列表
func (projectModuleService *ProjectModuleService) ListProjectModule(listProjectModuleQuery *query.ListProjectModuleQuery) (interface{}, error) {
if err := listProjectModuleQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var projectModuleRepository domain.ProjectModuleRepository
if value, err := factory.CreateProjectModuleRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectModuleRepository = value
}
if count, projectModules, err := projectModuleRepository.Find(tool_funs.SimpleStructToMap(listProjectModuleQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"projectModules": projectModules,
}, nil
}
}
// 移除
func (projectModuleService *ProjectModuleService) RemoveProjectModule(removeProjectModuleCommand *command.RemoveProjectModuleCommand) (interface{}, error) {
if err := removeProjectModuleCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var projectModuleRepository domain.ProjectModuleRepository
if value, err := factory.CreateProjectModuleRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectModuleRepository = value
}
projectModule, err := projectModuleRepository.FindOne(map[string]interface{}{"projectModuleId": removeProjectModuleCommand.ProjectModuleId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if projectModule == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProjectModuleCommand.ProjectModuleId)))
}
if projectModule, err := projectModuleRepository.Remove(projectModule); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return projectModule, nil
}
}
// 更新
func (projectModuleService *ProjectModuleService) UpdateProjectModule(updateProjectModuleCommand *command.UpdateProjectModuleCommand) (interface{}, error) {
if err := updateProjectModuleCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var projectModuleRepository domain.ProjectModuleRepository
if value, err := factory.CreateProjectModuleRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectModuleRepository = value
}
projectModule, err := projectModuleRepository.FindOne(map[string]interface{}{"projectModuleId": updateProjectModuleCommand.ProjectModuleId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if projectModule == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProjectModuleCommand.ProjectModuleId)))
}
if err := projectModule.Update(tool_funs.SimpleStructToMap(updateProjectModuleCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if projectModule, err := projectModuleRepository.Save(projectModule); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return projectModule, nil
}
}
func NewProjectModuleService(options map[string]interface{}) *ProjectModuleService {
newProjectModuleService := &ProjectModuleService{}
return newProjectModuleService
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type CreateProjectModuleFilesCommand struct {
// 项目编号
ProjectModuleId int64 `json:"projectModuleId" valid:"Required"`
// 项目版本编号
ProjectModuleVersion int64 `json:"projectModuleVersion" valid:"Required"`
// 文件类型 1:文件夹 2:文件
FileType int `json:"fileType" valid:"Required"`
// 代码块
CodeBlock string `json:"codeBlock" valid:"Required"`
// 父级Id
ParentId int64 `json:"parentId" valid:"Required"`
// 排序
Sort int `json:"sort" valid:"Required"`
// 备注信息
Remark string `json:"remark,omitempty"`
}
func (createProjectModuleFilesCommand *CreateProjectModuleFilesCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createProjectModuleFilesCommand *CreateProjectModuleFilesCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createProjectModuleFilesCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type RemoveProjectModuleFilesCommand struct {
// 项目文件编号
ProjectModuleFilesId int64 `json:"projectModuleFilesId" valid:"Required"`
}
func (removeProjectModuleFilesCommand *RemoveProjectModuleFilesCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProjectModuleFilesCommand *RemoveProjectModuleFilesCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeProjectModuleFilesCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type UpdateProjectModuleFilesCommand struct {
// 项目文件编号
ProjectModuleFilesId int64 `json:"projectModuleFilesId" valid:"Required"`
// 代码块
CodeBlock string `json:"codeBlock" valid:"Required"`
// 备注信息
Remark string `json:"remark,omitempty"`
}
func (updateProjectModuleFilesCommand *UpdateProjectModuleFilesCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateProjectModuleFilesCommand *UpdateProjectModuleFilesCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateProjectModuleFilesCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type GetProjectModuleFilesQuery struct {
// 项目文件编号
ProjectModuleFilesId int64 `json:"projectModuleFilesId" valid:"Required"`
}
func (getProjectModuleFilesQuery *GetProjectModuleFilesQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getProjectModuleFilesQuery *GetProjectModuleFilesQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getProjectModuleFilesQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ListProjectModuleFilesQuery struct {
// 查询偏离量
Offset int `json:"offset" valid:"Required"`
// 查询限制
Limit int `json:"limit" valid:"Required"`
}
func (listProjectModuleFilesQuery *ListProjectModuleFilesQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProjectModuleFilesQuery *ListProjectModuleFilesQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listProjectModuleFilesQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"github.com/tiptok/godevp/pkg/application/factory"
"github.com/tiptok/godevp/pkg/application/projectModuleFiles/command"
"github.com/tiptok/godevp/pkg/application/projectModuleFiles/query"
"github.com/tiptok/godevp/pkg/domain"
)
// 项目模块文件
type ProjectModuleFilesService struct {
}
// 创建
func (projectModuleFilesService *ProjectModuleFilesService) CreateProjectModuleFiles(createProjectModuleFilesCommand *command.CreateProjectModuleFilesCommand) (interface{}, error) {
if err := createProjectModuleFilesCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
newProjectModuleFiles := &domain.ProjectModuleFiles{
ProjectModuleId: createProjectModuleFilesCommand.ProjectModuleId,
ProjectModuleVersion: createProjectModuleFilesCommand.ProjectModuleVersion,
FileType: createProjectModuleFilesCommand.FileType,
CodeBlock: createProjectModuleFilesCommand.CodeBlock,
ParentId: createProjectModuleFilesCommand.ParentId,
Sort: createProjectModuleFilesCommand.Sort,
Remark: createProjectModuleFilesCommand.Remark,
}
var projectModuleFilesRepository domain.ProjectModuleFilesRepository
if value, err := factory.CreateProjectModuleFilesRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectModuleFilesRepository = value
}
if projectModuleFiles, err := projectModuleFilesRepository.Save(newProjectModuleFiles); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return projectModuleFiles, nil
}
}
// 返回
func (projectModuleFilesService *ProjectModuleFilesService) GetProjectModuleFiles(getProjectModuleFilesQuery *query.GetProjectModuleFilesQuery) (interface{}, error) {
if err := getProjectModuleFilesQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var projectModuleFilesRepository domain.ProjectModuleFilesRepository
if value, err := factory.CreateProjectModuleFilesRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectModuleFilesRepository = value
}
projectModuleFiles, err := projectModuleFilesRepository.FindOne(map[string]interface{}{"projectModuleFilesId": getProjectModuleFilesQuery.ProjectModuleFilesId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if projectModuleFiles == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProjectModuleFilesQuery.ProjectModuleFilesId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return projectModuleFiles, nil
}
}
// 返回列表
func (projectModuleFilesService *ProjectModuleFilesService) ListProjectModuleFiles(listProjectModuleFilesQuery *query.ListProjectModuleFilesQuery) (interface{}, error) {
if err := listProjectModuleFilesQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var projectModuleFilesRepository domain.ProjectModuleFilesRepository
if value, err := factory.CreateProjectModuleFilesRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectModuleFilesRepository = value
}
if count, projectModuleFiless, err := projectModuleFilesRepository.Find(tool_funs.SimpleStructToMap(listProjectModuleFilesQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"projectModuleFiless": projectModuleFiless,
}, nil
}
}
// 移除
func (projectModuleFilesService *ProjectModuleFilesService) RemoveProjectModuleFiles(removeProjectModuleFilesCommand *command.RemoveProjectModuleFilesCommand) (interface{}, error) {
if err := removeProjectModuleFilesCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var projectModuleFilesRepository domain.ProjectModuleFilesRepository
if value, err := factory.CreateProjectModuleFilesRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectModuleFilesRepository = value
}
projectModuleFiles, err := projectModuleFilesRepository.FindOne(map[string]interface{}{"projectModuleFilesId": removeProjectModuleFilesCommand.ProjectModuleFilesId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if projectModuleFiles == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProjectModuleFilesCommand.ProjectModuleFilesId)))
}
if projectModuleFiles, err := projectModuleFilesRepository.Remove(projectModuleFiles); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return projectModuleFiles, nil
}
}
// 更新
func (projectModuleFilesService *ProjectModuleFilesService) UpdateProjectModuleFiles(updateProjectModuleFilesCommand *command.UpdateProjectModuleFilesCommand) (interface{}, error) {
if err := updateProjectModuleFilesCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var projectModuleFilesRepository domain.ProjectModuleFilesRepository
if value, err := factory.CreateProjectModuleFilesRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectModuleFilesRepository = value
}
projectModuleFiles, err := projectModuleFilesRepository.FindOne(map[string]interface{}{"projectModuleFilesId": updateProjectModuleFilesCommand.ProjectModuleFilesId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if projectModuleFiles == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProjectModuleFilesCommand.ProjectModuleFilesId)))
}
if err := projectModuleFiles.Update(tool_funs.SimpleStructToMap(updateProjectModuleFilesCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if projectModuleFiles, err := projectModuleFilesRepository.Save(projectModuleFiles); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return projectModuleFiles, nil
}
}
func NewProjectModuleFilesService(options map[string]interface{}) *ProjectModuleFilesService {
newProjectModuleFilesService := &ProjectModuleFilesService{}
return newProjectModuleFilesService
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type CreateProjectModuleVersionCommand struct {
// 项目编号
ProjectModuleId int64 `json:"projectModuleId" valid:"Required"`
// 唯一标识
Version int64 `json:"version" valid:"Required"`
// 描述信息
Description string `json:"description" valid:"Required"`
}
func (createProjectModuleVersionCommand *CreateProjectModuleVersionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (createProjectModuleVersionCommand *CreateProjectModuleVersionCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(createProjectModuleVersionCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type RemoveProjectModuleVersionCommand struct {
ProjectModuleVersionId int64 `json:"projectModuleVersionId" valid:"Required"`
// 项目版本编号
ProjectModuleVersion int64 `json:"projectModuleVersion" valid:"Required"`
}
func (removeProjectModuleVersionCommand *RemoveProjectModuleVersionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (removeProjectModuleVersionCommand *RemoveProjectModuleVersionCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(removeProjectModuleVersionCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package command
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type UpdateProjectModuleVersionCommand struct {
ProjectModuleVersionId int64 `json:"projectModuleVersionId" valid:"Required"`
// 项目版本编号
ProjectModuleVersion int64 `json:"projectModuleVersion" valid:"Required"`
// 项目编号
ProjectModuleId int64 `json:"projectModuleId" valid:"Required"`
// 唯一标识
Version int64 `json:"version" valid:"Required"`
// 描述信息
Description string `json:"description" valid:"Required"`
// 状态 1:正常 2:删除
Status int `json:"status" valid:"Required"`
}
func (updateProjectModuleVersionCommand *UpdateProjectModuleVersionCommand) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (updateProjectModuleVersionCommand *UpdateProjectModuleVersionCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(updateProjectModuleVersionCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type GetProjectModuleVersionQuery struct {
ProjectModuleVersionId int64 `json:"projectModuleVersionId" valid:"Required"`
// 项目版本编号
ProjectModuleVersion int64 `json:"projectModuleVersion" valid:"Required"`
}
func (getProjectModuleVersionQuery *GetProjectModuleVersionQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (getProjectModuleVersionQuery *GetProjectModuleVersionQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(getProjectModuleVersionQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/astaxie/beego/validation"
)
type ListProjectModuleVersionQuery struct {
// 查询偏离量
Offset int `json:"offset" valid:"Required"`
// 查询限制
Limit int `json:"limit" valid:"Required"`
}
func (listProjectModuleVersionQuery *ListProjectModuleVersionQuery) Valid(validation *validation.Validation) {
validation.SetError("CustomValid", "未实现的自定义认证")
}
func (listProjectModuleVersionQuery *ListProjectModuleVersionQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(listProjectModuleVersionQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"github.com/tiptok/godevp/pkg/application/factory"
"github.com/tiptok/godevp/pkg/application/projectModuleVersion/command"
"github.com/tiptok/godevp/pkg/application/projectModuleVersion/query"
"github.com/tiptok/godevp/pkg/domain"
)
// 项目模板版本
type ProjectModuleVersionService struct {
}
// 创建
func (projectModuleVersionService *ProjectModuleVersionService) CreateProjectModuleVersion(createProjectModuleVersionCommand *command.CreateProjectModuleVersionCommand) (interface{}, error) {
if err := createProjectModuleVersionCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
newProjectModuleVersion := &domain.ProjectModuleVersion{
ProjectModuleId: createProjectModuleVersionCommand.ProjectModuleId,
Version: createProjectModuleVersionCommand.Version,
Description: createProjectModuleVersionCommand.Description,
}
var projectModuleVersionRepository domain.ProjectModuleVersionRepository
if value, err := factory.CreateProjectModuleVersionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectModuleVersionRepository = value
}
if projectModuleVersion, err := projectModuleVersionRepository.Save(newProjectModuleVersion); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return projectModuleVersion, nil
}
}
// 返回
func (projectModuleVersionService *ProjectModuleVersionService) GetProjectModuleVersion(getProjectModuleVersionQuery *query.GetProjectModuleVersionQuery) (interface{}, error) {
if err := getProjectModuleVersionQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var projectModuleVersionRepository domain.ProjectModuleVersionRepository
if value, err := factory.CreateProjectModuleVersionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectModuleVersionRepository = value
}
projectModuleVersion, err := projectModuleVersionRepository.FindOne(map[string]interface{}{"projectModuleVersionId": getProjectModuleVersionQuery.ProjectModuleVersionId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if projectModuleVersion == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getProjectModuleVersionQuery.ProjectModuleVersionId)))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return projectModuleVersion, nil
}
}
// 返回列表
func (projectModuleVersionService *ProjectModuleVersionService) ListProjectModuleVersion(listProjectModuleVersionQuery *query.ListProjectModuleVersionQuery) (interface{}, error) {
if err := listProjectModuleVersionQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var projectModuleVersionRepository domain.ProjectModuleVersionRepository
if value, err := factory.CreateProjectModuleVersionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectModuleVersionRepository = value
}
if count, projectModuleVersions, err := projectModuleVersionRepository.Find(tool_funs.SimpleStructToMap(listProjectModuleVersionQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"projectModuleVersions": projectModuleVersions,
}, nil
}
}
// 移除
func (projectModuleVersionService *ProjectModuleVersionService) RemoveProjectModuleVersion(removeProjectModuleVersionCommand *command.RemoveProjectModuleVersionCommand) (interface{}, error) {
if err := removeProjectModuleVersionCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var projectModuleVersionRepository domain.ProjectModuleVersionRepository
if value, err := factory.CreateProjectModuleVersionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectModuleVersionRepository = value
}
projectModuleVersion, err := projectModuleVersionRepository.FindOne(map[string]interface{}{"projectModuleVersionId": removeProjectModuleVersionCommand.ProjectModuleVersionId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if projectModuleVersion == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeProjectModuleVersionCommand.ProjectModuleVersionId)))
}
if projectModuleVersion, err := projectModuleVersionRepository.Remove(projectModuleVersion); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return projectModuleVersion, nil
}
}
// 更新
func (projectModuleVersionService *ProjectModuleVersionService) UpdateProjectModuleVersion(updateProjectModuleVersionCommand *command.UpdateProjectModuleVersionCommand) (interface{}, error) {
if err := updateProjectModuleVersionCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var projectModuleVersionRepository domain.ProjectModuleVersionRepository
if value, err := factory.CreateProjectModuleVersionRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
projectModuleVersionRepository = value
}
projectModuleVersion, err := projectModuleVersionRepository.FindOne(map[string]interface{}{"projectModuleVersionId": updateProjectModuleVersionCommand.ProjectModuleVersionId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if projectModuleVersion == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateProjectModuleVersionCommand.ProjectModuleVersionId)))
}
if err := projectModuleVersion.Update(tool_funs.SimpleStructToMap(updateProjectModuleVersionCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if projectModuleVersion, err := projectModuleVersionRepository.Save(projectModuleVersion); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return projectModuleVersion, nil
}
}
func NewProjectModuleVersionService(options map[string]interface{}) *ProjectModuleVersionService {
newProjectModuleVersionService := &ProjectModuleVersionService{}
return newProjectModuleVersionService
}
... ...
package domain
import "time"
// 项目模块
type ProjectModule struct {
// 唯一标识
Id int64 `json:"id"`
// 项目名称
ProjectName string `json:"projectName"`
// 项目唯一键值
ProjectKey string `json:"projectKey"`
// 描述信息
Description string `json:"description"`
// 状态 1:正常 2:删除
Status int `json:"status"`
// 创建时间
CreateTime time.Time `json:"createTime"`
// 更新时间
UpdateTime time.Time `json:"updateTime"`
// 项目模板版本信息
ProjectModuleVersion *ProjectModuleVersion `json:"projectModuleVersion"`
}
type ProjectModuleRepository interface {
Save(projectModule *ProjectModule) (*ProjectModule, error)
Remove(projectModule *ProjectModule) (*ProjectModule, error)
FindOne(queryOptions map[string]interface{}) (*ProjectModule, error)
Find(queryOptions map[string]interface{}) (int64, []*ProjectModule, error)
}
func (projectModule *ProjectModule) Identify() interface{} {
if projectModule.Id == 0 {
return nil
}
return projectModule.Id
}
func (projectModule *ProjectModule) Update(data map[string]interface{}) error {
if projectName, ok := data["projectName"]; ok {
projectModule.ProjectName = projectName.(string)
}
if projectKey, ok := data["projectKey"]; ok {
projectModule.ProjectKey = projectKey.(string)
}
if description, ok := data["description"]; ok {
projectModule.Description = description.(string)
}
if status, ok := data["status"]; ok {
projectModule.Status = status.(int)
}
if CreateTime, ok := data["CreateTime"]; ok {
projectModule.CreateTime = CreateTime.(time.Time)
}
if UpdateTime, ok := data["UpdateTime"]; ok {
projectModule.UpdateTime = UpdateTime.(time.Time)
}
//if id, ok := data["id"]; ok {
// projectModule.ProjectModuleVersion.Id = id.(int64)
//}
//if projectModuleId, ok := data["projectModuleId"]; ok {
// projectModule.ProjectModuleVersion.ProjectModuleId = projectModuleId.(int64)
//}
//if version, ok := data["version"]; ok {
// projectModule.ProjectModuleVersion.Version = version.(int64)
//}
//if description, ok := data["description"]; ok {
// projectModule.ProjectModuleVersion.Description = description.(string)
//}
//if status, ok := data["status"]; ok {
// projectModule.ProjectModuleVersion.Status = status.(int)
//}
//if CreateTime, ok := data["CreateTime"]; ok {
// projectModule.ProjectModuleVersion.CreateTime = CreateTime.(datetime)
//}
//if UpdateTime, ok := data["UpdateTime"]; ok {
// projectModule.ProjectModuleVersion.UpdateTime = UpdateTime.(datetime)
//}
return nil
}
... ...
package domain
import "time"
// 项目模板文件
type ProjectModuleFiles struct {
// 唯一标识
Id int64 `json:"id"`
// 项目编号
ProjectModuleId int64 `json:"projectModuleId"`
// 项目版本编号
ProjectModuleVersion int64 `json:"projectModuleVersion"`
// 文件类型 1:文件夹 2:文件
FileType int `json:"fileType"`
// 代码块
CodeBlock string `json:"codeBlock"`
// 父级Id
ParentId int64 `json:"parentId"`
// 排序
Sort int `json:"sort"`
// 备注信息
Remark string `json:"remark"`
// 创建时间
CreateTime time.Time `json:"createTime"`
// 更新时间
UpdateTime time.Time `json:"updateTime"`
// 当前文件相对路径 a/b/c
Path string `json:"path"`
// 标签
Tag string `json:"tag"`
}
type ProjectModuleFilesRepository interface {
Save(projectModuleFiles *ProjectModuleFiles) (*ProjectModuleFiles, error)
Remove(projectModuleFiles *ProjectModuleFiles) (*ProjectModuleFiles, error)
FindOne(queryOptions map[string]interface{}) (*ProjectModuleFiles, error)
Find(queryOptions map[string]interface{}) (int64, []*ProjectModuleFiles, error)
}
func (projectModuleFiles *ProjectModuleFiles) Identify() interface{} {
if projectModuleFiles.Id == 0 {
return nil
}
return projectModuleFiles.Id
}
func (projectModuleFiles *ProjectModuleFiles) Update(data map[string]interface{}) error {
if id, ok := data["id"]; ok {
projectModuleFiles.Id = id.(int64)
}
if projectModuleId, ok := data["projectModuleId"]; ok {
projectModuleFiles.ProjectModuleId = projectModuleId.(int64)
}
if projectModuleVersion, ok := data["projectModuleVersion"]; ok {
projectModuleFiles.ProjectModuleVersion = projectModuleVersion.(int64)
}
if fileType, ok := data["fileType"]; ok {
projectModuleFiles.FileType = fileType.(int)
}
if codeBlock, ok := data["codeBlock"]; ok {
projectModuleFiles.CodeBlock = codeBlock.(string)
}
if ParentId, ok := data["ParentId"]; ok {
projectModuleFiles.ParentId = ParentId.(int64)
}
if Sort, ok := data["Sort"]; ok {
projectModuleFiles.Sort = Sort.(int)
}
if remark, ok := data["remark"]; ok {
projectModuleFiles.Remark = remark.(string)
}
if CreateTime, ok := data["CreateTime"]; ok {
projectModuleFiles.CreateTime = CreateTime.(time.Time)
}
if UpdateTime, ok := data["UpdateTime"]; ok {
projectModuleFiles.UpdateTime = UpdateTime.(time.Time)
}
if path, ok := data["path"]; ok {
projectModuleFiles.Path = path.(string)
}
if tag, ok := data["tag"]; ok {
projectModuleFiles.Tag = tag.(string)
}
return nil
}
... ...
package domain
import "time"
// 项目模块版本
type ProjectModuleVersion struct {
// 唯一标识
Id int64 `json:"id"`
// 项目编号
ProjectModuleId int64 `json:"projectModuleId"`
// 唯一标识
Version int64 `json:"version"`
// 描述信息
Description string `json:"description"`
// 状态 1:正常 2:删除
Status int `json:"status"`
// 创建时间
CreateTime time.Time `json:"createTime"`
// 更新时间
UpdateTime time.Time `json:"updateTime"`
}
type ProjectModuleVersionRepository interface {
Save(projectModuleVersion *ProjectModuleVersion) (*ProjectModuleVersion, error)
Remove(projectModuleVersion *ProjectModuleVersion) (*ProjectModuleVersion, error)
FindOne(queryOptions map[string]interface{}) (*ProjectModuleVersion, error)
Find(queryOptions map[string]interface{}) (int64, []*ProjectModuleVersion, error)
}
func (projectModuleVersion *ProjectModuleVersion) Identify() interface{} {
if projectModuleVersion.Id == 0 {
return nil
}
return projectModuleVersion.Id
}
func (projectModuleVersion *ProjectModuleVersion) Update(data map[string]interface{}) error {
if id, ok := data["id"]; ok {
projectModuleVersion.Id = id.(int64)
}
if projectModuleId, ok := data["projectModuleId"]; ok {
projectModuleVersion.ProjectModuleId = projectModuleId.(int64)
}
if version, ok := data["version"]; ok {
projectModuleVersion.Version = version.(int64)
}
if description, ok := data["description"]; ok {
projectModuleVersion.Description = description.(string)
}
if status, ok := data["status"]; ok {
projectModuleVersion.Status = status.(int)
}
if CreateTime, ok := data["CreateTime"]; ok {
projectModuleVersion.CreateTime = CreateTime.(time.Time)
}
if UpdateTime, ok := data["UpdateTime"]; ok {
projectModuleVersion.UpdateTime = UpdateTime.(time.Time)
}
return nil
}
... ...
... ... @@ -6,7 +6,7 @@ import (
)
type ClientVersion struct {
TableName string `pg:"client_versions,alias:client_version"`
tableName struct{} `pg:"client_version,alias:client_version"`
// dcc
Id int64
// 提交人
... ...
package models
import "time"
type ProjectModule struct {
tableName struct{} `pg:"project_module,alias:project_module"`
// 唯一标识
Id int64 `pg:"pk"`
// 项目名称
ProjectName string
// 项目唯一键值
ProjectKey string
// 描述信息
Description string
// 状态 1:正常 2:删除
Status int
// 创建时间
CreateTime time.Time
// 更新时间
UpdateTime time.Time
// 项目模板版本信息
ProjectModuleVersion *ProjectModuleVersion
}
... ...
package models
import "time"
type ProjectModuleFiles struct {
tableName struct{} `pg:"project_module_files,alias:project_module_files"`
// 唯一标识
Id int64 `pg:"pk"`
// 项目编号
ProjectModuleId int64
// 项目版本编号
ProjectModuleVersion int64
// 文件类型 1:文件夹 2:文件
FileType int
// 代码块
CodeBlock string
// 父级Id
ParentId int64
// 排序
Sort int
// 备注信息
Remark string
// 创建时间
CreateTime time.Time
// 更新时间
UpdateTime time.Time
// 当前文件相对路径 a/b/c
Path string
// 标签
Tag string
}
... ...
package models
import "time"
type ProjectModuleVersion struct {
tableName struct{} `pg:"project_module_version,alias:project_module_version"`
// 唯一标识
Id int64 `pg:"pk"`
// 项目编号
ProjectModuleId int64
// 唯一标识
Version int64
// 描述信息
Description string
// 状态 1:正常 2:删除
Status int
// 创建时间
CreateTime time.Time
// 更新时间
UpdateTime time.Time
}
... ...
package models
type RoleAccess struct {
TableName string `pg:"role_access,alias:role_access"`
tableName struct{} `pg:"role_access,alias:role_access"`
// dcc
Id int64
// 角色id
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/tiptok/godevp/pkg/domain"
"github.com/tiptok/godevp/pkg/infrastructure/pg/models"
)
type ProjectModuleFilesRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *ProjectModuleFilesRepository) nextIdentify() (int64, error) {
return 0, nil
}
func (repository *ProjectModuleFilesRepository) Save(projectModuleFiles *domain.ProjectModuleFiles) (*domain.ProjectModuleFiles, error) {
tx := repository.transactionContext.PgTx
if projectModuleFiles.Identify() == nil {
_, err := repository.nextIdentify()
if err != nil {
return projectModuleFiles, err
}
if _, err := tx.QueryOne(
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),
"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",
projectModuleFiles.ProjectModuleId, projectModuleFiles.ProjectModuleVersion, projectModuleFiles.FileType, projectModuleFiles.CodeBlock, projectModuleFiles.ParentId, projectModuleFiles.Sort, projectModuleFiles.Remark, projectModuleFiles.CreateTime, projectModuleFiles.UpdateTime, projectModuleFiles.Path, projectModuleFiles.Tag); err != nil {
return projectModuleFiles, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&projectModuleFiles.ProjectModuleId, &projectModuleFiles.ProjectModuleVersion, &projectModuleFiles.FileType, &projectModuleFiles.CodeBlock, &projectModuleFiles.ParentId, &projectModuleFiles.Sort, &projectModuleFiles.Remark, &projectModuleFiles.CreateTime, &projectModuleFiles.UpdateTime, &projectModuleFiles.Path, &projectModuleFiles.Tag),
"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",
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 {
return projectModuleFiles, err
}
}
return projectModuleFiles, nil
}
func (repository *ProjectModuleFilesRepository) Remove(projectModuleFiles *domain.ProjectModuleFiles) (*domain.ProjectModuleFiles, error) {
tx := repository.transactionContext.PgTx
projectModuleFilesModel := new(models.ProjectModuleFiles)
projectModuleFilesModel.Id = projectModuleFiles.Identify().(int64)
if _, err := tx.Model(projectModuleFilesModel).WherePK().Delete(); err != nil {
return projectModuleFiles, err
}
return projectModuleFiles, nil
}
func (repository *ProjectModuleFilesRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProjectModuleFiles, error) {
tx := repository.transactionContext.PgTx
projectModuleFilesModel := new(models.ProjectModuleFiles)
query := tx.Model(projectModuleFilesModel)
if projectModuleFilesId, ok := queryOptions["projectModuleFilesId"]; ok {
query = query.Where("project_module_files.id = ?", projectModuleFilesId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if projectModuleFilesModel.Id == 0 {
return nil, nil
} else {
return repository.transformPgModelToDomainModel(projectModuleFilesModel)
}
}
func (repository *ProjectModuleFilesRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProjectModuleFiles, error) {
tx := repository.transactionContext.PgTx
var projectModuleFilesModels []*models.ProjectModuleFiles
projectModuleFiless := make([]*domain.ProjectModuleFiles, 0)
query := tx.Model(&projectModuleFilesModels)
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
query = query.Offset(offset)
}
} else {
query = query.Offset(0)
}
if limit, ok := queryOptions["limit"]; ok {
limit := limit.(int)
if limit > -1 {
query = query.Limit(limit)
}
} else {
query = query.Limit(20)
}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
return 0, projectModuleFiless, err
} else {
for _, projectModuleFilesModel := range projectModuleFilesModels {
if projectModuleFiles, err := repository.transformPgModelToDomainModel(projectModuleFilesModel); err != nil {
return 0, projectModuleFiless, err
} else {
projectModuleFiless = append(projectModuleFiless, projectModuleFiles)
}
}
return int64(count), projectModuleFiless, nil
}
}
func (repository *ProjectModuleFilesRepository) transformPgModelToDomainModel(projectModuleFilesModel *models.ProjectModuleFiles) (*domain.ProjectModuleFiles, error) {
return &domain.ProjectModuleFiles{
Id: projectModuleFilesModel.Id,
ProjectModuleId: projectModuleFilesModel.ProjectModuleId,
ProjectModuleVersion: projectModuleFilesModel.ProjectModuleVersion,
FileType: projectModuleFilesModel.FileType,
CodeBlock: projectModuleFilesModel.CodeBlock,
ParentId: projectModuleFilesModel.ParentId,
Sort: projectModuleFilesModel.Sort,
Remark: projectModuleFilesModel.Remark,
CreateTime: projectModuleFilesModel.CreateTime,
UpdateTime: projectModuleFilesModel.UpdateTime,
Path: projectModuleFilesModel.Path,
Tag: projectModuleFilesModel.Tag,
}, nil
}
func NewProjectModuleFilesRepository(transactionContext *pgTransaction.TransactionContext) (*ProjectModuleFilesRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ProjectModuleFilesRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/tiptok/godevp/pkg/domain"
"github.com/tiptok/godevp/pkg/infrastructure/pg/models"
)
type ProjectModuleRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *ProjectModuleRepository) nextIdentify() (int64, error) {
return 0, nil
}
func (repository *ProjectModuleRepository) Save(projectModule *domain.ProjectModule) (*domain.ProjectModule, error) {
tx := repository.transactionContext.PgTx
if projectModule.Identify() == nil {
_, err := repository.nextIdentify()
if err != nil {
return projectModule, err
}
if _, err := tx.QueryOne(
pg.Scan(&projectModule.Id, &projectModule.ProjectName, &projectModule.ProjectKey, &projectModule.Description, &projectModule.Status, &projectModule.CreateTime, &projectModule.UpdateTime, &projectModule.ProjectModuleVersion),
"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",
projectModule.ProjectName, projectModule.ProjectKey, projectModule.Description, projectModule.Status, projectModule.CreateTime, projectModule.UpdateTime, projectModule.ProjectModuleVersion); err != nil {
return projectModule, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&projectModule.ProjectName, &projectModule.ProjectKey, &projectModule.Description, &projectModule.Status, &projectModule.CreateTime, &projectModule.UpdateTime, &projectModule.ProjectModuleVersion),
"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",
projectModule.ProjectName, projectModule.ProjectKey, projectModule.Description, projectModule.Status, projectModule.CreateTime, projectModule.UpdateTime, projectModule.ProjectModuleVersion, projectModule.Identify()); err != nil {
return projectModule, err
}
}
return projectModule, nil
}
func (repository *ProjectModuleRepository) Remove(projectModule *domain.ProjectModule) (*domain.ProjectModule, error) {
tx := repository.transactionContext.PgTx
projectModuleModel := new(models.ProjectModule)
projectModuleModel.Id = projectModule.Identify().(int64)
if _, err := tx.Model(projectModuleModel).WherePK().Delete(); err != nil {
return projectModule, err
}
return projectModule, nil
}
func (repository *ProjectModuleRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProjectModule, error) {
tx := repository.transactionContext.PgTx
projectModuleModel := new(models.ProjectModule)
query := tx.Model(projectModuleModel)
if projectModuleId, ok := queryOptions["projectModuleId"]; ok {
query = query.Where("project_module.id = ?", projectModuleId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if projectModuleModel.Id == 0 {
return nil, nil
} else {
return repository.transformPgModelToDomainModel(projectModuleModel)
}
}
func (repository *ProjectModuleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProjectModule, error) {
tx := repository.transactionContext.PgTx
var projectModuleModels []*models.ProjectModule
projectModules := make([]*domain.ProjectModule, 0)
query := tx.Model(&projectModuleModels)
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
query = query.Offset(offset)
}
} else {
query = query.Offset(0)
}
if limit, ok := queryOptions["limit"]; ok {
limit := limit.(int)
if limit > -1 {
query = query.Limit(limit)
}
} else {
query = query.Limit(20)
}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
return 0, projectModules, err
} else {
for _, projectModuleModel := range projectModuleModels {
if projectModule, err := repository.transformPgModelToDomainModel(projectModuleModel); err != nil {
return 0, projectModules, err
} else {
projectModules = append(projectModules, projectModule)
}
}
return int64(count), projectModules, nil
}
}
func (repository *ProjectModuleRepository) transformPgModelToDomainModel(projectModuleModel *models.ProjectModule) (*domain.ProjectModule, error) {
return &domain.ProjectModule{
Id: projectModuleModel.Id,
ProjectName: projectModuleModel.ProjectName,
ProjectKey: projectModuleModel.ProjectKey,
Description: projectModuleModel.Description,
Status: projectModuleModel.Status,
CreateTime: projectModuleModel.CreateTime,
UpdateTime: projectModuleModel.UpdateTime,
//ProjectModuleVersion: projectModuleModel.ProjectModuleVersion,
}, nil
}
func NewProjectModuleRepository(transactionContext *pgTransaction.TransactionContext) (*ProjectModuleRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ProjectModuleRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
package repository
import (
"fmt"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/tiptok/godevp/pkg/domain"
"github.com/tiptok/godevp/pkg/infrastructure/pg/models"
)
type ProjectModuleVersionRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func (repository *ProjectModuleVersionRepository) nextIdentify() (int64, error) {
return 0, nil
}
func (repository *ProjectModuleVersionRepository) Save(projectModuleVersion *domain.ProjectModuleVersion) (*domain.ProjectModuleVersion, error) {
tx := repository.transactionContext.PgTx
if projectModuleVersion.Identify() == nil {
_, err := repository.nextIdentify()
if err != nil {
return projectModuleVersion, err
}
if _, err := tx.QueryOne(
pg.Scan(&projectModuleVersion.Id, &projectModuleVersion.ProjectModuleId, &projectModuleVersion.Version, &projectModuleVersion.Description, &projectModuleVersion.Status, &projectModuleVersion.CreateTime, &projectModuleVersion.UpdateTime),
"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",
projectModuleVersion.ProjectModuleId, projectModuleVersion.Version, projectModuleVersion.Description, projectModuleVersion.Status, projectModuleVersion.CreateTime, projectModuleVersion.UpdateTime); err != nil {
return projectModuleVersion, err
}
} else {
if _, err := tx.QueryOne(
pg.Scan(&projectModuleVersion.ProjectModuleId, &projectModuleVersion.Version, &projectModuleVersion.Description, &projectModuleVersion.Status, &projectModuleVersion.CreateTime, &projectModuleVersion.UpdateTime),
"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",
projectModuleVersion.ProjectModuleId, projectModuleVersion.Version, projectModuleVersion.Description, projectModuleVersion.Status, projectModuleVersion.CreateTime, projectModuleVersion.UpdateTime, projectModuleVersion.Identify()); err != nil {
return projectModuleVersion, err
}
}
return projectModuleVersion, nil
}
func (repository *ProjectModuleVersionRepository) Remove(projectModuleVersion *domain.ProjectModuleVersion) (*domain.ProjectModuleVersion, error) {
tx := repository.transactionContext.PgTx
projectModuleVersionModel := new(models.ProjectModuleVersion)
projectModuleVersionModel.Id = projectModuleVersion.Identify().(int64)
if _, err := tx.Model(projectModuleVersionModel).WherePK().Delete(); err != nil {
return projectModuleVersion, err
}
return projectModuleVersion, nil
}
func (repository *ProjectModuleVersionRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProjectModuleVersion, error) {
tx := repository.transactionContext.PgTx
projectModuleVersionModel := new(models.ProjectModuleVersion)
query := tx.Model(projectModuleVersionModel)
if projectModuleVersionId, ok := queryOptions["projectModuleVersionId"]; ok {
query = query.Where("project_module_version.id = ?", projectModuleVersionId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if projectModuleVersionModel.Id == 0 {
return nil, nil
} else {
return repository.transformPgModelToDomainModel(projectModuleVersionModel)
}
}
func (repository *ProjectModuleVersionRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProjectModuleVersion, error) {
tx := repository.transactionContext.PgTx
var projectModuleVersionModels []*models.ProjectModuleVersion
projectModuleVersions := make([]*domain.ProjectModuleVersion, 0)
query := tx.Model(&projectModuleVersionModels)
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
query = query.Offset(offset)
}
} else {
query = query.Offset(0)
}
if limit, ok := queryOptions["limit"]; ok {
limit := limit.(int)
if limit > -1 {
query = query.Limit(limit)
}
} else {
query = query.Limit(20)
}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
return 0, projectModuleVersions, err
} else {
for _, projectModuleVersionModel := range projectModuleVersionModels {
if projectModuleVersion, err := repository.transformPgModelToDomainModel(projectModuleVersionModel); err != nil {
return 0, projectModuleVersions, err
} else {
projectModuleVersions = append(projectModuleVersions, projectModuleVersion)
}
}
return int64(count), projectModuleVersions, nil
}
}
func (repository *ProjectModuleVersionRepository) transformPgModelToDomainModel(projectModuleVersionModel *models.ProjectModuleVersion) (*domain.ProjectModuleVersion, error) {
return &domain.ProjectModuleVersion{
Id: projectModuleVersionModel.Id,
ProjectModuleId: projectModuleVersionModel.ProjectModuleId,
Version: projectModuleVersionModel.Version,
Description: projectModuleVersionModel.Description,
Status: projectModuleVersionModel.Status,
CreateTime: projectModuleVersionModel.CreateTime,
UpdateTime: projectModuleVersionModel.UpdateTime,
}, nil
}
func NewProjectModuleVersionRepository(transactionContext *pgTransaction.TransactionContext) (*ProjectModuleVersionRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &ProjectModuleVersionRepository{
transactionContext: transactionContext,
}, nil
}
}
... ...
package controllers
import (
"encoding/json"
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"github.com/tiptok/godevp/pkg/application/projectModule/command"
"github.com/tiptok/godevp/pkg/application/projectModule/query"
"github.com/tiptok/godevp/pkg/application/projectModule/service"
)
type ProjectModuleController struct {
beego.Controller
}
func (controller *ProjectModuleController) CreateProjectModule() {
projectModuleService := service.NewProjectModuleService(nil)
createProjectModuleCommand := &command.CreateProjectModuleCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createProjectModuleCommand)
data, err := projectModuleService.CreateProjectModule(createProjectModuleCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ProjectModuleController) UpdateProjectModule() {
projectModuleService := service.NewProjectModuleService(nil)
updateProjectModuleCommand := &command.UpdateProjectModuleCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateProjectModuleCommand)
projectModuleId, _ := controller.GetInt64(":projectModuleId")
updateProjectModuleCommand.ProjectModuleId = projectModuleId
data, err := projectModuleService.UpdateProjectModule(updateProjectModuleCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ProjectModuleController) GetProjectModule() {
projectModuleService := service.NewProjectModuleService(nil)
getProjectModuleQuery := &query.GetProjectModuleQuery{}
projectModuleId, _ := controller.GetInt64(":projectModuleId")
getProjectModuleQuery.ProjectModuleId = projectModuleId
data, err := projectModuleService.GetProjectModule(getProjectModuleQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ProjectModuleController) RemoveProjectModule() {
projectModuleService := service.NewProjectModuleService(nil)
removeProjectModuleCommand := &command.RemoveProjectModuleCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), removeProjectModuleCommand)
projectModuleId, _ := controller.GetInt64(":projectModuleId")
removeProjectModuleCommand.ProjectModuleId = projectModuleId
data, err := projectModuleService.RemoveProjectModule(removeProjectModuleCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ProjectModuleController) ListProjectModule() {
projectModuleService := service.NewProjectModuleService(nil)
listProjectModuleQuery := &query.ListProjectModuleQuery{}
offset, _ := controller.GetInt("offset")
listProjectModuleQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listProjectModuleQuery.Limit = limit
data, err := projectModuleService.ListProjectModule(listProjectModuleQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
... ...
package controllers
import (
"encoding/json"
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"github.com/tiptok/godevp/pkg/application/projectModuleFiles/command"
"github.com/tiptok/godevp/pkg/application/projectModuleFiles/query"
"github.com/tiptok/godevp/pkg/application/projectModuleFiles/service"
)
type ProjectModuleFilesController struct {
beego.Controller
}
func (controller *ProjectModuleFilesController) CreateProjectModuleFiles() {
projectModuleFilesService := service.NewProjectModuleFilesService(nil)
createProjectModuleFilesCommand := &command.CreateProjectModuleFilesCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createProjectModuleFilesCommand)
data, err := projectModuleFilesService.CreateProjectModuleFiles(createProjectModuleFilesCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ProjectModuleFilesController) UpdateProjectModuleFiles() {
projectModuleFilesService := service.NewProjectModuleFilesService(nil)
updateProjectModuleFilesCommand := &command.UpdateProjectModuleFilesCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateProjectModuleFilesCommand)
projectModuleFilesId, _ := controller.GetInt64(":projectModuleFilesId")
updateProjectModuleFilesCommand.ProjectModuleFilesId = projectModuleFilesId
data, err := projectModuleFilesService.UpdateProjectModuleFiles(updateProjectModuleFilesCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ProjectModuleFilesController) GetProjectModuleFiles() {
projectModuleFilesService := service.NewProjectModuleFilesService(nil)
getProjectModuleFilesQuery := &query.GetProjectModuleFilesQuery{}
projectModuleFilesId, _ := controller.GetInt64(":projectModuleFilesId")
getProjectModuleFilesQuery.ProjectModuleFilesId = projectModuleFilesId
data, err := projectModuleFilesService.GetProjectModuleFiles(getProjectModuleFilesQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ProjectModuleFilesController) RemoveProjectModuleFiles() {
projectModuleFilesService := service.NewProjectModuleFilesService(nil)
removeProjectModuleFilesCommand := &command.RemoveProjectModuleFilesCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), removeProjectModuleFilesCommand)
projectModuleFilesId, _ := controller.GetInt64(":projectModuleFilesId")
removeProjectModuleFilesCommand.ProjectModuleFilesId = projectModuleFilesId
data, err := projectModuleFilesService.RemoveProjectModuleFiles(removeProjectModuleFilesCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ProjectModuleFilesController) ListProjectModuleFiles() {
projectModuleFilesService := service.NewProjectModuleFilesService(nil)
listProjectModuleFilesQuery := &query.ListProjectModuleFilesQuery{}
offset, _ := controller.GetInt("offset")
listProjectModuleFilesQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listProjectModuleFilesQuery.Limit = limit
data, err := projectModuleFilesService.ListProjectModuleFiles(listProjectModuleFilesQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
... ...
package controllers
import (
"encoding/json"
"github.com/astaxie/beego"
"github.com/linmadan/egglib-go/web/beego/utils"
"github.com/tiptok/godevp/pkg/application/projectModuleVersion/command"
"github.com/tiptok/godevp/pkg/application/projectModuleVersion/query"
"github.com/tiptok/godevp/pkg/application/projectModuleVersion/service"
)
type ProjectModuleVersionController struct {
beego.Controller
}
func (controller *ProjectModuleVersionController) CreateProjectModuleVersion() {
projectModuleVersionService := service.NewProjectModuleVersionService(nil)
createProjectModuleVersionCommand := &command.CreateProjectModuleVersionCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createProjectModuleVersionCommand)
data, err := projectModuleVersionService.CreateProjectModuleVersion(createProjectModuleVersionCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ProjectModuleVersionController) UpdateProjectModuleVersion() {
projectModuleVersionService := service.NewProjectModuleVersionService(nil)
updateProjectModuleVersionCommand := &command.UpdateProjectModuleVersionCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateProjectModuleVersionCommand)
projectModuleVersionId, _ := controller.GetInt64(":projectModuleVersionId")
updateProjectModuleVersionCommand.ProjectModuleVersionId = projectModuleVersionId
data, err := projectModuleVersionService.UpdateProjectModuleVersion(updateProjectModuleVersionCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ProjectModuleVersionController) GetProjectModuleVersion() {
projectModuleVersionService := service.NewProjectModuleVersionService(nil)
getProjectModuleVersionQuery := &query.GetProjectModuleVersionQuery{}
projectModuleVersionId, _ := controller.GetInt64(":projectModuleVersionId")
getProjectModuleVersionQuery.ProjectModuleVersionId = projectModuleVersionId
data, err := projectModuleVersionService.GetProjectModuleVersion(getProjectModuleVersionQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ProjectModuleVersionController) RemoveProjectModuleVersion() {
projectModuleVersionService := service.NewProjectModuleVersionService(nil)
removeProjectModuleVersionCommand := &command.RemoveProjectModuleVersionCommand{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), removeProjectModuleVersionCommand)
projectModuleVersionId, _ := controller.GetInt64(":projectModuleVersionId")
removeProjectModuleVersionCommand.ProjectModuleVersionId = projectModuleVersionId
data, err := projectModuleVersionService.RemoveProjectModuleVersion(removeProjectModuleVersionCommand)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
func (controller *ProjectModuleVersionController) ListProjectModuleVersion() {
projectModuleVersionService := service.NewProjectModuleVersionService(nil)
listProjectModuleVersionQuery := &query.ListProjectModuleVersionQuery{}
offset, _ := controller.GetInt("offset")
listProjectModuleVersionQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listProjectModuleVersionQuery.Limit = limit
data, err := projectModuleVersionService.ListProjectModuleVersion(listProjectModuleVersionQuery)
var response utils.JsonResponse
if err != nil {
response = utils.ResponseError(controller.Ctx, err)
} else {
response = utils.ResponseData(controller.Ctx, data)
}
controller.Data["json"] = response
controller.ServeJSON()
}
... ...
package routers
import (
"github.com/astaxie/beego"
"github.com/tiptok/godevp/pkg/port/beego/controllers"
)
func init() {
beego.Router("/project-module-filess/", &controllers.ProjectModuleFilesController{}, "Post:CreateProjectModuleFiles")
beego.Router("/project-module-filess/:projectModuleFilesId", &controllers.ProjectModuleFilesController{}, "Put:UpdateProjectModuleFiles")
beego.Router("/project-module-filess/:projectModuleFilesId", &controllers.ProjectModuleFilesController{}, "Get:GetProjectModuleFiles")
beego.Router("/project-module-filess/:projectModuleFilesId", &controllers.ProjectModuleFilesController{}, "Delete:RemoveProjectModuleFiles")
beego.Router("/project-module-filess/", &controllers.ProjectModuleFilesController{}, "Get:ListProjectModuleFiles")
}
... ...
package routers
import (
"github.com/astaxie/beego"
"github.com/tiptok/godevp/pkg/port/beego/controllers"
)
func init() {
beego.Router("/project-modules/", &controllers.ProjectModuleController{}, "Post:CreateProjectModule")
beego.Router("/project-modules/:projectModuleId", &controllers.ProjectModuleController{}, "Put:UpdateProjectModule")
beego.Router("/project-modules/:projectModuleId", &controllers.ProjectModuleController{}, "Get:GetProjectModule")
beego.Router("/project-modules/:projectModuleId", &controllers.ProjectModuleController{}, "Delete:RemoveProjectModule")
beego.Router("/project-modules/", &controllers.ProjectModuleController{}, "Get:ListProjectModule")
}
... ...
package routers
import (
"github.com/astaxie/beego"
"github.com/tiptok/godevp/pkg/port/beego/controllers"
)
func init() {
beego.Router("/project-module-versions/", &controllers.ProjectModuleVersionController{}, "Post:CreateProjectModuleVersion")
beego.Router("/project-module-versions/:projectModuleVersionId", &controllers.ProjectModuleVersionController{}, "Put:UpdateProjectModuleVersion")
beego.Router("/project-module-versions/:projectModuleVersionId", &controllers.ProjectModuleVersionController{}, "Get:GetProjectModuleVersion")
beego.Router("/project-module-versions/:projectModuleVersionId", &controllers.ProjectModuleVersionController{}, "Delete:RemoveProjectModuleVersion")
beego.Router("/project-module-versions/", &controllers.ProjectModuleVersionController{}, "Get:ListProjectModuleVersion")
}
... ...
package project_module
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
)
var _ = Describe("创建", func() {
Describe("提交数据创建", func() {
Context("提交正确的新项目模块数据", func() {
It("返回项目模块数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"projectName": "string",
"projectKey": "string",
"description": "string",
"status": "int",
}
httpExpect.POST("/project-modules/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("id").ValueNotEqual("id", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_modules WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_module
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg/v10"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
)
var _ = Describe("返回", func() {
var projectModuleId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&projectModuleId),
"INSERT INTO project_modules (id, project_name, project_key, description, status, create_time, update_time, project_module_version) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
"testProjectName", "testProjectKey", "testDescription", "testStatus", "testCreateTime", "testUpdateTime", "testProjectModuleVersion")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据projectModuleId参数返回项目模块", func() {
Context("传入有效的projectModuleId", func() {
It("返回项目模块数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/project-modules/{projectModuleId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_modules WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_module
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg/v10"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
)
var _ = Describe("返回列表", func() {
var projectModuleId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&projectModuleId),
"INSERT INTO project_modules (id, project_name, project_key, description, status, create_time, update_time, project_module_version) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
"testProjectName", "testProjectKey", "testDescription", "testStatus", "testCreateTime", "testUpdateTime", "testProjectModuleVersion")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回项目模块列表", func() {
Context("传入有效的参数", func() {
It("返回项目模块数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/project-modules/").
WithQuery("offset", "int").
WithQuery("limit", "int").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("projectModules").Value("projectModules").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_modules WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_module
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/astaxie/beego"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
_ "github.com/tiptok/godevp/pkg/infrastructure/pg"
_ "github.com/tiptok/godevp/pkg/port/beego"
)
func TestProjectModule(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port ProjectModule Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = BeforeSuite(func() {
handler = beego.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = AfterSuite(func() {
server.Close()
})
... ...
package project_module
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg/v10"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
)
var _ = Describe("移除", func() {
var projectModuleId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&projectModuleId),
"INSERT INTO project_modules (id, project_name, project_key, description, status, create_time, update_time, project_module_version) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
"testProjectName", "testProjectKey", "testDescription", "testStatus", "testCreateTime", "testUpdateTime", "testProjectModuleVersion")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除", func() {
Context("传入有效的projectModuleId", func() {
It("返回被移除项目模块的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/project-modules/{projectModuleId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_modules WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_module
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg/v10"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
)
var _ = Describe("更新", func() {
var projectModuleId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&projectModuleId),
"INSERT INTO project_modules (id, project_name, project_key, description, status, create_time, update_time, project_module_version) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
"testProjectName", "testProjectKey", "testDescription", "testStatus", "testCreateTime", "testUpdateTime", "testProjectModuleVersion")
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新", func() {
Context("提交正确的项目模块数据", func() {
It("返回更新后的项目模块数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"projectName": "string",
"projectKey": "string",
"description": "string",
"status": "int",
}
httpExpect.PUT("/project-modules/{projectModuleId}").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("id").ValueEqual("id", projectModuleId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_modules WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_module_files
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
)
var _ = Describe("创建", func() {
Describe("提交数据创建", func() {
Context("提交正确的新项目模板文件数据", func() {
It("返回项目模板文件数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"projectModuleId": "int64",
"projectModuleVersion": "int64",
"fileType": "int",
"codeBlock": "string",
"ParentId": "int64",
"Sort": "int",
"remark": "string",
}
httpExpect.POST("/project-module-filess/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("id").ValueNotEqual("id", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_module_filess WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_module_files
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg/v10"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
)
var _ = Describe("返回", func() {
var projectModuleFilesId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&projectModuleFilesId),
"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",
"testProjectModuleId", "testProjectModuleVersion", "testFileType", "testCodeBlock", "testParentId", "testSort", "testRemark", "testCreateTime", "testUpdateTime", "testPath", "testTag")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据projectModuleFilesId参数返回项目模板文件", func() {
Context("传入有效的projectModuleFilesId", func() {
It("返回项目模板文件数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/project-module-filess/{projectModuleFilesId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_module_filess WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_module_files
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg/v10"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
)
var _ = Describe("返回列表", func() {
var projectModuleFilesId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&projectModuleFilesId),
"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",
"testProjectModuleId", "testProjectModuleVersion", "testFileType", "testCodeBlock", "testParentId", "testSort", "testRemark", "testCreateTime", "testUpdateTime", "testPath", "testTag")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回项目模板文件列表", func() {
Context("传入有效的参数", func() {
It("返回项目模板文件数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/project-module-filess/").
WithQuery("offset", "int").
WithQuery("limit", "int").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("projectModuleFiless").Value("projectModuleFiless").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_module_filess WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_module_files
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/astaxie/beego"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
_ "github.com/tiptok/godevp/pkg/infrastructure/pg"
_ "github.com/tiptok/godevp/pkg/port/beego"
)
func TestProjectModuleFiles(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port ProjectModuleFiles Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = BeforeSuite(func() {
handler = beego.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = AfterSuite(func() {
server.Close()
})
... ...
package project_module_files
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg/v10"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
)
var _ = Describe("移除", func() {
var projectModuleFilesId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&projectModuleFilesId),
"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",
"testProjectModuleId", "testProjectModuleVersion", "testFileType", "testCodeBlock", "testParentId", "testSort", "testRemark", "testCreateTime", "testUpdateTime", "testPath", "testTag")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除", func() {
Context("传入有效的projectModuleFilesId", func() {
It("返回被移除项目模板文件的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/project-module-filess/{projectModuleFilesId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_module_filess WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_module_files
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg/v10"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
)
var _ = Describe("更新", func() {
var projectModuleFilesId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&projectModuleFilesId),
"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",
"testProjectModuleId", "testProjectModuleVersion", "testFileType", "testCodeBlock", "testParentId", "testSort", "testRemark", "testCreateTime", "testUpdateTime", "testPath", "testTag")
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新", func() {
Context("提交正确的项目模板文件数据", func() {
It("返回更新后的项目模板文件数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"codeBlock": "string",
"remark": "string",
}
httpExpect.PUT("/project-module-filess/{projectModuleFilesId}").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("id").ValueEqual("id", projectModuleFilesId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_module_filess WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_module_version
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
)
var _ = Describe("创建", func() {
Describe("提交数据创建", func() {
Context("提交正确的新项目模块版本数据", func() {
It("返回项目模块版本数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"projectModuleId": "int64",
"version": "int64",
"description": "string",
}
httpExpect.POST("/project-module-versions/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("id").ValueNotEqual("id", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_module_versions WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_module_version
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg/v10"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
)
var _ = Describe("返回", func() {
var projectModuleVersionId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&projectModuleVersionId),
"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",
"testProjectModuleVersionId", "testProjectModuleVersionProjectModuleId", "testProjectModuleVersionVersion", "testProjectModuleVersionDescription", "testProjectModuleVersionStatus", "testProjectModuleVersionCreateTime", "testProjectModuleVersionUpdateTime", "testProjectModuleId", "testVersion", "testDescription", "testStatus", "testCreateTime", "testUpdateTime")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据projectModuleVersionId参数返回项目模块版本", func() {
Context("传入有效的projectModuleVersionId", func() {
It("返回项目模块版本数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/project-module-versions/{projectModuleVersionId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_module_versions WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_module_version
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg/v10"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
)
var _ = Describe("返回列表", func() {
var projectModuleVersionId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&projectModuleVersionId),
"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",
"testProjectModuleVersionId", "testProjectModuleVersionProjectModuleId", "testProjectModuleVersionVersion", "testProjectModuleVersionDescription", "testProjectModuleVersionStatus", "testProjectModuleVersionCreateTime", "testProjectModuleVersionUpdateTime", "testProjectModuleId", "testVersion", "testDescription", "testStatus", "testCreateTime", "testUpdateTime")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回项目模块版本列表", func() {
Context("传入有效的参数", func() {
It("返回项目模块版本数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/project-module-versions/").
WithQuery("offset", "int").
WithQuery("limit", "int").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("count").ValueEqual("count", 1).
ContainsKey("projectModuleVersions").Value("projectModuleVersions").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_module_versions WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_module_version
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/astaxie/beego"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
_ "github.com/tiptok/godevp/pkg/infrastructure/pg"
_ "github.com/tiptok/godevp/pkg/port/beego"
)
func TestProjectModuleVersion(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port ProjectModuleVersion Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = BeforeSuite(func() {
handler = beego.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = AfterSuite(func() {
server.Close()
})
... ...
package project_module_version
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg/v10"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
)
var _ = Describe("移除", func() {
var projectModuleVersionId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&projectModuleVersionId),
"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",
"testProjectModuleVersionId", "testProjectModuleVersionProjectModuleId", "testProjectModuleVersionVersion", "testProjectModuleVersionDescription", "testProjectModuleVersionStatus", "testProjectModuleVersionCreateTime", "testProjectModuleVersionUpdateTime", "testProjectModuleId", "testVersion", "testDescription", "testStatus", "testCreateTime", "testUpdateTime")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除", func() {
Context("传入有效的projectModuleVersionId", func() {
It("返回被移除项目模块版本的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/project-module-versions/{projectModuleVersionId}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_module_versions WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package project_module_version
import (
"net/http"
"github.com/gavv/httpexpect"
"github.com/go-pg/pg/v10"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "github.com/tiptok/godevp/pkg/infrastructure/pg"
)
var _ = Describe("更新", func() {
var projectModuleVersionId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&projectModuleVersionId),
"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",
"testProjectModuleVersionId", "testProjectModuleVersionProjectModuleId", "testProjectModuleVersionVersion", "testProjectModuleVersionDescription", "testProjectModuleVersionStatus", "testProjectModuleVersionCreateTime", "testProjectModuleVersionUpdateTime", "testProjectModuleId", "testVersion", "testDescription", "testStatus", "testCreateTime", "testUpdateTime")
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新", func() {
Context("提交正确的项目模块版本数据", func() {
It("返回更新后的项目模块版本数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"projectModuleVersion": "int64",
"projectModuleId": "int64",
"version": "int64",
"description": "string",
"status": "int",
}
httpExpect.PUT("/project-module-versions/{projectModuleVersionId}").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("id").ValueEqual("id", projectModuleVersionId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM project_module_versions WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...