作者 陈志颖

feat:添加用户网关服务

... ... @@ -10,7 +10,7 @@ import (
type UpdateCooperationProjectCommand struct {
// 共创项目ID
CooperationProjectId int64 `cname:"共创项目ID" json:"cooperationProjectId,string" valid:"Required"`
CooperationProjectId string `cname:"共创项目ID" json:"cooperationProjectId" valid:"Required"`
// 共创项目名称
CooperationProjectName string `cname:"共创项目名称" json:"cooperationProjectName" valid:"Required"`
// 承接对象,1员工,2共创用户,3公开,可以多选
... ...
... ... @@ -4,10 +4,14 @@ import "os"
const SERVICE_NAME = "allied-creation-cooperation"
// 日志相关设置
var LOG_LEVEL = "debug"
var LOG_FILE = "app.log"
var LOG_PREFIX = "[allied-creation-cooperation]"
// 用户信息模块地址
var USER_MODULE_HOST = ""
func init() {
if os.Getenv("LOG_LEVEL") != "" {
LOG_LEVEL = os.Getenv("LOG_LEVEL")
... ... @@ -18,4 +22,7 @@ func init() {
if os.Getenv("LOG_PREFIX") != "" {
LOG_PREFIX = os.Getenv("LOG_PREFIX")
}
if os.Getenv("USER_MODULE_HOST") != "" {
USER_MODULE_HOST = os.Getenv("USER_MODULE_HOST")
}
}
... ...
package service_gateway
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
"strings"
"time"
)
type HttplibUserServiceGateway struct {
httplibBaseServiceGateway
}
func (serviceGateway *HttplibUserServiceGateway) GetUser(uid int64) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, ""}, "/")
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["uid"] = uid
request.JSONBody(options)
response := make(map[string]interface{})
request.ToJSON(&response)
data, err := serviceGateway.responseHandle(response)
return data, err
}
func (serviceGateway *HttplibUserServiceGateway) GetCompany(companyId int64) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, ""}, "/")
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["companyId"] = companyId
request.JSONBody(options)
response := make(map[string]interface{})
request.ToJSON(&response)
data, err := serviceGateway.responseHandle(response)
return data, err
}
func (serviceGateway *HttplibUserServiceGateway) GetOrganization(organizationId int64) (map[string]interface{}, error) {
url := strings.Join([]string{serviceGateway.baseURL, ""}, "/")
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["orgId"] = organizationId
request.JSONBody(options)
response := make(map[string]interface{})
request.ToJSON(&response)
data, err := serviceGateway.responseHandle(response)
return data, err
}
func NewHttplibUserServiceGateway() *HttplibUserServiceGateway {
return &HttplibUserServiceGateway{
httplibBaseServiceGateway: httplibBaseServiceGateway{
baseURL: constant.USER_MODULE_HOST,
connectTimeout: 100 * time.Second,
readWriteTimeout: 30 * time.Second,
},
}
}
... ...
package service_gateway
type UserServiceGateway interface {
GetUser(uid int64) (map[string]interface{}, error)
GetCompany(companyId int64) (map[string]interface{}, error)
}
... ...
package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/service"
)
type CooperationProjectController struct {
beego.BaseController
}
func (controller *CooperationProjectController) ReleaseCooperationProject() {
cooperationProjectService := service.NewCooperationProjectService(nil)
releaseCooperationProjectCommand := &command.ReleaseCooperationProjectCommand{}
controller.Unmarshal(releaseCooperationProjectCommand)
data, err := cooperationProjectService.ReleaseCooperationProject(releaseCooperationProjectCommand)
controller.Response(data, err)
}
func (controller *CooperationProjectController) CreateCooperationProject() {
cooperationProjectService := service.NewCooperationProjectService(nil)
createCooperationProjectCommand := &command.CreateCooperationProjectCommand{}
controller.Unmarshal(createCooperationProjectCommand)
data, err := cooperationProjectService.CreateCooperationProject(createCooperationProjectCommand)
controller.Response(data, err)
}
func (controller *CooperationProjectController) UpdateCooperationProject() {
cooperationProjectService := service.NewCooperationProjectService(nil)
updateCooperationProjectCommand := &command.UpdateCooperationProjectCommand{}
controller.Unmarshal(updateCooperationProjectCommand)
cooperationProjectId := controller.GetString(":cooperationProjectId")
updateCooperationProjectCommand.CooperationProjectId = cooperationProjectId
data, err := cooperationProjectService.UpdateCooperationProject(updateCooperationProjectCommand)
controller.Response(data, err)
}
func (controller *CooperationProjectController) GetCooperationProject() {
cooperationProjectService := service.NewCooperationProjectService(nil)
getCooperationProjectQuery := &query.GetCooperationProjectQuery{}
cooperationProjectId, _ := controller.GetInt64(":cooperationProjectId")
getCooperationProjectQuery.CooperationProjectId = cooperationProjectId
data, err := cooperationProjectService.GetCooperationProject(getCooperationProjectQuery)
controller.Response(data, err)
}
func (controller *CooperationProjectController) RemoveCooperationProject() {
cooperationProjectService := service.NewCooperationProjectService(nil)
removeCooperationProjectCommand := &command.RemoveCooperationProjectCommand{}
controller.Unmarshal(removeCooperationProjectCommand)
cooperationProjectId, _ := controller.GetInt64(":cooperationProjectId")
removeCooperationProjectCommand.CooperationProjectId = cooperationProjectId
data, err := cooperationProjectService.RemoveCooperationProject(removeCooperationProjectCommand)
controller.Response(data, err)
}
func (controller *CooperationProjectController) SearchCooperationProject() {
cooperationProjectService := service.NewCooperationProjectService(nil)
searchCooperationProjectQuery := &query.SearchCooperationProjectQuery{}
data, err := cooperationProjectService.SearchCooperationProject(searchCooperationProjectQuery)
controller.Response(data, err)
}
func (controller *CooperationProjectController) CheckUndertaker() {
cooperationProjectService := service.NewCooperationProjectService(nil)
checkUndertakerQuery := &query.CheckUndertakerQuery{}
data, err := cooperationProjectService.CheckUndertaker(checkUndertakerQuery)
controller.Response(data, err)
}
func (controller *CooperationProjectController) ListCooperationProject() {
cooperationProjectService := service.NewCooperationProjectService(nil)
listCooperationProjectQuery := &query.ListCooperationProjectQuery{}
offset, _ := controller.GetInt("offset")
listCooperationProjectQuery.Offset = offset
limit, _ := controller.GetInt("limit")
listCooperationProjectQuery.Limit = limit
data, err := cooperationProjectService.ListCooperationProject(listCooperationProjectQuery)
controller.Response(data, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego/controllers"
)
func init() {
web.Router("/cooperation-projects/release-cooperation-project", &controllers.CooperationProjectController{}, "Post:ReleaseCooperationProject")
web.Router("/cooperation-projects/", &controllers.CooperationProjectController{}, "Post:CreateCooperationProject")
web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Put:UpdateCooperationProject")
web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Get:GetCooperationProject")
web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Delete:RemoveCooperationProject")
web.Router("/cooperation-projects/search", &controllers.CooperationProjectController{}, "Post:SearchCooperationProject")
web.Router("/cooperation-projects/check", &controllers.CooperationProjectController{}, "Post:CheckUndertaker")
web.Router("/cooperation-projects/", &controllers.CooperationProjectController{}, "Get:ListCooperationProject")
}
... ...
package cooperation_project
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("判断当前勾选的承接对象是否存在用户", func() {
var cooperationProjectId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationProjectId),
"INSERT INTO cooperation_projects (cooperation_project_id, cooperation_project_number, cooperation_project_description, cooperation_project_name, cooperation_project_publish_time, cooperation_project_publisher, cooperation_project_sponsor, cooperation_project_undertaker_type, org, company, operator, operate_time, status, updated_at, deleted_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_project_id",
"testCooperationProjectId", "testCooperationProjectNumber", "testCooperationProjectDescription", "testCooperationProjectName", "testCooperationProjectPublishTime", "testCooperationProjectPublisher", "testCooperationProjectSponsor", "testCooperationProjectUndertakerType", "testOrg", "testCompany", "testOperator", "testOperateTime", "testStatus", "testUpdatedAt", "testDeletedAt", "testCreatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("判断当前勾选的承接对象是否存在用户", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"cooperationProjectUndertakerType": "array",
"cooperationProjectId": "int64",
}
httpExpect.POST("/cooperation-projects/check").
WithJSON(body).
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 cooperation_projects WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_project
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/beego/beego/v2/server/web"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego"
)
func TestCooperationProject(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port CooperationProject Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = BeforeSuite(func() {
handler = web.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = AfterSuite(func() {
server.Close()
})
... ...
package cooperation_project
import (
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("创建共创项目服务", func() {
Describe("提交数据创建共创项目服务", func() {
Context("提交正确的新共创项目实体数据", func() {
It("返回共创项目实体数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"cooperationProjectName": "string",
"cooperationProjectUndertakerType": "array",
"sponsorUid": "string",
"publisherUid": "string",
"cooperationProjectDescription": "string",
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.POST("/cooperation-projects/").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("cooperationProjectId").ValueNotEqual("cooperationProjectId", BeZero())
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM cooperation_projects WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_project
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("返回共创项目服务", func() {
var cooperationProjectId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationProjectId),
"INSERT INTO cooperation_projects (cooperation_project_id, cooperation_project_number, cooperation_project_description, cooperation_project_name, cooperation_project_publish_time, cooperation_project_publisher, cooperation_project_sponsor, cooperation_project_undertaker_type, org, company, operator, operate_time, status, updated_at, deleted_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_project_id",
"testCooperationProjectId", "testCooperationProjectNumber", "testCooperationProjectDescription", "testCooperationProjectName", "testCooperationProjectPublishTime", "testCooperationProjectPublisher", "testCooperationProjectSponsor", "testCooperationProjectUndertakerType", "testOrg", "testCompany", "testOperator", "testOperateTime", "testStatus", "testUpdatedAt", "testDeletedAt", "testCreatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据cooperationProjectId参数返回共创项目实体", func() {
Context("传入有效的cooperationProjectId", func() {
It("返回共创项目实体数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/cooperation-projects/{cooperationProjectId}").
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 cooperation_projects WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_project
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("返回共创项目服务列表", func() {
var cooperationProjectId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationProjectId),
"INSERT INTO cooperation_projects (cooperation_project_id, cooperation_project_number, cooperation_project_description, cooperation_project_name, cooperation_project_publish_time, cooperation_project_publisher, cooperation_project_sponsor, cooperation_project_undertaker_type, org, company, operator, operate_time, status, updated_at, deleted_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_project_id",
"testCooperationProjectId", "testCooperationProjectNumber", "testCooperationProjectDescription", "testCooperationProjectName", "testCooperationProjectPublishTime", "testCooperationProjectPublisher", "testCooperationProjectSponsor", "testCooperationProjectUndertakerType", "testOrg", "testCompany", "testOperator", "testOperateTime", "testStatus", "testUpdatedAt", "testDeletedAt", "testCreatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数返回共创项目实体列表", func() {
Context("传入有效的参数", func() {
It("返回共创项目实体数据列表", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/cooperation-projects/").
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("cooperationProjects").Value("cooperationProjects").Array()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM cooperation_projects WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_project
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("发布共创项目", func() {
var cooperationProjectId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationProjectId),
"INSERT INTO cooperation_projects (cooperation_project_id, cooperation_project_number, cooperation_project_description, cooperation_project_name, cooperation_project_publish_time, cooperation_project_publisher, cooperation_project_sponsor, cooperation_project_undertaker_type, org, company, operator, operate_time, status, updated_at, deleted_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_project_id",
"testCooperationProjectId", "testCooperationProjectNumber", "testCooperationProjectDescription", "testCooperationProjectName", "testCooperationProjectPublishTime", "testCooperationProjectPublisher", "testCooperationProjectSponsor", "testCooperationProjectUndertakerType", "testOrg", "testCompany", "testOperator", "testOperateTime", "testStatus", "testUpdatedAt", "testDeletedAt", "testCreatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("发布共创项目", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"cooperationProjectName": "string",
"cooperationModeId": "int64",
"userId": "int64",
"userBaseId": "int64",
"orgId": "int64",
"orgName": "string",
"companyId": "int64",
"companyLogo": "string",
"companyName": "string",
"orgs": "array",
"departmentId": "int64",
"departmentName": "string",
"departmentNumber": "string",
"isOrganization": "boolean",
"roleId": "int64",
"roleName": "string",
"userAvatar": "string",
"userEmail": "string",
"userName": "string",
"userPhone": "string",
"userAccount": "string",
"userType": "int32",
"status": "int32",
"cooperationProjectUndertakerType": "array",
"cooperationProjectDescription": "string",
}
httpExpect.POST("/cooperation-projects/release-cooperation-project").
WithJSON(body).
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 cooperation_projects WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_project
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("移除共创项目服务", func() {
var cooperationProjectId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationProjectId),
"INSERT INTO cooperation_projects (cooperation_project_id, cooperation_project_number, cooperation_project_description, cooperation_project_name, cooperation_project_publish_time, cooperation_project_publisher, cooperation_project_sponsor, cooperation_project_undertaker_type, org, company, operator, operate_time, status, updated_at, deleted_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_project_id",
"testCooperationProjectId", "testCooperationProjectNumber", "testCooperationProjectDescription", "testCooperationProjectName", "testCooperationProjectPublishTime", "testCooperationProjectPublisher", "testCooperationProjectSponsor", "testCooperationProjectUndertakerType", "testOrg", "testCompany", "testOperator", "testOperateTime", "testStatus", "testUpdatedAt", "testDeletedAt", "testCreatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("根据参数移除共创项目服务", func() {
Context("传入有效的cooperationProjectId", func() {
It("返回被移除共创项目实体的数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/cooperation-projects/{cooperationProjectId}").
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 cooperation_projects WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_project
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("查询共创项目", func() {
var cooperationProjectId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationProjectId),
"INSERT INTO cooperation_projects (cooperation_project_id, cooperation_project_number, cooperation_project_description, cooperation_project_name, cooperation_project_publish_time, cooperation_project_publisher, cooperation_project_sponsor, cooperation_project_undertaker_type, org, company, operator, operate_time, status, updated_at, deleted_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_project_id",
"testCooperationProjectId", "testCooperationProjectNumber", "testCooperationProjectDescription", "testCooperationProjectName", "testCooperationProjectPublishTime", "testCooperationProjectPublisher", "testCooperationProjectSponsor", "testCooperationProjectUndertakerType", "testOrg", "testCompany", "testOperator", "testOperateTime", "testStatus", "testUpdatedAt", "testDeletedAt", "testCreatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("查询共创项目", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"pageNumber": "int32",
"pageSize": "int32",
"cooperationProjectName": "string",
"departmentName": "string",
"status": "int32",
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.POST("/cooperation-projects/search").
WithJSON(body).
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 cooperation_projects WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
package cooperation_project
import (
"github.com/go-pg/pg/v10"
"net/http"
"github.com/gavv/httpexpect"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
)
var _ = Describe("更新共创项目服务", func() {
var cooperationProjectId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&cooperationProjectId),
"INSERT INTO cooperation_projects (cooperation_project_id, cooperation_project_number, cooperation_project_description, cooperation_project_name, cooperation_project_publish_time, cooperation_project_publisher, cooperation_project_sponsor, cooperation_project_undertaker_type, org, company, operator, operate_time, status, updated_at, deleted_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_project_id",
"testCooperationProjectId", "testCooperationProjectNumber", "testCooperationProjectDescription", "testCooperationProjectName", "testCooperationProjectPublishTime", "testCooperationProjectPublisher", "testCooperationProjectSponsor", "testCooperationProjectUndertakerType", "testOrg", "testCompany", "testOperator", "testOperateTime", "testStatus", "testUpdatedAt", "testDeletedAt", "testCreatedAt")
Expect(err).NotTo(HaveOccurred())
})
Describe("提交数据更新共创项目服务", func() {
Context("提交正确的共创项目实体数据", func() {
It("返回更新后的共创项目实体数据", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"cooperationProjectName": "string",
"cooperationProjectUndertakerType": "array",
"sponsorUid": "string",
"publisherUid": "string",
"cooperationProjectDescription": "string",
"companyId": "int64",
"orgId": "int64",
"userId": "int64",
}
httpExpect.PUT("/cooperation-projects/{cooperationProjectId}").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object().
ContainsKey("cooperationProjectId").ValueEqual("cooperationProjectId", cooperationProjectId)
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM cooperation_projects WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...