作者 linmadan

完成任务发布接口

... ... @@ -122,10 +122,14 @@ func (taskService *TaskService) ReleaseTask(releaseTaskCommand *command.ReleaseT
} else {
releaseTaskService = value
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
if task, err := releaseTaskService.Release(releaseTaskCommand.TaskId, releaseTaskCommand.Operator); 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 task, nil
}
return nil, nil
}
// 关闭任务
... ...
... ... @@ -44,7 +44,7 @@ func (service *ReleaseTaskService) Release(taskId int64, operatorUid int64) (*do
if task == nil {
return nil, fmt.Errorf("无效的任务")
}
if operator.EmployeeId != task.Sponsor.Uid {
if operator.EmployeeInfo.Uid != task.Sponsor.Uid {
return nil, fmt.Errorf("无效的发布者")
}
if err := task.Release(); err != nil {
... ...
... ... @@ -63,8 +63,12 @@ func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{
if uid, ok := queryOptions["uid"]; ok {
query = query.Where("employee.uid = ?", uid)
}
if err := query.Limit(1).Select(); err != nil {
return nil, err
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if employeeModel.Id == 0 {
return nil, nil
... ...
... ... @@ -71,7 +71,11 @@ func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) (
}
if err := query.First(); err != nil {
return nil, err
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
if taskModel.Id == 0 {
return nil, nil
... ...
... ... @@ -30,8 +30,13 @@ var _ = Describe("发布任务", func() {
},
}, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
Expect(err).NotTo(HaveOccurred())
_, err1 := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO employees (id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?)",
1, 2499036607974745088, "testEmployeeName", "testEmployeeAccount", 0)
Expect(err1).NotTo(HaveOccurred())
})
FIt("发布任务成功", func() {
It("发布任务成功", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"operator": 2499036607974745088,
... ... @@ -47,6 +52,44 @@ var _ = Describe("发布任务", func() {
ContainsKey("data").Value("data").Object()
})
})
Context("任务发起者发布不是待发布的任务", func() {
BeforeEach(func() {
dayAfter, _ := time.ParseDuration("72h")
_, err := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, receiver_uid, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
1, 101, "抢单任务1",1, &domain.EmployeeInfo{
Uid: 2499036607974745088,
}, 3, "null", pg.Array([]string{"口感", "便利", "品牌", "售后服务"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, []*domain.EmployeeInfo{
{
Uid: 2499036607974745077,
},
{
Uid: 2499036607974745066,
},
}, "null", "", pg.Array([]string{}), 2499036607974745099, time.Now(), time.Now().Add(dayAfter))
Expect(err).NotTo(HaveOccurred())
_, err1 := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO employees (id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?)",
1, 2499036607974745088, "testEmployeeName", "testEmployeeAccount", 0)
Expect(err1).NotTo(HaveOccurred())
})
It("发布任务失败", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"operator": 2499036607974745088,
}
httpExpect.POST("/tasks/1/release").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 501).
ContainsKey("msg").ValueEqual("msg", "内部服务出错:进行中的任务不允许重新发布")
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM tasks WHERE true")
... ... @@ -55,5 +98,7 @@ var _ = Describe("发布任务", func() {
Expect(err1).NotTo(HaveOccurred())
_, err2 := pG.DB.Exec("DELETE FROM bidder_infos WHERE true")
Expect(err2).NotTo(HaveOccurred())
_, err3 := pG.DB.Exec("DELETE FROM employees WHERE true")
Expect(err3).NotTo(HaveOccurred())
})
})
... ...