From 7563bc918897325e2701f0a9516d817de823ec2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=B1=A0=E4=BF=8A=E8=BC=94?= Date: Sat, 30 Nov 2024 15:38:35 +0900 Subject: [PATCH] =?UTF-8?q?feat:=E3=82=BF=E3=82=B0=E3=81=AE=E5=8F=96?= =?UTF-8?q?=E5=BE=97=E3=81=AEN=20+=201=E5=95=8F=E9=A1=8C=E3=81=AE=E8=A7=A3?= =?UTF-8?q?=E6=B1=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/livestream_handler.go | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/go/livestream_handler.go b/go/livestream_handler.go index 4716dc5..c13df0c 100644 --- a/go/livestream_handler.go +++ b/go/livestream_handler.go @@ -121,17 +121,15 @@ func reserveLivestreamHandler(c echo.Context) error { } } - var ( - livestreamModel = &LivestreamModel{ - UserID: int64(userID), - Title: req.Title, - Description: req.Description, - PlaylistUrl: req.PlaylistUrl, - ThumbnailUrl: req.ThumbnailUrl, - StartAt: req.StartAt, - EndAt: req.EndAt, - } - ) + livestreamModel := &LivestreamModel{ + UserID: int64(userID), + Title: req.Title, + Description: req.Description, + PlaylistUrl: req.PlaylistUrl, + ThumbnailUrl: req.ThumbnailUrl, + StartAt: req.StartAt, + EndAt: req.EndAt, + } if _, err := tx.ExecContext(ctx, "UPDATE reservation_slots SET slot = slot - 1 WHERE start_at >= ? AND end_at <= ?", req.StartAt, req.EndAt); err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "failed to update reservation_slot: "+err.Error()) @@ -499,16 +497,19 @@ func fillLivestreamResponse(ctx context.Context, tx *sqlx.Tx, livestreamModel Li return Livestream{}, err } - tags := make([]Tag, len(livestreamTagModels)) + var tagIDs []int64 for i := range livestreamTagModels { - tagModel := TagModel{} - if err := tx.GetContext(ctx, &tagModel, "SELECT * FROM tags WHERE id = ?", livestreamTagModels[i].TagID); err != nil { + tagIDs = append(tagIDs, livestreamTagModels[i].TagID) + } + tags := make([]Tag, len(livestreamTagModels)) + if len(tagIDs) > 0 { + query, params, err := sqlx.In("SELECT * FROM tags WHERE id IN (?)", tagIDs) + if err != nil { return Livestream{}, err } - - tags[i] = Tag{ - ID: tagModel.ID, - Name: tagModel.Name, + query = tx.Rebind(query) + if err := tx.SelectContext(ctx, &tags, query, params...); err != nil { + return Livestream{}, err } }