作者 linmadan

修复级联查询bug

... ... @@ -137,11 +137,10 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int
query = query.Where(`task.is_reward_take = ?`, isRewardTake)
}
if bidTimeMatch, ok := queryOptions["bidTimeMatch"]; ok && (bidTimeMatch != 0) {
query = query.Join("JOIN bid_infos ON bid_info.task_id = task.id")
if bidTimeMatch == 1 {
if bidTimeMatch == 2 {
query = query.Where("bid_info.bid_end_time < ?", time.Now())
}
if bidTimeMatch == 2 {
if bidTimeMatch == 3 {
query = query.Where("bid_info.bid_end_time > ?", time.Now())
}
}
... ...
... ... @@ -43,6 +43,11 @@ var _ = Describe("搜索任务", func() {
Uid: 2499036607974745088,
}, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), true, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
Expect(err2).NotTo(HaveOccurred())
_, err3 := pG.DB.QueryOne(
pg.Scan(),
"INSERT INTO bid_infos (task_id, bid_start_time, bid_end_time) VALUES (?, ?, ?)",
1, time.Date(2020, time.Month(4), 5, 8, 0, 0, 0, time.Now().Location()), time.Now().Add(dayAfter))
Expect(err3).NotTo(HaveOccurred())
})
Describe("搜索任务", func() {
Context("", func() {
... ... @@ -91,6 +96,27 @@ var _ = Describe("搜索任务", func() {
ContainsKey("data").Value("data").Object()
})
})
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"companyId": 101,
"sponsor": 2499036607974745088,
"bidTimeMatch": 1,
"offset": 0,
"limit": 20,
}
httpExpect.POST("/tasks/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 tasks WHERE true")
... ...