From 34c0042f4037dc9720aa11eff9587499c8f5bb7d Mon Sep 17 00:00:00 2001 From: masky5859 Date: Tue, 29 Oct 2024 00:02:34 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:event=E3=81=AE=E5=8F=96=E5=BE=97?= =?UTF-8?q?=E3=83=AD=E3=82=B8=E3=83=83=E3=82=AF=E3=81=AE=E6=99=82=E9=96=93?= =?UTF-8?q?=E3=83=95=E3=82=A3=E3=83=AB=E3=82=BF=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/filter/shorthand.go | 55 +++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/domain/filter/shorthand.go b/domain/filter/shorthand.go index d91ae875..6468dccd 100644 --- a/domain/filter/shorthand.go +++ b/domain/filter/shorthand.go @@ -54,30 +54,65 @@ func FilterTime(start, end time.Time) Expr { if start.IsZero() && end.IsZero() { return nil } - timeStart := &CmpExpr{ + + // イベント開始時刻が指定された範囲内にあるか + eventStartInRangeRight := &CmpExpr{ + Attr: AttrTimeStart, + Relation: LessEq, + Value: end, + } + eventStartInRangeLeft := &CmpExpr{ Attr: AttrTimeStart, Relation: GreterEq, Value: start, } - timeEnd := &CmpExpr{ + + // イベント終了時刻が指定された範囲内にあるか + eventEndInRangeRight := &CmpExpr{ Attr: AttrTimeEnd, Relation: LessEq, Value: end, } + eventEndInRangeLeft := &CmpExpr{ + Attr: AttrTimeEnd, + Relation: GreterEq, + Value: start, + } - if start.IsZero() { - return timeEnd + // イベントの開催期間が指定された範囲を包含しているか + eventStartBeforeRangeStart := &CmpExpr{ + Attr: AttrTimeStart, + Relation: LessEq, + Value: start, } - if end.IsZero() { - return timeStart + eventEndAfterRangeEnd := &CmpExpr{ + Attr: AttrTimeEnd, + Relation: GreterEq, + Value: end, } + return &LogicOpExpr{ - LogicOp: And, - Lhs: timeStart, - Rhs: timeEnd, + LogicOp: Or, + Lhs: &LogicOpExpr{ + LogicOp: Or, + Lhs: &LogicOpExpr{ + LogicOp: And, + Lhs: eventStartInRangeRight, + Rhs: eventStartInRangeLeft, + }, + Rhs: &LogicOpExpr{ + LogicOp: And, + Lhs: eventEndInRangeRight, + Rhs: eventEndInRangeLeft, + }, + }, + Rhs: &LogicOpExpr{ + LogicOp: And, + Lhs: eventStartBeforeRangeStart, + Rhs: eventEndAfterRangeEnd, + }, } } - func AddAnd(lhs, rhs Expr) Expr { if lhs == nil && rhs == nil { return nil From adde449beaae085aa12971b274bc7f9754a9ebbc Mon Sep 17 00:00:00 2001 From: masky5859 Date: Tue, 29 Oct 2024 14:26:03 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:start=E3=81=BE=E3=81=9F=E3=81=AFend?= =?UTF-8?q?=E3=81=8C=E3=81=AA=E3=81=84=E3=81=A8=E3=81=8D=E3=81=AE=E5=87=A6?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/filter/shorthand.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/domain/filter/shorthand.go b/domain/filter/shorthand.go index 6468dccd..d8176011 100644 --- a/domain/filter/shorthand.go +++ b/domain/filter/shorthand.go @@ -55,6 +55,23 @@ func FilterTime(start, end time.Time) Expr { return nil } + // startがゼロの時はend以前に一部でもイベントが含まれるものを返す + if start.IsZero() { + return &CmpExpr{ + Attr: AttrTimeStart, + Relation: LessEq, + Value: end, + } + } + // endがゼロの時はstart以降に一部でもイベントが含まれるものを返す + if end.IsZero() { + return &CmpExpr{ + Attr: AttrTimeEnd, + Relation: GreterEq, + Value: start, + } + } + // イベント開始時刻が指定された範囲内にあるか eventStartInRangeRight := &CmpExpr{ Attr: AttrTimeStart, @@ -113,6 +130,7 @@ func FilterTime(start, end time.Time) Expr { }, } } + func AddAnd(lhs, rhs Expr) Expr { if lhs == nil && rhs == nil { return nil From 3ba23d4c5775b2515e9aca998a1d72d20c107799 Mon Sep 17 00:00:00 2001 From: masky5859 Date: Thu, 31 Oct 2024 21:01:40 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:FilterDuration=E3=82=92=E4=BD=BF?= =?UTF-8?q?=E3=81=86=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/filter/shorthand.go | 71 +++++--------------------------------- router/events.go | 12 +++++-- 2 files changed, 18 insertions(+), 65 deletions(-) diff --git a/domain/filter/shorthand.go b/domain/filter/shorthand.go index d8176011..d91ae875 100644 --- a/domain/filter/shorthand.go +++ b/domain/filter/shorthand.go @@ -54,80 +54,27 @@ func FilterTime(start, end time.Time) Expr { if start.IsZero() && end.IsZero() { return nil } - - // startがゼロの時はend以前に一部でもイベントが含まれるものを返す - if start.IsZero() { - return &CmpExpr{ - Attr: AttrTimeStart, - Relation: LessEq, - Value: end, - } - } - // endがゼロの時はstart以降に一部でもイベントが含まれるものを返す - if end.IsZero() { - return &CmpExpr{ - Attr: AttrTimeEnd, - Relation: GreterEq, - Value: start, - } - } - - // イベント開始時刻が指定された範囲内にあるか - eventStartInRangeRight := &CmpExpr{ - Attr: AttrTimeStart, - Relation: LessEq, - Value: end, - } - eventStartInRangeLeft := &CmpExpr{ + timeStart := &CmpExpr{ Attr: AttrTimeStart, Relation: GreterEq, Value: start, } - - // イベント終了時刻が指定された範囲内にあるか - eventEndInRangeRight := &CmpExpr{ + timeEnd := &CmpExpr{ Attr: AttrTimeEnd, Relation: LessEq, Value: end, } - eventEndInRangeLeft := &CmpExpr{ - Attr: AttrTimeEnd, - Relation: GreterEq, - Value: start, - } - // イベントの開催期間が指定された範囲を包含しているか - eventStartBeforeRangeStart := &CmpExpr{ - Attr: AttrTimeStart, - Relation: LessEq, - Value: start, + if start.IsZero() { + return timeEnd } - eventEndAfterRangeEnd := &CmpExpr{ - Attr: AttrTimeEnd, - Relation: GreterEq, - Value: end, + if end.IsZero() { + return timeStart } - return &LogicOpExpr{ - LogicOp: Or, - Lhs: &LogicOpExpr{ - LogicOp: Or, - Lhs: &LogicOpExpr{ - LogicOp: And, - Lhs: eventStartInRangeRight, - Rhs: eventStartInRangeLeft, - }, - Rhs: &LogicOpExpr{ - LogicOp: And, - Lhs: eventEndInRangeRight, - Rhs: eventEndInRangeLeft, - }, - }, - Rhs: &LogicOpExpr{ - LogicOp: And, - Lhs: eventStartBeforeRangeStart, - Rhs: eventEndAfterRangeEnd, - }, + LogicOp: And, + Lhs: timeStart, + Rhs: timeEnd, } } diff --git a/router/events.go b/router/events.go index e82b9c21..ec0568c1 100644 --- a/router/events.go +++ b/router/events.go @@ -91,9 +91,15 @@ func (h *Handlers) HandleGetEvents(c echo.Context) error { if err != nil { return badRequest(err, message("invalid time")) } - events, err := h.Repo.GetEvents( - filter.AddAnd(expr, filter.FilterTime(start, end)), - getConinfo(c)) + + durationExpr, err := filter.FilterDuration(start, end) + if err != nil { + return badRequest(err, message("filter duration error")) + } + + combinedExpr := filter.AddAnd(expr, durationExpr) + + events, err := h.Repo.GetEvents(combinedExpr, getConinfo(c)) if err != nil { return judgeErrorResponse(err) }