From e8a43bf48e5156dfd9ce2f575da076ee0062e58d Mon Sep 17 00:00:00 2001 From: Kubosaka Date: Fri, 27 Dec 2024 11:22:46 +0900 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8B=95=E6=95=B4=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/externals/repository/sponsor_repository.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/api/externals/repository/sponsor_repository.go b/api/externals/repository/sponsor_repository.go index 25f18a44..f2f3e8c2 100644 --- a/api/externals/repository/sponsor_repository.go +++ b/api/externals/repository/sponsor_repository.go @@ -55,7 +55,8 @@ func (sr *sponsorRepository) Create( address string, representative string, ) error { - ds := dialect.Insert("sponsors").Rows(goqu.Record{"name": name, "tel": tel, "email": email, "address": address, "representative": representative}) + ds := dialect.Insert("sponsors"). + Rows(goqu.Record{"name": name, "tel": tel, "email": email, "address": address, "representative": representative}) query, _, err := ds.ToSQL() if err != nil { return err @@ -73,7 +74,9 @@ func (sr *sponsorRepository) Update( address string, representative string, ) error { - ds := dialect.Update("sponsors").Set(goqu.Record{"name": name, "tel": tel, "email": email, "address": address, "representative": representative}).Where(goqu.Ex{"id": id}) + ds := dialect.Update("sponsors"). + Set(goqu.Record{"name": name, "tel": tel, "email": email, "address": address, "representative": representative}). + Where(goqu.Ex{"id": id}) query, _, err := ds.ToSQL() if err != nil { return err @@ -106,7 +109,13 @@ func (sr *sponsorRepository) FindLatestRecord(c context.Context) (*sql.Row, erro // 年度別に取得 func (sr *sponsorRepository) AllByPeriod(c context.Context, year string) (*sql.Rows, error) { - query, _, err := dialect.Select("sponsors.*").From("sponsors").InnerJoin(goqu.I("year_periods"), goqu.On(goqu.I("sponsors.created_at").Gt(goqu.I("year_periods.started_at")), goqu.I("sponsors.created_at").Lt(goqu.I("year_periods.ended_at")))).InnerJoin(goqu.I("years"), goqu.On(goqu.I("year_periods.year_id").Eq(goqu.I("years.id")))).Where(goqu.Ex{"years.year": year}).Order(goqu.I("sponsors.id").Desc()).ToSQL() + query, _, err := dialect.Select("sponsors.*"). + From("sponsors"). + InnerJoin(goqu.I("year_periods"), goqu.On(goqu.I("sponsors.created_at").Gt(goqu.I("year_periods.started_at")), goqu.I("sponsors.created_at").Lt(goqu.I("year_periods.ended_at")))). + InnerJoin(goqu.I("years"), goqu.On(goqu.I("year_periods.year_id").Eq(goqu.I("years.id")))). + Where(goqu.Ex{"years.year": year}). + Order(goqu.I("sponsors.id").Desc()). + ToSQL() if err != nil { return nil, err }