Skip to content

Commit

Permalink
Merge branch 'feat/coupon' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
sjatsh committed Nov 23, 2023
2 parents 35fddb7 + 260624a commit 1dd6030
Showing 1 changed file with 0 additions and 22 deletions.
22 changes: 0 additions & 22 deletions http_server/handle/coupon_set_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"github.com/gin-gonic/gin"
"golang.org/x/sync/errgroup"
"net/http"
"sort"
"time"
)

type ReqCouponSetList struct {
Expand Down Expand Up @@ -71,7 +69,6 @@ func (h *HttpHandle) doCouponSetList(req *ReqCouponSetList, apiResp *api_code.Ap
return nil
}

now := time.Now()
resp := &RespCouponSetInfoList{
Total: total,
List: make([]RespCouponSetInfo, 0, len(setInfo)),
Expand All @@ -87,8 +84,6 @@ func (h *HttpHandle) doCouponSetList(req *ReqCouponSetList, apiResp *api_code.Ap
return nil
})

expiredAtIdx := -1

errWg.Go(func() error {
for idx := range ch {
v := setInfo[idx]
Expand Down Expand Up @@ -117,29 +112,12 @@ func (h *HttpHandle) doCouponSetList(req *ReqCouponSetList, apiResp *api_code.Ap
ExpiredAt: v.ExpiredAt,
CreatedAt: v.CreatedAt.UnixMilli(),
})
if expiredAtIdx == -1 && now.After(time.UnixMilli(v.ExpiredAt)) {
expiredAtIdx = idx
}
}
return nil
})
if err := errWg.Wait(); err != nil {
return err
}

respList := resp.List
if expiredAtIdx > 1 {
respList = resp.List[:expiredAtIdx]
}
sort.Slice(respList, func(i, j int) bool {
li := respList[i].Num - respList[i].Used
lj := respList[j].Num - respList[j].Used
return li > lj
})
if expiredAtIdx > 1 {
respList = append(respList, resp.List[expiredAtIdx:]...)
}
resp.List = respList
apiResp.ApiRespOK(resp)
return nil
}

0 comments on commit 1dd6030

Please sign in to comment.