From 9af807afa0f9f29a97b34daa4dd09b7226450214 Mon Sep 17 00:00:00 2001 From: Hueter Date: Fri, 26 Jul 2024 11:57:29 +0900 Subject: [PATCH 01/11] =?UTF-8?q?router=E4=B8=8B=E3=81=AEappend=E3=82=92lo?= =?UTF-8?q?.Map=E3=81=A7=E7=BD=AE=E3=81=8D=E6=8F=9B=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router/admin.go | 9 +- router/group.go | 30 +++---- router/group_test.go | 10 +-- router/request.go | 147 +++++++++++++++----------------- router/tag.go | 11 +-- router/tag_test.go | 11 +-- router/transaction.go | 49 ++++++----- router/transaction_test.go | 169 ++++++++++++++++++------------------- router/user.go | 11 +-- 9 files changed, 214 insertions(+), 233 deletions(-) diff --git a/router/admin.go b/router/admin.go index dd9741b7..df3035c0 100644 --- a/router/admin.go +++ b/router/admin.go @@ -5,7 +5,9 @@ import ( "github.com/google/uuid" "github.com/labstack/echo/v4" + "github.com/samber/lo" "github.com/traPtitech/Jomon/ent" + "github.com/traPtitech/Jomon/model" "go.uber.org/zap" ) @@ -17,10 +19,9 @@ func (h Handlers) GetAdmins(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - res := []*uuid.UUID{} - for _, admin := range admins { - res = append(res, &admin.ID) - } + res := lo.Map(admins, func(admin *model.Admin, index int) *uuid.UUID { + return &admin.ID + }) return c.JSON(http.StatusOK, res) } diff --git a/router/group.go b/router/group.go index b468f4ba..07f83b4e 100644 --- a/router/group.go +++ b/router/group.go @@ -7,7 +7,9 @@ import ( "github.com/google/uuid" "github.com/labstack/echo/v4" + "github.com/samber/lo" "github.com/traPtitech/Jomon/ent" + "github.com/traPtitech/Jomon/model" "go.uber.org/zap" ) @@ -61,17 +63,16 @@ func (h Handlers) GetGroups(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - res := []*GroupOverview{} - for _, group := range groups { - res = append(res, &GroupOverview{ + res := lo.Map(groups, func(group *model.Group, index int) *GroupOverview { + return &GroupOverview{ ID: group.ID, Name: group.Name, Description: group.Description, Budget: group.Budget, CreatedAt: group.CreatedAt, UpdatedAt: group.UpdatedAt, - }) - } + } + }) return c.JSON(http.StatusOK, res) } @@ -143,17 +144,17 @@ func (h Handlers) GetGroupDetail(c echo.Context) error { h.Logger.Error("failed to get owners from repository", zap.Error(err)) return echo.NewHTTPError(http.StatusInternalServerError, err) } - for _, owner := range owners { - res.Owners = append(res.Owners, &owner.ID) - } + res.Owners = lo.Map(owners, func(owner *model.Owner, index int) *uuid.UUID { + return &owner.ID + }) members, err := h.Repository.GetMembers(ctx, groupID) if err != nil { h.Logger.Error("failed to get members from repository", zap.Error(err)) return echo.NewHTTPError(http.StatusInternalServerError, err) } - for _, member := range members { - res.Members = append(res.Members, &member.ID) - } + res.Members = lo.Map(members, func(member *model.Member, indec int) *uuid.UUID { + return &member.ID + }) return c.JSON(http.StatusOK, res) } @@ -238,10 +239,9 @@ func (h Handlers) PostMember(c echo.Context) error { h.Logger.Error("failed to add member in repository", zap.Error(err)) return echo.NewHTTPError(http.StatusInternalServerError, err) } - res := []*uuid.UUID{} - for _, m := range added { - res = append(res, &m.ID) - } + res := lo.Map(added, func(m *model.Member, index int) *uuid.UUID { + return &m.ID + }) return c.JSON(http.StatusOK, res) } diff --git a/router/group_test.go b/router/group_test.go index 438d11a9..087fb10f 100644 --- a/router/group_test.go +++ b/router/group_test.go @@ -14,6 +14,7 @@ import ( "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/labstack/echo/v4" + "github.com/samber/lo" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/traPtitech/Jomon/ent" @@ -66,17 +67,16 @@ func TestHandlers_GetGroups(t *testing.T) { GetGroups(c.Request().Context()). Return(groups, nil) - resOverview := []*GroupOverview{} - for _, group := range groups { - resOverview = append(resOverview, &GroupOverview{ + resOverview := lo.Map(groups, func(group *model.Group, index int) *GroupOverview { + return &GroupOverview{ ID: group.ID, Name: group.Name, Description: group.Description, Budget: group.Budget, CreatedAt: group.CreatedAt, UpdatedAt: group.UpdatedAt, - }) - } + } + }) resBody, err := json.Marshal(resOverview) require.NoError(t, err) diff --git a/router/request.go b/router/request.go index 0ef214e4..2438626b 100644 --- a/router/request.go +++ b/router/request.go @@ -9,6 +9,7 @@ import ( "github.com/google/uuid" "github.com/labstack/echo-contrib/session" "github.com/labstack/echo/v4" + "github.com/samber/lo" "github.com/traPtitech/Jomon/ent" "github.com/traPtitech/Jomon/model" "github.com/traPtitech/Jomon/service" @@ -182,28 +183,25 @@ func (h Handlers) GetRequests(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - tags := []*TagOverview{} - requests := []*RequestResponse{} - for _, request := range modelrequests { - for _, tag := range request.Tags { - tags = append(tags, &TagOverview{ + requests := lo.Map(modelrequests, func(request *model.RequestResponse, index int) *RequestResponse { + tags := lo.Map(request.Tags, func(tag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: tag.ID, Name: tag.Name, CreatedAt: tag.CreatedAt, UpdatedAt: tag.UpdatedAt, - }) - } + } + }) - restargets := []*TargetOverview{} - for _, target := range request.Targets { - restargets = append(restargets, &TargetOverview{ + restargets := lo.Map(request.Targets, func(target *model.RequestTargetDetail, index int) *TargetOverview { + return &TargetOverview{ ID: target.ID, Target: target.Target, Amount: target.Amount, PaidAt: target.PaidAt, CreatedAt: target.CreatedAt, - }) - } + } + }) var resgroup *GroupOverview if request.Group != nil { @@ -217,7 +215,7 @@ func (h Handlers) GetRequests(c echo.Context) error { } } - res := &RequestResponse{ + return &RequestResponse{ ID: request.ID, Status: request.Status, CreatedAt: request.CreatedAt, @@ -230,8 +228,7 @@ func (h Handlers) GetRequests(c echo.Context) error { Group: resgroup, Comments: []*CommentDetail{}, } - requests = append(requests, res) - } + }) return c.JSON(http.StatusOK, requests) } @@ -256,13 +253,12 @@ func (h Handlers) PostRequest(c echo.Context) error { } tags = append(tags, tag) } - targets := []*model.RequestTarget{} - for _, target := range req.Targets { - targets = append(targets, &model.RequestTarget{ + targets := lo.Map(req.Targets, func(target *Target, index int) *model.RequestTarget { + return &model.RequestTarget{ Target: target.Target, Amount: target.Amount, - }) - } + } + }) var group *model.Group if req.Group != nil { group, err = h.Repository.GetGroup(ctx, *req.Group) @@ -295,33 +291,30 @@ func (h Handlers) PostRequest(c echo.Context) error { UpdatedAt: request.Group.UpdatedAt, } } - var reqtargets []*TargetOverview - for _, target := range request.Targets { - reqtargets = append(reqtargets, &TargetOverview{ + reqtargets := lo.Map(request.Targets, func(target *model.RequestTargetDetail, index int) *TargetOverview { + return &TargetOverview{ ID: target.ID, Target: target.Target, Amount: target.Amount, PaidAt: target.PaidAt, CreatedAt: target.CreatedAt, - }) - } - var restags []*TagOverview - for _, tag := range request.Tags { - restags = append(restags, &TagOverview{ + } + }) + restags := lo.Map(request.Tags, func(tag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: tag.ID, Name: tag.Name, CreatedAt: tag.CreatedAt, UpdatedAt: tag.UpdatedAt, - }) - } - var statuses []*StatusResponseOverview - for _, status := range request.Statuses { - statuses = append(statuses, &StatusResponseOverview{ + } + }) + statuses := lo.Map(request.Statuses, func(status *model.RequestStatus, index int) *StatusResponseOverview { + return &StatusResponseOverview{ Status: status.Status, CreatedAt: status.CreatedAt, CreatedBy: status.CreatedBy, - }) - } + } + }) res := &RequestResponse{ ID: request.ID, @@ -368,17 +361,15 @@ func (h Handlers) GetRequest(c echo.Context) error { h.Logger.Error("failed to get comments from repository", zap.Error(err)) return echo.NewHTTPError(http.StatusInternalServerError, err) } - comments := []*CommentDetail{} - for _, modelcomment := range modelcomments { - comment := &CommentDetail{ + comments := lo.Map(modelcomments, func(modelcomment *model.Comment, index int) *CommentDetail { + return &CommentDetail{ ID: modelcomment.ID, User: modelcomment.User, Comment: modelcomment.Comment, CreatedAt: modelcomment.CreatedAt, UpdatedAt: modelcomment.UpdatedAt, } - comments = append(comments, comment) - } + }) var resgroup *GroupOverview if request.Group != nil { resgroup = &GroupOverview{ @@ -390,33 +381,32 @@ func (h Handlers) GetRequest(c echo.Context) error { UpdatedAt: request.Group.UpdatedAt, } } - reqtargets := []*TargetOverview{} - for _, target := range request.Targets { - reqtargets = append(reqtargets, &TargetOverview{ + reqtargets := lo.Map(request.Targets, func(target *model.RequestTargetDetail, index int) *TargetOverview { + return &TargetOverview{ ID: target.ID, Target: target.Target, Amount: target.Amount, PaidAt: target.PaidAt, CreatedAt: target.CreatedAt, - }) - } - restags := []*TagOverview{} - for _, tag := range request.Tags { - restags = append(restags, &TagOverview{ + } + }) + restags := lo.Map(request.Tags, func(tag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: tag.ID, Name: tag.Name, CreatedAt: tag.CreatedAt, UpdatedAt: tag.UpdatedAt, - }) - } - var resstatuses []*StatusResponseOverview - for _, status := range request.Statuses { - resstatuses = append(resstatuses, &StatusResponseOverview{ + } + }) + + resstatuses := lo.Map(request.Statuses, func(status *model.RequestStatus, index int) *StatusResponseOverview { + return &StatusResponseOverview{ CreatedBy: status.CreatedBy, Status: status.Status, CreatedAt: status.CreatedAt, - }) - } + } + }) + res := &RequestResponse{ ID: request.ID, Status: request.Status, @@ -465,13 +455,12 @@ func (h Handlers) PutRequest(c echo.Context) error { } tags = append(tags, tag) } - targets := []*model.RequestTarget{} - for _, target := range req.Targets { - targets = append(targets, &model.RequestTarget{ + targets := lo.Map(req.Targets, func(target *Target, index int) *model.RequestTarget { + return &model.RequestTarget{ Target: target.Target, Amount: target.Amount, - }) - } + } + }) var group *model.Group if req.Group != nil { group, err = h.Repository.GetGroup(ctx, *req.Group) @@ -498,17 +487,15 @@ func (h Handlers) PutRequest(c echo.Context) error { h.Logger.Error("failed to get comments from repository", zap.Error(err)) return echo.NewHTTPError(http.StatusInternalServerError, err) } - var comments []*CommentDetail - for _, modelcomment := range modelcomments { - comment := &CommentDetail{ + comments := lo.Map(modelcomments, func(modelcomment *model.Comment, index int) *CommentDetail { + return &CommentDetail{ ID: modelcomment.ID, User: modelcomment.User, Comment: modelcomment.Comment, CreatedAt: modelcomment.CreatedAt, UpdatedAt: modelcomment.UpdatedAt, } - comments = append(comments, comment) - } + }) var resgroup *GroupOverview if group != nil { @@ -521,33 +508,33 @@ func (h Handlers) PutRequest(c echo.Context) error { UpdatedAt: request.Group.UpdatedAt, } } - var restags []*TagOverview - for _, tag := range request.Tags { - restags = append(restags, &TagOverview{ + restags := lo.Map(request.Tags, func(tag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: tag.ID, Name: tag.Name, CreatedAt: tag.CreatedAt, UpdatedAt: tag.UpdatedAt, - }) - } - var restargets []*TargetOverview - for _, target := range request.Targets { - restargets = append(restargets, &TargetOverview{ + } + }) + + restargets := lo.Map(request.Targets, func(target *model.RequestTargetDetail, index int) *TargetOverview { + return &TargetOverview{ ID: target.ID, Target: target.Target, Amount: target.Amount, PaidAt: target.PaidAt, CreatedAt: target.CreatedAt, - }) - } - var resstatuses []*StatusResponseOverview - for _, status := range request.Statuses { - resstatuses = append(resstatuses, &StatusResponseOverview{ + } + }) + + resstatuses := lo.Map(request.Statuses, func(status *model.RequestStatus, index int) *StatusResponseOverview { + return &StatusResponseOverview{ CreatedBy: status.CreatedBy, Status: status.Status, CreatedAt: status.CreatedAt, - }) - } + } + }) + res := &RequestResponse{ ID: request.ID, Status: request.Status, diff --git a/router/tag.go b/router/tag.go index 34c88ee5..a8ba0b1e 100644 --- a/router/tag.go +++ b/router/tag.go @@ -7,6 +7,8 @@ import ( "github.com/google/uuid" "github.com/labstack/echo/v4" + "github.com/samber/lo" + "github.com/traPtitech/Jomon/model" "go.uber.org/zap" ) @@ -30,15 +32,14 @@ func (h Handlers) GetTags(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - res := []*TagOverview{} - for _, tag := range tags { - res = append(res, &TagOverview{ + res := lo.Map(tags, func(tag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: tag.ID, Name: tag.Name, CreatedAt: tag.CreatedAt, UpdatedAt: tag.UpdatedAt, - }) - } + } + }) return c.JSON(http.StatusOK, res) } diff --git a/router/tag_test.go b/router/tag_test.go index 1eeb3748..eebc751d 100644 --- a/router/tag_test.go +++ b/router/tag_test.go @@ -14,6 +14,7 @@ import ( "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/labstack/echo/v4" + "github.com/samber/lo" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/traPtitech/Jomon/model" @@ -57,15 +58,15 @@ func TestHandlers_GetTags(t *testing.T) { GetTags(c.Request().Context()). Return(tags, nil) - resOverview := []*TagOverview{} - for _, tag := range tags { - resOverview = append(resOverview, &TagOverview{ + resOverview := lo.Map(tags, func(tag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: tag.ID, Name: tag.Name, CreatedAt: tag.CreatedAt, UpdatedAt: tag.UpdatedAt, - }) - } + } + }) + res := resOverview resBody, err := json.Marshal(res) require.NoError(t, err) diff --git a/router/transaction.go b/router/transaction.go index 36f760dc..69ff4af9 100644 --- a/router/transaction.go +++ b/router/transaction.go @@ -8,6 +8,7 @@ import ( "github.com/google/uuid" "github.com/labstack/echo/v4" + "github.com/samber/lo" "github.com/traPtitech/Jomon/model" "github.com/traPtitech/Jomon/service" "go.uber.org/zap" @@ -134,17 +135,16 @@ func (h Handlers) GetTransactions(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - res := []*Transaction{} - for _, tx := range txs { - tags := []*TagOverview{} - for _, tag := range tx.Tags { - tags = append(tags, &TagOverview{ + res := lo.Map(txs, func(tx *model.TransactionResponse, index int) *Transaction { + tags := lo.Map(tx.Tags, func(tag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: tag.ID, Name: tag.Name, CreatedAt: tag.CreatedAt, UpdatedAt: tag.UpdatedAt, - }) - } + } + }) + var group *GroupOverview if tx.Group != nil { group = &GroupOverview{ @@ -156,7 +156,7 @@ func (h Handlers) GetTransactions(c echo.Context) error { UpdatedAt: tx.Group.UpdatedAt, } } - tx := &Transaction{ + return &Transaction{ ID: tx.ID, Amount: tx.Amount, Target: tx.Target, @@ -166,8 +166,7 @@ func (h Handlers) GetTransactions(c echo.Context) error { CreatedAt: tx.CreatedAt, UpdatedAt: tx.UpdatedAt, } - res = append(res, tx) - } + }) return c.JSON(http.StatusOK, res) } @@ -192,15 +191,15 @@ func (h Handlers) PostTransaction(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - tags := []*TagOverview{} - for _, tag := range created.Tags { - tags = append(tags, &TagOverview{ + tags := lo.Map(created.Tags, func(tag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: tag.ID, Name: tag.Name, CreatedAt: tag.CreatedAt, UpdatedAt: tag.UpdatedAt, - }) - } + } + }) + var group *GroupOverview if created.Group != nil { group = &GroupOverview{ @@ -242,15 +241,15 @@ func (h Handlers) GetTransaction(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - tags := []*TagOverview{} - for _, tag := range tx.Tags { - tags = append(tags, &TagOverview{ + tags := lo.Map(tx.Tags, func(tag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: tag.ID, Name: tag.Name, CreatedAt: tag.CreatedAt, UpdatedAt: tag.UpdatedAt, - }) - } + } + }) + var group *GroupOverview if tx.Group != nil { group = &GroupOverview{ @@ -296,15 +295,15 @@ func (h Handlers) PutTransaction(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - tags := []*TagOverview{} - for _, tag := range updated.Tags { - tags = append(tags, &TagOverview{ + tags := lo.Map(updated.Tags, func(tag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: tag.ID, Name: tag.Name, CreatedAt: tag.CreatedAt, UpdatedAt: tag.UpdatedAt, - }) - } + } + }) + var group *GroupOverview if updated.Group != nil { group = &GroupOverview{ diff --git a/router/transaction_test.go b/router/transaction_test.go index ed0d6e06..4bf2e5d3 100644 --- a/router/transaction_test.go +++ b/router/transaction_test.go @@ -13,6 +13,7 @@ import ( "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/labstack/echo/v4" + "github.com/samber/lo" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/traPtitech/Jomon/model" @@ -100,17 +101,16 @@ func TestHandlers_GetTransactions(t *testing.T) { }). Return(txs, nil) - resOverview := []*Transaction{} - for _, tx := range txs { - tag := []*TagOverview{} - for _, modelTag := range tx.Tags { - tag = append(tag, &TagOverview{ + res := lo.Map(txs, func(tx *model.TransactionResponse, index int) *Transaction { + tag := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, CreatedAt: modelTag.CreatedAt, UpdatedAt: modelTag.UpdatedAt, - }) - } + } + }) + group := &GroupOverview{ ID: tx.Group.ID, Name: tx.Group.Name, @@ -119,7 +119,7 @@ func TestHandlers_GetTransactions(t *testing.T) { CreatedAt: tx.Group.CreatedAt, UpdatedAt: tx.Group.UpdatedAt, } - resOverview = append(resOverview, &Transaction{ + return &Transaction{ ID: tx.ID, Amount: tx.Amount, Target: tx.Target, @@ -127,9 +127,9 @@ func TestHandlers_GetTransactions(t *testing.T) { Group: group, CreatedAt: tx.CreatedAt, UpdatedAt: tx.UpdatedAt, - }) - } - res := resOverview + } + }) + resBody, err := json.Marshal(res) require.NoError(t, err) @@ -214,17 +214,16 @@ func TestHandlers_GetTransactions(t *testing.T) { }). Return(txs, nil) - resOverview := []*Transaction{} - for _, tx := range txs { - tag := []*TagOverview{} - for _, modelTag := range tx.Tags { - tag = append(tag, &TagOverview{ + res := lo.Map(txs, func(tx *model.TransactionResponse, index int) *Transaction { + tag := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, CreatedAt: modelTag.CreatedAt, UpdatedAt: modelTag.UpdatedAt, - }) - } + } + }) + group := &GroupOverview{ ID: tx.Group.ID, Name: tx.Group.Name, @@ -233,7 +232,7 @@ func TestHandlers_GetTransactions(t *testing.T) { CreatedAt: tx.Group.CreatedAt, UpdatedAt: tx.Group.UpdatedAt, } - resOverview = append(resOverview, &Transaction{ + return &Transaction{ ID: tx.ID, Amount: tx.Amount, Target: tx.Target, @@ -241,9 +240,9 @@ func TestHandlers_GetTransactions(t *testing.T) { Group: group, CreatedAt: tx.CreatedAt, UpdatedAt: tx.UpdatedAt, - }) - } - res := resOverview + } + }) + resBody, err := json.Marshal(res) require.NoError(t, err) @@ -329,17 +328,16 @@ func TestHandlers_GetTransactions(t *testing.T) { }). Return(txs, nil) - resOverview := []*Transaction{} - for _, tx := range txs { - tag := []*TagOverview{} - for _, modelTag := range tx.Tags { - tag = append(tag, &TagOverview{ + res := lo.Map(txs, func(tx *model.TransactionResponse, index int) *Transaction { + tag := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, CreatedAt: modelTag.CreatedAt, UpdatedAt: modelTag.UpdatedAt, - }) - } + } + }) + group := &GroupOverview{ ID: tx.Group.ID, Name: tx.Group.Name, @@ -348,7 +346,7 @@ func TestHandlers_GetTransactions(t *testing.T) { CreatedAt: tx.Group.CreatedAt, UpdatedAt: tx.Group.UpdatedAt, } - resOverview = append(resOverview, &Transaction{ + return &Transaction{ ID: tx.ID, Amount: tx.Amount, Target: tx.Target, @@ -356,9 +354,9 @@ func TestHandlers_GetTransactions(t *testing.T) { Group: group, CreatedAt: tx.CreatedAt, UpdatedAt: tx.UpdatedAt, - }) - } - res := resOverview + } + }) + resBody, err := json.Marshal(res) require.NoError(t, err) @@ -446,17 +444,16 @@ func TestHandlers_GetTransactions(t *testing.T) { }). Return(txs, nil) - resOverview := []*Transaction{} - for _, tx := range txs { - tag := []*TagOverview{} - for _, modelTag := range tx.Tags { - tag = append(tag, &TagOverview{ + res := lo.Map(txs, func(tx *model.TransactionResponse, index int) *Transaction { + tag := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, CreatedAt: modelTag.CreatedAt, UpdatedAt: modelTag.UpdatedAt, - }) - } + } + }) + group := &GroupOverview{ ID: tx.Group.ID, Name: tx.Group.Name, @@ -465,7 +462,7 @@ func TestHandlers_GetTransactions(t *testing.T) { CreatedAt: tx.Group.CreatedAt, UpdatedAt: tx.Group.UpdatedAt, } - resOverview = append(resOverview, &Transaction{ + return &Transaction{ ID: tx.ID, Amount: tx.Amount, Target: tx.Target, @@ -473,9 +470,9 @@ func TestHandlers_GetTransactions(t *testing.T) { Group: group, CreatedAt: tx.CreatedAt, UpdatedAt: tx.UpdatedAt, - }) - } - res := resOverview + } + }) + resBody, err := json.Marshal(res) require.NoError(t, err) @@ -547,17 +544,16 @@ func TestHandlers_GetTransactions(t *testing.T) { }). Return(txs, nil) - resOverview := []*Transaction{} - for _, tx := range txs { - tag := []*TagOverview{} - for _, modelTag := range tx.Tags { - tag = append(tag, &TagOverview{ + res := lo.Map(txs, func(tx *model.TransactionResponse, index int) *Transaction { + tag := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, CreatedAt: modelTag.CreatedAt, UpdatedAt: modelTag.UpdatedAt, - }) - } + } + }) + group := &GroupOverview{ ID: tx.Group.ID, Name: tx.Group.Name, @@ -566,7 +562,7 @@ func TestHandlers_GetTransactions(t *testing.T) { CreatedAt: tx.Group.CreatedAt, UpdatedAt: tx.Group.UpdatedAt, } - resOverview = append(resOverview, &Transaction{ + return &Transaction{ ID: tx.ID, Amount: tx.Amount, Target: tx.Target, @@ -574,9 +570,9 @@ func TestHandlers_GetTransactions(t *testing.T) { Group: group, CreatedAt: tx.CreatedAt, UpdatedAt: tx.UpdatedAt, - }) - } - res := resOverview + } + }) + resBody, err := json.Marshal(res) require.NoError(t, err) @@ -648,18 +644,17 @@ func TestHandlers_PostTransaction(t *testing.T) { CreateTransaction(c.Request().Context(), tx1.Amount, tx1.Target, tags, &group, nil). Return(tx1, nil) - var resOverview Transaction - reses := []*Transaction{} - for _, tx := range txs { - tag := []*TagOverview{} - for _, modelTag := range tx.Tags { - tag = append(tag, &TagOverview{ + res := lo.Map(txs, func(tx *model.TransactionResponse, index int) *Transaction { + + tag := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, CreatedAt: modelTag.CreatedAt, UpdatedAt: modelTag.UpdatedAt, - }) - } + } + }) + group := &GroupOverview{ ID: tx.Group.ID, Name: tx.Group.Name, @@ -668,7 +663,7 @@ func TestHandlers_PostTransaction(t *testing.T) { CreatedAt: tx.Group.CreatedAt, UpdatedAt: tx.Group.UpdatedAt, } - resOverview = Transaction{ + return &Transaction{ ID: tx.ID, Amount: tx.Amount, Target: tx.Target, @@ -677,9 +672,8 @@ func TestHandlers_PostTransaction(t *testing.T) { CreatedAt: tx.CreatedAt, UpdatedAt: tx.UpdatedAt, } - reses = append(reses, &resOverview) - } - res := reses + }) + resBody, err := json.Marshal(res) require.NoError(t, err) @@ -759,16 +753,16 @@ func TestHandlers_PostTransaction(t *testing.T) { Return(tx, nil) var resOverview Transaction - reses := []*Transaction{} - to := []*TagOverview{} - for _, modelTag := range tx.Tags { - to = append(to, &TagOverview{ + res := []*Transaction{} + to := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, CreatedAt: modelTag.CreatedAt, UpdatedAt: modelTag.UpdatedAt, - }) - } + } + }) + grov := &GroupOverview{ ID: tx.Group.ID, Name: tx.Group.Name, @@ -786,8 +780,7 @@ func TestHandlers_PostTransaction(t *testing.T) { CreatedAt: tx.CreatedAt, UpdatedAt: tx.UpdatedAt, } - reses = append(reses, &resOverview) - res := reses + res = append(res, &resOverview) resBody, err := json.Marshal(res) require.NoError(t, err) @@ -851,15 +844,15 @@ func TestHandlers_GetTransaction(t *testing.T) { Return(tx, nil) var resOverview Transaction - to := []*TagOverview{} - for _, modelTag := range tx.Tags { - to = append(to, &TagOverview{ + to := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, CreatedAt: modelTag.CreatedAt, UpdatedAt: modelTag.UpdatedAt, - }) - } + } + }) + grov := &GroupOverview{ ID: tx.Group.ID, Name: tx.Group.Name, @@ -949,10 +942,9 @@ func TestHandlers_PutTransaction(t *testing.T) { UpdatedAt: time.Now(), } - updatedTags := []*uuid.UUID{} - for _, modelTag := range updated.Tags { - updatedTags = append(updatedTags, &modelTag.ID) - } + updatedTags := lo.Map(updated.Tags, func(modelTag *model.Tag, index int) *uuid.UUID { + return &modelTag.ID + }) e := echo.New() req, err := http.NewRequest(http.MethodPut, fmt.Sprintf("/api/transactions/%s", tx.ID), strings.NewReader(fmt.Sprintf(`{"amount": %d, "target": "%s", "tags": ["%s"]}`, updated.Amount, updated.Target, updatedTag.ID))) @@ -972,15 +964,14 @@ func TestHandlers_PutTransaction(t *testing.T) { Return(updated, nil) var resOverview Transaction - to := []*TagOverview{} - for _, modelTag := range updated.Tags { - to = append(to, &TagOverview{ + to := lo.Map(updated.Tags, func(modelTag *model.Tag, index int) *TagOverview { + return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, CreatedAt: modelTag.CreatedAt, UpdatedAt: modelTag.UpdatedAt, - }) - } + } + }) grov := &GroupOverview{ ID: updated.Group.ID, Name: updated.Group.Name, diff --git a/router/user.go b/router/user.go index eb5095e5..5a6cf5c6 100644 --- a/router/user.go +++ b/router/user.go @@ -7,6 +7,8 @@ import ( "github.com/google/uuid" "github.com/labstack/echo-contrib/session" "github.com/labstack/echo/v4" + "github.com/samber/lo" + "github.com/traPtitech/Jomon/model" "go.uber.org/zap" ) @@ -27,9 +29,8 @@ func (h Handlers) GetUsers(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - res := make([]User, 0, len(users)) - for _, user := range users { - res = append(res, User{ + res := lo.Map(users, func(user *model.User, index int) User { + return User{ ID: user.ID, Name: user.Name, DisplayName: user.DisplayName, @@ -37,8 +38,8 @@ func (h Handlers) GetUsers(c echo.Context) error { CreatedAt: user.CreatedAt, UpdatedAt: user.UpdatedAt, DeletedAt: user.DeletedAt, - }) - } + } + }) return c.JSON(http.StatusOK, res) } From f7822d9448bf6ce22df313b94f4531d0a9f9cce2 Mon Sep 17 00:00:00 2001 From: Hueter Date: Fri, 26 Jul 2024 17:36:14 +0900 Subject: [PATCH 02/11] =?UTF-8?q?testutil/random=E4=B8=8B=E3=81=AEappend?= =?UTF-8?q?=E3=82=92lo.Times=E3=81=A7=E7=BD=AE=E3=81=8D=E6=8F=9B=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- testutil/random/ramdom.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/testutil/random/ramdom.go b/testutil/random/ramdom.go index 98a3c558..94b2043e 100644 --- a/testutil/random/ramdom.go +++ b/testutil/random/ramdom.go @@ -3,6 +3,8 @@ package random import ( "math/rand/v2" "testing" + + "github.com/samber/lo" ) const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" @@ -31,25 +33,19 @@ func Numeric64(t *testing.T, max int64) int64 { } func AlphaNumericSlice(t *testing.T, length int, max int64) []string { - slice := []string{} - for range length { - slice = append(slice, AlphaNumeric(t, int(max))) - } - return slice + return lo.Times(length, func(index int) string { + return AlphaNumeric(t, int(max)) + }) } func NumericSlice(t *testing.T, length int, max int) []int { - slice := []int{} - for range length { - slice = append(slice, Numeric(t, max)) - } - return slice + return lo.Times(length, func(index int) int { + return Numeric(t, max) + }) } func Numeric64Slice(t *testing.T, length int, max int64) []int64 { - slice := []int64{} - for range length { - slice = append(slice, Numeric64(t, max)) - } - return slice + return lo.Times(length, func(index int) int64 { + return Numeric64(t, max) + }) } From d7431bebd7e33f0d9f515d78542f9f89bdb64c33 Mon Sep 17 00:00:00 2001 From: Hueter Date: Sat, 3 Aug 2024 18:01:52 +0900 Subject: [PATCH 03/11] =?UTF-8?q?model=E7=9B=B4=E4=B8=8B=E3=81=AEappend?= =?UTF-8?q?=E3=82=92lo.Map=E3=81=A7=E7=BD=AE=E3=81=8D=E6=8F=9B=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/admin_impl.go | 11 +++--- model/comment_impl.go | 8 ++--- model/group_impl.go | 37 ++++++++++---------- model/request_impl.go | 65 ++++++++++++++++-------------------- model/request_target_impl.go | 39 ++++++++++------------ model/tag_impl.go | 9 ++--- model/transaction_impl.go | 29 ++++++++-------- model/user_impl.go | 8 ++--- 8 files changed, 95 insertions(+), 111 deletions(-) diff --git a/model/admin_impl.go b/model/admin_impl.go index 42cc0ad7..90c30834 100644 --- a/model/admin_impl.go +++ b/model/admin_impl.go @@ -4,6 +4,8 @@ import ( "context" "github.com/google/uuid" + "github.com/samber/lo" + "github.com/traPtitech/Jomon/ent" "github.com/traPtitech/Jomon/ent/user" ) @@ -16,12 +18,11 @@ func (repo *EntRepository) GetAdmins(ctx context.Context) ([]*Admin, error) { return nil, err } - admins := []*Admin{} - for _, u := range users { - admins = append(admins, &Admin{ + admins := lo.Map(users, func(u *ent.User, insex int) *Admin { + return &Admin{ ID: u.ID, - }) - } + } + }) return admins, nil } diff --git a/model/comment_impl.go b/model/comment_impl.go index ffde2012..f23dfe5f 100644 --- a/model/comment_impl.go +++ b/model/comment_impl.go @@ -5,6 +5,7 @@ import ( "time" "github.com/google/uuid" + "github.com/samber/lo" "github.com/traPtitech/Jomon/ent" "github.com/traPtitech/Jomon/ent/comment" "github.com/traPtitech/Jomon/ent/request" @@ -31,10 +32,9 @@ func (repo *EntRepository) GetComments(ctx context.Context, requestID uuid.UUID) if err != nil { return nil, err } - modelcomments := []*Comment{} - for _, c := range comments { - modelcomments = append(modelcomments, ConvertEntCommentToModelComment(c, c.Edges.User.ID)) - } + modelcomments := lo.Map(comments, func(c *ent.Comment, index int) *Comment { + return ConvertEntCommentToModelComment(c, c.Edges.User.ID) + }) return modelcomments, nil } diff --git a/model/group_impl.go b/model/group_impl.go index f272f2dd..a7cae0ac 100644 --- a/model/group_impl.go +++ b/model/group_impl.go @@ -4,6 +4,7 @@ import ( "context" "github.com/google/uuid" + "github.com/samber/lo" "github.com/traPtitech/Jomon/ent" "github.com/traPtitech/Jomon/ent/group" "github.com/traPtitech/Jomon/ent/user" @@ -16,10 +17,9 @@ func (repo *EntRepository) GetGroups(ctx context.Context) ([]*Group, error) { if err != nil { return nil, err } - modelgroups := []*Group{} - for _, g := range groups { - modelgroups = append(modelgroups, ConvertEntGroupToModelGroup(g)) - } + modelgroups := lo.Map(groups, func(g *ent.Group, index int) *Group { + return ConvertEntGroupToModelGroup(g) + }) return modelgroups, nil } @@ -81,10 +81,9 @@ func (repo *EntRepository) GetOwners(ctx context.Context, groupID uuid.UUID) ([] if err != nil { return nil, err } - owners := []*Owner{} - for _, groupowner := range groupowners { - owners = append(owners, &Owner{ID: groupowner.ID}) - } + owners := lo.Map(groupowners, func(groupowner *ent.User, index int) *Owner { + return &Owner{ID: groupowner.ID} + }) return owners, nil } @@ -98,10 +97,9 @@ func (repo *EntRepository) AddOwners(ctx context.Context, groupID uuid.UUID, own if err != nil { return nil, err } - resowners := []*Owner{} - for _, owner := range ownerIDs { - resowners = append(resowners, &Owner{ID: owner}) - } + resowners := lo.Map(ownerIDs, func(owner uuid.UUID, index int) *Owner { + return &Owner{ID: owner} + }) return resowners, nil } @@ -127,10 +125,10 @@ func (repo *EntRepository) GetMembers(ctx context.Context, groupID uuid.UUID) ([ if err != nil { return nil, err } - modelmembers := []*Member{} - for _, member := range members { - modelmembers = append(modelmembers, &Member{member.ID}) - } + modelmembers := lo.Map(members, func(member *ent.User, index int) *Member { + return &Member{member.ID} + }) + return modelmembers, nil } @@ -144,11 +142,10 @@ func (repo *EntRepository) AddMembers(ctx context.Context, groupID uuid.UUID, us if err != nil { return nil, err } + resMembers := lo.Map(userIDs, func(member uuid.UUID, index int) *Member { + return &Member{member} + }) - resMembers := []*Member{} - for _, member := range userIDs { - resMembers = append(resMembers, &Member{member}) - } return resMembers, nil } diff --git a/model/request_impl.go b/model/request_impl.go index bc419ec8..51e7a5ab 100644 --- a/model/request_impl.go +++ b/model/request_impl.go @@ -5,6 +5,7 @@ import ( "time" "github.com/google/uuid" + "github.com/samber/lo" "github.com/traPtitech/Jomon/ent" "github.com/traPtitech/Jomon/ent/group" "github.com/traPtitech/Jomon/ent/request" @@ -113,10 +114,10 @@ func (repo *EntRepository) GetRequests(ctx context.Context, query RequestQuery) return nil, err } - reqres := []*RequestResponse{} - for _, r := range requests { - reqres = append(reqres, convertEntRequestResponseToModelRequestResponse(r, r.Edges.Tag, r.Edges.Group, r.Edges.Status[0], r.Edges.User)) - } + reqres := lo.Map(requests, func(r *ent.Request, index int) *RequestResponse { + return convertEntRequestResponseToModelRequestResponse(r, r.Edges.Tag, r.Edges.Group, r.Edges.Status[0], r.Edges.User) + }) + return reqres, nil } @@ -131,10 +132,9 @@ func (repo *EntRepository) CreateRequest(ctx context.Context, title string, cont panic(v) } }() - var tagIDs []uuid.UUID - for _, t := range tags { - tagIDs = append(tagIDs, t.ID) - } + tagIDs := lo.Map(tags, func(t *Tag, index int) uuid.UUID { + return t.ID + }) created, err := tx.Client().Request. Create(). SetTitle(title). @@ -227,19 +227,16 @@ func (repo *EntRepository) GetRequest(ctx context.Context, requestID uuid.UUID) if err != nil { return nil, err } - var tags []*Tag - for _, t := range r.Edges.Tag { - tags = append(tags, ConvertEntTagToModelTag(t)) - } - var targets []*RequestTargetDetail - for _, target := range r.Edges.Target { - targets = append(targets, ConvertEntRequestTargetToModelRequestTargetDetail(target)) - } + tags := lo.Map(r.Edges.Tag, func(t *ent.Tag, index int) *Tag { + return ConvertEntTagToModelTag(t) + }) + targets := lo.Map(r.Edges.Target, func(target *ent.RequestTarget, index int) *RequestTargetDetail { + return ConvertEntRequestTargetToModelRequestTargetDetail(target) + }) modelGroup := ConvertEntGroupToModelGroup(r.Edges.Group) - var statuses []*RequestStatus - for _, status := range r.Edges.Status { - statuses = append(statuses, convertEntRequestStatusToModelRequestStatus(status)) - } + statuses := lo.Map(r.Edges.Status, func(status *ent.RequestStatus, index int) *RequestStatus { + return convertEntRequestStatusToModelRequestStatus(status) + }) reqdetail := &RequestDetail{ ID: r.ID, Status: convertEntRequestStatusToModelStatus(&r.Edges.Status[0].Status), @@ -267,10 +264,9 @@ func (repo *EntRepository) UpdateRequest(ctx context.Context, requestID uuid.UUI panic(v) } }() - var tagIDs []uuid.UUID - for _, t := range tags { - tagIDs = append(tagIDs, t.ID) - } + tagIDs := lo.Map(tags, func(t *Tag, index int) uuid.UUID { + return t.ID + }) updated, err := tx.Client().Request. UpdateOneID(requestID). SetTitle(title). @@ -320,10 +316,9 @@ func (repo *EntRepository) UpdateRequest(ctx context.Context, requestID uuid.UUI err = RollbackWithError(tx, err) return nil, err } - var modeltags []*Tag - for _, enttag := range enttags { - modeltags = append(modeltags, ConvertEntTagToModelTag(enttag)) - } + modeltags := lo.Map(enttags, func(enttag *ent.Tag, index int) *Tag { + return ConvertEntTagToModelTag(enttag) + }) var entgroup *ent.Group if group != nil { entgroup, err = updated.QueryGroup().Only(ctx) @@ -347,10 +342,9 @@ func (repo *EntRepository) UpdateRequest(ctx context.Context, requestID uuid.UUI if err != nil { return nil, err } - var statuses []*RequestStatus - for _, s := range entstatuses { - statuses = append(statuses, convertEntRequestStatusToModelRequestStatus(s)) - } + statuses := lo.Map(entstatuses, func(s *ent.RequestStatus, index int) *RequestStatus { + return convertEntRequestStatusToModelRequestStatus(s) + }) modelgroup := ConvertEntGroupToModelGroup(entgroup) reqdetail := &RequestDetail{ @@ -373,10 +367,9 @@ func convertEntRequestResponseToModelRequestResponse(request *ent.Request, tags if request == nil { return nil } - modeltags := []*Tag{} - for _, t := range tags { - modeltags = append(modeltags, ConvertEntTagToModelTag(t)) - } + modeltags := lo.Map(tags, func(t *ent.Tag, index int) *Tag { + return ConvertEntTagToModelTag(t) + }) return &RequestResponse{ ID: request.ID, Status: convertEntRequestStatusToModelStatus(&status.Status), diff --git a/model/request_target_impl.go b/model/request_target_impl.go index c2b67fe0..c108a836 100644 --- a/model/request_target_impl.go +++ b/model/request_target_impl.go @@ -4,6 +4,7 @@ import ( "context" "github.com/google/uuid" + "github.com/samber/lo" "github.com/traPtitech/Jomon/ent" "github.com/traPtitech/Jomon/ent/request" "github.com/traPtitech/Jomon/ent/requesttarget" @@ -23,33 +24,28 @@ func (repo *EntRepository) GetRequestTargets(ctx context.Context, requestID uuid if err != nil { return nil, err } - var targets []*RequestTargetDetail - for _, t := range ts { - targets = append(targets, ConvertEntRequestTargetToModelRequestTargetDetail(t)) - } + targets := lo.Map(ts, func(t *ent.RequestTarget, index int) *RequestTargetDetail { + return ConvertEntRequestTargetToModelRequestTargetDetail(t) + }) return targets, err } func (repo *EntRepository) createRequestTargets(ctx context.Context, tx *ent.Tx, requestID uuid.UUID, targets []*RequestTarget) ([]*RequestTargetDetail, error) { - var bulk []*ent.RequestTargetCreate - for _, t := range targets { - bulk = append(bulk, - tx.Client().RequestTarget. - Create(). - SetAmount(t.Amount). - SetRequestID(requestID). - SetUserID(t.Target), - ) - } + bulk := lo.Map(targets, func(t *RequestTarget, index int) *ent.RequestTargetCreate { + return tx.Client().RequestTarget. + Create(). + SetAmount(t.Amount). + SetRequestID(requestID). + SetUserID(t.Target) + }) cs, err := tx.Client().RequestTarget.CreateBulk(bulk...). Save(ctx) if err != nil { return nil, err } - ids := []uuid.UUID{} - for _, c := range cs { - ids = append(ids, c.ID) - } + ids := lo.Map(cs, func(c *ent.RequestTarget, index int) uuid.UUID { + return c.ID + }) created, err := tx.Client().RequestTarget. Query(). Where( @@ -61,10 +57,9 @@ func (repo *EntRepository) createRequestTargets(ctx context.Context, tx *ent.Tx, return nil, err } // []*ent.RequestTarget to []*RequestTargetDetail - var ts []*RequestTargetDetail - for _, t := range created { - ts = append(ts, ConvertEntRequestTargetToModelRequestTargetDetail(t)) - } + ts := lo.Map(created, func(t *ent.RequestTarget, index int) *RequestTargetDetail { + return ConvertEntRequestTargetToModelRequestTargetDetail(t) + }) return ts, nil } diff --git a/model/tag_impl.go b/model/tag_impl.go index dc79bee8..8dab3fa7 100644 --- a/model/tag_impl.go +++ b/model/tag_impl.go @@ -5,6 +5,7 @@ import ( "time" "github.com/google/uuid" + "github.com/samber/lo" "github.com/traPtitech/Jomon/ent" "github.com/traPtitech/Jomon/ent/tag" ) @@ -16,10 +17,10 @@ func (repo *EntRepository) GetTags(ctx context.Context) ([]*Tag, error) { if err != nil { return nil, err } - modeltags := []*Tag{} - for _, t := range tags { - modeltags = append(modeltags, ConvertEntTagToModelTag(t)) - } + modeltags := lo.Map(tags, func(t *ent.Tag, index int) *Tag { + return ConvertEntTagToModelTag(t) + }) + return modeltags, nil } diff --git a/model/transaction_impl.go b/model/transaction_impl.go index 03200874..7539aba0 100644 --- a/model/transaction_impl.go +++ b/model/transaction_impl.go @@ -5,6 +5,7 @@ import ( "entgo.io/ent/dialect/sql" "github.com/google/uuid" + "github.com/samber/lo" "github.com/traPtitech/Jomon/ent" "github.com/traPtitech/Jomon/ent/group" "github.com/traPtitech/Jomon/ent/groupbudget" @@ -114,10 +115,9 @@ func (repo *EntRepository) GetTransactions(ctx context.Context, query Transactio } // Converting - var res []*TransactionResponse - for _, tx := range txs { - res = append(res, ConvertEntTransactionToModelTransactionResponse(tx)) - } + res := lo.Map(txs, func(tx *ent.Transaction, index int) *TransactionResponse { + return ConvertEntTransactionToModelTransactionResponse(tx) + }) return res, nil } @@ -155,10 +155,9 @@ func (repo *EntRepository) CreateTransaction(ctx context.Context, amount int, ta }() // Get Tags - var tagIDs []uuid.UUID - for _, t := range tags { - tagIDs = append(tagIDs, *t) - } + tagIDs := lo.Map(tags, func(t *uuid.UUID, index int) uuid.UUID { + return *t + }) // Create Transaction Detail detail, err := repo.createTransactionDetail(ctx, tx, amount, target) @@ -261,10 +260,9 @@ func (repo *EntRepository) UpdateTransaction(ctx context.Context, transactionID } // Get Tags - var tagIDs []uuid.UUID - for _, t := range tags { - tagIDs = append(tagIDs, *t) - } + tagIDs := lo.Map(tags, func(t *uuid.UUID, index int) uuid.UUID { + return *t + }) // Delete Tag Transaction Edge _, err = tx.Client().Tag. @@ -369,10 +367,9 @@ func ConvertEntTransactionToModelTransaction(transaction *ent.Transaction) *Tran } func ConvertEntTransactionToModelTransactionResponse(transaction *ent.Transaction) *TransactionResponse { - var tags []*Tag - for _, t := range transaction.Edges.Tag { - tags = append(tags, ConvertEntTagToModelTag(t)) - } + tags := lo.Map(transaction.Edges.Tag, func(t *ent.Tag, index int) *Tag { + return ConvertEntTagToModelTag(t) + }) var g *Group if transaction.Edges.GroupBudget != nil { g = ConvertEntGroupToModelGroup(transaction.Edges.GroupBudget.Edges.Group) diff --git a/model/user_impl.go b/model/user_impl.go index 7e0c873a..d14fb451 100644 --- a/model/user_impl.go +++ b/model/user_impl.go @@ -5,6 +5,7 @@ import ( "time" "github.com/google/uuid" + "github.com/samber/lo" "github.com/traPtitech/Jomon/ent" "github.com/traPtitech/Jomon/ent/user" ) @@ -51,10 +52,9 @@ func (repo *EntRepository) GetUsers(ctx context.Context) ([]*User, error) { if err != nil { return nil, err } - var modelusers []*User - for _, u := range users { - modelusers = append(modelusers, convertEntUserToModelUser(u)) - } + modelusers := lo.Map(users, func(u *ent.User, index int) *User { + return convertEntUserToModelUser(u) + }) return modelusers, nil } From fef7daebd9a19572981faf28799aaf84d5a8afdf Mon Sep 17 00:00:00 2001 From: Hueter Date: Sat, 10 Aug 2024 14:46:08 +0900 Subject: [PATCH 04/11] =?UTF-8?q?CI=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router/transaction_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/router/transaction_test.go b/router/transaction_test.go index 0275a2e8..9f1b2a2d 100644 --- a/router/transaction_test.go +++ b/router/transaction_test.go @@ -656,7 +656,6 @@ func TestHandlers_PostTransaction(t *testing.T) { Return(tx1, nil) res := lo.Map(txs, func(tx *model.TransactionResponse, index int) *Transaction { - tag := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { return &TagOverview{ ID: modelTag.ID, From b063680d0bb7a9d07c4df939e94b7d5a9808d3ce Mon Sep 17 00:00:00 2001 From: Hueter Date: Sat, 10 Aug 2024 15:57:41 +0900 Subject: [PATCH 05/11] =?UTF-8?q?CI=E5=AF=BE=E5=BF=9C2=20(lll)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/request_impl.go | 9 +- router/request.go | 208 +++++++++++++++++++++++------------------- 2 files changed, 122 insertions(+), 95 deletions(-) diff --git a/model/request_impl.go b/model/request_impl.go index 7caabf23..ea0d0796 100644 --- a/model/request_impl.go +++ b/model/request_impl.go @@ -238,9 +238,12 @@ func (repo *EntRepository) GetRequest( tags := lo.Map(r.Edges.Tag, func(t *ent.Tag, index int) *Tag { return ConvertEntTagToModelTag(t) }) - targets := lo.Map(r.Edges.Target, func(target *ent.RequestTarget, index int) *RequestTargetDetail { - return ConvertEntRequestTargetToModelRequestTargetDetail(target) - }) + targets := lo.Map( + r.Edges.Target, + func(target *ent.RequestTarget, index int) *RequestTargetDetail { + return ConvertEntRequestTargetToModelRequestTargetDetail(target) + }, + ) modelGroup := ConvertEntGroupToModelGroup(r.Edges.Group) statuses := lo.Map(r.Edges.Status, func(status *ent.RequestStatus, index int) *RequestStatus { return convertEntRequestStatusToModelRequestStatus(status) diff --git a/router/request.go b/router/request.go index c8ba9e72..0777862a 100644 --- a/router/request.go +++ b/router/request.go @@ -183,52 +183,58 @@ func (h Handlers) GetRequests(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - requests := lo.Map(modelrequests, func(request *model.RequestResponse, index int) *RequestResponse { - tags := lo.Map(request.Tags, func(tag *model.Tag, index int) *TagOverview { - return &TagOverview{ - ID: tag.ID, - Name: tag.Name, - CreatedAt: tag.CreatedAt, - UpdatedAt: tag.UpdatedAt, + requests := lo.Map( + modelrequests, + func(request *model.RequestResponse, index int) *RequestResponse { + tags := lo.Map(request.Tags, func(tag *model.Tag, index int) *TagOverview { + return &TagOverview{ + ID: tag.ID, + Name: tag.Name, + CreatedAt: tag.CreatedAt, + UpdatedAt: tag.UpdatedAt, + } + }) + + restargets := lo.Map( + request.Targets, + func(target *model.RequestTargetDetail, index int) *TargetOverview { + return &TargetOverview{ + ID: target.ID, + Target: target.Target, + Amount: target.Amount, + PaidAt: target.PaidAt, + CreatedAt: target.CreatedAt, + } + }, + ) + + var resgroup *GroupOverview + if request.Group != nil { + resgroup = &GroupOverview{ + ID: request.Group.ID, + Name: request.Group.Name, + Description: request.Group.Description, + Budget: request.Group.Budget, + CreatedAt: request.Group.CreatedAt, + UpdatedAt: request.Group.UpdatedAt, + } } - }) - restargets := lo.Map(request.Targets, func(target *model.RequestTargetDetail, index int) *TargetOverview { - return &TargetOverview{ - ID: target.ID, - Target: target.Target, - Amount: target.Amount, - PaidAt: target.PaidAt, - CreatedAt: target.CreatedAt, - } - }) - - var resgroup *GroupOverview - if request.Group != nil { - resgroup = &GroupOverview{ - ID: request.Group.ID, - Name: request.Group.Name, - Description: request.Group.Description, - Budget: request.Group.Budget, - CreatedAt: request.Group.CreatedAt, - UpdatedAt: request.Group.UpdatedAt, + return &RequestResponse{ + ID: request.ID, + Status: request.Status, + CreatedAt: request.CreatedAt, + UpdatedAt: request.UpdatedAt, + CreatedBy: request.CreatedBy, + Title: request.Title, + Content: request.Content, + Targets: restargets, + Tags: tags, + Group: resgroup, + Comments: []*CommentDetail{}, } - } - - return &RequestResponse{ - ID: request.ID, - Status: request.Status, - CreatedAt: request.CreatedAt, - UpdatedAt: request.UpdatedAt, - CreatedBy: request.CreatedBy, - Title: request.Title, - Content: request.Content, - Targets: restargets, - Tags: tags, - Group: resgroup, - Comments: []*CommentDetail{}, - } - }) + }, + ) return c.JSON(http.StatusOK, requests) } @@ -297,15 +303,18 @@ func (h Handlers) PostRequest(c echo.Context) error { UpdatedAt: request.Group.UpdatedAt, } } - reqtargets := lo.Map(request.Targets, func(target *model.RequestTargetDetail, index int) *TargetOverview { - return &TargetOverview{ - ID: target.ID, - Target: target.Target, - Amount: target.Amount, - PaidAt: target.PaidAt, - CreatedAt: target.CreatedAt, - } - }) + reqtargets := lo.Map( + request.Targets, + func(target *model.RequestTargetDetail, index int) *TargetOverview { + return &TargetOverview{ + ID: target.ID, + Target: target.Target, + Amount: target.Amount, + PaidAt: target.PaidAt, + CreatedAt: target.CreatedAt, + } + }, + ) restags := lo.Map(request.Tags, func(tag *model.Tag, index int) *TagOverview { return &TagOverview{ ID: tag.ID, @@ -314,13 +323,16 @@ func (h Handlers) PostRequest(c echo.Context) error { UpdatedAt: tag.UpdatedAt, } }) - statuses := lo.Map(request.Statuses, func(status *model.RequestStatus, index int) *StatusResponseOverview { - return &StatusResponseOverview{ - Status: status.Status, - CreatedAt: status.CreatedAt, - CreatedBy: status.CreatedBy, - } - }) + statuses := lo.Map( + request.Statuses, + func(status *model.RequestStatus, index int) *StatusResponseOverview { + return &StatusResponseOverview{ + Status: status.Status, + CreatedAt: status.CreatedAt, + CreatedBy: status.CreatedBy, + } + }, + ) res := &RequestResponse{ ID: request.ID, @@ -387,15 +399,18 @@ func (h Handlers) GetRequest(c echo.Context) error { UpdatedAt: request.Group.UpdatedAt, } } - reqtargets := lo.Map(request.Targets, func(target *model.RequestTargetDetail, index int) *TargetOverview { - return &TargetOverview{ - ID: target.ID, - Target: target.Target, - Amount: target.Amount, - PaidAt: target.PaidAt, - CreatedAt: target.CreatedAt, - } - }) + reqtargets := lo.Map( + request.Targets, + func(target *model.RequestTargetDetail, index int) *TargetOverview { + return &TargetOverview{ + ID: target.ID, + Target: target.Target, + Amount: target.Amount, + PaidAt: target.PaidAt, + CreatedAt: target.CreatedAt, + } + }, + ) restags := lo.Map(request.Tags, func(tag *model.Tag, index int) *TagOverview { return &TagOverview{ ID: tag.ID, @@ -405,13 +420,16 @@ func (h Handlers) GetRequest(c echo.Context) error { } }) - resstatuses := lo.Map(request.Statuses, func(status *model.RequestStatus, index int) *StatusResponseOverview { - return &StatusResponseOverview{ - CreatedBy: status.CreatedBy, - Status: status.Status, - CreatedAt: status.CreatedAt, - } - }) + resstatuses := lo.Map( + request.Statuses, + func(status *model.RequestStatus, index int) *StatusResponseOverview { + return &StatusResponseOverview{ + CreatedBy: status.CreatedBy, + Status: status.Status, + CreatedAt: status.CreatedAt, + } + }, + ) res := &RequestResponse{ ID: request.ID, @@ -529,23 +547,29 @@ func (h Handlers) PutRequest(c echo.Context) error { } }) - restargets := lo.Map(request.Targets, func(target *model.RequestTargetDetail, index int) *TargetOverview { - return &TargetOverview{ - ID: target.ID, - Target: target.Target, - Amount: target.Amount, - PaidAt: target.PaidAt, - CreatedAt: target.CreatedAt, - } - }) - - resstatuses := lo.Map(request.Statuses, func(status *model.RequestStatus, index int) *StatusResponseOverview { - return &StatusResponseOverview{ - CreatedBy: status.CreatedBy, - Status: status.Status, - CreatedAt: status.CreatedAt, - } - }) + restargets := lo.Map( + request.Targets, + func(target *model.RequestTargetDetail, index int) *TargetOverview { + return &TargetOverview{ + ID: target.ID, + Target: target.Target, + Amount: target.Amount, + PaidAt: target.PaidAt, + CreatedAt: target.CreatedAt, + } + }, + ) + + resstatuses := lo.Map( + request.Statuses, + func(status *model.RequestStatus, index int) *StatusResponseOverview { + return &StatusResponseOverview{ + CreatedBy: status.CreatedBy, + Status: status.Status, + CreatedAt: status.CreatedAt, + } + }, + ) res := &RequestResponse{ ID: request.ID, From 3e71a37ae6e6480dc24c122bb303273ba6c54213 Mon Sep 17 00:00:00 2001 From: Hueter Date: Tue, 24 Sep 2024 02:26:00 +0900 Subject: [PATCH 06/11] Merge branch 'v2' of github.com:traPtitech/Jomon into samber_lo_adapt --- .github/workflows/go.yml | 12 +- Dockerfile | 2 +- Dockerfile.dev | 2 +- ent/client.go | 182 +++++++++++++- ent/comment.go | 28 ++- ent/comment/comment.go | 58 +++++ ent/comment/where.go | 35 +-- ent/comment_create.go | 22 +- ent/comment_delete.go | 2 +- ent/comment_query.go | 27 ++- ent/comment_update.go | 68 +++--- ent/ent.go | 76 +++--- ent/file.go | 28 ++- ent/file/file.go | 58 +++++ ent/file/where.go | 35 +-- ent/file_create.go | 20 +- ent/file_delete.go | 2 +- ent/file_query.go | 27 ++- ent/file_update.go | 80 +++--- ent/group.go | 14 +- ent/group/group.go | 124 ++++++++++ ent/group/where.go | 47 +--- ent/group_create.go | 28 +-- ent/group_delete.go | 2 +- ent/group_query.go | 35 +-- ent/group_update.go | 156 +++++------- ent/groupbudget.go | 20 +- ent/groupbudget/groupbudget.go | 60 +++++ ent/groupbudget/where.go | 35 +-- ent/groupbudget_create.go | 20 +- ent/groupbudget_delete.go | 2 +- ent/groupbudget_query.go | 31 +-- ent/groupbudget_update.go | 74 +++--- ent/request.go | 28 ++- ent/request/request.go | 184 ++++++++++++++ ent/request/where.go | 71 +----- ent/request_create.go | 48 ++-- ent/request_delete.go | 2 +- ent/request_query.go | 47 ++-- ent/request_update.go | 256 ++++++-------------- ent/requeststatus.go | 28 ++- ent/requeststatus/requeststatus.go | 48 ++++ ent/requeststatus/where.go | 35 +-- ent/requeststatus_create.go | 22 +- ent/requeststatus_delete.go | 2 +- ent/requeststatus_query.go | 27 ++- ent/requeststatus_update.go | 52 ++-- ent/requesttarget.go | 28 ++- ent/requesttarget/requesttarget.go | 53 ++++ ent/requesttarget/where.go | 35 +-- ent/requesttarget_create.go | 22 +- ent/requesttarget_delete.go | 2 +- ent/requesttarget_query.go | 27 ++- ent/requesttarget_update.go | 68 +++--- ent/runtime/runtime.go | 4 +- ent/tag.go | 14 +- ent/tag/tag.go | 72 ++++++ ent/tag/where.go | 35 +-- ent/tag_create.go | 18 +- ent/tag_delete.go | 2 +- ent/tag_query.go | 27 ++- ent/tag_update.go | 80 +++--- ent/transaction.go | 36 +-- ent/transaction/transaction.go | 78 ++++++ ent/transaction/where.go | 47 +--- ent/transaction_create.go | 30 +-- ent/transaction_delete.go | 2 +- ent/transaction_query.go | 31 +-- ent/transaction_update.go | 98 ++------ ent/transactiondetail.go | 20 +- ent/transactiondetail/transactiondetail.go | 44 ++++ ent/transactiondetail/where.go | 29 +-- ent/transactiondetail_create.go | 13 +- ent/transactiondetail_delete.go | 2 +- ent/transactiondetail_query.go | 27 ++- ent/transactiondetail_update.go | 24 +- ent/user.go | 14 +- ent/user/user.go | 187 ++++++++++++++ ent/user/where.go | 65 +---- ent/user_create.go | 43 +--- ent/user_delete.go | 2 +- ent/user_query.go | 47 ++-- ent/user_update.go | 246 ++++++------------- go.mod | 11 +- go.sum | 45 +--- model/mock_model/mock_admin.go | 13 +- model/mock_model/mock_comment.go | 15 +- model/mock_model/mock_file.go | 13 +- model/mock_model/mock_group.go | 29 ++- model/mock_model/mock_group_budget.go | 7 +- model/mock_model/mock_request.go | 15 +- model/mock_model/mock_request_file.go | 7 +- model/mock_model/mock_request_status.go | 9 +- model/mock_model/mock_request_tag.go | 7 +- model/mock_model/mock_request_target.go | 9 +- model/mock_model/mock_tag.go | 17 +- model/mock_model/mock_transaction.go | 15 +- model/mock_model/mock_transaction_detail.go | 7 +- model/mock_model/mock_transaction_tag.go | 7 +- model/mock_model/mock_user.go | 17 +- router/admin_test.go | 2 +- router/file_test.go | 2 +- router/group_test.go | 2 +- router/request_test.go | 2 +- router/router_test.go | 2 +- router/tag_test.go | 2 +- router/transaction_test.go | 2 +- router/user_test.go | 2 +- service/webhook.go | 4 +- storage/mock_storage/mock_storage.go | 13 +- testutil/random/ramdom.go | 40 +-- 111 files changed, 2338 insertions(+), 1812 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 4207de22..cfdc62ec 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,5 +1,15 @@ name: Go -on: push + +on: + push: + branches: + - v2 + pull_request: + branches: + - v2 + workflow_dispatch: + schedule: + - cron: "0 0 1 * *" jobs: diff --git a/Dockerfile b/Dockerfile index 1fdd5bfb..77eca2c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ ## build backend -FROM golang:1.22.5-alpine as server-build +FROM golang:1.23.0-alpine as server-build WORKDIR /github.com/traPtitech/Jomon COPY go.mod go.sum ./ diff --git a/Dockerfile.dev b/Dockerfile.dev index 619137b9..43a158a7 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,4 +1,4 @@ -FROM golang:1.22.5-alpine as build +FROM golang:1.23.0-alpine as build ENV CGO_ENABLED 0 ENV TZ Asia/Tokyo diff --git a/ent/client.go b/ent/client.go index 83e67a1d..ecd0cf05 100644 --- a/ent/client.go +++ b/ent/client.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "reflect" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/migrate" @@ -59,9 +60,7 @@ type Client struct { // NewClient creates a new client configured with the given options. func NewClient(opts ...Option) *Client { - cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}} - cfg.options(opts...) - client := &Client{config: cfg} + client := &Client{config: newConfig(opts...)} client.init() return client } @@ -99,6 +98,13 @@ type ( Option func(*config) ) +// newConfig creates a new config for the client. +func newConfig(opts ...Option) config { + cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}} + cfg.options(opts...) + return cfg +} + // options applies the options on the config object. func (c *config) options(opts ...Option) { for _, opt := range opts { @@ -146,11 +152,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -312,6 +321,21 @@ func (c *CommentClient) CreateBulk(builders ...*CommentCreate) *CommentCreateBul return &CommentCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *CommentClient) MapCreateBulk(slice any, setFunc func(*CommentCreate, int)) *CommentCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &CommentCreateBulk{err: fmt.Errorf("calling to CommentClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*CommentCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &CommentCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Comment. func (c *CommentClient) Update() *CommentUpdate { mutation := newCommentMutation(c.config, OpUpdate) @@ -462,6 +486,21 @@ func (c *FileClient) CreateBulk(builders ...*FileCreate) *FileCreateBulk { return &FileCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *FileClient) MapCreateBulk(slice any, setFunc func(*FileCreate, int)) *FileCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &FileCreateBulk{err: fmt.Errorf("calling to FileClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*FileCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &FileCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for File. func (c *FileClient) Update() *FileUpdate { mutation := newFileMutation(c.config, OpUpdate) @@ -612,6 +651,21 @@ func (c *GroupClient) CreateBulk(builders ...*GroupCreate) *GroupCreateBulk { return &GroupCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *GroupClient) MapCreateBulk(slice any, setFunc func(*GroupCreate, int)) *GroupCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &GroupCreateBulk{err: fmt.Errorf("calling to GroupClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*GroupCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &GroupCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Group. func (c *GroupClient) Update() *GroupUpdate { mutation := newGroupMutation(c.config, OpUpdate) @@ -794,6 +848,21 @@ func (c *GroupBudgetClient) CreateBulk(builders ...*GroupBudgetCreate) *GroupBud return &GroupBudgetCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *GroupBudgetClient) MapCreateBulk(slice any, setFunc func(*GroupBudgetCreate, int)) *GroupBudgetCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &GroupBudgetCreateBulk{err: fmt.Errorf("calling to GroupBudgetClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*GroupBudgetCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &GroupBudgetCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for GroupBudget. func (c *GroupBudgetClient) Update() *GroupBudgetUpdate { mutation := newGroupBudgetMutation(c.config, OpUpdate) @@ -944,6 +1013,21 @@ func (c *RequestClient) CreateBulk(builders ...*RequestCreate) *RequestCreateBul return &RequestCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *RequestClient) MapCreateBulk(slice any, setFunc func(*RequestCreate, int)) *RequestCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &RequestCreateBulk{err: fmt.Errorf("calling to RequestClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*RequestCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &RequestCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Request. func (c *RequestClient) Update() *RequestUpdate { mutation := newRequestMutation(c.config, OpUpdate) @@ -1190,6 +1274,21 @@ func (c *RequestStatusClient) CreateBulk(builders ...*RequestStatusCreate) *Requ return &RequestStatusCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *RequestStatusClient) MapCreateBulk(slice any, setFunc func(*RequestStatusCreate, int)) *RequestStatusCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &RequestStatusCreateBulk{err: fmt.Errorf("calling to RequestStatusClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*RequestStatusCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &RequestStatusCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for RequestStatus. func (c *RequestStatusClient) Update() *RequestStatusUpdate { mutation := newRequestStatusMutation(c.config, OpUpdate) @@ -1340,6 +1439,21 @@ func (c *RequestTargetClient) CreateBulk(builders ...*RequestTargetCreate) *Requ return &RequestTargetCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *RequestTargetClient) MapCreateBulk(slice any, setFunc func(*RequestTargetCreate, int)) *RequestTargetCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &RequestTargetCreateBulk{err: fmt.Errorf("calling to RequestTargetClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*RequestTargetCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &RequestTargetCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for RequestTarget. func (c *RequestTargetClient) Update() *RequestTargetUpdate { mutation := newRequestTargetMutation(c.config, OpUpdate) @@ -1490,6 +1604,21 @@ func (c *TagClient) CreateBulk(builders ...*TagCreate) *TagCreateBulk { return &TagCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TagClient) MapCreateBulk(slice any, setFunc func(*TagCreate, int)) *TagCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TagCreateBulk{err: fmt.Errorf("calling to TagClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TagCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TagCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Tag. func (c *TagClient) Update() *TagUpdate { mutation := newTagMutation(c.config, OpUpdate) @@ -1640,6 +1769,21 @@ func (c *TransactionClient) CreateBulk(builders ...*TransactionCreate) *Transact return &TransactionCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TransactionClient) MapCreateBulk(slice any, setFunc func(*TransactionCreate, int)) *TransactionCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TransactionCreateBulk{err: fmt.Errorf("calling to TransactionClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TransactionCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TransactionCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Transaction. func (c *TransactionClient) Update() *TransactionUpdate { mutation := newTransactionMutation(c.config, OpUpdate) @@ -1822,6 +1966,21 @@ func (c *TransactionDetailClient) CreateBulk(builders ...*TransactionDetailCreat return &TransactionDetailCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TransactionDetailClient) MapCreateBulk(slice any, setFunc func(*TransactionDetailCreate, int)) *TransactionDetailCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TransactionDetailCreateBulk{err: fmt.Errorf("calling to TransactionDetailClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TransactionDetailCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TransactionDetailCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for TransactionDetail. func (c *TransactionDetailClient) Update() *TransactionDetailUpdate { mutation := newTransactionDetailMutation(c.config, OpUpdate) @@ -1956,6 +2115,21 @@ func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) diff --git a/ent/comment.go b/ent/comment.go index 707f5a9c..818af558 100644 --- a/ent/comment.go +++ b/ent/comment.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/comment" @@ -32,6 +33,7 @@ type Comment struct { Edges CommentEdges `json:"edges"` comment_user *uuid.UUID request_comment *uuid.UUID + selectValues sql.SelectValues } // CommentEdges holds the relations/edges for other nodes in the graph. @@ -48,12 +50,10 @@ type CommentEdges struct { // RequestOrErr returns the Request value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e CommentEdges) RequestOrErr() (*Request, error) { - if e.loadedTypes[0] { - if e.Request == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: request.Label} - } + if e.Request != nil { return e.Request, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: request.Label} } return nil, &NotLoadedError{edge: "request"} } @@ -61,12 +61,10 @@ func (e CommentEdges) RequestOrErr() (*Request, error) { // UserOrErr returns the User value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e CommentEdges) UserOrErr() (*User, error) { - if e.loadedTypes[1] { - if e.User == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: user.Label} - } + if e.User != nil { return e.User, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: user.Label} } return nil, &NotLoadedError{edge: "user"} } @@ -87,7 +85,7 @@ func (*Comment) scanValues(columns []string) ([]any, error) { case comment.ForeignKeys[1]: // request_comment values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: - return nil, fmt.Errorf("unexpected column %q for type Comment", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -146,11 +144,19 @@ func (c *Comment) assignValues(columns []string, values []any) error { c.request_comment = new(uuid.UUID) *c.request_comment = *value.S.(*uuid.UUID) } + default: + c.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the Comment. +// This includes values selected through modifiers, order, etc. +func (c *Comment) Value(name string) (ent.Value, error) { + return c.selectValues.Get(name) +} + // QueryRequest queries the "request" edge of the Comment entity. func (c *Comment) QueryRequest() *RequestQuery { return NewCommentClient(c.config).QueryRequest(c) diff --git a/ent/comment/comment.go b/ent/comment/comment.go index 5e1bbc56..45ed22d6 100644 --- a/ent/comment/comment.go +++ b/ent/comment/comment.go @@ -5,6 +5,8 @@ package comment import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -84,3 +86,59 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the Comment queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByComment orders the results by the comment field. +func ByComment(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldComment, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByDeletedAt orders the results by the deleted_at field. +func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() +} + +// ByRequestField orders the results by request field. +func ByRequestField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStep(), sql.OrderByField(field, opts...)) + } +} + +// ByUserField orders the results by user field. +func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...)) + } +} +func newRequestStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), + ) +} +func newUserStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(UserInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), + ) +} diff --git a/ent/comment/where.go b/ent/comment/where.go index 4ddde755..cbf57f6c 100644 --- a/ent/comment/where.go +++ b/ent/comment/where.go @@ -285,11 +285,7 @@ func HasRequest() predicate.Comment { // HasRequestWith applies the HasEdge predicate on the "request" edge with a given conditions (other predicates). func HasRequestWith(preds ...predicate.Request) predicate.Comment { return predicate.Comment(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), - ) + step := newRequestStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -312,11 +308,7 @@ func HasUser() predicate.Comment { // HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates). func HasUserWith(preds ...predicate.User) predicate.Comment { return predicate.Comment(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(UserInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), - ) + step := newUserStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -327,32 +319,15 @@ func HasUserWith(preds ...predicate.User) predicate.Comment { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Comment) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Comment(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Comment) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Comment(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Comment) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Comment(sql.NotPredicates(p)) } diff --git a/ent/comment_create.go b/ent/comment_create.go index 58522acc..eabdec9e 100644 --- a/ent/comment_create.go +++ b/ent/comment_create.go @@ -115,7 +115,7 @@ func (cc *CommentCreate) Mutation() *CommentMutation { // Save creates the Comment in the database. func (cc *CommentCreate) Save(ctx context.Context) (*Comment, error) { cc.defaults() - return withHooks[*Comment, CommentMutation](ctx, cc.sqlSave, cc.mutation, cc.hooks) + return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -167,10 +167,10 @@ func (cc *CommentCreate) check() error { if _, ok := cc.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Comment.updated_at"`)} } - if _, ok := cc.mutation.RequestID(); !ok { + if len(cc.mutation.RequestIDs()) == 0 { return &ValidationError{Name: "request", err: errors.New(`ent: missing required edge "Comment.request"`)} } - if _, ok := cc.mutation.UserID(); !ok { + if len(cc.mutation.UserIDs()) == 0 { return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "Comment.user"`)} } return nil @@ -232,10 +232,7 @@ func (cc *CommentCreate) createSpec() (*Comment, *sqlgraph.CreateSpec) { Columns: []string{comment.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -252,10 +249,7 @@ func (cc *CommentCreate) createSpec() (*Comment, *sqlgraph.CreateSpec) { Columns: []string{comment.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -270,11 +264,15 @@ func (cc *CommentCreate) createSpec() (*Comment, *sqlgraph.CreateSpec) { // CommentCreateBulk is the builder for creating many Comment entities in bulk. type CommentCreateBulk struct { config + err error builders []*CommentCreate } // Save creates the Comment entities in the database. func (ccb *CommentCreateBulk) Save(ctx context.Context) ([]*Comment, error) { + if ccb.err != nil { + return nil, ccb.err + } specs := make([]*sqlgraph.CreateSpec, len(ccb.builders)) nodes := make([]*Comment, len(ccb.builders)) mutators := make([]Mutator, len(ccb.builders)) @@ -291,8 +289,8 @@ func (ccb *CommentCreateBulk) Save(ctx context.Context) ([]*Comment, error) { return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, ccb.builders[i+1].mutation) } else { diff --git a/ent/comment_delete.go b/ent/comment_delete.go index de823842..4836b072 100644 --- a/ent/comment_delete.go +++ b/ent/comment_delete.go @@ -27,7 +27,7 @@ func (cd *CommentDelete) Where(ps ...predicate.Comment) *CommentDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (cd *CommentDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, CommentMutation](ctx, cd.sqlExec, cd.mutation, cd.hooks) + return withHooks(ctx, cd.sqlExec, cd.mutation, cd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/comment_query.go b/ent/comment_query.go index 813d9542..95fe65b0 100644 --- a/ent/comment_query.go +++ b/ent/comment_query.go @@ -7,6 +7,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -21,7 +22,7 @@ import ( type CommentQuery struct { config ctx *QueryContext - order []OrderFunc + order []comment.OrderOption inters []Interceptor predicates []predicate.Comment withRequest *RequestQuery @@ -58,7 +59,7 @@ func (cq *CommentQuery) Unique(unique bool) *CommentQuery { } // Order specifies how the records should be ordered. -func (cq *CommentQuery) Order(o ...OrderFunc) *CommentQuery { +func (cq *CommentQuery) Order(o ...comment.OrderOption) *CommentQuery { cq.order = append(cq.order, o...) return cq } @@ -110,7 +111,7 @@ func (cq *CommentQuery) QueryUser() *UserQuery { // First returns the first Comment entity from the query. // Returns a *NotFoundError when no Comment was found. func (cq *CommentQuery) First(ctx context.Context) (*Comment, error) { - nodes, err := cq.Limit(1).All(setContextOp(ctx, cq.ctx, "First")) + nodes, err := cq.Limit(1).All(setContextOp(ctx, cq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -133,7 +134,7 @@ func (cq *CommentQuery) FirstX(ctx context.Context) *Comment { // Returns a *NotFoundError when no Comment ID was found. func (cq *CommentQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = cq.Limit(1).IDs(setContextOp(ctx, cq.ctx, "FirstID")); err != nil { + if ids, err = cq.Limit(1).IDs(setContextOp(ctx, cq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -156,7 +157,7 @@ func (cq *CommentQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Comment entity is found. // Returns a *NotFoundError when no Comment entities are found. func (cq *CommentQuery) Only(ctx context.Context) (*Comment, error) { - nodes, err := cq.Limit(2).All(setContextOp(ctx, cq.ctx, "Only")) + nodes, err := cq.Limit(2).All(setContextOp(ctx, cq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -184,7 +185,7 @@ func (cq *CommentQuery) OnlyX(ctx context.Context) *Comment { // Returns a *NotFoundError when no entities are found. func (cq *CommentQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = cq.Limit(2).IDs(setContextOp(ctx, cq.ctx, "OnlyID")); err != nil { + if ids, err = cq.Limit(2).IDs(setContextOp(ctx, cq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -209,7 +210,7 @@ func (cq *CommentQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Comments. func (cq *CommentQuery) All(ctx context.Context) ([]*Comment, error) { - ctx = setContextOp(ctx, cq.ctx, "All") + ctx = setContextOp(ctx, cq.ctx, ent.OpQueryAll) if err := cq.prepareQuery(ctx); err != nil { return nil, err } @@ -231,7 +232,7 @@ func (cq *CommentQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if cq.ctx.Unique == nil && cq.path != nil { cq.Unique(true) } - ctx = setContextOp(ctx, cq.ctx, "IDs") + ctx = setContextOp(ctx, cq.ctx, ent.OpQueryIDs) if err = cq.Select(comment.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -249,7 +250,7 @@ func (cq *CommentQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (cq *CommentQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, cq.ctx, "Count") + ctx = setContextOp(ctx, cq.ctx, ent.OpQueryCount) if err := cq.prepareQuery(ctx); err != nil { return 0, err } @@ -267,7 +268,7 @@ func (cq *CommentQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (cq *CommentQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, cq.ctx, "Exist") + ctx = setContextOp(ctx, cq.ctx, ent.OpQueryExist) switch _, err := cq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -296,7 +297,7 @@ func (cq *CommentQuery) Clone() *CommentQuery { return &CommentQuery{ config: cq.config, ctx: cq.ctx.Clone(), - order: append([]OrderFunc{}, cq.order...), + order: append([]comment.OrderOption{}, cq.order...), inters: append([]Interceptor{}, cq.inters...), predicates: append([]predicate.Comment{}, cq.predicates...), withRequest: cq.withRequest.Clone(), @@ -612,7 +613,7 @@ func (cgb *CommentGroupBy) Aggregate(fns ...AggregateFunc) *CommentGroupBy { // Scan applies the selector query and scans the result into the given value. func (cgb *CommentGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, cgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, cgb.build.ctx, ent.OpQueryGroupBy) if err := cgb.build.prepareQuery(ctx); err != nil { return err } @@ -660,7 +661,7 @@ func (cs *CommentSelect) Aggregate(fns ...AggregateFunc) *CommentSelect { // Scan applies the selector query and scans the result into the given value. func (cs *CommentSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, cs.ctx, "Select") + ctx = setContextOp(ctx, cs.ctx, ent.OpQuerySelect) if err := cs.prepareQuery(ctx); err != nil { return err } diff --git a/ent/comment_update.go b/ent/comment_update.go index 3e09796d..81033aad 100644 --- a/ent/comment_update.go +++ b/ent/comment_update.go @@ -37,6 +37,14 @@ func (cu *CommentUpdate) SetComment(s string) *CommentUpdate { return cu } +// SetNillableComment sets the "comment" field if the given value is not nil. +func (cu *CommentUpdate) SetNillableComment(s *string) *CommentUpdate { + if s != nil { + cu.SetComment(*s) + } + return cu +} + // SetCreatedAt sets the "created_at" field. func (cu *CommentUpdate) SetCreatedAt(t time.Time) *CommentUpdate { cu.mutation.SetCreatedAt(t) @@ -119,7 +127,7 @@ func (cu *CommentUpdate) ClearUser() *CommentUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (cu *CommentUpdate) Save(ctx context.Context) (int, error) { cu.defaults() - return withHooks[int, CommentMutation](ctx, cu.sqlSave, cu.mutation, cu.hooks) + return withHooks(ctx, cu.sqlSave, cu.mutation, cu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -154,10 +162,10 @@ func (cu *CommentUpdate) defaults() { // check runs all checks and user-defined validators on the builder. func (cu *CommentUpdate) check() error { - if _, ok := cu.mutation.RequestID(); cu.mutation.RequestCleared() && !ok { + if cu.mutation.RequestCleared() && len(cu.mutation.RequestIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Comment.request"`) } - if _, ok := cu.mutation.UserID(); cu.mutation.UserCleared() && !ok { + if cu.mutation.UserCleared() && len(cu.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Comment.user"`) } return nil @@ -198,10 +206,7 @@ func (cu *CommentUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{comment.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -214,10 +219,7 @@ func (cu *CommentUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{comment.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -233,10 +235,7 @@ func (cu *CommentUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{comment.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -249,10 +248,7 @@ func (cu *CommentUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{comment.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -286,6 +282,14 @@ func (cuo *CommentUpdateOne) SetComment(s string) *CommentUpdateOne { return cuo } +// SetNillableComment sets the "comment" field if the given value is not nil. +func (cuo *CommentUpdateOne) SetNillableComment(s *string) *CommentUpdateOne { + if s != nil { + cuo.SetComment(*s) + } + return cuo +} + // SetCreatedAt sets the "created_at" field. func (cuo *CommentUpdateOne) SetCreatedAt(t time.Time) *CommentUpdateOne { cuo.mutation.SetCreatedAt(t) @@ -381,7 +385,7 @@ func (cuo *CommentUpdateOne) Select(field string, fields ...string) *CommentUpda // Save executes the query and returns the updated Comment entity. func (cuo *CommentUpdateOne) Save(ctx context.Context) (*Comment, error) { cuo.defaults() - return withHooks[*Comment, CommentMutation](ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) + return withHooks(ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -416,10 +420,10 @@ func (cuo *CommentUpdateOne) defaults() { // check runs all checks and user-defined validators on the builder. func (cuo *CommentUpdateOne) check() error { - if _, ok := cuo.mutation.RequestID(); cuo.mutation.RequestCleared() && !ok { + if cuo.mutation.RequestCleared() && len(cuo.mutation.RequestIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Comment.request"`) } - if _, ok := cuo.mutation.UserID(); cuo.mutation.UserCleared() && !ok { + if cuo.mutation.UserCleared() && len(cuo.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Comment.user"`) } return nil @@ -477,10 +481,7 @@ func (cuo *CommentUpdateOne) sqlSave(ctx context.Context) (_node *Comment, err e Columns: []string{comment.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -493,10 +494,7 @@ func (cuo *CommentUpdateOne) sqlSave(ctx context.Context) (_node *Comment, err e Columns: []string{comment.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -512,10 +510,7 @@ func (cuo *CommentUpdateOne) sqlSave(ctx context.Context) (_node *Comment, err e Columns: []string{comment.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -528,10 +523,7 @@ func (cuo *CommentUpdateOne) sqlSave(ctx context.Context) (_node *Comment, err e Columns: []string{comment.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/ent.go b/ent/ent.go index 83db7ea2..66cc8996 100644 --- a/ent/ent.go +++ b/ent/ent.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "reflect" + "sync" "entgo.io/ent" "entgo.io/ent/dialect/sql" @@ -70,43 +71,39 @@ func NewTxContext(parent context.Context, tx *Tx) context.Context { } // OrderFunc applies an ordering on the sql selector. +// Deprecated: Use Asc/Desc functions or the package builders instead. type OrderFunc func(*sql.Selector) -// columnChecker returns a function indicates if the column exists in the given column. -func columnChecker(table string) func(string) error { - checks := map[string]func(string) bool{ - comment.Table: comment.ValidColumn, - file.Table: file.ValidColumn, - group.Table: group.ValidColumn, - groupbudget.Table: groupbudget.ValidColumn, - request.Table: request.ValidColumn, - requeststatus.Table: requeststatus.ValidColumn, - requesttarget.Table: requesttarget.ValidColumn, - tag.Table: tag.ValidColumn, - transaction.Table: transaction.ValidColumn, - transactiondetail.Table: transactiondetail.ValidColumn, - user.Table: user.ValidColumn, - } - check, ok := checks[table] - if !ok { - return func(string) error { - return fmt.Errorf("unknown table %q", table) - } - } - return func(column string) error { - if !check(column) { - return fmt.Errorf("unknown column %q for table %q", column, table) - } - return nil - } +var ( + initCheck sync.Once + columnCheck sql.ColumnCheck +) + +// checkColumn checks if the column exists in the given table. +func checkColumn(table, column string) error { + initCheck.Do(func() { + columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ + comment.Table: comment.ValidColumn, + file.Table: file.ValidColumn, + group.Table: group.ValidColumn, + groupbudget.Table: groupbudget.ValidColumn, + request.Table: request.ValidColumn, + requeststatus.Table: requeststatus.ValidColumn, + requesttarget.Table: requesttarget.ValidColumn, + tag.Table: tag.ValidColumn, + transaction.Table: transaction.ValidColumn, + transactiondetail.Table: transactiondetail.ValidColumn, + user.Table: user.ValidColumn, + }) + }) + return columnCheck(table, column) } // Asc applies the given fields in ASC order. -func Asc(fields ...string) OrderFunc { +func Asc(fields ...string) func(*sql.Selector) { return func(s *sql.Selector) { - check := columnChecker(s.TableName()) for _, f := range fields { - if err := check(f); err != nil { + if err := checkColumn(s.TableName(), f); err != nil { s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) } s.OrderBy(sql.Asc(s.C(f))) @@ -115,11 +112,10 @@ func Asc(fields ...string) OrderFunc { } // Desc applies the given fields in DESC order. -func Desc(fields ...string) OrderFunc { +func Desc(fields ...string) func(*sql.Selector) { return func(s *sql.Selector) { - check := columnChecker(s.TableName()) for _, f := range fields { - if err := check(f); err != nil { + if err := checkColumn(s.TableName(), f); err != nil { s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) } s.OrderBy(sql.Desc(s.C(f))) @@ -151,8 +147,7 @@ func Count() AggregateFunc { // Max applies the "max" aggregation function on the given field of each group. func Max(field string) AggregateFunc { return func(s *sql.Selector) string { - check := columnChecker(s.TableName()) - if err := check(field); err != nil { + if err := checkColumn(s.TableName(), field); err != nil { s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) return "" } @@ -163,8 +158,7 @@ func Max(field string) AggregateFunc { // Mean applies the "mean" aggregation function on the given field of each group. func Mean(field string) AggregateFunc { return func(s *sql.Selector) string { - check := columnChecker(s.TableName()) - if err := check(field); err != nil { + if err := checkColumn(s.TableName(), field); err != nil { s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) return "" } @@ -175,8 +169,7 @@ func Mean(field string) AggregateFunc { // Min applies the "min" aggregation function on the given field of each group. func Min(field string) AggregateFunc { return func(s *sql.Selector) string { - check := columnChecker(s.TableName()) - if err := check(field); err != nil { + if err := checkColumn(s.TableName(), field); err != nil { s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) return "" } @@ -187,8 +180,7 @@ func Min(field string) AggregateFunc { // Sum applies the "sum" aggregation function on the given field of each group. func Sum(field string) AggregateFunc { return func(s *sql.Selector) string { - check := columnChecker(s.TableName()) - if err := check(field); err != nil { + if err := checkColumn(s.TableName(), field); err != nil { s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) return "" } @@ -525,7 +517,7 @@ func withHooks[V Value, M any, PM interface { return exec(ctx) } var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutationT, ok := m.(PM) + mutationT, ok := any(m).(PM) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } diff --git a/ent/file.go b/ent/file.go index d4594796..40473a12 100644 --- a/ent/file.go +++ b/ent/file.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/file" @@ -32,6 +33,7 @@ type File struct { Edges FileEdges `json:"edges"` file_user *uuid.UUID request_file *uuid.UUID + selectValues sql.SelectValues } // FileEdges holds the relations/edges for other nodes in the graph. @@ -48,12 +50,10 @@ type FileEdges struct { // RequestOrErr returns the Request value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e FileEdges) RequestOrErr() (*Request, error) { - if e.loadedTypes[0] { - if e.Request == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: request.Label} - } + if e.Request != nil { return e.Request, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: request.Label} } return nil, &NotLoadedError{edge: "request"} } @@ -61,12 +61,10 @@ func (e FileEdges) RequestOrErr() (*Request, error) { // UserOrErr returns the User value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e FileEdges) UserOrErr() (*User, error) { - if e.loadedTypes[1] { - if e.User == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: user.Label} - } + if e.User != nil { return e.User, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: user.Label} } return nil, &NotLoadedError{edge: "user"} } @@ -87,7 +85,7 @@ func (*File) scanValues(columns []string) ([]any, error) { case file.ForeignKeys[1]: // request_file values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: - return nil, fmt.Errorf("unexpected column %q for type File", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -146,11 +144,19 @@ func (f *File) assignValues(columns []string, values []any) error { f.request_file = new(uuid.UUID) *f.request_file = *value.S.(*uuid.UUID) } + default: + f.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the File. +// This includes values selected through modifiers, order, etc. +func (f *File) Value(name string) (ent.Value, error) { + return f.selectValues.Get(name) +} + // QueryRequest queries the "request" edge of the File entity. func (f *File) QueryRequest() *RequestQuery { return NewFileClient(f.config).QueryRequest(f) diff --git a/ent/file/file.go b/ent/file/file.go index 70ed49da..afcddad1 100644 --- a/ent/file/file.go +++ b/ent/file/file.go @@ -5,6 +5,8 @@ package file import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -82,3 +84,59 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the File queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByMimeType orders the results by the mime_type field. +func ByMimeType(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldMimeType, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByDeletedAt orders the results by the deleted_at field. +func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() +} + +// ByRequestField orders the results by request field. +func ByRequestField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStep(), sql.OrderByField(field, opts...)) + } +} + +// ByUserField orders the results by user field. +func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...)) + } +} +func newRequestStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), + ) +} +func newUserStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(UserInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), + ) +} diff --git a/ent/file/where.go b/ent/file/where.go index e2ae3eba..5f512919 100644 --- a/ent/file/where.go +++ b/ent/file/where.go @@ -310,11 +310,7 @@ func HasRequest() predicate.File { // HasRequestWith applies the HasEdge predicate on the "request" edge with a given conditions (other predicates). func HasRequestWith(preds ...predicate.Request) predicate.File { return predicate.File(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), - ) + step := newRequestStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -337,11 +333,7 @@ func HasUser() predicate.File { // HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates). func HasUserWith(preds ...predicate.User) predicate.File { return predicate.File(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(UserInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), - ) + step := newUserStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -352,32 +344,15 @@ func HasUserWith(preds ...predicate.User) predicate.File { // And groups predicates with the AND operator between them. func And(predicates ...predicate.File) predicate.File { - return predicate.File(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.File(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.File) predicate.File { - return predicate.File(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.File(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.File) predicate.File { - return predicate.File(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.File(sql.NotPredicates(p)) } diff --git a/ent/file_create.go b/ent/file_create.go index 13a60867..fcd0b5f1 100644 --- a/ent/file_create.go +++ b/ent/file_create.go @@ -115,7 +115,7 @@ func (fc *FileCreate) Mutation() *FileMutation { // Save creates the File in the database. func (fc *FileCreate) Save(ctx context.Context) (*File, error) { fc.defaults() - return withHooks[*File, FileMutation](ctx, fc.sqlSave, fc.mutation, fc.hooks) + return withHooks(ctx, fc.sqlSave, fc.mutation, fc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -168,7 +168,7 @@ func (fc *FileCreate) check() error { if _, ok := fc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "File.created_at"`)} } - if _, ok := fc.mutation.UserID(); !ok { + if len(fc.mutation.UserIDs()) == 0 { return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "File.user"`)} } return nil @@ -230,10 +230,7 @@ func (fc *FileCreate) createSpec() (*File, *sqlgraph.CreateSpec) { Columns: []string{file.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -250,10 +247,7 @@ func (fc *FileCreate) createSpec() (*File, *sqlgraph.CreateSpec) { Columns: []string{file.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -268,11 +262,15 @@ func (fc *FileCreate) createSpec() (*File, *sqlgraph.CreateSpec) { // FileCreateBulk is the builder for creating many File entities in bulk. type FileCreateBulk struct { config + err error builders []*FileCreate } // Save creates the File entities in the database. func (fcb *FileCreateBulk) Save(ctx context.Context) ([]*File, error) { + if fcb.err != nil { + return nil, fcb.err + } specs := make([]*sqlgraph.CreateSpec, len(fcb.builders)) nodes := make([]*File, len(fcb.builders)) mutators := make([]Mutator, len(fcb.builders)) @@ -289,8 +287,8 @@ func (fcb *FileCreateBulk) Save(ctx context.Context) ([]*File, error) { return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, fcb.builders[i+1].mutation) } else { diff --git a/ent/file_delete.go b/ent/file_delete.go index ee248650..d9ac5486 100644 --- a/ent/file_delete.go +++ b/ent/file_delete.go @@ -27,7 +27,7 @@ func (fd *FileDelete) Where(ps ...predicate.File) *FileDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (fd *FileDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, FileMutation](ctx, fd.sqlExec, fd.mutation, fd.hooks) + return withHooks(ctx, fd.sqlExec, fd.mutation, fd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/file_query.go b/ent/file_query.go index 2ee9dc17..8bec1e1a 100644 --- a/ent/file_query.go +++ b/ent/file_query.go @@ -7,6 +7,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -21,7 +22,7 @@ import ( type FileQuery struct { config ctx *QueryContext - order []OrderFunc + order []file.OrderOption inters []Interceptor predicates []predicate.File withRequest *RequestQuery @@ -58,7 +59,7 @@ func (fq *FileQuery) Unique(unique bool) *FileQuery { } // Order specifies how the records should be ordered. -func (fq *FileQuery) Order(o ...OrderFunc) *FileQuery { +func (fq *FileQuery) Order(o ...file.OrderOption) *FileQuery { fq.order = append(fq.order, o...) return fq } @@ -110,7 +111,7 @@ func (fq *FileQuery) QueryUser() *UserQuery { // First returns the first File entity from the query. // Returns a *NotFoundError when no File was found. func (fq *FileQuery) First(ctx context.Context) (*File, error) { - nodes, err := fq.Limit(1).All(setContextOp(ctx, fq.ctx, "First")) + nodes, err := fq.Limit(1).All(setContextOp(ctx, fq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -133,7 +134,7 @@ func (fq *FileQuery) FirstX(ctx context.Context) *File { // Returns a *NotFoundError when no File ID was found. func (fq *FileQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = fq.Limit(1).IDs(setContextOp(ctx, fq.ctx, "FirstID")); err != nil { + if ids, err = fq.Limit(1).IDs(setContextOp(ctx, fq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -156,7 +157,7 @@ func (fq *FileQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one File entity is found. // Returns a *NotFoundError when no File entities are found. func (fq *FileQuery) Only(ctx context.Context) (*File, error) { - nodes, err := fq.Limit(2).All(setContextOp(ctx, fq.ctx, "Only")) + nodes, err := fq.Limit(2).All(setContextOp(ctx, fq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -184,7 +185,7 @@ func (fq *FileQuery) OnlyX(ctx context.Context) *File { // Returns a *NotFoundError when no entities are found. func (fq *FileQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = fq.Limit(2).IDs(setContextOp(ctx, fq.ctx, "OnlyID")); err != nil { + if ids, err = fq.Limit(2).IDs(setContextOp(ctx, fq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -209,7 +210,7 @@ func (fq *FileQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Files. func (fq *FileQuery) All(ctx context.Context) ([]*File, error) { - ctx = setContextOp(ctx, fq.ctx, "All") + ctx = setContextOp(ctx, fq.ctx, ent.OpQueryAll) if err := fq.prepareQuery(ctx); err != nil { return nil, err } @@ -231,7 +232,7 @@ func (fq *FileQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if fq.ctx.Unique == nil && fq.path != nil { fq.Unique(true) } - ctx = setContextOp(ctx, fq.ctx, "IDs") + ctx = setContextOp(ctx, fq.ctx, ent.OpQueryIDs) if err = fq.Select(file.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -249,7 +250,7 @@ func (fq *FileQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (fq *FileQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, fq.ctx, "Count") + ctx = setContextOp(ctx, fq.ctx, ent.OpQueryCount) if err := fq.prepareQuery(ctx); err != nil { return 0, err } @@ -267,7 +268,7 @@ func (fq *FileQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (fq *FileQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, fq.ctx, "Exist") + ctx = setContextOp(ctx, fq.ctx, ent.OpQueryExist) switch _, err := fq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -296,7 +297,7 @@ func (fq *FileQuery) Clone() *FileQuery { return &FileQuery{ config: fq.config, ctx: fq.ctx.Clone(), - order: append([]OrderFunc{}, fq.order...), + order: append([]file.OrderOption{}, fq.order...), inters: append([]Interceptor{}, fq.inters...), predicates: append([]predicate.File{}, fq.predicates...), withRequest: fq.withRequest.Clone(), @@ -612,7 +613,7 @@ func (fgb *FileGroupBy) Aggregate(fns ...AggregateFunc) *FileGroupBy { // Scan applies the selector query and scans the result into the given value. func (fgb *FileGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, fgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, fgb.build.ctx, ent.OpQueryGroupBy) if err := fgb.build.prepareQuery(ctx); err != nil { return err } @@ -660,7 +661,7 @@ func (fs *FileSelect) Aggregate(fns ...AggregateFunc) *FileSelect { // Scan applies the selector query and scans the result into the given value. func (fs *FileSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, fs.ctx, "Select") + ctx = setContextOp(ctx, fs.ctx, ent.OpQuerySelect) if err := fs.prepareQuery(ctx); err != nil { return err } diff --git a/ent/file_update.go b/ent/file_update.go index 30267e44..ef42d01a 100644 --- a/ent/file_update.go +++ b/ent/file_update.go @@ -37,12 +37,28 @@ func (fu *FileUpdate) SetName(s string) *FileUpdate { return fu } +// SetNillableName sets the "name" field if the given value is not nil. +func (fu *FileUpdate) SetNillableName(s *string) *FileUpdate { + if s != nil { + fu.SetName(*s) + } + return fu +} + // SetMimeType sets the "mime_type" field. func (fu *FileUpdate) SetMimeType(s string) *FileUpdate { fu.mutation.SetMimeType(s) return fu } +// SetNillableMimeType sets the "mime_type" field if the given value is not nil. +func (fu *FileUpdate) SetNillableMimeType(s *string) *FileUpdate { + if s != nil { + fu.SetMimeType(*s) + } + return fu +} + // SetCreatedAt sets the "created_at" field. func (fu *FileUpdate) SetCreatedAt(t time.Time) *FileUpdate { fu.mutation.SetCreatedAt(t) @@ -126,7 +142,7 @@ func (fu *FileUpdate) ClearUser() *FileUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (fu *FileUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, FileMutation](ctx, fu.sqlSave, fu.mutation, fu.hooks) + return withHooks(ctx, fu.sqlSave, fu.mutation, fu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -158,7 +174,7 @@ func (fu *FileUpdate) check() error { return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "File.name": %w`, err)} } } - if _, ok := fu.mutation.UserID(); fu.mutation.UserCleared() && !ok { + if fu.mutation.UserCleared() && len(fu.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "File.user"`) } return nil @@ -199,10 +215,7 @@ func (fu *FileUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{file.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -215,10 +228,7 @@ func (fu *FileUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{file.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -234,10 +244,7 @@ func (fu *FileUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{file.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -250,10 +257,7 @@ func (fu *FileUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{file.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -287,12 +291,28 @@ func (fuo *FileUpdateOne) SetName(s string) *FileUpdateOne { return fuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (fuo *FileUpdateOne) SetNillableName(s *string) *FileUpdateOne { + if s != nil { + fuo.SetName(*s) + } + return fuo +} + // SetMimeType sets the "mime_type" field. func (fuo *FileUpdateOne) SetMimeType(s string) *FileUpdateOne { fuo.mutation.SetMimeType(s) return fuo } +// SetNillableMimeType sets the "mime_type" field if the given value is not nil. +func (fuo *FileUpdateOne) SetNillableMimeType(s *string) *FileUpdateOne { + if s != nil { + fuo.SetMimeType(*s) + } + return fuo +} + // SetCreatedAt sets the "created_at" field. func (fuo *FileUpdateOne) SetCreatedAt(t time.Time) *FileUpdateOne { fuo.mutation.SetCreatedAt(t) @@ -389,7 +409,7 @@ func (fuo *FileUpdateOne) Select(field string, fields ...string) *FileUpdateOne // Save executes the query and returns the updated File entity. func (fuo *FileUpdateOne) Save(ctx context.Context) (*File, error) { - return withHooks[*File, FileMutation](ctx, fuo.sqlSave, fuo.mutation, fuo.hooks) + return withHooks(ctx, fuo.sqlSave, fuo.mutation, fuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -421,7 +441,7 @@ func (fuo *FileUpdateOne) check() error { return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "File.name": %w`, err)} } } - if _, ok := fuo.mutation.UserID(); fuo.mutation.UserCleared() && !ok { + if fuo.mutation.UserCleared() && len(fuo.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "File.user"`) } return nil @@ -479,10 +499,7 @@ func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (_node *File, err error) Columns: []string{file.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -495,10 +512,7 @@ func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (_node *File, err error) Columns: []string{file.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -514,10 +528,7 @@ func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (_node *File, err error) Columns: []string{file.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -530,10 +541,7 @@ func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (_node *File, err error) Columns: []string{file.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/group.go b/ent/group.go index 059d8f46..f8d15da2 100644 --- a/ent/group.go +++ b/ent/group.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/group" @@ -31,7 +32,8 @@ type Group struct { DeletedAt *time.Time `json:"deleted_at,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the GroupQuery when eager-loading is set. - Edges GroupEdges `json:"edges"` + Edges GroupEdges `json:"edges"` + selectValues sql.SelectValues } // GroupEdges holds the relations/edges for other nodes in the graph. @@ -99,7 +101,7 @@ func (*Group) scanValues(columns []string) ([]any, error) { case group.FieldID: values[i] = new(uuid.UUID) default: - return nil, fmt.Errorf("unexpected column %q for type Group", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -157,11 +159,19 @@ func (gr *Group) assignValues(columns []string, values []any) error { gr.DeletedAt = new(time.Time) *gr.DeletedAt = value.Time } + default: + gr.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the Group. +// This includes values selected through modifiers, order, etc. +func (gr *Group) Value(name string) (ent.Value, error) { + return gr.selectValues.Get(name) +} + // QueryGroupBudget queries the "group_budget" edge of the Group entity. func (gr *Group) QueryGroupBudget() *GroupBudgetQuery { return NewGroupClient(gr.config).QueryGroupBudget(gr) diff --git a/ent/group/group.go b/ent/group/group.go index 52e5cef3..f836cd5f 100644 --- a/ent/group/group.go +++ b/ent/group/group.go @@ -5,6 +5,8 @@ package group import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -103,3 +105,125 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the Group queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByDescription orders the results by the description field. +func ByDescription(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDescription, opts...).ToFunc() +} + +// ByBudget orders the results by the budget field. +func ByBudget(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldBudget, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByDeletedAt orders the results by the deleted_at field. +func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() +} + +// ByGroupBudgetCount orders the results by group_budget count. +func ByGroupBudgetCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newGroupBudgetStep(), opts...) + } +} + +// ByGroupBudget orders the results by group_budget terms. +func ByGroupBudget(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newGroupBudgetStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByUserCount orders the results by user count. +func ByUserCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newUserStep(), opts...) + } +} + +// ByUser orders the results by user terms. +func ByUser(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newUserStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByOwnerCount orders the results by owner count. +func ByOwnerCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newOwnerStep(), opts...) + } +} + +// ByOwner orders the results by owner terms. +func ByOwner(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newOwnerStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByRequestCount orders the results by request count. +func ByRequestCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newRequestStep(), opts...) + } +} + +// ByRequest orders the results by request terms. +func ByRequest(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newGroupBudgetStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(GroupBudgetInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, GroupBudgetTable, GroupBudgetColumn), + ) +} +func newUserStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(UserInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, UserTable, UserPrimaryKey...), + ) +} +func newOwnerStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(OwnerInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, OwnerTable, OwnerPrimaryKey...), + ) +} +func newRequestStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, RequestTable, RequestColumn), + ) +} diff --git a/ent/group/where.go b/ent/group/where.go index 4eb89bc1..dc7fa48a 100644 --- a/ent/group/where.go +++ b/ent/group/where.go @@ -410,11 +410,7 @@ func HasGroupBudget() predicate.Group { // HasGroupBudgetWith applies the HasEdge predicate on the "group_budget" edge with a given conditions (other predicates). func HasGroupBudgetWith(preds ...predicate.GroupBudget) predicate.Group { return predicate.Group(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupBudgetInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, GroupBudgetTable, GroupBudgetColumn), - ) + step := newGroupBudgetStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -437,11 +433,7 @@ func HasUser() predicate.Group { // HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates). func HasUserWith(preds ...predicate.User) predicate.Group { return predicate.Group(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(UserInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, UserTable, UserPrimaryKey...), - ) + step := newUserStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -464,11 +456,7 @@ func HasOwner() predicate.Group { // HasOwnerWith applies the HasEdge predicate on the "owner" edge with a given conditions (other predicates). func HasOwnerWith(preds ...predicate.User) predicate.Group { return predicate.Group(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(OwnerInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, OwnerTable, OwnerPrimaryKey...), - ) + step := newOwnerStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -491,11 +479,7 @@ func HasRequest() predicate.Group { // HasRequestWith applies the HasEdge predicate on the "request" edge with a given conditions (other predicates). func HasRequestWith(preds ...predicate.Request) predicate.Group { return predicate.Group(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, RequestTable, RequestColumn), - ) + step := newRequestStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -506,32 +490,15 @@ func HasRequestWith(preds ...predicate.Request) predicate.Group { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Group(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Group(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Group(sql.NotPredicates(p)) } diff --git a/ent/group_create.go b/ent/group_create.go index e739620a..fe6b778c 100644 --- a/ent/group_create.go +++ b/ent/group_create.go @@ -174,7 +174,7 @@ func (gc *GroupCreate) Mutation() *GroupMutation { // Save creates the Group in the database. func (gc *GroupCreate) Save(ctx context.Context) (*Group, error) { gc.defaults() - return withHooks[*Group, GroupMutation](ctx, gc.sqlSave, gc.mutation, gc.hooks) + return withHooks(ctx, gc.sqlSave, gc.mutation, gc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -301,10 +301,7 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { Columns: []string{group.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -320,10 +317,7 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { Columns: group.UserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -339,10 +333,7 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { Columns: group.OwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -358,10 +349,7 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { Columns: []string{group.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -375,11 +363,15 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { // GroupCreateBulk is the builder for creating many Group entities in bulk. type GroupCreateBulk struct { config + err error builders []*GroupCreate } // Save creates the Group entities in the database. func (gcb *GroupCreateBulk) Save(ctx context.Context) ([]*Group, error) { + if gcb.err != nil { + return nil, gcb.err + } specs := make([]*sqlgraph.CreateSpec, len(gcb.builders)) nodes := make([]*Group, len(gcb.builders)) mutators := make([]Mutator, len(gcb.builders)) @@ -396,8 +388,8 @@ func (gcb *GroupCreateBulk) Save(ctx context.Context) ([]*Group, error) { return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, gcb.builders[i+1].mutation) } else { diff --git a/ent/group_delete.go b/ent/group_delete.go index 64f73624..50655ab3 100644 --- a/ent/group_delete.go +++ b/ent/group_delete.go @@ -27,7 +27,7 @@ func (gd *GroupDelete) Where(ps ...predicate.Group) *GroupDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (gd *GroupDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, GroupMutation](ctx, gd.sqlExec, gd.mutation, gd.hooks) + return withHooks(ctx, gd.sqlExec, gd.mutation, gd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/group_query.go b/ent/group_query.go index 111f95a2..8765b248 100644 --- a/ent/group_query.go +++ b/ent/group_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -23,7 +24,7 @@ import ( type GroupQuery struct { config ctx *QueryContext - order []OrderFunc + order []group.OrderOption inters []Interceptor predicates []predicate.Group withGroupBudget *GroupBudgetQuery @@ -61,7 +62,7 @@ func (gq *GroupQuery) Unique(unique bool) *GroupQuery { } // Order specifies how the records should be ordered. -func (gq *GroupQuery) Order(o ...OrderFunc) *GroupQuery { +func (gq *GroupQuery) Order(o ...group.OrderOption) *GroupQuery { gq.order = append(gq.order, o...) return gq } @@ -157,7 +158,7 @@ func (gq *GroupQuery) QueryRequest() *RequestQuery { // First returns the first Group entity from the query. // Returns a *NotFoundError when no Group was found. func (gq *GroupQuery) First(ctx context.Context) (*Group, error) { - nodes, err := gq.Limit(1).All(setContextOp(ctx, gq.ctx, "First")) + nodes, err := gq.Limit(1).All(setContextOp(ctx, gq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -180,7 +181,7 @@ func (gq *GroupQuery) FirstX(ctx context.Context) *Group { // Returns a *NotFoundError when no Group ID was found. func (gq *GroupQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = gq.Limit(1).IDs(setContextOp(ctx, gq.ctx, "FirstID")); err != nil { + if ids, err = gq.Limit(1).IDs(setContextOp(ctx, gq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -203,7 +204,7 @@ func (gq *GroupQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Group entity is found. // Returns a *NotFoundError when no Group entities are found. func (gq *GroupQuery) Only(ctx context.Context) (*Group, error) { - nodes, err := gq.Limit(2).All(setContextOp(ctx, gq.ctx, "Only")) + nodes, err := gq.Limit(2).All(setContextOp(ctx, gq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -231,7 +232,7 @@ func (gq *GroupQuery) OnlyX(ctx context.Context) *Group { // Returns a *NotFoundError when no entities are found. func (gq *GroupQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = gq.Limit(2).IDs(setContextOp(ctx, gq.ctx, "OnlyID")); err != nil { + if ids, err = gq.Limit(2).IDs(setContextOp(ctx, gq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -256,7 +257,7 @@ func (gq *GroupQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Groups. func (gq *GroupQuery) All(ctx context.Context) ([]*Group, error) { - ctx = setContextOp(ctx, gq.ctx, "All") + ctx = setContextOp(ctx, gq.ctx, ent.OpQueryAll) if err := gq.prepareQuery(ctx); err != nil { return nil, err } @@ -278,7 +279,7 @@ func (gq *GroupQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if gq.ctx.Unique == nil && gq.path != nil { gq.Unique(true) } - ctx = setContextOp(ctx, gq.ctx, "IDs") + ctx = setContextOp(ctx, gq.ctx, ent.OpQueryIDs) if err = gq.Select(group.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -296,7 +297,7 @@ func (gq *GroupQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (gq *GroupQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, gq.ctx, "Count") + ctx = setContextOp(ctx, gq.ctx, ent.OpQueryCount) if err := gq.prepareQuery(ctx); err != nil { return 0, err } @@ -314,7 +315,7 @@ func (gq *GroupQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (gq *GroupQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, gq.ctx, "Exist") + ctx = setContextOp(ctx, gq.ctx, ent.OpQueryExist) switch _, err := gq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -343,7 +344,7 @@ func (gq *GroupQuery) Clone() *GroupQuery { return &GroupQuery{ config: gq.config, ctx: gq.ctx.Clone(), - order: append([]OrderFunc{}, gq.order...), + order: append([]group.OrderOption{}, gq.order...), inters: append([]Interceptor{}, gq.inters...), predicates: append([]predicate.Group{}, gq.predicates...), withGroupBudget: gq.withGroupBudget.Clone(), @@ -546,7 +547,7 @@ func (gq *GroupQuery) loadGroupBudget(ctx context.Context, query *GroupBudgetQue } query.withFKs = true query.Where(predicate.GroupBudget(func(s *sql.Selector) { - s.Where(sql.InValues(group.GroupBudgetColumn, fks...)) + s.Where(sql.InValues(s.C(group.GroupBudgetColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -559,7 +560,7 @@ func (gq *GroupQuery) loadGroupBudget(ctx context.Context, query *GroupBudgetQue } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "group_group_budget" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "group_group_budget" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -699,7 +700,7 @@ func (gq *GroupQuery) loadRequest(ctx context.Context, query *RequestQuery, node } query.withFKs = true query.Where(predicate.Request(func(s *sql.Selector) { - s.Where(sql.InValues(group.RequestColumn, fks...)) + s.Where(sql.InValues(s.C(group.RequestColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -712,7 +713,7 @@ func (gq *GroupQuery) loadRequest(ctx context.Context, query *RequestQuery, node } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "group_request" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "group_request" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -814,7 +815,7 @@ func (ggb *GroupGroupBy) Aggregate(fns ...AggregateFunc) *GroupGroupBy { // Scan applies the selector query and scans the result into the given value. func (ggb *GroupGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ggb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, ggb.build.ctx, ent.OpQueryGroupBy) if err := ggb.build.prepareQuery(ctx); err != nil { return err } @@ -862,7 +863,7 @@ func (gs *GroupSelect) Aggregate(fns ...AggregateFunc) *GroupSelect { // Scan applies the selector query and scans the result into the given value. func (gs *GroupSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, gs.ctx, "Select") + ctx = setContextOp(ctx, gs.ctx, ent.OpQuerySelect) if err := gs.prepareQuery(ctx); err != nil { return err } diff --git a/ent/group_update.go b/ent/group_update.go index b75e274a..9d7685fc 100644 --- a/ent/group_update.go +++ b/ent/group_update.go @@ -38,12 +38,28 @@ func (gu *GroupUpdate) SetName(s string) *GroupUpdate { return gu } +// SetNillableName sets the "name" field if the given value is not nil. +func (gu *GroupUpdate) SetNillableName(s *string) *GroupUpdate { + if s != nil { + gu.SetName(*s) + } + return gu +} + // SetDescription sets the "description" field. func (gu *GroupUpdate) SetDescription(s string) *GroupUpdate { gu.mutation.SetDescription(s) return gu } +// SetNillableDescription sets the "description" field if the given value is not nil. +func (gu *GroupUpdate) SetNillableDescription(s *string) *GroupUpdate { + if s != nil { + gu.SetDescription(*s) + } + return gu +} + // SetBudget sets the "budget" field. func (gu *GroupUpdate) SetBudget(i int) *GroupUpdate { gu.mutation.ResetBudget() @@ -263,7 +279,7 @@ func (gu *GroupUpdate) RemoveRequest(r ...*Request) *GroupUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (gu *GroupUpdate) Save(ctx context.Context) (int, error) { gu.defaults() - return withHooks[int, GroupMutation](ctx, gu.sqlSave, gu.mutation, gu.hooks) + return withHooks(ctx, gu.sqlSave, gu.mutation, gu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -353,10 +369,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{group.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -369,10 +382,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{group.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -388,10 +398,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{group.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -407,10 +414,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: group.UserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -423,10 +427,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: group.UserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -442,10 +443,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: group.UserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -461,10 +459,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: group.OwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -477,10 +472,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: group.OwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -496,10 +488,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: group.OwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -515,10 +504,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{group.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -531,10 +517,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{group.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -550,10 +533,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{group.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -587,12 +567,28 @@ func (guo *GroupUpdateOne) SetName(s string) *GroupUpdateOne { return guo } +// SetNillableName sets the "name" field if the given value is not nil. +func (guo *GroupUpdateOne) SetNillableName(s *string) *GroupUpdateOne { + if s != nil { + guo.SetName(*s) + } + return guo +} + // SetDescription sets the "description" field. func (guo *GroupUpdateOne) SetDescription(s string) *GroupUpdateOne { guo.mutation.SetDescription(s) return guo } +// SetNillableDescription sets the "description" field if the given value is not nil. +func (guo *GroupUpdateOne) SetNillableDescription(s *string) *GroupUpdateOne { + if s != nil { + guo.SetDescription(*s) + } + return guo +} + // SetBudget sets the "budget" field. func (guo *GroupUpdateOne) SetBudget(i int) *GroupUpdateOne { guo.mutation.ResetBudget() @@ -825,7 +821,7 @@ func (guo *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOn // Save executes the query and returns the updated Group entity. func (guo *GroupUpdateOne) Save(ctx context.Context) (*Group, error) { guo.defaults() - return withHooks[*Group, GroupMutation](ctx, guo.sqlSave, guo.mutation, guo.hooks) + return withHooks(ctx, guo.sqlSave, guo.mutation, guo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -932,10 +928,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: []string{group.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -948,10 +941,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: []string{group.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -967,10 +957,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: []string{group.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -986,10 +973,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: group.UserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1002,10 +986,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: group.UserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1021,10 +1002,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: group.UserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1040,10 +1018,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: group.OwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1056,10 +1031,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: group.OwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1075,10 +1047,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: group.OwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1094,10 +1063,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: []string{group.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1110,10 +1076,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: []string{group.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1129,10 +1092,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: []string{group.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/groupbudget.go b/ent/groupbudget.go index 4d869d05..f373dff0 100644 --- a/ent/groupbudget.go +++ b/ent/groupbudget.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/group" @@ -28,6 +29,7 @@ type GroupBudget struct { // The values are being populated by the GroupBudgetQuery when eager-loading is set. Edges GroupBudgetEdges `json:"edges"` group_group_budget *uuid.UUID + selectValues sql.SelectValues } // GroupBudgetEdges holds the relations/edges for other nodes in the graph. @@ -44,12 +46,10 @@ type GroupBudgetEdges struct { // GroupOrErr returns the Group value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e GroupBudgetEdges) GroupOrErr() (*Group, error) { - if e.loadedTypes[0] { - if e.Group == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: group.Label} - } + if e.Group != nil { return e.Group, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: group.Label} } return nil, &NotLoadedError{edge: "group"} } @@ -79,7 +79,7 @@ func (*GroupBudget) scanValues(columns []string) ([]any, error) { case groupbudget.ForeignKeys[0]: // group_group_budget values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: - return nil, fmt.Errorf("unexpected column %q for type GroupBudget", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -125,11 +125,19 @@ func (gb *GroupBudget) assignValues(columns []string, values []any) error { gb.group_group_budget = new(uuid.UUID) *gb.group_group_budget = *value.S.(*uuid.UUID) } + default: + gb.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the GroupBudget. +// This includes values selected through modifiers, order, etc. +func (gb *GroupBudget) Value(name string) (ent.Value, error) { + return gb.selectValues.Get(name) +} + // QueryGroup queries the "group" edge of the GroupBudget entity. func (gb *GroupBudget) QueryGroup() *GroupQuery { return NewGroupBudgetClient(gb.config).QueryGroup(gb) diff --git a/ent/groupbudget/groupbudget.go b/ent/groupbudget/groupbudget.go index 2fea902b..12d93201 100644 --- a/ent/groupbudget/groupbudget.go +++ b/ent/groupbudget/groupbudget.go @@ -5,6 +5,8 @@ package groupbudget import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -76,3 +78,61 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the GroupBudget queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByAmount orders the results by the amount field. +func ByAmount(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAmount, opts...).ToFunc() +} + +// ByComment orders the results by the comment field. +func ByComment(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldComment, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByGroupField orders the results by group field. +func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newGroupStep(), sql.OrderByField(field, opts...)) + } +} + +// ByTransactionCount orders the results by transaction count. +func ByTransactionCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTransactionStep(), opts...) + } +} + +// ByTransaction orders the results by transaction terms. +func ByTransaction(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTransactionStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newGroupStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(GroupInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), + ) +} +func newTransactionStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TransactionInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, TransactionTable, TransactionColumn), + ) +} diff --git a/ent/groupbudget/where.go b/ent/groupbudget/where.go index 67cc17d2..d2c63277 100644 --- a/ent/groupbudget/where.go +++ b/ent/groupbudget/where.go @@ -240,11 +240,7 @@ func HasGroup() predicate.GroupBudget { // HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates). func HasGroupWith(preds ...predicate.Group) predicate.GroupBudget { return predicate.GroupBudget(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), - ) + step := newGroupStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -267,11 +263,7 @@ func HasTransaction() predicate.GroupBudget { // HasTransactionWith applies the HasEdge predicate on the "transaction" edge with a given conditions (other predicates). func HasTransactionWith(preds ...predicate.Transaction) predicate.GroupBudget { return predicate.GroupBudget(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TransactionInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, TransactionTable, TransactionColumn), - ) + step := newTransactionStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -282,32 +274,15 @@ func HasTransactionWith(preds ...predicate.Transaction) predicate.GroupBudget { // And groups predicates with the AND operator between them. func And(predicates ...predicate.GroupBudget) predicate.GroupBudget { - return predicate.GroupBudget(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.GroupBudget(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.GroupBudget) predicate.GroupBudget { - return predicate.GroupBudget(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.GroupBudget(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.GroupBudget) predicate.GroupBudget { - return predicate.GroupBudget(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.GroupBudget(sql.NotPredicates(p)) } diff --git a/ent/groupbudget_create.go b/ent/groupbudget_create.go index 94f0fa95..fe88b38f 100644 --- a/ent/groupbudget_create.go +++ b/ent/groupbudget_create.go @@ -105,7 +105,7 @@ func (gbc *GroupBudgetCreate) Mutation() *GroupBudgetMutation { // Save creates the GroupBudget in the database. func (gbc *GroupBudgetCreate) Save(ctx context.Context) (*GroupBudget, error) { gbc.defaults() - return withHooks[*GroupBudget, GroupBudgetMutation](ctx, gbc.sqlSave, gbc.mutation, gbc.hooks) + return withHooks(ctx, gbc.sqlSave, gbc.mutation, gbc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -150,7 +150,7 @@ func (gbc *GroupBudgetCreate) check() error { if _, ok := gbc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "GroupBudget.created_at"`)} } - if _, ok := gbc.mutation.GroupID(); !ok { + if len(gbc.mutation.GroupIDs()) == 0 { return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "GroupBudget.group"`)} } return nil @@ -208,10 +208,7 @@ func (gbc *GroupBudgetCreate) createSpec() (*GroupBudget, *sqlgraph.CreateSpec) Columns: []string{groupbudget.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -228,10 +225,7 @@ func (gbc *GroupBudgetCreate) createSpec() (*GroupBudget, *sqlgraph.CreateSpec) Columns: []string{groupbudget.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -245,11 +239,15 @@ func (gbc *GroupBudgetCreate) createSpec() (*GroupBudget, *sqlgraph.CreateSpec) // GroupBudgetCreateBulk is the builder for creating many GroupBudget entities in bulk. type GroupBudgetCreateBulk struct { config + err error builders []*GroupBudgetCreate } // Save creates the GroupBudget entities in the database. func (gbcb *GroupBudgetCreateBulk) Save(ctx context.Context) ([]*GroupBudget, error) { + if gbcb.err != nil { + return nil, gbcb.err + } specs := make([]*sqlgraph.CreateSpec, len(gbcb.builders)) nodes := make([]*GroupBudget, len(gbcb.builders)) mutators := make([]Mutator, len(gbcb.builders)) @@ -266,8 +264,8 @@ func (gbcb *GroupBudgetCreateBulk) Save(ctx context.Context) ([]*GroupBudget, er return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, gbcb.builders[i+1].mutation) } else { diff --git a/ent/groupbudget_delete.go b/ent/groupbudget_delete.go index 6b95cf18..70842da9 100644 --- a/ent/groupbudget_delete.go +++ b/ent/groupbudget_delete.go @@ -27,7 +27,7 @@ func (gbd *GroupBudgetDelete) Where(ps ...predicate.GroupBudget) *GroupBudgetDel // Exec executes the deletion query and returns how many vertices were deleted. func (gbd *GroupBudgetDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, GroupBudgetMutation](ctx, gbd.sqlExec, gbd.mutation, gbd.hooks) + return withHooks(ctx, gbd.sqlExec, gbd.mutation, gbd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/groupbudget_query.go b/ent/groupbudget_query.go index 8b6e0cb1..dea30497 100644 --- a/ent/groupbudget_query.go +++ b/ent/groupbudget_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -22,7 +23,7 @@ import ( type GroupBudgetQuery struct { config ctx *QueryContext - order []OrderFunc + order []groupbudget.OrderOption inters []Interceptor predicates []predicate.GroupBudget withGroup *GroupQuery @@ -59,7 +60,7 @@ func (gbq *GroupBudgetQuery) Unique(unique bool) *GroupBudgetQuery { } // Order specifies how the records should be ordered. -func (gbq *GroupBudgetQuery) Order(o ...OrderFunc) *GroupBudgetQuery { +func (gbq *GroupBudgetQuery) Order(o ...groupbudget.OrderOption) *GroupBudgetQuery { gbq.order = append(gbq.order, o...) return gbq } @@ -111,7 +112,7 @@ func (gbq *GroupBudgetQuery) QueryTransaction() *TransactionQuery { // First returns the first GroupBudget entity from the query. // Returns a *NotFoundError when no GroupBudget was found. func (gbq *GroupBudgetQuery) First(ctx context.Context) (*GroupBudget, error) { - nodes, err := gbq.Limit(1).All(setContextOp(ctx, gbq.ctx, "First")) + nodes, err := gbq.Limit(1).All(setContextOp(ctx, gbq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -134,7 +135,7 @@ func (gbq *GroupBudgetQuery) FirstX(ctx context.Context) *GroupBudget { // Returns a *NotFoundError when no GroupBudget ID was found. func (gbq *GroupBudgetQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = gbq.Limit(1).IDs(setContextOp(ctx, gbq.ctx, "FirstID")); err != nil { + if ids, err = gbq.Limit(1).IDs(setContextOp(ctx, gbq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -157,7 +158,7 @@ func (gbq *GroupBudgetQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one GroupBudget entity is found. // Returns a *NotFoundError when no GroupBudget entities are found. func (gbq *GroupBudgetQuery) Only(ctx context.Context) (*GroupBudget, error) { - nodes, err := gbq.Limit(2).All(setContextOp(ctx, gbq.ctx, "Only")) + nodes, err := gbq.Limit(2).All(setContextOp(ctx, gbq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -185,7 +186,7 @@ func (gbq *GroupBudgetQuery) OnlyX(ctx context.Context) *GroupBudget { // Returns a *NotFoundError when no entities are found. func (gbq *GroupBudgetQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = gbq.Limit(2).IDs(setContextOp(ctx, gbq.ctx, "OnlyID")); err != nil { + if ids, err = gbq.Limit(2).IDs(setContextOp(ctx, gbq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -210,7 +211,7 @@ func (gbq *GroupBudgetQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of GroupBudgets. func (gbq *GroupBudgetQuery) All(ctx context.Context) ([]*GroupBudget, error) { - ctx = setContextOp(ctx, gbq.ctx, "All") + ctx = setContextOp(ctx, gbq.ctx, ent.OpQueryAll) if err := gbq.prepareQuery(ctx); err != nil { return nil, err } @@ -232,7 +233,7 @@ func (gbq *GroupBudgetQuery) IDs(ctx context.Context) (ids []uuid.UUID, err erro if gbq.ctx.Unique == nil && gbq.path != nil { gbq.Unique(true) } - ctx = setContextOp(ctx, gbq.ctx, "IDs") + ctx = setContextOp(ctx, gbq.ctx, ent.OpQueryIDs) if err = gbq.Select(groupbudget.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -250,7 +251,7 @@ func (gbq *GroupBudgetQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (gbq *GroupBudgetQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, gbq.ctx, "Count") + ctx = setContextOp(ctx, gbq.ctx, ent.OpQueryCount) if err := gbq.prepareQuery(ctx); err != nil { return 0, err } @@ -268,7 +269,7 @@ func (gbq *GroupBudgetQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (gbq *GroupBudgetQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, gbq.ctx, "Exist") + ctx = setContextOp(ctx, gbq.ctx, ent.OpQueryExist) switch _, err := gbq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -297,7 +298,7 @@ func (gbq *GroupBudgetQuery) Clone() *GroupBudgetQuery { return &GroupBudgetQuery{ config: gbq.config, ctx: gbq.ctx.Clone(), - order: append([]OrderFunc{}, gbq.order...), + order: append([]groupbudget.OrderOption{}, gbq.order...), inters: append([]Interceptor{}, gbq.inters...), predicates: append([]predicate.GroupBudget{}, gbq.predicates...), withGroup: gbq.withGroup.Clone(), @@ -498,7 +499,7 @@ func (gbq *GroupBudgetQuery) loadTransaction(ctx context.Context, query *Transac } query.withFKs = true query.Where(predicate.Transaction(func(s *sql.Selector) { - s.Where(sql.InValues(groupbudget.TransactionColumn, fks...)) + s.Where(sql.InValues(s.C(groupbudget.TransactionColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -511,7 +512,7 @@ func (gbq *GroupBudgetQuery) loadTransaction(ctx context.Context, query *Transac } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "group_budget_transaction" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "group_budget_transaction" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -613,7 +614,7 @@ func (gbgb *GroupBudgetGroupBy) Aggregate(fns ...AggregateFunc) *GroupBudgetGrou // Scan applies the selector query and scans the result into the given value. func (gbgb *GroupBudgetGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, gbgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, gbgb.build.ctx, ent.OpQueryGroupBy) if err := gbgb.build.prepareQuery(ctx); err != nil { return err } @@ -661,7 +662,7 @@ func (gbs *GroupBudgetSelect) Aggregate(fns ...AggregateFunc) *GroupBudgetSelect // Scan applies the selector query and scans the result into the given value. func (gbs *GroupBudgetSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, gbs.ctx, "Select") + ctx = setContextOp(ctx, gbs.ctx, ent.OpQuerySelect) if err := gbs.prepareQuery(ctx); err != nil { return err } diff --git a/ent/groupbudget_update.go b/ent/groupbudget_update.go index 901f1aa3..ef423c5e 100644 --- a/ent/groupbudget_update.go +++ b/ent/groupbudget_update.go @@ -38,6 +38,14 @@ func (gbu *GroupBudgetUpdate) SetAmount(i int) *GroupBudgetUpdate { return gbu } +// SetNillableAmount sets the "amount" field if the given value is not nil. +func (gbu *GroupBudgetUpdate) SetNillableAmount(i *int) *GroupBudgetUpdate { + if i != nil { + gbu.SetAmount(*i) + } + return gbu +} + // AddAmount adds i to the "amount" field. func (gbu *GroupBudgetUpdate) AddAmount(i int) *GroupBudgetUpdate { gbu.mutation.AddAmount(i) @@ -138,7 +146,7 @@ func (gbu *GroupBudgetUpdate) RemoveTransaction(t ...*Transaction) *GroupBudgetU // Save executes the query and returns the number of nodes affected by the update operation. func (gbu *GroupBudgetUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, GroupBudgetMutation](ctx, gbu.sqlSave, gbu.mutation, gbu.hooks) + return withHooks(ctx, gbu.sqlSave, gbu.mutation, gbu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -165,7 +173,7 @@ func (gbu *GroupBudgetUpdate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (gbu *GroupBudgetUpdate) check() error { - if _, ok := gbu.mutation.GroupID(); gbu.mutation.GroupCleared() && !ok { + if gbu.mutation.GroupCleared() && len(gbu.mutation.GroupIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "GroupBudget.group"`) } return nil @@ -206,10 +214,7 @@ func (gbu *GroupBudgetUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{groupbudget.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -222,10 +227,7 @@ func (gbu *GroupBudgetUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{groupbudget.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -241,10 +243,7 @@ func (gbu *GroupBudgetUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{groupbudget.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -257,10 +256,7 @@ func (gbu *GroupBudgetUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{groupbudget.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -276,10 +272,7 @@ func (gbu *GroupBudgetUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{groupbudget.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -314,6 +307,14 @@ func (gbuo *GroupBudgetUpdateOne) SetAmount(i int) *GroupBudgetUpdateOne { return gbuo } +// SetNillableAmount sets the "amount" field if the given value is not nil. +func (gbuo *GroupBudgetUpdateOne) SetNillableAmount(i *int) *GroupBudgetUpdateOne { + if i != nil { + gbuo.SetAmount(*i) + } + return gbuo +} + // AddAmount adds i to the "amount" field. func (gbuo *GroupBudgetUpdateOne) AddAmount(i int) *GroupBudgetUpdateOne { gbuo.mutation.AddAmount(i) @@ -427,7 +428,7 @@ func (gbuo *GroupBudgetUpdateOne) Select(field string, fields ...string) *GroupB // Save executes the query and returns the updated GroupBudget entity. func (gbuo *GroupBudgetUpdateOne) Save(ctx context.Context) (*GroupBudget, error) { - return withHooks[*GroupBudget, GroupBudgetMutation](ctx, gbuo.sqlSave, gbuo.mutation, gbuo.hooks) + return withHooks(ctx, gbuo.sqlSave, gbuo.mutation, gbuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -454,7 +455,7 @@ func (gbuo *GroupBudgetUpdateOne) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (gbuo *GroupBudgetUpdateOne) check() error { - if _, ok := gbuo.mutation.GroupID(); gbuo.mutation.GroupCleared() && !ok { + if gbuo.mutation.GroupCleared() && len(gbuo.mutation.GroupIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "GroupBudget.group"`) } return nil @@ -512,10 +513,7 @@ func (gbuo *GroupBudgetUpdateOne) sqlSave(ctx context.Context) (_node *GroupBudg Columns: []string{groupbudget.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -528,10 +526,7 @@ func (gbuo *GroupBudgetUpdateOne) sqlSave(ctx context.Context) (_node *GroupBudg Columns: []string{groupbudget.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -547,10 +542,7 @@ func (gbuo *GroupBudgetUpdateOne) sqlSave(ctx context.Context) (_node *GroupBudg Columns: []string{groupbudget.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -563,10 +555,7 @@ func (gbuo *GroupBudgetUpdateOne) sqlSave(ctx context.Context) (_node *GroupBudg Columns: []string{groupbudget.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -582,10 +571,7 @@ func (gbuo *GroupBudgetUpdateOne) sqlSave(ctx context.Context) (_node *GroupBudg Columns: []string{groupbudget.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/request.go b/ent/request.go index cb757486..46c6d442 100644 --- a/ent/request.go +++ b/ent/request.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/group" @@ -32,6 +33,7 @@ type Request struct { Edges RequestEdges `json:"edges"` group_request *uuid.UUID request_user *uuid.UUID + selectValues sql.SelectValues } // RequestEdges holds the relations/edges for other nodes in the graph. @@ -114,12 +116,10 @@ func (e RequestEdges) CommentOrErr() ([]*Comment, error) { // UserOrErr returns the User value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e RequestEdges) UserOrErr() (*User, error) { - if e.loadedTypes[6] { - if e.User == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: user.Label} - } + if e.User != nil { return e.User, nil + } else if e.loadedTypes[6] { + return nil, &NotFoundError{label: user.Label} } return nil, &NotLoadedError{edge: "user"} } @@ -127,12 +127,10 @@ func (e RequestEdges) UserOrErr() (*User, error) { // GroupOrErr returns the Group value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e RequestEdges) GroupOrErr() (*Group, error) { - if e.loadedTypes[7] { - if e.Group == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: group.Label} - } + if e.Group != nil { return e.Group, nil + } else if e.loadedTypes[7] { + return nil, &NotFoundError{label: group.Label} } return nil, &NotLoadedError{edge: "group"} } @@ -153,7 +151,7 @@ func (*Request) scanValues(columns []string) ([]any, error) { case request.ForeignKeys[1]: // request_user values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: - return nil, fmt.Errorf("unexpected column %q for type Request", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -211,11 +209,19 @@ func (r *Request) assignValues(columns []string, values []any) error { r.request_user = new(uuid.UUID) *r.request_user = *value.S.(*uuid.UUID) } + default: + r.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the Request. +// This includes values selected through modifiers, order, etc. +func (r *Request) Value(name string) (ent.Value, error) { + return r.selectValues.Get(name) +} + // QueryStatus queries the "status" edge of the Request entity. func (r *Request) QueryStatus() *RequestStatusQuery { return NewRequestClient(r.config).QueryStatus(r) diff --git a/ent/request/request.go b/ent/request/request.go index f8a9146a..00b7d712 100644 --- a/ent/request/request.go +++ b/ent/request/request.go @@ -5,6 +5,8 @@ package request import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -142,3 +144,185 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the Request queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByTitle orders the results by the title field. +func ByTitle(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldTitle, opts...).ToFunc() +} + +// ByContent orders the results by the content field. +func ByContent(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldContent, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByStatusCount orders the results by status count. +func ByStatusCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newStatusStep(), opts...) + } +} + +// ByStatus orders the results by status terms. +func ByStatus(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newStatusStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByTargetCount orders the results by target count. +func ByTargetCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTargetStep(), opts...) + } +} + +// ByTarget orders the results by target terms. +func ByTarget(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTargetStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByFileCount orders the results by file count. +func ByFileCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newFileStep(), opts...) + } +} + +// ByFile orders the results by file terms. +func ByFile(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newFileStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByTagCount orders the results by tag count. +func ByTagCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTagStep(), opts...) + } +} + +// ByTag orders the results by tag terms. +func ByTag(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTagStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByTransactionCount orders the results by transaction count. +func ByTransactionCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTransactionStep(), opts...) + } +} + +// ByTransaction orders the results by transaction terms. +func ByTransaction(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTransactionStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByCommentCount orders the results by comment count. +func ByCommentCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newCommentStep(), opts...) + } +} + +// ByComment orders the results by comment terms. +func ByComment(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newCommentStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByUserField orders the results by user field. +func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...)) + } +} + +// ByGroupField orders the results by group field. +func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newGroupStep(), sql.OrderByField(field, opts...)) + } +} +func newStatusStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(StatusInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, StatusTable, StatusColumn), + ) +} +func newTargetStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TargetInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, TargetTable, TargetColumn), + ) +} +func newFileStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(FileInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, FileTable, FileColumn), + ) +} +func newTagStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TagInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, TagTable, TagPrimaryKey...), + ) +} +func newTransactionStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TransactionInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, TransactionTable, TransactionColumn), + ) +} +func newCommentStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(CommentInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, CommentTable, CommentColumn), + ) +} +func newUserStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(UserInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), + ) +} +func newGroupStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(GroupInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), + ) +} diff --git a/ent/request/where.go b/ent/request/where.go index 73ed133b..240fb92b 100644 --- a/ent/request/where.go +++ b/ent/request/where.go @@ -300,11 +300,7 @@ func HasStatus() predicate.Request { // HasStatusWith applies the HasEdge predicate on the "status" edge with a given conditions (other predicates). func HasStatusWith(preds ...predicate.RequestStatus) predicate.Request { return predicate.Request(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(StatusInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, StatusTable, StatusColumn), - ) + step := newStatusStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -327,11 +323,7 @@ func HasTarget() predicate.Request { // HasTargetWith applies the HasEdge predicate on the "target" edge with a given conditions (other predicates). func HasTargetWith(preds ...predicate.RequestTarget) predicate.Request { return predicate.Request(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TargetInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, TargetTable, TargetColumn), - ) + step := newTargetStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -354,11 +346,7 @@ func HasFile() predicate.Request { // HasFileWith applies the HasEdge predicate on the "file" edge with a given conditions (other predicates). func HasFileWith(preds ...predicate.File) predicate.Request { return predicate.Request(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(FileInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, FileTable, FileColumn), - ) + step := newFileStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -381,11 +369,7 @@ func HasTag() predicate.Request { // HasTagWith applies the HasEdge predicate on the "tag" edge with a given conditions (other predicates). func HasTagWith(preds ...predicate.Tag) predicate.Request { return predicate.Request(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TagInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, TagTable, TagPrimaryKey...), - ) + step := newTagStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -408,11 +392,7 @@ func HasTransaction() predicate.Request { // HasTransactionWith applies the HasEdge predicate on the "transaction" edge with a given conditions (other predicates). func HasTransactionWith(preds ...predicate.Transaction) predicate.Request { return predicate.Request(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TransactionInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, TransactionTable, TransactionColumn), - ) + step := newTransactionStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -435,11 +415,7 @@ func HasComment() predicate.Request { // HasCommentWith applies the HasEdge predicate on the "comment" edge with a given conditions (other predicates). func HasCommentWith(preds ...predicate.Comment) predicate.Request { return predicate.Request(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(CommentInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, CommentTable, CommentColumn), - ) + step := newCommentStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -462,11 +438,7 @@ func HasUser() predicate.Request { // HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates). func HasUserWith(preds ...predicate.User) predicate.Request { return predicate.Request(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(UserInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), - ) + step := newUserStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -489,11 +461,7 @@ func HasGroup() predicate.Request { // HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates). func HasGroupWith(preds ...predicate.Group) predicate.Request { return predicate.Request(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), - ) + step := newGroupStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -504,32 +472,15 @@ func HasGroupWith(preds ...predicate.Group) predicate.Request { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Request) predicate.Request { - return predicate.Request(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Request(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Request) predicate.Request { - return predicate.Request(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Request(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Request) predicate.Request { - return predicate.Request(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Request(sql.NotPredicates(p)) } diff --git a/ent/request_create.go b/ent/request_create.go index 244bc526..bfb0c57a 100644 --- a/ent/request_create.go +++ b/ent/request_create.go @@ -219,7 +219,7 @@ func (rc *RequestCreate) Mutation() *RequestMutation { // Save creates the Request in the database. func (rc *RequestCreate) Save(ctx context.Context) (*Request, error) { rc.defaults() - return withHooks[*Request, RequestMutation](ctx, rc.sqlSave, rc.mutation, rc.hooks) + return withHooks(ctx, rc.sqlSave, rc.mutation, rc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -333,10 +333,7 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { Columns: []string{request.StatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -352,10 +349,7 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { Columns: []string{request.TargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -371,10 +365,7 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { Columns: []string{request.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -390,10 +381,7 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { Columns: request.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -409,10 +397,7 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { Columns: []string{request.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -428,10 +413,7 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { Columns: []string{request.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -447,10 +429,7 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { Columns: []string{request.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -467,10 +446,7 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { Columns: []string{request.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -485,11 +461,15 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { // RequestCreateBulk is the builder for creating many Request entities in bulk. type RequestCreateBulk struct { config + err error builders []*RequestCreate } // Save creates the Request entities in the database. func (rcb *RequestCreateBulk) Save(ctx context.Context) ([]*Request, error) { + if rcb.err != nil { + return nil, rcb.err + } specs := make([]*sqlgraph.CreateSpec, len(rcb.builders)) nodes := make([]*Request, len(rcb.builders)) mutators := make([]Mutator, len(rcb.builders)) @@ -506,8 +486,8 @@ func (rcb *RequestCreateBulk) Save(ctx context.Context) ([]*Request, error) { return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, rcb.builders[i+1].mutation) } else { diff --git a/ent/request_delete.go b/ent/request_delete.go index f0d5be3c..c49c508f 100644 --- a/ent/request_delete.go +++ b/ent/request_delete.go @@ -27,7 +27,7 @@ func (rd *RequestDelete) Where(ps ...predicate.Request) *RequestDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (rd *RequestDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, RequestMutation](ctx, rd.sqlExec, rd.mutation, rd.hooks) + return withHooks(ctx, rd.sqlExec, rd.mutation, rd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/request_query.go b/ent/request_query.go index 6954adba..73d29e75 100644 --- a/ent/request_query.go +++ b/ent/request_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -28,7 +29,7 @@ import ( type RequestQuery struct { config ctx *QueryContext - order []OrderFunc + order []request.OrderOption inters []Interceptor predicates []predicate.Request withStatus *RequestStatusQuery @@ -71,7 +72,7 @@ func (rq *RequestQuery) Unique(unique bool) *RequestQuery { } // Order specifies how the records should be ordered. -func (rq *RequestQuery) Order(o ...OrderFunc) *RequestQuery { +func (rq *RequestQuery) Order(o ...request.OrderOption) *RequestQuery { rq.order = append(rq.order, o...) return rq } @@ -255,7 +256,7 @@ func (rq *RequestQuery) QueryGroup() *GroupQuery { // First returns the first Request entity from the query. // Returns a *NotFoundError when no Request was found. func (rq *RequestQuery) First(ctx context.Context) (*Request, error) { - nodes, err := rq.Limit(1).All(setContextOp(ctx, rq.ctx, "First")) + nodes, err := rq.Limit(1).All(setContextOp(ctx, rq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -278,7 +279,7 @@ func (rq *RequestQuery) FirstX(ctx context.Context) *Request { // Returns a *NotFoundError when no Request ID was found. func (rq *RequestQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = rq.Limit(1).IDs(setContextOp(ctx, rq.ctx, "FirstID")); err != nil { + if ids, err = rq.Limit(1).IDs(setContextOp(ctx, rq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -301,7 +302,7 @@ func (rq *RequestQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Request entity is found. // Returns a *NotFoundError when no Request entities are found. func (rq *RequestQuery) Only(ctx context.Context) (*Request, error) { - nodes, err := rq.Limit(2).All(setContextOp(ctx, rq.ctx, "Only")) + nodes, err := rq.Limit(2).All(setContextOp(ctx, rq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -329,7 +330,7 @@ func (rq *RequestQuery) OnlyX(ctx context.Context) *Request { // Returns a *NotFoundError when no entities are found. func (rq *RequestQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = rq.Limit(2).IDs(setContextOp(ctx, rq.ctx, "OnlyID")); err != nil { + if ids, err = rq.Limit(2).IDs(setContextOp(ctx, rq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -354,7 +355,7 @@ func (rq *RequestQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Requests. func (rq *RequestQuery) All(ctx context.Context) ([]*Request, error) { - ctx = setContextOp(ctx, rq.ctx, "All") + ctx = setContextOp(ctx, rq.ctx, ent.OpQueryAll) if err := rq.prepareQuery(ctx); err != nil { return nil, err } @@ -376,7 +377,7 @@ func (rq *RequestQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if rq.ctx.Unique == nil && rq.path != nil { rq.Unique(true) } - ctx = setContextOp(ctx, rq.ctx, "IDs") + ctx = setContextOp(ctx, rq.ctx, ent.OpQueryIDs) if err = rq.Select(request.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -394,7 +395,7 @@ func (rq *RequestQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (rq *RequestQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, rq.ctx, "Count") + ctx = setContextOp(ctx, rq.ctx, ent.OpQueryCount) if err := rq.prepareQuery(ctx); err != nil { return 0, err } @@ -412,7 +413,7 @@ func (rq *RequestQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (rq *RequestQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, rq.ctx, "Exist") + ctx = setContextOp(ctx, rq.ctx, ent.OpQueryExist) switch _, err := rq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -441,7 +442,7 @@ func (rq *RequestQuery) Clone() *RequestQuery { return &RequestQuery{ config: rq.config, ctx: rq.ctx.Clone(), - order: append([]OrderFunc{}, rq.order...), + order: append([]request.OrderOption{}, rq.order...), inters: append([]Interceptor{}, rq.inters...), predicates: append([]predicate.Request{}, rq.predicates...), withStatus: rq.withStatus.Clone(), @@ -729,7 +730,7 @@ func (rq *RequestQuery) loadStatus(ctx context.Context, query *RequestStatusQuer } query.withFKs = true query.Where(predicate.RequestStatus(func(s *sql.Selector) { - s.Where(sql.InValues(request.StatusColumn, fks...)) + s.Where(sql.InValues(s.C(request.StatusColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -742,7 +743,7 @@ func (rq *RequestQuery) loadStatus(ctx context.Context, query *RequestStatusQuer } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "request_status" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "request_status" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -760,7 +761,7 @@ func (rq *RequestQuery) loadTarget(ctx context.Context, query *RequestTargetQuer } query.withFKs = true query.Where(predicate.RequestTarget(func(s *sql.Selector) { - s.Where(sql.InValues(request.TargetColumn, fks...)) + s.Where(sql.InValues(s.C(request.TargetColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -773,7 +774,7 @@ func (rq *RequestQuery) loadTarget(ctx context.Context, query *RequestTargetQuer } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "request_target" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "request_target" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -791,7 +792,7 @@ func (rq *RequestQuery) loadFile(ctx context.Context, query *FileQuery, nodes [] } query.withFKs = true query.Where(predicate.File(func(s *sql.Selector) { - s.Where(sql.InValues(request.FileColumn, fks...)) + s.Where(sql.InValues(s.C(request.FileColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -804,7 +805,7 @@ func (rq *RequestQuery) loadFile(ctx context.Context, query *FileQuery, nodes [] } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "request_file" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "request_file" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -883,7 +884,7 @@ func (rq *RequestQuery) loadTransaction(ctx context.Context, query *TransactionQ } query.withFKs = true query.Where(predicate.Transaction(func(s *sql.Selector) { - s.Where(sql.InValues(request.TransactionColumn, fks...)) + s.Where(sql.InValues(s.C(request.TransactionColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -896,7 +897,7 @@ func (rq *RequestQuery) loadTransaction(ctx context.Context, query *TransactionQ } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "request_transaction" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "request_transaction" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -914,7 +915,7 @@ func (rq *RequestQuery) loadComment(ctx context.Context, query *CommentQuery, no } query.withFKs = true query.Where(predicate.Comment(func(s *sql.Selector) { - s.Where(sql.InValues(request.CommentColumn, fks...)) + s.Where(sql.InValues(s.C(request.CommentColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -927,7 +928,7 @@ func (rq *RequestQuery) loadComment(ctx context.Context, query *CommentQuery, no } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "request_comment" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "request_comment" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -1093,7 +1094,7 @@ func (rgb *RequestGroupBy) Aggregate(fns ...AggregateFunc) *RequestGroupBy { // Scan applies the selector query and scans the result into the given value. func (rgb *RequestGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, rgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, rgb.build.ctx, ent.OpQueryGroupBy) if err := rgb.build.prepareQuery(ctx); err != nil { return err } @@ -1141,7 +1142,7 @@ func (rs *RequestSelect) Aggregate(fns ...AggregateFunc) *RequestSelect { // Scan applies the selector query and scans the result into the given value. func (rs *RequestSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, rs.ctx, "Select") + ctx = setContextOp(ctx, rs.ctx, ent.OpQuerySelect) if err := rs.prepareQuery(ctx); err != nil { return err } diff --git a/ent/request_update.go b/ent/request_update.go index 922211fd..b1453c90 100644 --- a/ent/request_update.go +++ b/ent/request_update.go @@ -43,12 +43,28 @@ func (ru *RequestUpdate) SetTitle(s string) *RequestUpdate { return ru } +// SetNillableTitle sets the "title" field if the given value is not nil. +func (ru *RequestUpdate) SetNillableTitle(s *string) *RequestUpdate { + if s != nil { + ru.SetTitle(*s) + } + return ru +} + // SetContent sets the "content" field. func (ru *RequestUpdate) SetContent(s string) *RequestUpdate { ru.mutation.SetContent(s) return ru } +// SetNillableContent sets the "content" field if the given value is not nil. +func (ru *RequestUpdate) SetNillableContent(s *string) *RequestUpdate { + if s != nil { + ru.SetContent(*s) + } + return ru +} + // SetCreatedAt sets the "created_at" field. func (ru *RequestUpdate) SetCreatedAt(t time.Time) *RequestUpdate { ru.mutation.SetCreatedAt(t) @@ -343,7 +359,7 @@ func (ru *RequestUpdate) ClearGroup() *RequestUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (ru *RequestUpdate) Save(ctx context.Context) (int, error) { ru.defaults() - return withHooks[int, RequestMutation](ctx, ru.sqlSave, ru.mutation, ru.hooks) + return withHooks(ctx, ru.sqlSave, ru.mutation, ru.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -405,10 +421,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.StatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -421,10 +434,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.StatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -440,10 +450,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.StatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -459,10 +466,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.TargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -475,10 +479,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.TargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -494,10 +495,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.TargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -513,10 +511,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -529,10 +524,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -548,10 +540,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -567,10 +556,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: request.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -583,10 +569,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: request.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -602,10 +585,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: request.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -621,10 +601,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -637,10 +614,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -656,10 +630,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -675,10 +646,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -691,10 +659,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -710,10 +675,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -729,10 +691,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -745,10 +704,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -764,10 +720,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -780,10 +733,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -817,12 +767,28 @@ func (ruo *RequestUpdateOne) SetTitle(s string) *RequestUpdateOne { return ruo } +// SetNillableTitle sets the "title" field if the given value is not nil. +func (ruo *RequestUpdateOne) SetNillableTitle(s *string) *RequestUpdateOne { + if s != nil { + ruo.SetTitle(*s) + } + return ruo +} + // SetContent sets the "content" field. func (ruo *RequestUpdateOne) SetContent(s string) *RequestUpdateOne { ruo.mutation.SetContent(s) return ruo } +// SetNillableContent sets the "content" field if the given value is not nil. +func (ruo *RequestUpdateOne) SetNillableContent(s *string) *RequestUpdateOne { + if s != nil { + ruo.SetContent(*s) + } + return ruo +} + // SetCreatedAt sets the "created_at" field. func (ruo *RequestUpdateOne) SetCreatedAt(t time.Time) *RequestUpdateOne { ruo.mutation.SetCreatedAt(t) @@ -1130,7 +1096,7 @@ func (ruo *RequestUpdateOne) Select(field string, fields ...string) *RequestUpda // Save executes the query and returns the updated Request entity. func (ruo *RequestUpdateOne) Save(ctx context.Context) (*Request, error) { ruo.defaults() - return withHooks[*Request, RequestMutation](ctx, ruo.sqlSave, ruo.mutation, ruo.hooks) + return withHooks(ctx, ruo.sqlSave, ruo.mutation, ruo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -1209,10 +1175,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.StatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1225,10 +1188,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.StatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1244,10 +1204,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.StatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1263,10 +1220,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.TargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1279,10 +1233,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.TargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1298,10 +1249,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.TargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1317,10 +1265,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1333,10 +1278,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1352,10 +1294,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1371,10 +1310,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: request.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1387,10 +1323,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: request.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1406,10 +1339,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: request.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1425,10 +1355,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1441,10 +1368,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1460,10 +1384,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1479,10 +1400,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1495,10 +1413,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1514,10 +1429,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1533,10 +1445,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1549,10 +1458,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1568,10 +1474,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1584,10 +1487,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/requeststatus.go b/ent/requeststatus.go index a9ae69b5..7988d716 100644 --- a/ent/requeststatus.go +++ b/ent/requeststatus.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/request" @@ -28,6 +29,7 @@ type RequestStatus struct { Edges RequestStatusEdges `json:"edges"` request_status *uuid.UUID request_status_user *uuid.UUID + selectValues sql.SelectValues } // RequestStatusEdges holds the relations/edges for other nodes in the graph. @@ -44,12 +46,10 @@ type RequestStatusEdges struct { // RequestOrErr returns the Request value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e RequestStatusEdges) RequestOrErr() (*Request, error) { - if e.loadedTypes[0] { - if e.Request == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: request.Label} - } + if e.Request != nil { return e.Request, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: request.Label} } return nil, &NotLoadedError{edge: "request"} } @@ -57,12 +57,10 @@ func (e RequestStatusEdges) RequestOrErr() (*Request, error) { // UserOrErr returns the User value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e RequestStatusEdges) UserOrErr() (*User, error) { - if e.loadedTypes[1] { - if e.User == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: user.Label} - } + if e.User != nil { return e.User, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: user.Label} } return nil, &NotLoadedError{edge: "user"} } @@ -83,7 +81,7 @@ func (*RequestStatus) scanValues(columns []string) ([]any, error) { case requeststatus.ForeignKeys[1]: // request_status_user values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: - return nil, fmt.Errorf("unexpected column %q for type RequestStatus", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -129,11 +127,19 @@ func (rs *RequestStatus) assignValues(columns []string, values []any) error { rs.request_status_user = new(uuid.UUID) *rs.request_status_user = *value.S.(*uuid.UUID) } + default: + rs.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the RequestStatus. +// This includes values selected through modifiers, order, etc. +func (rs *RequestStatus) Value(name string) (ent.Value, error) { + return rs.selectValues.Get(name) +} + // QueryRequest queries the "request" edge of the RequestStatus entity. func (rs *RequestStatus) QueryRequest() *RequestQuery { return NewRequestStatusClient(rs.config).QueryRequest(rs) diff --git a/ent/requeststatus/requeststatus.go b/ent/requeststatus/requeststatus.go index 9295ff47..3b766bd6 100644 --- a/ent/requeststatus/requeststatus.go +++ b/ent/requeststatus/requeststatus.go @@ -6,6 +6,8 @@ import ( "fmt" "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -104,3 +106,49 @@ func StatusValidator(s Status) error { return fmt.Errorf("requeststatus: invalid enum value for status field: %q", s) } } + +// OrderOption defines the ordering options for the RequestStatus queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByStatus orders the results by the status field. +func ByStatus(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStatus, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByRequestField orders the results by request field. +func ByRequestField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStep(), sql.OrderByField(field, opts...)) + } +} + +// ByUserField orders the results by user field. +func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...)) + } +} +func newRequestStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), + ) +} +func newUserStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(UserInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), + ) +} diff --git a/ent/requeststatus/where.go b/ent/requeststatus/where.go index d034c0c6..38591a28 100644 --- a/ent/requeststatus/where.go +++ b/ent/requeststatus/where.go @@ -135,11 +135,7 @@ func HasRequest() predicate.RequestStatus { // HasRequestWith applies the HasEdge predicate on the "request" edge with a given conditions (other predicates). func HasRequestWith(preds ...predicate.Request) predicate.RequestStatus { return predicate.RequestStatus(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), - ) + step := newRequestStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -162,11 +158,7 @@ func HasUser() predicate.RequestStatus { // HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates). func HasUserWith(preds ...predicate.User) predicate.RequestStatus { return predicate.RequestStatus(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(UserInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), - ) + step := newUserStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -177,32 +169,15 @@ func HasUserWith(preds ...predicate.User) predicate.RequestStatus { // And groups predicates with the AND operator between them. func And(predicates ...predicate.RequestStatus) predicate.RequestStatus { - return predicate.RequestStatus(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.RequestStatus(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.RequestStatus) predicate.RequestStatus { - return predicate.RequestStatus(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.RequestStatus(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.RequestStatus) predicate.RequestStatus { - return predicate.RequestStatus(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.RequestStatus(sql.NotPredicates(p)) } diff --git a/ent/requeststatus_create.go b/ent/requeststatus_create.go index 0b102337..5dc73b6c 100644 --- a/ent/requeststatus_create.go +++ b/ent/requeststatus_create.go @@ -95,7 +95,7 @@ func (rsc *RequestStatusCreate) Mutation() *RequestStatusMutation { // Save creates the RequestStatus in the database. func (rsc *RequestStatusCreate) Save(ctx context.Context) (*RequestStatus, error) { rsc.defaults() - return withHooks[*RequestStatus, RequestStatusMutation](ctx, rsc.sqlSave, rsc.mutation, rsc.hooks) + return withHooks(ctx, rsc.sqlSave, rsc.mutation, rsc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -149,10 +149,10 @@ func (rsc *RequestStatusCreate) check() error { if _, ok := rsc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "RequestStatus.created_at"`)} } - if _, ok := rsc.mutation.RequestID(); !ok { + if len(rsc.mutation.RequestIDs()) == 0 { return &ValidationError{Name: "request", err: errors.New(`ent: missing required edge "RequestStatus.request"`)} } - if _, ok := rsc.mutation.UserID(); !ok { + if len(rsc.mutation.UserIDs()) == 0 { return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "RequestStatus.user"`)} } return nil @@ -206,10 +206,7 @@ func (rsc *RequestStatusCreate) createSpec() (*RequestStatus, *sqlgraph.CreateSp Columns: []string{requeststatus.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -226,10 +223,7 @@ func (rsc *RequestStatusCreate) createSpec() (*RequestStatus, *sqlgraph.CreateSp Columns: []string{requeststatus.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -244,11 +238,15 @@ func (rsc *RequestStatusCreate) createSpec() (*RequestStatus, *sqlgraph.CreateSp // RequestStatusCreateBulk is the builder for creating many RequestStatus entities in bulk. type RequestStatusCreateBulk struct { config + err error builders []*RequestStatusCreate } // Save creates the RequestStatus entities in the database. func (rscb *RequestStatusCreateBulk) Save(ctx context.Context) ([]*RequestStatus, error) { + if rscb.err != nil { + return nil, rscb.err + } specs := make([]*sqlgraph.CreateSpec, len(rscb.builders)) nodes := make([]*RequestStatus, len(rscb.builders)) mutators := make([]Mutator, len(rscb.builders)) @@ -265,8 +263,8 @@ func (rscb *RequestStatusCreateBulk) Save(ctx context.Context) ([]*RequestStatus return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, rscb.builders[i+1].mutation) } else { diff --git a/ent/requeststatus_delete.go b/ent/requeststatus_delete.go index bf63f8dc..11396686 100644 --- a/ent/requeststatus_delete.go +++ b/ent/requeststatus_delete.go @@ -27,7 +27,7 @@ func (rsd *RequestStatusDelete) Where(ps ...predicate.RequestStatus) *RequestSta // Exec executes the deletion query and returns how many vertices were deleted. func (rsd *RequestStatusDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, RequestStatusMutation](ctx, rsd.sqlExec, rsd.mutation, rsd.hooks) + return withHooks(ctx, rsd.sqlExec, rsd.mutation, rsd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/requeststatus_query.go b/ent/requeststatus_query.go index 7dcef240..0c331734 100644 --- a/ent/requeststatus_query.go +++ b/ent/requeststatus_query.go @@ -7,6 +7,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -21,7 +22,7 @@ import ( type RequestStatusQuery struct { config ctx *QueryContext - order []OrderFunc + order []requeststatus.OrderOption inters []Interceptor predicates []predicate.RequestStatus withRequest *RequestQuery @@ -58,7 +59,7 @@ func (rsq *RequestStatusQuery) Unique(unique bool) *RequestStatusQuery { } // Order specifies how the records should be ordered. -func (rsq *RequestStatusQuery) Order(o ...OrderFunc) *RequestStatusQuery { +func (rsq *RequestStatusQuery) Order(o ...requeststatus.OrderOption) *RequestStatusQuery { rsq.order = append(rsq.order, o...) return rsq } @@ -110,7 +111,7 @@ func (rsq *RequestStatusQuery) QueryUser() *UserQuery { // First returns the first RequestStatus entity from the query. // Returns a *NotFoundError when no RequestStatus was found. func (rsq *RequestStatusQuery) First(ctx context.Context) (*RequestStatus, error) { - nodes, err := rsq.Limit(1).All(setContextOp(ctx, rsq.ctx, "First")) + nodes, err := rsq.Limit(1).All(setContextOp(ctx, rsq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -133,7 +134,7 @@ func (rsq *RequestStatusQuery) FirstX(ctx context.Context) *RequestStatus { // Returns a *NotFoundError when no RequestStatus ID was found. func (rsq *RequestStatusQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = rsq.Limit(1).IDs(setContextOp(ctx, rsq.ctx, "FirstID")); err != nil { + if ids, err = rsq.Limit(1).IDs(setContextOp(ctx, rsq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -156,7 +157,7 @@ func (rsq *RequestStatusQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one RequestStatus entity is found. // Returns a *NotFoundError when no RequestStatus entities are found. func (rsq *RequestStatusQuery) Only(ctx context.Context) (*RequestStatus, error) { - nodes, err := rsq.Limit(2).All(setContextOp(ctx, rsq.ctx, "Only")) + nodes, err := rsq.Limit(2).All(setContextOp(ctx, rsq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -184,7 +185,7 @@ func (rsq *RequestStatusQuery) OnlyX(ctx context.Context) *RequestStatus { // Returns a *NotFoundError when no entities are found. func (rsq *RequestStatusQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = rsq.Limit(2).IDs(setContextOp(ctx, rsq.ctx, "OnlyID")); err != nil { + if ids, err = rsq.Limit(2).IDs(setContextOp(ctx, rsq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -209,7 +210,7 @@ func (rsq *RequestStatusQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of RequestStatusSlice. func (rsq *RequestStatusQuery) All(ctx context.Context) ([]*RequestStatus, error) { - ctx = setContextOp(ctx, rsq.ctx, "All") + ctx = setContextOp(ctx, rsq.ctx, ent.OpQueryAll) if err := rsq.prepareQuery(ctx); err != nil { return nil, err } @@ -231,7 +232,7 @@ func (rsq *RequestStatusQuery) IDs(ctx context.Context) (ids []uuid.UUID, err er if rsq.ctx.Unique == nil && rsq.path != nil { rsq.Unique(true) } - ctx = setContextOp(ctx, rsq.ctx, "IDs") + ctx = setContextOp(ctx, rsq.ctx, ent.OpQueryIDs) if err = rsq.Select(requeststatus.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -249,7 +250,7 @@ func (rsq *RequestStatusQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (rsq *RequestStatusQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, rsq.ctx, "Count") + ctx = setContextOp(ctx, rsq.ctx, ent.OpQueryCount) if err := rsq.prepareQuery(ctx); err != nil { return 0, err } @@ -267,7 +268,7 @@ func (rsq *RequestStatusQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (rsq *RequestStatusQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, rsq.ctx, "Exist") + ctx = setContextOp(ctx, rsq.ctx, ent.OpQueryExist) switch _, err := rsq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -296,7 +297,7 @@ func (rsq *RequestStatusQuery) Clone() *RequestStatusQuery { return &RequestStatusQuery{ config: rsq.config, ctx: rsq.ctx.Clone(), - order: append([]OrderFunc{}, rsq.order...), + order: append([]requeststatus.OrderOption{}, rsq.order...), inters: append([]Interceptor{}, rsq.inters...), predicates: append([]predicate.RequestStatus{}, rsq.predicates...), withRequest: rsq.withRequest.Clone(), @@ -612,7 +613,7 @@ func (rsgb *RequestStatusGroupBy) Aggregate(fns ...AggregateFunc) *RequestStatus // Scan applies the selector query and scans the result into the given value. func (rsgb *RequestStatusGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, rsgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, rsgb.build.ctx, ent.OpQueryGroupBy) if err := rsgb.build.prepareQuery(ctx); err != nil { return err } @@ -660,7 +661,7 @@ func (rss *RequestStatusSelect) Aggregate(fns ...AggregateFunc) *RequestStatusSe // Scan applies the selector query and scans the result into the given value. func (rss *RequestStatusSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, rss.ctx, "Select") + ctx = setContextOp(ctx, rss.ctx, ent.OpQuerySelect) if err := rss.prepareQuery(ctx); err != nil { return err } diff --git a/ent/requeststatus_update.go b/ent/requeststatus_update.go index 891aeded..7c5c35a1 100644 --- a/ent/requeststatus_update.go +++ b/ent/requeststatus_update.go @@ -100,7 +100,7 @@ func (rsu *RequestStatusUpdate) ClearUser() *RequestStatusUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (rsu *RequestStatusUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, RequestStatusMutation](ctx, rsu.sqlSave, rsu.mutation, rsu.hooks) + return withHooks(ctx, rsu.sqlSave, rsu.mutation, rsu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -132,10 +132,10 @@ func (rsu *RequestStatusUpdate) check() error { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "RequestStatus.status": %w`, err)} } } - if _, ok := rsu.mutation.RequestID(); rsu.mutation.RequestCleared() && !ok { + if rsu.mutation.RequestCleared() && len(rsu.mutation.RequestIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "RequestStatus.request"`) } - if _, ok := rsu.mutation.UserID(); rsu.mutation.UserCleared() && !ok { + if rsu.mutation.UserCleared() && len(rsu.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "RequestStatus.user"`) } return nil @@ -167,10 +167,7 @@ func (rsu *RequestStatusUpdate) sqlSave(ctx context.Context) (n int, err error) Columns: []string{requeststatus.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -183,10 +180,7 @@ func (rsu *RequestStatusUpdate) sqlSave(ctx context.Context) (n int, err error) Columns: []string{requeststatus.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -202,10 +196,7 @@ func (rsu *RequestStatusUpdate) sqlSave(ctx context.Context) (n int, err error) Columns: []string{requeststatus.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -218,10 +209,7 @@ func (rsu *RequestStatusUpdate) sqlSave(ctx context.Context) (n int, err error) Columns: []string{requeststatus.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -331,7 +319,7 @@ func (rsuo *RequestStatusUpdateOne) Select(field string, fields ...string) *Requ // Save executes the query and returns the updated RequestStatus entity. func (rsuo *RequestStatusUpdateOne) Save(ctx context.Context) (*RequestStatus, error) { - return withHooks[*RequestStatus, RequestStatusMutation](ctx, rsuo.sqlSave, rsuo.mutation, rsuo.hooks) + return withHooks(ctx, rsuo.sqlSave, rsuo.mutation, rsuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -363,10 +351,10 @@ func (rsuo *RequestStatusUpdateOne) check() error { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "RequestStatus.status": %w`, err)} } } - if _, ok := rsuo.mutation.RequestID(); rsuo.mutation.RequestCleared() && !ok { + if rsuo.mutation.RequestCleared() && len(rsuo.mutation.RequestIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "RequestStatus.request"`) } - if _, ok := rsuo.mutation.UserID(); rsuo.mutation.UserCleared() && !ok { + if rsuo.mutation.UserCleared() && len(rsuo.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "RequestStatus.user"`) } return nil @@ -415,10 +403,7 @@ func (rsuo *RequestStatusUpdateOne) sqlSave(ctx context.Context) (_node *Request Columns: []string{requeststatus.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -431,10 +416,7 @@ func (rsuo *RequestStatusUpdateOne) sqlSave(ctx context.Context) (_node *Request Columns: []string{requeststatus.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -450,10 +432,7 @@ func (rsuo *RequestStatusUpdateOne) sqlSave(ctx context.Context) (_node *Request Columns: []string{requeststatus.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -466,10 +445,7 @@ func (rsuo *RequestStatusUpdateOne) sqlSave(ctx context.Context) (_node *Request Columns: []string{requeststatus.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/requesttarget.go b/ent/requesttarget.go index bb54e6ef..9b4324c1 100644 --- a/ent/requesttarget.go +++ b/ent/requesttarget.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/request" @@ -30,6 +31,7 @@ type RequestTarget struct { Edges RequestTargetEdges `json:"edges"` request_target *uuid.UUID request_target_user *uuid.UUID + selectValues sql.SelectValues } // RequestTargetEdges holds the relations/edges for other nodes in the graph. @@ -46,12 +48,10 @@ type RequestTargetEdges struct { // RequestOrErr returns the Request value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e RequestTargetEdges) RequestOrErr() (*Request, error) { - if e.loadedTypes[0] { - if e.Request == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: request.Label} - } + if e.Request != nil { return e.Request, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: request.Label} } return nil, &NotLoadedError{edge: "request"} } @@ -59,12 +59,10 @@ func (e RequestTargetEdges) RequestOrErr() (*Request, error) { // UserOrErr returns the User value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e RequestTargetEdges) UserOrErr() (*User, error) { - if e.loadedTypes[1] { - if e.User == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: user.Label} - } + if e.User != nil { return e.User, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: user.Label} } return nil, &NotLoadedError{edge: "user"} } @@ -85,7 +83,7 @@ func (*RequestTarget) scanValues(columns []string) ([]any, error) { case requesttarget.ForeignKeys[1]: // request_target_user values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: - return nil, fmt.Errorf("unexpected column %q for type RequestTarget", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -138,11 +136,19 @@ func (rt *RequestTarget) assignValues(columns []string, values []any) error { rt.request_target_user = new(uuid.UUID) *rt.request_target_user = *value.S.(*uuid.UUID) } + default: + rt.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the RequestTarget. +// This includes values selected through modifiers, order, etc. +func (rt *RequestTarget) Value(name string) (ent.Value, error) { + return rt.selectValues.Get(name) +} + // QueryRequest queries the "request" edge of the RequestTarget entity. func (rt *RequestTarget) QueryRequest() *RequestQuery { return NewRequestTargetClient(rt.config).QueryRequest(rt) diff --git a/ent/requesttarget/requesttarget.go b/ent/requesttarget/requesttarget.go index 45398815..0473493c 100644 --- a/ent/requesttarget/requesttarget.go +++ b/ent/requesttarget/requesttarget.go @@ -5,6 +5,8 @@ package requesttarget import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -77,3 +79,54 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the RequestTarget queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByAmount orders the results by the amount field. +func ByAmount(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAmount, opts...).ToFunc() +} + +// ByPaidAt orders the results by the paid_at field. +func ByPaidAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPaidAt, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByRequestField orders the results by request field. +func ByRequestField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStep(), sql.OrderByField(field, opts...)) + } +} + +// ByUserField orders the results by user field. +func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...)) + } +} +func newRequestStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), + ) +} +func newUserStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(UserInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), + ) +} diff --git a/ent/requesttarget/where.go b/ent/requesttarget/where.go index 0f96a624..31b8ffd5 100644 --- a/ent/requesttarget/where.go +++ b/ent/requesttarget/where.go @@ -215,11 +215,7 @@ func HasRequest() predicate.RequestTarget { // HasRequestWith applies the HasEdge predicate on the "request" edge with a given conditions (other predicates). func HasRequestWith(preds ...predicate.Request) predicate.RequestTarget { return predicate.RequestTarget(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), - ) + step := newRequestStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -242,11 +238,7 @@ func HasUser() predicate.RequestTarget { // HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates). func HasUserWith(preds ...predicate.User) predicate.RequestTarget { return predicate.RequestTarget(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(UserInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), - ) + step := newUserStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -257,32 +249,15 @@ func HasUserWith(preds ...predicate.User) predicate.RequestTarget { // And groups predicates with the AND operator between them. func And(predicates ...predicate.RequestTarget) predicate.RequestTarget { - return predicate.RequestTarget(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.RequestTarget(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.RequestTarget) predicate.RequestTarget { - return predicate.RequestTarget(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.RequestTarget(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.RequestTarget) predicate.RequestTarget { - return predicate.RequestTarget(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.RequestTarget(sql.NotPredicates(p)) } diff --git a/ent/requesttarget_create.go b/ent/requesttarget_create.go index 1702e3ae..d991ee39 100644 --- a/ent/requesttarget_create.go +++ b/ent/requesttarget_create.go @@ -101,7 +101,7 @@ func (rtc *RequestTargetCreate) Mutation() *RequestTargetMutation { // Save creates the RequestTarget in the database. func (rtc *RequestTargetCreate) Save(ctx context.Context) (*RequestTarget, error) { rtc.defaults() - return withHooks[*RequestTarget, RequestTargetMutation](ctx, rtc.sqlSave, rtc.mutation, rtc.hooks) + return withHooks(ctx, rtc.sqlSave, rtc.mutation, rtc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -146,10 +146,10 @@ func (rtc *RequestTargetCreate) check() error { if _, ok := rtc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "RequestTarget.created_at"`)} } - if _, ok := rtc.mutation.RequestID(); !ok { + if len(rtc.mutation.RequestIDs()) == 0 { return &ValidationError{Name: "request", err: errors.New(`ent: missing required edge "RequestTarget.request"`)} } - if _, ok := rtc.mutation.UserID(); !ok { + if len(rtc.mutation.UserIDs()) == 0 { return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "RequestTarget.user"`)} } return nil @@ -207,10 +207,7 @@ func (rtc *RequestTargetCreate) createSpec() (*RequestTarget, *sqlgraph.CreateSp Columns: []string{requesttarget.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -227,10 +224,7 @@ func (rtc *RequestTargetCreate) createSpec() (*RequestTarget, *sqlgraph.CreateSp Columns: []string{requesttarget.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -245,11 +239,15 @@ func (rtc *RequestTargetCreate) createSpec() (*RequestTarget, *sqlgraph.CreateSp // RequestTargetCreateBulk is the builder for creating many RequestTarget entities in bulk. type RequestTargetCreateBulk struct { config + err error builders []*RequestTargetCreate } // Save creates the RequestTarget entities in the database. func (rtcb *RequestTargetCreateBulk) Save(ctx context.Context) ([]*RequestTarget, error) { + if rtcb.err != nil { + return nil, rtcb.err + } specs := make([]*sqlgraph.CreateSpec, len(rtcb.builders)) nodes := make([]*RequestTarget, len(rtcb.builders)) mutators := make([]Mutator, len(rtcb.builders)) @@ -266,8 +264,8 @@ func (rtcb *RequestTargetCreateBulk) Save(ctx context.Context) ([]*RequestTarget return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, rtcb.builders[i+1].mutation) } else { diff --git a/ent/requesttarget_delete.go b/ent/requesttarget_delete.go index 6018e83d..8e8fd257 100644 --- a/ent/requesttarget_delete.go +++ b/ent/requesttarget_delete.go @@ -27,7 +27,7 @@ func (rtd *RequestTargetDelete) Where(ps ...predicate.RequestTarget) *RequestTar // Exec executes the deletion query and returns how many vertices were deleted. func (rtd *RequestTargetDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, RequestTargetMutation](ctx, rtd.sqlExec, rtd.mutation, rtd.hooks) + return withHooks(ctx, rtd.sqlExec, rtd.mutation, rtd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/requesttarget_query.go b/ent/requesttarget_query.go index eba23543..8ed19a27 100644 --- a/ent/requesttarget_query.go +++ b/ent/requesttarget_query.go @@ -7,6 +7,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -21,7 +22,7 @@ import ( type RequestTargetQuery struct { config ctx *QueryContext - order []OrderFunc + order []requesttarget.OrderOption inters []Interceptor predicates []predicate.RequestTarget withRequest *RequestQuery @@ -58,7 +59,7 @@ func (rtq *RequestTargetQuery) Unique(unique bool) *RequestTargetQuery { } // Order specifies how the records should be ordered. -func (rtq *RequestTargetQuery) Order(o ...OrderFunc) *RequestTargetQuery { +func (rtq *RequestTargetQuery) Order(o ...requesttarget.OrderOption) *RequestTargetQuery { rtq.order = append(rtq.order, o...) return rtq } @@ -110,7 +111,7 @@ func (rtq *RequestTargetQuery) QueryUser() *UserQuery { // First returns the first RequestTarget entity from the query. // Returns a *NotFoundError when no RequestTarget was found. func (rtq *RequestTargetQuery) First(ctx context.Context) (*RequestTarget, error) { - nodes, err := rtq.Limit(1).All(setContextOp(ctx, rtq.ctx, "First")) + nodes, err := rtq.Limit(1).All(setContextOp(ctx, rtq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -133,7 +134,7 @@ func (rtq *RequestTargetQuery) FirstX(ctx context.Context) *RequestTarget { // Returns a *NotFoundError when no RequestTarget ID was found. func (rtq *RequestTargetQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = rtq.Limit(1).IDs(setContextOp(ctx, rtq.ctx, "FirstID")); err != nil { + if ids, err = rtq.Limit(1).IDs(setContextOp(ctx, rtq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -156,7 +157,7 @@ func (rtq *RequestTargetQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one RequestTarget entity is found. // Returns a *NotFoundError when no RequestTarget entities are found. func (rtq *RequestTargetQuery) Only(ctx context.Context) (*RequestTarget, error) { - nodes, err := rtq.Limit(2).All(setContextOp(ctx, rtq.ctx, "Only")) + nodes, err := rtq.Limit(2).All(setContextOp(ctx, rtq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -184,7 +185,7 @@ func (rtq *RequestTargetQuery) OnlyX(ctx context.Context) *RequestTarget { // Returns a *NotFoundError when no entities are found. func (rtq *RequestTargetQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = rtq.Limit(2).IDs(setContextOp(ctx, rtq.ctx, "OnlyID")); err != nil { + if ids, err = rtq.Limit(2).IDs(setContextOp(ctx, rtq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -209,7 +210,7 @@ func (rtq *RequestTargetQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of RequestTargets. func (rtq *RequestTargetQuery) All(ctx context.Context) ([]*RequestTarget, error) { - ctx = setContextOp(ctx, rtq.ctx, "All") + ctx = setContextOp(ctx, rtq.ctx, ent.OpQueryAll) if err := rtq.prepareQuery(ctx); err != nil { return nil, err } @@ -231,7 +232,7 @@ func (rtq *RequestTargetQuery) IDs(ctx context.Context) (ids []uuid.UUID, err er if rtq.ctx.Unique == nil && rtq.path != nil { rtq.Unique(true) } - ctx = setContextOp(ctx, rtq.ctx, "IDs") + ctx = setContextOp(ctx, rtq.ctx, ent.OpQueryIDs) if err = rtq.Select(requesttarget.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -249,7 +250,7 @@ func (rtq *RequestTargetQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (rtq *RequestTargetQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, rtq.ctx, "Count") + ctx = setContextOp(ctx, rtq.ctx, ent.OpQueryCount) if err := rtq.prepareQuery(ctx); err != nil { return 0, err } @@ -267,7 +268,7 @@ func (rtq *RequestTargetQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (rtq *RequestTargetQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, rtq.ctx, "Exist") + ctx = setContextOp(ctx, rtq.ctx, ent.OpQueryExist) switch _, err := rtq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -296,7 +297,7 @@ func (rtq *RequestTargetQuery) Clone() *RequestTargetQuery { return &RequestTargetQuery{ config: rtq.config, ctx: rtq.ctx.Clone(), - order: append([]OrderFunc{}, rtq.order...), + order: append([]requesttarget.OrderOption{}, rtq.order...), inters: append([]Interceptor{}, rtq.inters...), predicates: append([]predicate.RequestTarget{}, rtq.predicates...), withRequest: rtq.withRequest.Clone(), @@ -612,7 +613,7 @@ func (rtgb *RequestTargetGroupBy) Aggregate(fns ...AggregateFunc) *RequestTarget // Scan applies the selector query and scans the result into the given value. func (rtgb *RequestTargetGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, rtgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, rtgb.build.ctx, ent.OpQueryGroupBy) if err := rtgb.build.prepareQuery(ctx); err != nil { return err } @@ -660,7 +661,7 @@ func (rts *RequestTargetSelect) Aggregate(fns ...AggregateFunc) *RequestTargetSe // Scan applies the selector query and scans the result into the given value. func (rts *RequestTargetSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, rts.ctx, "Select") + ctx = setContextOp(ctx, rts.ctx, ent.OpQuerySelect) if err := rts.prepareQuery(ctx); err != nil { return err } diff --git a/ent/requesttarget_update.go b/ent/requesttarget_update.go index 4ab9744b..ad261abb 100644 --- a/ent/requesttarget_update.go +++ b/ent/requesttarget_update.go @@ -38,6 +38,14 @@ func (rtu *RequestTargetUpdate) SetAmount(i int) *RequestTargetUpdate { return rtu } +// SetNillableAmount sets the "amount" field if the given value is not nil. +func (rtu *RequestTargetUpdate) SetNillableAmount(i *int) *RequestTargetUpdate { + if i != nil { + rtu.SetAmount(*i) + } + return rtu +} + // AddAmount adds i to the "amount" field. func (rtu *RequestTargetUpdate) AddAmount(i int) *RequestTargetUpdate { rtu.mutation.AddAmount(i) @@ -119,7 +127,7 @@ func (rtu *RequestTargetUpdate) ClearUser() *RequestTargetUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (rtu *RequestTargetUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, RequestTargetMutation](ctx, rtu.sqlSave, rtu.mutation, rtu.hooks) + return withHooks(ctx, rtu.sqlSave, rtu.mutation, rtu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -146,10 +154,10 @@ func (rtu *RequestTargetUpdate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (rtu *RequestTargetUpdate) check() error { - if _, ok := rtu.mutation.RequestID(); rtu.mutation.RequestCleared() && !ok { + if rtu.mutation.RequestCleared() && len(rtu.mutation.RequestIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "RequestTarget.request"`) } - if _, ok := rtu.mutation.UserID(); rtu.mutation.UserCleared() && !ok { + if rtu.mutation.UserCleared() && len(rtu.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "RequestTarget.user"`) } return nil @@ -190,10 +198,7 @@ func (rtu *RequestTargetUpdate) sqlSave(ctx context.Context) (n int, err error) Columns: []string{requesttarget.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -206,10 +211,7 @@ func (rtu *RequestTargetUpdate) sqlSave(ctx context.Context) (n int, err error) Columns: []string{requesttarget.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -225,10 +227,7 @@ func (rtu *RequestTargetUpdate) sqlSave(ctx context.Context) (n int, err error) Columns: []string{requesttarget.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -241,10 +240,7 @@ func (rtu *RequestTargetUpdate) sqlSave(ctx context.Context) (n int, err error) Columns: []string{requesttarget.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -279,6 +275,14 @@ func (rtuo *RequestTargetUpdateOne) SetAmount(i int) *RequestTargetUpdateOne { return rtuo } +// SetNillableAmount sets the "amount" field if the given value is not nil. +func (rtuo *RequestTargetUpdateOne) SetNillableAmount(i *int) *RequestTargetUpdateOne { + if i != nil { + rtuo.SetAmount(*i) + } + return rtuo +} + // AddAmount adds i to the "amount" field. func (rtuo *RequestTargetUpdateOne) AddAmount(i int) *RequestTargetUpdateOne { rtuo.mutation.AddAmount(i) @@ -373,7 +377,7 @@ func (rtuo *RequestTargetUpdateOne) Select(field string, fields ...string) *Requ // Save executes the query and returns the updated RequestTarget entity. func (rtuo *RequestTargetUpdateOne) Save(ctx context.Context) (*RequestTarget, error) { - return withHooks[*RequestTarget, RequestTargetMutation](ctx, rtuo.sqlSave, rtuo.mutation, rtuo.hooks) + return withHooks(ctx, rtuo.sqlSave, rtuo.mutation, rtuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -400,10 +404,10 @@ func (rtuo *RequestTargetUpdateOne) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (rtuo *RequestTargetUpdateOne) check() error { - if _, ok := rtuo.mutation.RequestID(); rtuo.mutation.RequestCleared() && !ok { + if rtuo.mutation.RequestCleared() && len(rtuo.mutation.RequestIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "RequestTarget.request"`) } - if _, ok := rtuo.mutation.UserID(); rtuo.mutation.UserCleared() && !ok { + if rtuo.mutation.UserCleared() && len(rtuo.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "RequestTarget.user"`) } return nil @@ -461,10 +465,7 @@ func (rtuo *RequestTargetUpdateOne) sqlSave(ctx context.Context) (_node *Request Columns: []string{requesttarget.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -477,10 +478,7 @@ func (rtuo *RequestTargetUpdateOne) sqlSave(ctx context.Context) (_node *Request Columns: []string{requesttarget.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -496,10 +494,7 @@ func (rtuo *RequestTargetUpdateOne) sqlSave(ctx context.Context) (_node *Request Columns: []string{requesttarget.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -512,10 +507,7 @@ func (rtuo *RequestTargetUpdateOne) sqlSave(ctx context.Context) (_node *Request Columns: []string{requesttarget.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/runtime/runtime.go b/ent/runtime/runtime.go index 4cc61091..f110b81d 100644 --- a/ent/runtime/runtime.go +++ b/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in github.com/traPtitech/Jomon/ent/runtime.go const ( - Version = "v0.11.9" // Version of ent codegen. - Sum = "h1:dbbCkAiPVTRBIJwoZctiSYjB7zxQIBOzVSU5H9VYIQI=" // Sum of ent codegen. + Version = "v0.14.0" // Version of ent codegen. + Sum = "h1:EO3Z9aZ5bXJatJeGqu/EVdnNr6K4mRq3rWe5owt0MC4=" // Sum of ent codegen. ) diff --git a/ent/tag.go b/ent/tag.go index c90d0374..67a8fd3c 100644 --- a/ent/tag.go +++ b/ent/tag.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/tag" @@ -27,7 +28,8 @@ type Tag struct { DeletedAt *time.Time `json:"deleted_at,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the TagQuery when eager-loading is set. - Edges TagEdges `json:"edges"` + Edges TagEdges `json:"edges"` + selectValues sql.SelectValues } // TagEdges holds the relations/edges for other nodes in the graph. @@ -71,7 +73,7 @@ func (*Tag) scanValues(columns []string) ([]any, error) { case tag.FieldID: values[i] = new(uuid.UUID) default: - return nil, fmt.Errorf("unexpected column %q for type Tag", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -116,11 +118,19 @@ func (t *Tag) assignValues(columns []string, values []any) error { t.DeletedAt = new(time.Time) *t.DeletedAt = value.Time } + default: + t.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the Tag. +// This includes values selected through modifiers, order, etc. +func (t *Tag) Value(name string) (ent.Value, error) { + return t.selectValues.Get(name) +} + // QueryRequest queries the "request" edge of the Tag entity. func (t *Tag) QueryRequest() *RequestQuery { return NewTagClient(t.config).QueryRequest(t) diff --git a/ent/tag/tag.go b/ent/tag/tag.go index cbfb4db6..439afd69 100644 --- a/ent/tag/tag.go +++ b/ent/tag/tag.go @@ -5,6 +5,8 @@ package tag import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -79,3 +81,73 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the Tag queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByDeletedAt orders the results by the deleted_at field. +func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() +} + +// ByRequestCount orders the results by request count. +func ByRequestCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newRequestStep(), opts...) + } +} + +// ByRequest orders the results by request terms. +func ByRequest(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByTransactionCount orders the results by transaction count. +func ByTransactionCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTransactionStep(), opts...) + } +} + +// ByTransaction orders the results by transaction terms. +func ByTransaction(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTransactionStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newRequestStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, RequestTable, RequestPrimaryKey...), + ) +} +func newTransactionStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TransactionInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, TransactionTable, TransactionPrimaryKey...), + ) +} diff --git a/ent/tag/where.go b/ent/tag/where.go index 8183c019..73a3d389 100644 --- a/ent/tag/where.go +++ b/ent/tag/where.go @@ -285,11 +285,7 @@ func HasRequest() predicate.Tag { // HasRequestWith applies the HasEdge predicate on the "request" edge with a given conditions (other predicates). func HasRequestWith(preds ...predicate.Request) predicate.Tag { return predicate.Tag(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, RequestTable, RequestPrimaryKey...), - ) + step := newRequestStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -312,11 +308,7 @@ func HasTransaction() predicate.Tag { // HasTransactionWith applies the HasEdge predicate on the "transaction" edge with a given conditions (other predicates). func HasTransactionWith(preds ...predicate.Transaction) predicate.Tag { return predicate.Tag(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TransactionInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, TransactionTable, TransactionPrimaryKey...), - ) + step := newTransactionStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -327,32 +319,15 @@ func HasTransactionWith(preds ...predicate.Transaction) predicate.Tag { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Tag) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Tag(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Tag) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Tag(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Tag) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Tag(sql.NotPredicates(p)) } diff --git a/ent/tag_create.go b/ent/tag_create.go index 5f1033fb..309c943b 100644 --- a/ent/tag_create.go +++ b/ent/tag_create.go @@ -123,7 +123,7 @@ func (tc *TagCreate) Mutation() *TagMutation { // Save creates the Tag in the database. func (tc *TagCreate) Save(ctx context.Context) (*Tag, error) { tc.defaults() - return withHooks[*Tag, TagMutation](ctx, tc.sqlSave, tc.mutation, tc.hooks) + return withHooks(ctx, tc.sqlSave, tc.mutation, tc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -239,10 +239,7 @@ func (tc *TagCreate) createSpec() (*Tag, *sqlgraph.CreateSpec) { Columns: tag.RequestPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -258,10 +255,7 @@ func (tc *TagCreate) createSpec() (*Tag, *sqlgraph.CreateSpec) { Columns: tag.TransactionPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -275,11 +269,15 @@ func (tc *TagCreate) createSpec() (*Tag, *sqlgraph.CreateSpec) { // TagCreateBulk is the builder for creating many Tag entities in bulk. type TagCreateBulk struct { config + err error builders []*TagCreate } // Save creates the Tag entities in the database. func (tcb *TagCreateBulk) Save(ctx context.Context) ([]*Tag, error) { + if tcb.err != nil { + return nil, tcb.err + } specs := make([]*sqlgraph.CreateSpec, len(tcb.builders)) nodes := make([]*Tag, len(tcb.builders)) mutators := make([]Mutator, len(tcb.builders)) @@ -296,8 +294,8 @@ func (tcb *TagCreateBulk) Save(ctx context.Context) ([]*Tag, error) { return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, tcb.builders[i+1].mutation) } else { diff --git a/ent/tag_delete.go b/ent/tag_delete.go index 78dd69a7..81c4d33a 100644 --- a/ent/tag_delete.go +++ b/ent/tag_delete.go @@ -27,7 +27,7 @@ func (td *TagDelete) Where(ps ...predicate.Tag) *TagDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (td *TagDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, TagMutation](ctx, td.sqlExec, td.mutation, td.hooks) + return withHooks(ctx, td.sqlExec, td.mutation, td.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/tag_query.go b/ent/tag_query.go index c6bacabb..46e5b12b 100644 --- a/ent/tag_query.go +++ b/ent/tag_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -22,7 +23,7 @@ import ( type TagQuery struct { config ctx *QueryContext - order []OrderFunc + order []tag.OrderOption inters []Interceptor predicates []predicate.Tag withRequest *RequestQuery @@ -58,7 +59,7 @@ func (tq *TagQuery) Unique(unique bool) *TagQuery { } // Order specifies how the records should be ordered. -func (tq *TagQuery) Order(o ...OrderFunc) *TagQuery { +func (tq *TagQuery) Order(o ...tag.OrderOption) *TagQuery { tq.order = append(tq.order, o...) return tq } @@ -110,7 +111,7 @@ func (tq *TagQuery) QueryTransaction() *TransactionQuery { // First returns the first Tag entity from the query. // Returns a *NotFoundError when no Tag was found. func (tq *TagQuery) First(ctx context.Context) (*Tag, error) { - nodes, err := tq.Limit(1).All(setContextOp(ctx, tq.ctx, "First")) + nodes, err := tq.Limit(1).All(setContextOp(ctx, tq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -133,7 +134,7 @@ func (tq *TagQuery) FirstX(ctx context.Context) *Tag { // Returns a *NotFoundError when no Tag ID was found. func (tq *TagQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = tq.Limit(1).IDs(setContextOp(ctx, tq.ctx, "FirstID")); err != nil { + if ids, err = tq.Limit(1).IDs(setContextOp(ctx, tq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -156,7 +157,7 @@ func (tq *TagQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Tag entity is found. // Returns a *NotFoundError when no Tag entities are found. func (tq *TagQuery) Only(ctx context.Context) (*Tag, error) { - nodes, err := tq.Limit(2).All(setContextOp(ctx, tq.ctx, "Only")) + nodes, err := tq.Limit(2).All(setContextOp(ctx, tq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -184,7 +185,7 @@ func (tq *TagQuery) OnlyX(ctx context.Context) *Tag { // Returns a *NotFoundError when no entities are found. func (tq *TagQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = tq.Limit(2).IDs(setContextOp(ctx, tq.ctx, "OnlyID")); err != nil { + if ids, err = tq.Limit(2).IDs(setContextOp(ctx, tq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -209,7 +210,7 @@ func (tq *TagQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Tags. func (tq *TagQuery) All(ctx context.Context) ([]*Tag, error) { - ctx = setContextOp(ctx, tq.ctx, "All") + ctx = setContextOp(ctx, tq.ctx, ent.OpQueryAll) if err := tq.prepareQuery(ctx); err != nil { return nil, err } @@ -231,7 +232,7 @@ func (tq *TagQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if tq.ctx.Unique == nil && tq.path != nil { tq.Unique(true) } - ctx = setContextOp(ctx, tq.ctx, "IDs") + ctx = setContextOp(ctx, tq.ctx, ent.OpQueryIDs) if err = tq.Select(tag.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -249,7 +250,7 @@ func (tq *TagQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (tq *TagQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, tq.ctx, "Count") + ctx = setContextOp(ctx, tq.ctx, ent.OpQueryCount) if err := tq.prepareQuery(ctx); err != nil { return 0, err } @@ -267,7 +268,7 @@ func (tq *TagQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (tq *TagQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, tq.ctx, "Exist") + ctx = setContextOp(ctx, tq.ctx, ent.OpQueryExist) switch _, err := tq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -296,7 +297,7 @@ func (tq *TagQuery) Clone() *TagQuery { return &TagQuery{ config: tq.config, ctx: tq.ctx.Clone(), - order: append([]OrderFunc{}, tq.order...), + order: append([]tag.OrderOption{}, tq.order...), inters: append([]Interceptor{}, tq.inters...), predicates: append([]predicate.Tag{}, tq.predicates...), withRequest: tq.withRequest.Clone(), @@ -665,7 +666,7 @@ func (tgb *TagGroupBy) Aggregate(fns ...AggregateFunc) *TagGroupBy { // Scan applies the selector query and scans the result into the given value. func (tgb *TagGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, tgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, tgb.build.ctx, ent.OpQueryGroupBy) if err := tgb.build.prepareQuery(ctx); err != nil { return err } @@ -713,7 +714,7 @@ func (ts *TagSelect) Aggregate(fns ...AggregateFunc) *TagSelect { // Scan applies the selector query and scans the result into the given value. func (ts *TagSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ts.ctx, "Select") + ctx = setContextOp(ctx, ts.ctx, ent.OpQuerySelect) if err := ts.prepareQuery(ctx); err != nil { return err } diff --git a/ent/tag_update.go b/ent/tag_update.go index 367e30d6..38b7f22d 100644 --- a/ent/tag_update.go +++ b/ent/tag_update.go @@ -37,6 +37,14 @@ func (tu *TagUpdate) SetName(s string) *TagUpdate { return tu } +// SetNillableName sets the "name" field if the given value is not nil. +func (tu *TagUpdate) SetNillableName(s *string) *TagUpdate { + if s != nil { + tu.SetName(*s) + } + return tu +} + // SetCreatedAt sets the "created_at" field. func (tu *TagUpdate) SetCreatedAt(t time.Time) *TagUpdate { tu.mutation.SetCreatedAt(t) @@ -157,7 +165,7 @@ func (tu *TagUpdate) RemoveTransaction(t ...*Transaction) *TagUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (tu *TagUpdate) Save(ctx context.Context) (int, error) { tu.defaults() - return withHooks[int, TagMutation](ctx, tu.sqlSave, tu.mutation, tu.hooks) + return withHooks(ctx, tu.sqlSave, tu.mutation, tu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -235,10 +243,7 @@ func (tu *TagUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: tag.RequestPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -251,10 +256,7 @@ func (tu *TagUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: tag.RequestPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -270,10 +272,7 @@ func (tu *TagUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: tag.RequestPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -289,10 +288,7 @@ func (tu *TagUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: tag.TransactionPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -305,10 +301,7 @@ func (tu *TagUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: tag.TransactionPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -324,10 +317,7 @@ func (tu *TagUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: tag.TransactionPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -361,6 +351,14 @@ func (tuo *TagUpdateOne) SetName(s string) *TagUpdateOne { return tuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (tuo *TagUpdateOne) SetNillableName(s *string) *TagUpdateOne { + if s != nil { + tuo.SetName(*s) + } + return tuo +} + // SetCreatedAt sets the "created_at" field. func (tuo *TagUpdateOne) SetCreatedAt(t time.Time) *TagUpdateOne { tuo.mutation.SetCreatedAt(t) @@ -494,7 +492,7 @@ func (tuo *TagUpdateOne) Select(field string, fields ...string) *TagUpdateOne { // Save executes the query and returns the updated Tag entity. func (tuo *TagUpdateOne) Save(ctx context.Context) (*Tag, error) { tuo.defaults() - return withHooks[*Tag, TagMutation](ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) + return withHooks(ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -589,10 +587,7 @@ func (tuo *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { Columns: tag.RequestPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -605,10 +600,7 @@ func (tuo *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { Columns: tag.RequestPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -624,10 +616,7 @@ func (tuo *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { Columns: tag.RequestPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -643,10 +632,7 @@ func (tuo *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { Columns: tag.TransactionPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -659,10 +645,7 @@ func (tuo *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { Columns: tag.TransactionPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -678,10 +661,7 @@ func (tuo *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { Columns: tag.TransactionPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/transaction.go b/ent/transaction.go index 22eaa9f9..a59e68b9 100644 --- a/ent/transaction.go +++ b/ent/transaction.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/groupbudget" @@ -27,6 +28,7 @@ type Transaction struct { Edges TransactionEdges `json:"edges"` group_budget_transaction *uuid.UUID request_transaction *uuid.UUID + selectValues sql.SelectValues } // TransactionEdges holds the relations/edges for other nodes in the graph. @@ -47,12 +49,10 @@ type TransactionEdges struct { // DetailOrErr returns the Detail value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e TransactionEdges) DetailOrErr() (*TransactionDetail, error) { - if e.loadedTypes[0] { - if e.Detail == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: transactiondetail.Label} - } + if e.Detail != nil { return e.Detail, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: transactiondetail.Label} } return nil, &NotLoadedError{edge: "detail"} } @@ -69,12 +69,10 @@ func (e TransactionEdges) TagOrErr() ([]*Tag, error) { // GroupBudgetOrErr returns the GroupBudget value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e TransactionEdges) GroupBudgetOrErr() (*GroupBudget, error) { - if e.loadedTypes[2] { - if e.GroupBudget == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: groupbudget.Label} - } + if e.GroupBudget != nil { return e.GroupBudget, nil + } else if e.loadedTypes[2] { + return nil, &NotFoundError{label: groupbudget.Label} } return nil, &NotLoadedError{edge: "group_budget"} } @@ -82,12 +80,10 @@ func (e TransactionEdges) GroupBudgetOrErr() (*GroupBudget, error) { // RequestOrErr returns the Request value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e TransactionEdges) RequestOrErr() (*Request, error) { - if e.loadedTypes[3] { - if e.Request == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: request.Label} - } + if e.Request != nil { return e.Request, nil + } else if e.loadedTypes[3] { + return nil, &NotFoundError{label: request.Label} } return nil, &NotLoadedError{edge: "request"} } @@ -106,7 +102,7 @@ func (*Transaction) scanValues(columns []string) ([]any, error) { case transaction.ForeignKeys[1]: // request_transaction values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: - return nil, fmt.Errorf("unexpected column %q for type Transaction", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -146,11 +142,19 @@ func (t *Transaction) assignValues(columns []string, values []any) error { t.request_transaction = new(uuid.UUID) *t.request_transaction = *value.S.(*uuid.UUID) } + default: + t.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the Transaction. +// This includes values selected through modifiers, order, etc. +func (t *Transaction) Value(name string) (ent.Value, error) { + return t.selectValues.Get(name) +} + // QueryDetail queries the "detail" edge of the Transaction entity. func (t *Transaction) QueryDetail() *TransactionDetailQuery { return NewTransactionClient(t.config).QueryDetail(t) diff --git a/ent/transaction/transaction.go b/ent/transaction/transaction.go index 0004eebc..413ad964 100644 --- a/ent/transaction/transaction.go +++ b/ent/transaction/transaction.go @@ -5,6 +5,8 @@ package transaction import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -93,3 +95,79 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the Transaction queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByDetailField orders the results by detail field. +func ByDetailField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newDetailStep(), sql.OrderByField(field, opts...)) + } +} + +// ByTagCount orders the results by tag count. +func ByTagCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTagStep(), opts...) + } +} + +// ByTag orders the results by tag terms. +func ByTag(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTagStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByGroupBudgetField orders the results by group_budget field. +func ByGroupBudgetField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newGroupBudgetStep(), sql.OrderByField(field, opts...)) + } +} + +// ByRequestField orders the results by request field. +func ByRequestField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStep(), sql.OrderByField(field, opts...)) + } +} +func newDetailStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(DetailInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2O, false, DetailTable, DetailColumn), + ) +} +func newTagStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TagInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, TagTable, TagPrimaryKey...), + ) +} +func newGroupBudgetStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(GroupBudgetInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, GroupBudgetTable, GroupBudgetColumn), + ) +} +func newRequestStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), + ) +} diff --git a/ent/transaction/where.go b/ent/transaction/where.go index 4df8f8b0..e48ba68c 100644 --- a/ent/transaction/where.go +++ b/ent/transaction/where.go @@ -115,11 +115,7 @@ func HasDetail() predicate.Transaction { // HasDetailWith applies the HasEdge predicate on the "detail" edge with a given conditions (other predicates). func HasDetailWith(preds ...predicate.TransactionDetail) predicate.Transaction { return predicate.Transaction(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(DetailInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2O, false, DetailTable, DetailColumn), - ) + step := newDetailStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -142,11 +138,7 @@ func HasTag() predicate.Transaction { // HasTagWith applies the HasEdge predicate on the "tag" edge with a given conditions (other predicates). func HasTagWith(preds ...predicate.Tag) predicate.Transaction { return predicate.Transaction(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TagInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, TagTable, TagPrimaryKey...), - ) + step := newTagStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -169,11 +161,7 @@ func HasGroupBudget() predicate.Transaction { // HasGroupBudgetWith applies the HasEdge predicate on the "group_budget" edge with a given conditions (other predicates). func HasGroupBudgetWith(preds ...predicate.GroupBudget) predicate.Transaction { return predicate.Transaction(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupBudgetInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, GroupBudgetTable, GroupBudgetColumn), - ) + step := newGroupBudgetStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -196,11 +184,7 @@ func HasRequest() predicate.Transaction { // HasRequestWith applies the HasEdge predicate on the "request" edge with a given conditions (other predicates). func HasRequestWith(preds ...predicate.Request) predicate.Transaction { return predicate.Transaction(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), - ) + step := newRequestStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -211,32 +195,15 @@ func HasRequestWith(preds ...predicate.Request) predicate.Transaction { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Transaction) predicate.Transaction { - return predicate.Transaction(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Transaction(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Transaction) predicate.Transaction { - return predicate.Transaction(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Transaction(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Transaction) predicate.Transaction { - return predicate.Transaction(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Transaction(sql.NotPredicates(p)) } diff --git a/ent/transaction_create.go b/ent/transaction_create.go index 2e6f23b0..d196fd07 100644 --- a/ent/transaction_create.go +++ b/ent/transaction_create.go @@ -125,7 +125,7 @@ func (tc *TransactionCreate) Mutation() *TransactionMutation { // Save creates the Transaction in the database. func (tc *TransactionCreate) Save(ctx context.Context) (*Transaction, error) { tc.defaults() - return withHooks[*Transaction, TransactionMutation](ctx, tc.sqlSave, tc.mutation, tc.hooks) + return withHooks(ctx, tc.sqlSave, tc.mutation, tc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -167,7 +167,7 @@ func (tc *TransactionCreate) check() error { if _, ok := tc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Transaction.created_at"`)} } - if _, ok := tc.mutation.DetailID(); !ok { + if len(tc.mutation.DetailIDs()) == 0 { return &ValidationError{Name: "detail", err: errors.New(`ent: missing required edge "Transaction.detail"`)} } return nil @@ -217,10 +217,7 @@ func (tc *TransactionCreate) createSpec() (*Transaction, *sqlgraph.CreateSpec) { Columns: []string{transaction.DetailColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transactiondetail.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transactiondetail.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -236,10 +233,7 @@ func (tc *TransactionCreate) createSpec() (*Transaction, *sqlgraph.CreateSpec) { Columns: transaction.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -255,10 +249,7 @@ func (tc *TransactionCreate) createSpec() (*Transaction, *sqlgraph.CreateSpec) { Columns: []string{transaction.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -275,10 +266,7 @@ func (tc *TransactionCreate) createSpec() (*Transaction, *sqlgraph.CreateSpec) { Columns: []string{transaction.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -293,11 +281,15 @@ func (tc *TransactionCreate) createSpec() (*Transaction, *sqlgraph.CreateSpec) { // TransactionCreateBulk is the builder for creating many Transaction entities in bulk. type TransactionCreateBulk struct { config + err error builders []*TransactionCreate } // Save creates the Transaction entities in the database. func (tcb *TransactionCreateBulk) Save(ctx context.Context) ([]*Transaction, error) { + if tcb.err != nil { + return nil, tcb.err + } specs := make([]*sqlgraph.CreateSpec, len(tcb.builders)) nodes := make([]*Transaction, len(tcb.builders)) mutators := make([]Mutator, len(tcb.builders)) @@ -314,8 +306,8 @@ func (tcb *TransactionCreateBulk) Save(ctx context.Context) ([]*Transaction, err return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, tcb.builders[i+1].mutation) } else { diff --git a/ent/transaction_delete.go b/ent/transaction_delete.go index 77ba20e4..882589b4 100644 --- a/ent/transaction_delete.go +++ b/ent/transaction_delete.go @@ -27,7 +27,7 @@ func (td *TransactionDelete) Where(ps ...predicate.Transaction) *TransactionDele // Exec executes the deletion query and returns how many vertices were deleted. func (td *TransactionDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, TransactionMutation](ctx, td.sqlExec, td.mutation, td.hooks) + return withHooks(ctx, td.sqlExec, td.mutation, td.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/transaction_query.go b/ent/transaction_query.go index 11a6bfe7..e13f8889 100644 --- a/ent/transaction_query.go +++ b/ent/transaction_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -24,7 +25,7 @@ import ( type TransactionQuery struct { config ctx *QueryContext - order []OrderFunc + order []transaction.OrderOption inters []Interceptor predicates []predicate.Transaction withDetail *TransactionDetailQuery @@ -63,7 +64,7 @@ func (tq *TransactionQuery) Unique(unique bool) *TransactionQuery { } // Order specifies how the records should be ordered. -func (tq *TransactionQuery) Order(o ...OrderFunc) *TransactionQuery { +func (tq *TransactionQuery) Order(o ...transaction.OrderOption) *TransactionQuery { tq.order = append(tq.order, o...) return tq } @@ -159,7 +160,7 @@ func (tq *TransactionQuery) QueryRequest() *RequestQuery { // First returns the first Transaction entity from the query. // Returns a *NotFoundError when no Transaction was found. func (tq *TransactionQuery) First(ctx context.Context) (*Transaction, error) { - nodes, err := tq.Limit(1).All(setContextOp(ctx, tq.ctx, "First")) + nodes, err := tq.Limit(1).All(setContextOp(ctx, tq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -182,7 +183,7 @@ func (tq *TransactionQuery) FirstX(ctx context.Context) *Transaction { // Returns a *NotFoundError when no Transaction ID was found. func (tq *TransactionQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = tq.Limit(1).IDs(setContextOp(ctx, tq.ctx, "FirstID")); err != nil { + if ids, err = tq.Limit(1).IDs(setContextOp(ctx, tq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -205,7 +206,7 @@ func (tq *TransactionQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Transaction entity is found. // Returns a *NotFoundError when no Transaction entities are found. func (tq *TransactionQuery) Only(ctx context.Context) (*Transaction, error) { - nodes, err := tq.Limit(2).All(setContextOp(ctx, tq.ctx, "Only")) + nodes, err := tq.Limit(2).All(setContextOp(ctx, tq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -233,7 +234,7 @@ func (tq *TransactionQuery) OnlyX(ctx context.Context) *Transaction { // Returns a *NotFoundError when no entities are found. func (tq *TransactionQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = tq.Limit(2).IDs(setContextOp(ctx, tq.ctx, "OnlyID")); err != nil { + if ids, err = tq.Limit(2).IDs(setContextOp(ctx, tq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -258,7 +259,7 @@ func (tq *TransactionQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Transactions. func (tq *TransactionQuery) All(ctx context.Context) ([]*Transaction, error) { - ctx = setContextOp(ctx, tq.ctx, "All") + ctx = setContextOp(ctx, tq.ctx, ent.OpQueryAll) if err := tq.prepareQuery(ctx); err != nil { return nil, err } @@ -280,7 +281,7 @@ func (tq *TransactionQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error if tq.ctx.Unique == nil && tq.path != nil { tq.Unique(true) } - ctx = setContextOp(ctx, tq.ctx, "IDs") + ctx = setContextOp(ctx, tq.ctx, ent.OpQueryIDs) if err = tq.Select(transaction.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -298,7 +299,7 @@ func (tq *TransactionQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (tq *TransactionQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, tq.ctx, "Count") + ctx = setContextOp(ctx, tq.ctx, ent.OpQueryCount) if err := tq.prepareQuery(ctx); err != nil { return 0, err } @@ -316,7 +317,7 @@ func (tq *TransactionQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (tq *TransactionQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, tq.ctx, "Exist") + ctx = setContextOp(ctx, tq.ctx, ent.OpQueryExist) switch _, err := tq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -345,7 +346,7 @@ func (tq *TransactionQuery) Clone() *TransactionQuery { return &TransactionQuery{ config: tq.config, ctx: tq.ctx.Clone(), - order: append([]OrderFunc{}, tq.order...), + order: append([]transaction.OrderOption{}, tq.order...), inters: append([]Interceptor{}, tq.inters...), predicates: append([]predicate.Transaction{}, tq.predicates...), withDetail: tq.withDetail.Clone(), @@ -549,7 +550,7 @@ func (tq *TransactionQuery) loadDetail(ctx context.Context, query *TransactionDe } query.withFKs = true query.Where(predicate.TransactionDetail(func(s *sql.Selector) { - s.Where(sql.InValues(transaction.DetailColumn, fks...)) + s.Where(sql.InValues(s.C(transaction.DetailColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -562,7 +563,7 @@ func (tq *TransactionQuery) loadDetail(ctx context.Context, query *TransactionDe } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "transaction_detail" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "transaction_detail" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -789,7 +790,7 @@ func (tgb *TransactionGroupBy) Aggregate(fns ...AggregateFunc) *TransactionGroup // Scan applies the selector query and scans the result into the given value. func (tgb *TransactionGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, tgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, tgb.build.ctx, ent.OpQueryGroupBy) if err := tgb.build.prepareQuery(ctx); err != nil { return err } @@ -837,7 +838,7 @@ func (ts *TransactionSelect) Aggregate(fns ...AggregateFunc) *TransactionSelect // Scan applies the selector query and scans the result into the given value. func (ts *TransactionSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ts.ctx, "Select") + ctx = setContextOp(ctx, ts.ctx, ent.OpQuerySelect) if err := ts.prepareQuery(ctx); err != nil { return err } diff --git a/ent/transaction_update.go b/ent/transaction_update.go index 2dfdaf9f..d877a806 100644 --- a/ent/transaction_update.go +++ b/ent/transaction_update.go @@ -157,7 +157,7 @@ func (tu *TransactionUpdate) ClearRequest() *TransactionUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (tu *TransactionUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, TransactionMutation](ctx, tu.sqlSave, tu.mutation, tu.hooks) + return withHooks(ctx, tu.sqlSave, tu.mutation, tu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -184,7 +184,7 @@ func (tu *TransactionUpdate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (tu *TransactionUpdate) check() error { - if _, ok := tu.mutation.DetailID(); tu.mutation.DetailCleared() && !ok { + if tu.mutation.DetailCleared() && len(tu.mutation.DetailIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Transaction.detail"`) } return nil @@ -213,10 +213,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{transaction.DetailColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transactiondetail.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transactiondetail.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -229,10 +226,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{transaction.DetailColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transactiondetail.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transactiondetail.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -248,10 +242,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: transaction.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -264,10 +255,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: transaction.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -283,10 +271,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: transaction.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -302,10 +287,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{transaction.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -318,10 +300,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{transaction.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -337,10 +316,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{transaction.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -353,10 +329,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{transaction.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -521,7 +494,7 @@ func (tuo *TransactionUpdateOne) Select(field string, fields ...string) *Transac // Save executes the query and returns the updated Transaction entity. func (tuo *TransactionUpdateOne) Save(ctx context.Context) (*Transaction, error) { - return withHooks[*Transaction, TransactionMutation](ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) + return withHooks(ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -548,7 +521,7 @@ func (tuo *TransactionUpdateOne) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (tuo *TransactionUpdateOne) check() error { - if _, ok := tuo.mutation.DetailID(); tuo.mutation.DetailCleared() && !ok { + if tuo.mutation.DetailCleared() && len(tuo.mutation.DetailIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Transaction.detail"`) } return nil @@ -594,10 +567,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: []string{transaction.DetailColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transactiondetail.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transactiondetail.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -610,10 +580,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: []string{transaction.DetailColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transactiondetail.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transactiondetail.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -629,10 +596,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: transaction.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -645,10 +609,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: transaction.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -664,10 +625,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: transaction.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -683,10 +641,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: []string{transaction.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -699,10 +654,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: []string{transaction.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -718,10 +670,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: []string{transaction.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -734,10 +683,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: []string{transaction.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/transactiondetail.go b/ent/transactiondetail.go index 50f156ab..fe3095f2 100644 --- a/ent/transactiondetail.go +++ b/ent/transactiondetail.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/transaction" @@ -30,6 +31,7 @@ type TransactionDetail struct { // The values are being populated by the TransactionDetailQuery when eager-loading is set. Edges TransactionDetailEdges `json:"edges"` transaction_detail *uuid.UUID + selectValues sql.SelectValues } // TransactionDetailEdges holds the relations/edges for other nodes in the graph. @@ -44,12 +46,10 @@ type TransactionDetailEdges struct { // TransactionOrErr returns the Transaction value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e TransactionDetailEdges) TransactionOrErr() (*Transaction, error) { - if e.loadedTypes[0] { - if e.Transaction == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: transaction.Label} - } + if e.Transaction != nil { return e.Transaction, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: transaction.Label} } return nil, &NotLoadedError{edge: "transaction"} } @@ -70,7 +70,7 @@ func (*TransactionDetail) scanValues(columns []string) ([]any, error) { case transactiondetail.ForeignKeys[0]: // transaction_detail values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: - return nil, fmt.Errorf("unexpected column %q for type TransactionDetail", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -121,11 +121,19 @@ func (td *TransactionDetail) assignValues(columns []string, values []any) error td.transaction_detail = new(uuid.UUID) *td.transaction_detail = *value.S.(*uuid.UUID) } + default: + td.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the TransactionDetail. +// This includes values selected through modifiers, order, etc. +func (td *TransactionDetail) Value(name string) (ent.Value, error) { + return td.selectValues.Get(name) +} + // QueryTransaction queries the "transaction" edge of the TransactionDetail entity. func (td *TransactionDetail) QueryTransaction() *TransactionQuery { return NewTransactionDetailClient(td.config).QueryTransaction(td) diff --git a/ent/transactiondetail/transactiondetail.go b/ent/transactiondetail/transactiondetail.go index d4cb01d2..7929c68c 100644 --- a/ent/transactiondetail/transactiondetail.go +++ b/ent/transactiondetail/transactiondetail.go @@ -5,6 +5,8 @@ package transactiondetail import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -78,3 +80,45 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the TransactionDetail queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByAmount orders the results by the amount field. +func ByAmount(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAmount, opts...).ToFunc() +} + +// ByTarget orders the results by the target field. +func ByTarget(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldTarget, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByTransactionField orders the results by transaction field. +func ByTransactionField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTransactionStep(), sql.OrderByField(field, opts...)) + } +} +func newTransactionStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TransactionInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2O, true, TransactionTable, TransactionColumn), + ) +} diff --git a/ent/transactiondetail/where.go b/ent/transactiondetail/where.go index 836f2812..60d337fe 100644 --- a/ent/transactiondetail/where.go +++ b/ent/transactiondetail/where.go @@ -275,11 +275,7 @@ func HasTransaction() predicate.TransactionDetail { // HasTransactionWith applies the HasEdge predicate on the "transaction" edge with a given conditions (other predicates). func HasTransactionWith(preds ...predicate.Transaction) predicate.TransactionDetail { return predicate.TransactionDetail(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TransactionInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2O, true, TransactionTable, TransactionColumn), - ) + step := newTransactionStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -290,32 +286,15 @@ func HasTransactionWith(preds ...predicate.Transaction) predicate.TransactionDet // And groups predicates with the AND operator between them. func And(predicates ...predicate.TransactionDetail) predicate.TransactionDetail { - return predicate.TransactionDetail(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.TransactionDetail(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.TransactionDetail) predicate.TransactionDetail { - return predicate.TransactionDetail(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.TransactionDetail(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.TransactionDetail) predicate.TransactionDetail { - return predicate.TransactionDetail(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.TransactionDetail(sql.NotPredicates(p)) } diff --git a/ent/transactiondetail_create.go b/ent/transactiondetail_create.go index ddefb40a..25cd01b6 100644 --- a/ent/transactiondetail_create.go +++ b/ent/transactiondetail_create.go @@ -119,7 +119,7 @@ func (tdc *TransactionDetailCreate) Mutation() *TransactionDetailMutation { // Save creates the TransactionDetail in the database. func (tdc *TransactionDetailCreate) Save(ctx context.Context) (*TransactionDetail, error) { tdc.defaults() - return withHooks[*TransactionDetail, TransactionDetailMutation](ctx, tdc.sqlSave, tdc.mutation, tdc.hooks) + return withHooks(ctx, tdc.sqlSave, tdc.mutation, tdc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -241,10 +241,7 @@ func (tdc *TransactionDetailCreate) createSpec() (*TransactionDetail, *sqlgraph. Columns: []string{transactiondetail.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -259,11 +256,15 @@ func (tdc *TransactionDetailCreate) createSpec() (*TransactionDetail, *sqlgraph. // TransactionDetailCreateBulk is the builder for creating many TransactionDetail entities in bulk. type TransactionDetailCreateBulk struct { config + err error builders []*TransactionDetailCreate } // Save creates the TransactionDetail entities in the database. func (tdcb *TransactionDetailCreateBulk) Save(ctx context.Context) ([]*TransactionDetail, error) { + if tdcb.err != nil { + return nil, tdcb.err + } specs := make([]*sqlgraph.CreateSpec, len(tdcb.builders)) nodes := make([]*TransactionDetail, len(tdcb.builders)) mutators := make([]Mutator, len(tdcb.builders)) @@ -280,8 +281,8 @@ func (tdcb *TransactionDetailCreateBulk) Save(ctx context.Context) ([]*Transacti return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, tdcb.builders[i+1].mutation) } else { diff --git a/ent/transactiondetail_delete.go b/ent/transactiondetail_delete.go index 60dfaa0c..733ff8aa 100644 --- a/ent/transactiondetail_delete.go +++ b/ent/transactiondetail_delete.go @@ -27,7 +27,7 @@ func (tdd *TransactionDetailDelete) Where(ps ...predicate.TransactionDetail) *Tr // Exec executes the deletion query and returns how many vertices were deleted. func (tdd *TransactionDetailDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, TransactionDetailMutation](ctx, tdd.sqlExec, tdd.mutation, tdd.hooks) + return withHooks(ctx, tdd.sqlExec, tdd.mutation, tdd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/transactiondetail_query.go b/ent/transactiondetail_query.go index 0d7714d3..e2dfe2a9 100644 --- a/ent/transactiondetail_query.go +++ b/ent/transactiondetail_query.go @@ -7,6 +7,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -20,7 +21,7 @@ import ( type TransactionDetailQuery struct { config ctx *QueryContext - order []OrderFunc + order []transactiondetail.OrderOption inters []Interceptor predicates []predicate.TransactionDetail withTransaction *TransactionQuery @@ -56,7 +57,7 @@ func (tdq *TransactionDetailQuery) Unique(unique bool) *TransactionDetailQuery { } // Order specifies how the records should be ordered. -func (tdq *TransactionDetailQuery) Order(o ...OrderFunc) *TransactionDetailQuery { +func (tdq *TransactionDetailQuery) Order(o ...transactiondetail.OrderOption) *TransactionDetailQuery { tdq.order = append(tdq.order, o...) return tdq } @@ -86,7 +87,7 @@ func (tdq *TransactionDetailQuery) QueryTransaction() *TransactionQuery { // First returns the first TransactionDetail entity from the query. // Returns a *NotFoundError when no TransactionDetail was found. func (tdq *TransactionDetailQuery) First(ctx context.Context) (*TransactionDetail, error) { - nodes, err := tdq.Limit(1).All(setContextOp(ctx, tdq.ctx, "First")) + nodes, err := tdq.Limit(1).All(setContextOp(ctx, tdq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -109,7 +110,7 @@ func (tdq *TransactionDetailQuery) FirstX(ctx context.Context) *TransactionDetai // Returns a *NotFoundError when no TransactionDetail ID was found. func (tdq *TransactionDetailQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = tdq.Limit(1).IDs(setContextOp(ctx, tdq.ctx, "FirstID")); err != nil { + if ids, err = tdq.Limit(1).IDs(setContextOp(ctx, tdq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -132,7 +133,7 @@ func (tdq *TransactionDetailQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one TransactionDetail entity is found. // Returns a *NotFoundError when no TransactionDetail entities are found. func (tdq *TransactionDetailQuery) Only(ctx context.Context) (*TransactionDetail, error) { - nodes, err := tdq.Limit(2).All(setContextOp(ctx, tdq.ctx, "Only")) + nodes, err := tdq.Limit(2).All(setContextOp(ctx, tdq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -160,7 +161,7 @@ func (tdq *TransactionDetailQuery) OnlyX(ctx context.Context) *TransactionDetail // Returns a *NotFoundError when no entities are found. func (tdq *TransactionDetailQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = tdq.Limit(2).IDs(setContextOp(ctx, tdq.ctx, "OnlyID")); err != nil { + if ids, err = tdq.Limit(2).IDs(setContextOp(ctx, tdq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -185,7 +186,7 @@ func (tdq *TransactionDetailQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of TransactionDetails. func (tdq *TransactionDetailQuery) All(ctx context.Context) ([]*TransactionDetail, error) { - ctx = setContextOp(ctx, tdq.ctx, "All") + ctx = setContextOp(ctx, tdq.ctx, ent.OpQueryAll) if err := tdq.prepareQuery(ctx); err != nil { return nil, err } @@ -207,7 +208,7 @@ func (tdq *TransactionDetailQuery) IDs(ctx context.Context) (ids []uuid.UUID, er if tdq.ctx.Unique == nil && tdq.path != nil { tdq.Unique(true) } - ctx = setContextOp(ctx, tdq.ctx, "IDs") + ctx = setContextOp(ctx, tdq.ctx, ent.OpQueryIDs) if err = tdq.Select(transactiondetail.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -225,7 +226,7 @@ func (tdq *TransactionDetailQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (tdq *TransactionDetailQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, tdq.ctx, "Count") + ctx = setContextOp(ctx, tdq.ctx, ent.OpQueryCount) if err := tdq.prepareQuery(ctx); err != nil { return 0, err } @@ -243,7 +244,7 @@ func (tdq *TransactionDetailQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (tdq *TransactionDetailQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, tdq.ctx, "Exist") + ctx = setContextOp(ctx, tdq.ctx, ent.OpQueryExist) switch _, err := tdq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -272,7 +273,7 @@ func (tdq *TransactionDetailQuery) Clone() *TransactionDetailQuery { return &TransactionDetailQuery{ config: tdq.config, ctx: tdq.ctx.Clone(), - order: append([]OrderFunc{}, tdq.order...), + order: append([]transactiondetail.OrderOption{}, tdq.order...), inters: append([]Interceptor{}, tdq.inters...), predicates: append([]predicate.TransactionDetail{}, tdq.predicates...), withTransaction: tdq.withTransaction.Clone(), @@ -537,7 +538,7 @@ func (tdgb *TransactionDetailGroupBy) Aggregate(fns ...AggregateFunc) *Transacti // Scan applies the selector query and scans the result into the given value. func (tdgb *TransactionDetailGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, tdgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, tdgb.build.ctx, ent.OpQueryGroupBy) if err := tdgb.build.prepareQuery(ctx); err != nil { return err } @@ -585,7 +586,7 @@ func (tds *TransactionDetailSelect) Aggregate(fns ...AggregateFunc) *Transaction // Scan applies the selector query and scans the result into the given value. func (tds *TransactionDetailSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, tds.ctx, "Select") + ctx = setContextOp(ctx, tds.ctx, ent.OpQuerySelect) if err := tds.prepareQuery(ctx); err != nil { return err } diff --git a/ent/transactiondetail_update.go b/ent/transactiondetail_update.go index 0583e60a..418fd1b9 100644 --- a/ent/transactiondetail_update.go +++ b/ent/transactiondetail_update.go @@ -118,7 +118,7 @@ func (tdu *TransactionDetailUpdate) ClearTransaction() *TransactionDetailUpdate // Save executes the query and returns the number of nodes affected by the update operation. func (tdu *TransactionDetailUpdate) Save(ctx context.Context) (int, error) { tdu.defaults() - return withHooks[int, TransactionDetailMutation](ctx, tdu.sqlSave, tdu.mutation, tdu.hooks) + return withHooks(ctx, tdu.sqlSave, tdu.mutation, tdu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -183,10 +183,7 @@ func (tdu *TransactionDetailUpdate) sqlSave(ctx context.Context) (n int, err err Columns: []string{transactiondetail.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -199,10 +196,7 @@ func (tdu *TransactionDetailUpdate) sqlSave(ctx context.Context) (n int, err err Columns: []string{transactiondetail.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -331,7 +325,7 @@ func (tduo *TransactionDetailUpdateOne) Select(field string, fields ...string) * // Save executes the query and returns the updated TransactionDetail entity. func (tduo *TransactionDetailUpdateOne) Save(ctx context.Context) (*TransactionDetail, error) { tduo.defaults() - return withHooks[*TransactionDetail, TransactionDetailMutation](ctx, tduo.sqlSave, tduo.mutation, tduo.hooks) + return withHooks(ctx, tduo.sqlSave, tduo.mutation, tduo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -413,10 +407,7 @@ func (tduo *TransactionDetailUpdateOne) sqlSave(ctx context.Context) (_node *Tra Columns: []string{transactiondetail.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -429,10 +420,7 @@ func (tduo *TransactionDetailUpdateOne) sqlSave(ctx context.Context) (_node *Tra Columns: []string{transactiondetail.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/user.go b/ent/user.go index 234e549b..ee2a0486 100644 --- a/ent/user.go +++ b/ent/user.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/user" @@ -31,7 +32,8 @@ type User struct { DeletedAt *time.Time `json:"deleted_at,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the UserQuery when eager-loading is set. - Edges UserEdges `json:"edges"` + Edges UserEdges `json:"edges"` + selectValues sql.SelectValues } // UserEdges holds the relations/edges for other nodes in the graph. @@ -132,7 +134,7 @@ func (*User) scanValues(columns []string) ([]any, error) { case user.FieldID: values[i] = new(uuid.UUID) default: - return nil, fmt.Errorf("unexpected column %q for type User", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -189,11 +191,19 @@ func (u *User) assignValues(columns []string, values []any) error { u.DeletedAt = new(time.Time) *u.DeletedAt = value.Time } + default: + u.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the User. +// This includes values selected through modifiers, order, etc. +func (u *User) Value(name string) (ent.Value, error) { + return u.selectValues.Get(name) +} + // QueryGroupUser queries the "group_user" edge of the User entity. func (u *User) QueryGroupUser() *GroupQuery { return NewUserClient(u.config).QueryGroupUser(u) diff --git a/ent/user/user.go b/ent/user/user.go index 1f18ab6f..43f58af7 100644 --- a/ent/user/user.go +++ b/ent/user/user.go @@ -5,6 +5,8 @@ package user import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -132,3 +134,188 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the User queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByDisplayName orders the results by the display_name field. +func ByDisplayName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDisplayName, opts...).ToFunc() +} + +// ByAdmin orders the results by the admin field. +func ByAdmin(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAdmin, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByDeletedAt orders the results by the deleted_at field. +func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() +} + +// ByGroupUserCount orders the results by group_user count. +func ByGroupUserCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newGroupUserStep(), opts...) + } +} + +// ByGroupUser orders the results by group_user terms. +func ByGroupUser(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newGroupUserStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByGroupOwnerCount orders the results by group_owner count. +func ByGroupOwnerCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newGroupOwnerStep(), opts...) + } +} + +// ByGroupOwner orders the results by group_owner terms. +func ByGroupOwner(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newGroupOwnerStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByCommentCount orders the results by comment count. +func ByCommentCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newCommentStep(), opts...) + } +} + +// ByComment orders the results by comment terms. +func ByComment(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newCommentStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByRequestStatusCount orders the results by request_status count. +func ByRequestStatusCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newRequestStatusStep(), opts...) + } +} + +// ByRequestStatus orders the results by request_status terms. +func ByRequestStatus(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStatusStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByRequestCount orders the results by request count. +func ByRequestCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newRequestStep(), opts...) + } +} + +// ByRequest orders the results by request terms. +func ByRequest(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByFileCount orders the results by file count. +func ByFileCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newFileStep(), opts...) + } +} + +// ByFile orders the results by file terms. +func ByFile(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newFileStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByRequestTargetCount orders the results by request_target count. +func ByRequestTargetCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newRequestTargetStep(), opts...) + } +} + +// ByRequestTarget orders the results by request_target terms. +func ByRequestTarget(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestTargetStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newGroupUserStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(GroupUserInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, GroupUserTable, GroupUserPrimaryKey...), + ) +} +func newGroupOwnerStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(GroupOwnerInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, GroupOwnerTable, GroupOwnerPrimaryKey...), + ) +} +func newCommentStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(CommentInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, CommentTable, CommentColumn), + ) +} +func newRequestStatusStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestStatusInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, RequestStatusTable, RequestStatusColumn), + ) +} +func newRequestStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, RequestTable, RequestColumn), + ) +} +func newFileStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(FileInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, FileTable, FileColumn), + ) +} +func newRequestTargetStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestTargetInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, RequestTargetTable, RequestTargetColumn), + ) +} diff --git a/ent/user/where.go b/ent/user/where.go index bf322de3..97d1d1aa 100644 --- a/ent/user/where.go +++ b/ent/user/where.go @@ -370,11 +370,7 @@ func HasGroupUser() predicate.User { // HasGroupUserWith applies the HasEdge predicate on the "group_user" edge with a given conditions (other predicates). func HasGroupUserWith(preds ...predicate.Group) predicate.User { return predicate.User(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupUserInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, GroupUserTable, GroupUserPrimaryKey...), - ) + step := newGroupUserStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -397,11 +393,7 @@ func HasGroupOwner() predicate.User { // HasGroupOwnerWith applies the HasEdge predicate on the "group_owner" edge with a given conditions (other predicates). func HasGroupOwnerWith(preds ...predicate.Group) predicate.User { return predicate.User(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupOwnerInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, GroupOwnerTable, GroupOwnerPrimaryKey...), - ) + step := newGroupOwnerStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -424,11 +416,7 @@ func HasComment() predicate.User { // HasCommentWith applies the HasEdge predicate on the "comment" edge with a given conditions (other predicates). func HasCommentWith(preds ...predicate.Comment) predicate.User { return predicate.User(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(CommentInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, CommentTable, CommentColumn), - ) + step := newCommentStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -451,11 +439,7 @@ func HasRequestStatus() predicate.User { // HasRequestStatusWith applies the HasEdge predicate on the "request_status" edge with a given conditions (other predicates). func HasRequestStatusWith(preds ...predicate.RequestStatus) predicate.User { return predicate.User(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestStatusInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, RequestStatusTable, RequestStatusColumn), - ) + step := newRequestStatusStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -478,11 +462,7 @@ func HasRequest() predicate.User { // HasRequestWith applies the HasEdge predicate on the "request" edge with a given conditions (other predicates). func HasRequestWith(preds ...predicate.Request) predicate.User { return predicate.User(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, RequestTable, RequestColumn), - ) + step := newRequestStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -505,11 +485,7 @@ func HasFile() predicate.User { // HasFileWith applies the HasEdge predicate on the "file" edge with a given conditions (other predicates). func HasFileWith(preds ...predicate.File) predicate.User { return predicate.User(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(FileInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, FileTable, FileColumn), - ) + step := newFileStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -532,11 +508,7 @@ func HasRequestTarget() predicate.User { // HasRequestTargetWith applies the HasEdge predicate on the "request_target" edge with a given conditions (other predicates). func HasRequestTargetWith(preds ...predicate.RequestTarget) predicate.User { return predicate.User(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestTargetInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, RequestTargetTable, RequestTargetColumn), - ) + step := newRequestTargetStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -547,32 +519,15 @@ func HasRequestTargetWith(preds ...predicate.RequestTarget) predicate.User { // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.User(sql.NotPredicates(p)) } diff --git a/ent/user_create.go b/ent/user_create.go index 68e1224f..9fbcd3ef 100644 --- a/ent/user_create.go +++ b/ent/user_create.go @@ -222,7 +222,7 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { uc.defaults() - return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) + return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -356,10 +356,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { Columns: user.GroupUserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -375,10 +372,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { Columns: user.GroupOwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -394,10 +388,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { Columns: []string{user.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -413,10 +404,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { Columns: []string{user.RequestStatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -432,10 +420,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { Columns: []string{user.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -451,10 +436,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { Columns: []string{user.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -470,10 +452,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { Columns: []string{user.RequestTargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -487,11 +466,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { // UserCreateBulk is the builder for creating many User entities in bulk. type UserCreateBulk struct { config + err error builders []*UserCreate } // Save creates the User entities in the database. func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { + if ucb.err != nil { + return nil, ucb.err + } specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) nodes := make([]*User, len(ucb.builders)) mutators := make([]Mutator, len(ucb.builders)) @@ -508,8 +491,8 @@ func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, ucb.builders[i+1].mutation) } else { diff --git a/ent/user_delete.go b/ent/user_delete.go index 9e0915a1..56efc0a6 100644 --- a/ent/user_delete.go +++ b/ent/user_delete.go @@ -27,7 +27,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) + return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/user_query.go b/ent/user_query.go index 84d6ee6b..5e6b3fe6 100644 --- a/ent/user_query.go +++ b/ent/user_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -26,7 +27,7 @@ import ( type UserQuery struct { config ctx *QueryContext - order []OrderFunc + order []user.OrderOption inters []Interceptor predicates []predicate.User withGroupUser *GroupQuery @@ -67,7 +68,7 @@ func (uq *UserQuery) Unique(unique bool) *UserQuery { } // Order specifies how the records should be ordered. -func (uq *UserQuery) Order(o ...OrderFunc) *UserQuery { +func (uq *UserQuery) Order(o ...user.OrderOption) *UserQuery { uq.order = append(uq.order, o...) return uq } @@ -229,7 +230,7 @@ func (uq *UserQuery) QueryRequestTarget() *RequestTargetQuery { // First returns the first User entity from the query. // Returns a *NotFoundError when no User was found. func (uq *UserQuery) First(ctx context.Context) (*User, error) { - nodes, err := uq.Limit(1).All(setContextOp(ctx, uq.ctx, "First")) + nodes, err := uq.Limit(1).All(setContextOp(ctx, uq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -252,7 +253,7 @@ func (uq *UserQuery) FirstX(ctx context.Context) *User { // Returns a *NotFoundError when no User ID was found. func (uq *UserQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = uq.Limit(1).IDs(setContextOp(ctx, uq.ctx, "FirstID")); err != nil { + if ids, err = uq.Limit(1).IDs(setContextOp(ctx, uq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -275,7 +276,7 @@ func (uq *UserQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one User entity is found. // Returns a *NotFoundError when no User entities are found. func (uq *UserQuery) Only(ctx context.Context) (*User, error) { - nodes, err := uq.Limit(2).All(setContextOp(ctx, uq.ctx, "Only")) + nodes, err := uq.Limit(2).All(setContextOp(ctx, uq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -303,7 +304,7 @@ func (uq *UserQuery) OnlyX(ctx context.Context) *User { // Returns a *NotFoundError when no entities are found. func (uq *UserQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = uq.Limit(2).IDs(setContextOp(ctx, uq.ctx, "OnlyID")); err != nil { + if ids, err = uq.Limit(2).IDs(setContextOp(ctx, uq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -328,7 +329,7 @@ func (uq *UserQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Users. func (uq *UserQuery) All(ctx context.Context) ([]*User, error) { - ctx = setContextOp(ctx, uq.ctx, "All") + ctx = setContextOp(ctx, uq.ctx, ent.OpQueryAll) if err := uq.prepareQuery(ctx); err != nil { return nil, err } @@ -350,7 +351,7 @@ func (uq *UserQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if uq.ctx.Unique == nil && uq.path != nil { uq.Unique(true) } - ctx = setContextOp(ctx, uq.ctx, "IDs") + ctx = setContextOp(ctx, uq.ctx, ent.OpQueryIDs) if err = uq.Select(user.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -368,7 +369,7 @@ func (uq *UserQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (uq *UserQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, uq.ctx, "Count") + ctx = setContextOp(ctx, uq.ctx, ent.OpQueryCount) if err := uq.prepareQuery(ctx); err != nil { return 0, err } @@ -386,7 +387,7 @@ func (uq *UserQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (uq *UserQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, uq.ctx, "Exist") + ctx = setContextOp(ctx, uq.ctx, ent.OpQueryExist) switch _, err := uq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -415,7 +416,7 @@ func (uq *UserQuery) Clone() *UserQuery { return &UserQuery{ config: uq.config, ctx: uq.ctx.Clone(), - order: append([]OrderFunc{}, uq.order...), + order: append([]user.OrderOption{}, uq.order...), inters: append([]Interceptor{}, uq.inters...), predicates: append([]predicate.User{}, uq.predicates...), withGroupUser: uq.withGroupUser.Clone(), @@ -800,7 +801,7 @@ func (uq *UserQuery) loadComment(ctx context.Context, query *CommentQuery, nodes } query.withFKs = true query.Where(predicate.Comment(func(s *sql.Selector) { - s.Where(sql.InValues(user.CommentColumn, fks...)) + s.Where(sql.InValues(s.C(user.CommentColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -813,7 +814,7 @@ func (uq *UserQuery) loadComment(ctx context.Context, query *CommentQuery, nodes } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "comment_user" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "comment_user" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -831,7 +832,7 @@ func (uq *UserQuery) loadRequestStatus(ctx context.Context, query *RequestStatus } query.withFKs = true query.Where(predicate.RequestStatus(func(s *sql.Selector) { - s.Where(sql.InValues(user.RequestStatusColumn, fks...)) + s.Where(sql.InValues(s.C(user.RequestStatusColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -844,7 +845,7 @@ func (uq *UserQuery) loadRequestStatus(ctx context.Context, query *RequestStatus } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "request_status_user" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "request_status_user" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -862,7 +863,7 @@ func (uq *UserQuery) loadRequest(ctx context.Context, query *RequestQuery, nodes } query.withFKs = true query.Where(predicate.Request(func(s *sql.Selector) { - s.Where(sql.InValues(user.RequestColumn, fks...)) + s.Where(sql.InValues(s.C(user.RequestColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -875,7 +876,7 @@ func (uq *UserQuery) loadRequest(ctx context.Context, query *RequestQuery, nodes } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "request_user" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "request_user" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -893,7 +894,7 @@ func (uq *UserQuery) loadFile(ctx context.Context, query *FileQuery, nodes []*Us } query.withFKs = true query.Where(predicate.File(func(s *sql.Selector) { - s.Where(sql.InValues(user.FileColumn, fks...)) + s.Where(sql.InValues(s.C(user.FileColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -906,7 +907,7 @@ func (uq *UserQuery) loadFile(ctx context.Context, query *FileQuery, nodes []*Us } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "file_user" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "file_user" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -924,7 +925,7 @@ func (uq *UserQuery) loadRequestTarget(ctx context.Context, query *RequestTarget } query.withFKs = true query.Where(predicate.RequestTarget(func(s *sql.Selector) { - s.Where(sql.InValues(user.RequestTargetColumn, fks...)) + s.Where(sql.InValues(s.C(user.RequestTargetColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -937,7 +938,7 @@ func (uq *UserQuery) loadRequestTarget(ctx context.Context, query *RequestTarget } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "request_target_user" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "request_target_user" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -1039,7 +1040,7 @@ func (ugb *UserGroupBy) Aggregate(fns ...AggregateFunc) *UserGroupBy { // Scan applies the selector query and scans the result into the given value. func (ugb *UserGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ugb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, ugb.build.ctx, ent.OpQueryGroupBy) if err := ugb.build.prepareQuery(ctx); err != nil { return err } @@ -1087,7 +1088,7 @@ func (us *UserSelect) Aggregate(fns ...AggregateFunc) *UserSelect { // Scan applies the selector query and scans the result into the given value. func (us *UserSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, us.ctx, "Select") + ctx = setContextOp(ctx, us.ctx, ent.OpQuerySelect) if err := us.prepareQuery(ctx); err != nil { return err } diff --git a/ent/user_update.go b/ent/user_update.go index 1d8fcf75..5da8cafb 100644 --- a/ent/user_update.go +++ b/ent/user_update.go @@ -41,12 +41,28 @@ func (uu *UserUpdate) SetName(s string) *UserUpdate { return uu } +// SetNillableName sets the "name" field if the given value is not nil. +func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate { + if s != nil { + uu.SetName(*s) + } + return uu +} + // SetDisplayName sets the "display_name" field. func (uu *UserUpdate) SetDisplayName(s string) *UserUpdate { uu.mutation.SetDisplayName(s) return uu } +// SetNillableDisplayName sets the "display_name" field if the given value is not nil. +func (uu *UserUpdate) SetNillableDisplayName(s *string) *UserUpdate { + if s != nil { + uu.SetDisplayName(*s) + } + return uu +} + // SetAdmin sets the "admin" field. func (uu *UserUpdate) SetAdmin(b bool) *UserUpdate { uu.mutation.SetAdmin(b) @@ -361,7 +377,7 @@ func (uu *UserUpdate) RemoveRequestTarget(r ...*RequestTarget) *UserUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { uu.defaults() - return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) + return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -445,10 +461,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: user.GroupUserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -461,10 +474,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: user.GroupUserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -480,10 +490,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: user.GroupUserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -499,10 +506,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: user.GroupOwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -515,10 +519,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: user.GroupOwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -534,10 +535,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: user.GroupOwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -553,10 +551,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -569,10 +564,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -588,10 +580,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -607,10 +596,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestStatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -623,10 +609,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestStatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -642,10 +625,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestStatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -661,10 +641,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -677,10 +654,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -696,10 +670,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -715,10 +686,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -731,10 +699,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -750,10 +715,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -769,10 +731,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestTargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -785,10 +744,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestTargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -804,10 +760,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestTargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -841,12 +794,28 @@ func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne { return uuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne { + if s != nil { + uuo.SetName(*s) + } + return uuo +} + // SetDisplayName sets the "display_name" field. func (uuo *UserUpdateOne) SetDisplayName(s string) *UserUpdateOne { uuo.mutation.SetDisplayName(s) return uuo } +// SetNillableDisplayName sets the "display_name" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableDisplayName(s *string) *UserUpdateOne { + if s != nil { + uuo.SetDisplayName(*s) + } + return uuo +} + // SetAdmin sets the "admin" field. func (uuo *UserUpdateOne) SetAdmin(b bool) *UserUpdateOne { uuo.mutation.SetAdmin(b) @@ -1174,7 +1143,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { uuo.defaults() - return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) + return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -1275,10 +1244,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: user.GroupUserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1291,10 +1257,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: user.GroupUserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1310,10 +1273,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: user.GroupUserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1329,10 +1289,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: user.GroupOwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1345,10 +1302,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: user.GroupOwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1364,10 +1318,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: user.GroupOwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1383,10 +1334,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1399,10 +1347,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1418,10 +1363,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1437,10 +1379,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestStatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1453,10 +1392,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestStatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1472,10 +1408,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestStatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1491,10 +1424,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1507,10 +1437,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1526,10 +1453,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1545,10 +1469,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1561,10 +1482,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1580,10 +1498,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1599,10 +1514,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestTargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1615,10 +1527,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestTargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1634,10 +1543,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestTargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/go.mod b/go.mod index 640e5cfb..3b792d53 100644 --- a/go.mod +++ b/go.mod @@ -1,17 +1,18 @@ module github.com/traPtitech/Jomon -go 1.22.3 +go 1.23.0 require ( - entgo.io/ent v0.13.1 + entgo.io/ent v0.14.0 github.com/go-sql-driver/mysql v1.8.1 - github.com/golang/mock v1.6.0 github.com/google/uuid v1.6.0 - github.com/gorilla/sessions v1.2.2 + github.com/gorilla/sessions v1.4.0 github.com/labstack/echo-contrib v0.17.1 github.com/labstack/echo/v4 v4.12.0 github.com/ncw/swift v1.0.53 + github.com/samber/lo v1.47.0 github.com/stretchr/testify v1.9.0 + go.uber.org/mock v0.4.0 go.uber.org/zap v1.27.0 ) @@ -32,13 +33,11 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/samber/lo v1.42.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect github.com/zclconf/go-cty v1.11.0 // indirect go.uber.org/multierr v1.10.0 // indirect golang.org/x/crypto v0.22.0 // indirect - golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/sys v0.19.0 // indirect diff --git a/go.sum b/go.sum index a93073bd..8a4cc276 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 h1:GwdJbXydHCYPedeeLt4x/lrlIISQ4JTH1mRWuE5ZZ14= ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43/go.mod h1:uj3pm+hUTVN/X5yfdBexHlZv+1Xu5u5ZbZx7+CDavNU= -entgo.io/ent v0.13.1 h1:uD8QwN1h6SNphdCCzmkMN3feSUzNnVvV/WIkHKMbzOE= -entgo.io/ent v0.13.1/go.mod h1:qCEmo+biw3ccBn9OyL4ZK5dfpwg++l1Gxwac5B1206A= +entgo.io/ent v0.14.0 h1:EO3Z9aZ5bXJatJeGqu/EVdnNr6K4mRq3rWe5owt0MC4= +entgo.io/ent v0.14.0/go.mod h1:qCEmo+biw3ccBn9OyL4ZK5dfpwg++l1Gxwac5B1206A= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= @@ -20,8 +20,6 @@ github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= -github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= -github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= @@ -32,8 +30,8 @@ github.com/gorilla/context v1.1.2 h1:WRkNAv2uoa03QNIc1A6u4O7DAGMUVoopZhkiXWA2V1o github.com/gorilla/context v1.1.2/go.mod h1:KDPwT9i/MeWHiLl90fuTgrt4/wPcv75vFAZLaOOcbxM= github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA= github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo= -github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTjY= -github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ= +github.com/gorilla/sessions v1.4.0 h1:kpIYOp/oi6MG/p5PgxApU8srsSw9tuFbt46Lt7auzqQ= +github.com/gorilla/sessions v1.4.0/go.mod h1:FLWm50oby91+hl7p/wRxDth9bWSuk0qVL2emc7lT5ik= github.com/hashicorp/hcl/v2 v2.14.0 h1:jX6+Q38Ly9zaAJlAjnFVyeNSNCKKW8D0wvyg7vij5Wc= github.com/hashicorp/hcl/v2 v2.14.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -61,8 +59,8 @@ github.com/ncw/swift v1.0.53 h1:luHjjTNtekIEvHg5KdAFIBaH7bWfNkefwFnpDffSIks= github.com/ncw/swift v1.0.53/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/samber/lo v1.42.0 h1:cuVp/4oZcTxK0w8vyj/MSEws9yTUjuTgZi7noEXMlZs= -github.com/samber/lo v1.42.0/go.mod h1:w7R6fO7h2lrnx/s0bWcZ55vXJI89p5UPM6+kyDL373E= +github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc= +github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= @@ -71,57 +69,30 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/zclconf/go-cty v1.11.0 h1:726SxLdi2SDnjY+BStqB9J1hNp4+2WlzyXLuimibIe0= github.com/zclconf/go-cty v1.11.0/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= -golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM= -golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= -golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/model/mock_model/mock_admin.go b/model/mock_model/mock_admin.go index 16ba8309..3a013220 100644 --- a/model/mock_model/mock_admin.go +++ b/model/mock_model/mock_admin.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: admin.go +// +// Generated by this command: +// +// mockgen -source=admin.go -destination=mock_model/mock_admin.go -package=mock_model +// // Package mock_model is a generated GoMock package. package mock_model @@ -8,9 +13,9 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" uuid "github.com/google/uuid" model "github.com/traPtitech/Jomon/model" + gomock "go.uber.org/mock/gomock" ) // MockAdminRepository is a mock of AdminRepository interface. @@ -45,7 +50,7 @@ func (m *MockAdminRepository) AddAdmins(ctx context.Context, userIDs []uuid.UUID } // AddAdmins indicates an expected call of AddAdmins. -func (mr *MockAdminRepositoryMockRecorder) AddAdmins(ctx, userIDs interface{}) *gomock.Call { +func (mr *MockAdminRepositoryMockRecorder) AddAdmins(ctx, userIDs any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddAdmins", reflect.TypeOf((*MockAdminRepository)(nil).AddAdmins), ctx, userIDs) } @@ -59,7 +64,7 @@ func (m *MockAdminRepository) DeleteAdmins(ctx context.Context, userIDs []uuid.U } // DeleteAdmins indicates an expected call of DeleteAdmins. -func (mr *MockAdminRepositoryMockRecorder) DeleteAdmins(ctx, userIDs interface{}) *gomock.Call { +func (mr *MockAdminRepositoryMockRecorder) DeleteAdmins(ctx, userIDs any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteAdmins", reflect.TypeOf((*MockAdminRepository)(nil).DeleteAdmins), ctx, userIDs) } @@ -74,7 +79,7 @@ func (m *MockAdminRepository) GetAdmins(ctx context.Context) ([]*model.Admin, er } // GetAdmins indicates an expected call of GetAdmins. -func (mr *MockAdminRepositoryMockRecorder) GetAdmins(ctx interface{}) *gomock.Call { +func (mr *MockAdminRepositoryMockRecorder) GetAdmins(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAdmins", reflect.TypeOf((*MockAdminRepository)(nil).GetAdmins), ctx) } diff --git a/model/mock_model/mock_comment.go b/model/mock_model/mock_comment.go index c43dc23f..3b450e9c 100644 --- a/model/mock_model/mock_comment.go +++ b/model/mock_model/mock_comment.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: comment.go +// +// Generated by this command: +// +// mockgen -source=comment.go -destination=mock_model/mock_comment.go -package=mock_model +// // Package mock_model is a generated GoMock package. package mock_model @@ -8,9 +13,9 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" uuid "github.com/google/uuid" model "github.com/traPtitech/Jomon/model" + gomock "go.uber.org/mock/gomock" ) // MockCommentRepository is a mock of CommentRepository interface. @@ -46,7 +51,7 @@ func (m *MockCommentRepository) CreateComment(ctx context.Context, comment strin } // CreateComment indicates an expected call of CreateComment. -func (mr *MockCommentRepositoryMockRecorder) CreateComment(ctx, comment, requestID, userID interface{}) *gomock.Call { +func (mr *MockCommentRepositoryMockRecorder) CreateComment(ctx, comment, requestID, userID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateComment", reflect.TypeOf((*MockCommentRepository)(nil).CreateComment), ctx, comment, requestID, userID) } @@ -60,7 +65,7 @@ func (m *MockCommentRepository) DeleteComment(ctx context.Context, requestID, co } // DeleteComment indicates an expected call of DeleteComment. -func (mr *MockCommentRepositoryMockRecorder) DeleteComment(ctx, requestID, commentID interface{}) *gomock.Call { +func (mr *MockCommentRepositoryMockRecorder) DeleteComment(ctx, requestID, commentID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteComment", reflect.TypeOf((*MockCommentRepository)(nil).DeleteComment), ctx, requestID, commentID) } @@ -75,7 +80,7 @@ func (m *MockCommentRepository) GetComments(ctx context.Context, requestID uuid. } // GetComments indicates an expected call of GetComments. -func (mr *MockCommentRepositoryMockRecorder) GetComments(ctx, requestID interface{}) *gomock.Call { +func (mr *MockCommentRepositoryMockRecorder) GetComments(ctx, requestID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetComments", reflect.TypeOf((*MockCommentRepository)(nil).GetComments), ctx, requestID) } @@ -90,7 +95,7 @@ func (m *MockCommentRepository) UpdateComment(ctx context.Context, comment strin } // UpdateComment indicates an expected call of UpdateComment. -func (mr *MockCommentRepositoryMockRecorder) UpdateComment(ctx, comment, requestID, commentID interface{}) *gomock.Call { +func (mr *MockCommentRepositoryMockRecorder) UpdateComment(ctx, comment, requestID, commentID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateComment", reflect.TypeOf((*MockCommentRepository)(nil).UpdateComment), ctx, comment, requestID, commentID) } diff --git a/model/mock_model/mock_file.go b/model/mock_model/mock_file.go index d481d6c5..3660c3af 100644 --- a/model/mock_model/mock_file.go +++ b/model/mock_model/mock_file.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: file.go +// +// Generated by this command: +// +// mockgen -source=file.go -destination=mock_model/mock_file.go -package=mock_model +// // Package mock_model is a generated GoMock package. package mock_model @@ -8,9 +13,9 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" uuid "github.com/google/uuid" model "github.com/traPtitech/Jomon/model" + gomock "go.uber.org/mock/gomock" ) // MockFileRepository is a mock of FileRepository interface. @@ -46,7 +51,7 @@ func (m *MockFileRepository) CreateFile(ctx context.Context, name, mimetype stri } // CreateFile indicates an expected call of CreateFile. -func (mr *MockFileRepositoryMockRecorder) CreateFile(ctx, name, mimetype, requestID, userID interface{}) *gomock.Call { +func (mr *MockFileRepositoryMockRecorder) CreateFile(ctx, name, mimetype, requestID, userID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateFile", reflect.TypeOf((*MockFileRepository)(nil).CreateFile), ctx, name, mimetype, requestID, userID) } @@ -60,7 +65,7 @@ func (m *MockFileRepository) DeleteFile(ctx context.Context, fileID uuid.UUID) e } // DeleteFile indicates an expected call of DeleteFile. -func (mr *MockFileRepositoryMockRecorder) DeleteFile(ctx, fileID interface{}) *gomock.Call { +func (mr *MockFileRepositoryMockRecorder) DeleteFile(ctx, fileID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteFile", reflect.TypeOf((*MockFileRepository)(nil).DeleteFile), ctx, fileID) } @@ -75,7 +80,7 @@ func (m *MockFileRepository) GetFile(ctx context.Context, fileID uuid.UUID) (*mo } // GetFile indicates an expected call of GetFile. -func (mr *MockFileRepositoryMockRecorder) GetFile(ctx, fileID interface{}) *gomock.Call { +func (mr *MockFileRepositoryMockRecorder) GetFile(ctx, fileID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFile", reflect.TypeOf((*MockFileRepository)(nil).GetFile), ctx, fileID) } diff --git a/model/mock_model/mock_group.go b/model/mock_model/mock_group.go index eab89931..f4174a23 100644 --- a/model/mock_model/mock_group.go +++ b/model/mock_model/mock_group.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: group.go +// +// Generated by this command: +// +// mockgen -source=group.go -destination=mock_model/mock_group.go -package=mock_model +// // Package mock_model is a generated GoMock package. package mock_model @@ -8,9 +13,9 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" uuid "github.com/google/uuid" model "github.com/traPtitech/Jomon/model" + gomock "go.uber.org/mock/gomock" ) // MockGroupRepository is a mock of GroupRepository interface. @@ -46,7 +51,7 @@ func (m *MockGroupRepository) AddMembers(ctx context.Context, groupID uuid.UUID, } // AddMembers indicates an expected call of AddMembers. -func (mr *MockGroupRepositoryMockRecorder) AddMembers(ctx, groupID, userIDs interface{}) *gomock.Call { +func (mr *MockGroupRepositoryMockRecorder) AddMembers(ctx, groupID, userIDs any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddMembers", reflect.TypeOf((*MockGroupRepository)(nil).AddMembers), ctx, groupID, userIDs) } @@ -61,7 +66,7 @@ func (m *MockGroupRepository) AddOwners(ctx context.Context, groupID uuid.UUID, } // AddOwners indicates an expected call of AddOwners. -func (mr *MockGroupRepositoryMockRecorder) AddOwners(ctx, groupID, ownerIDs interface{}) *gomock.Call { +func (mr *MockGroupRepositoryMockRecorder) AddOwners(ctx, groupID, ownerIDs any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddOwners", reflect.TypeOf((*MockGroupRepository)(nil).AddOwners), ctx, groupID, ownerIDs) } @@ -76,7 +81,7 @@ func (m *MockGroupRepository) CreateGroup(ctx context.Context, name, description } // CreateGroup indicates an expected call of CreateGroup. -func (mr *MockGroupRepositoryMockRecorder) CreateGroup(ctx, name, description, budget interface{}) *gomock.Call { +func (mr *MockGroupRepositoryMockRecorder) CreateGroup(ctx, name, description, budget any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateGroup", reflect.TypeOf((*MockGroupRepository)(nil).CreateGroup), ctx, name, description, budget) } @@ -90,7 +95,7 @@ func (m *MockGroupRepository) DeleteGroup(ctx context.Context, groupID uuid.UUID } // DeleteGroup indicates an expected call of DeleteGroup. -func (mr *MockGroupRepositoryMockRecorder) DeleteGroup(ctx, groupID interface{}) *gomock.Call { +func (mr *MockGroupRepositoryMockRecorder) DeleteGroup(ctx, groupID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteGroup", reflect.TypeOf((*MockGroupRepository)(nil).DeleteGroup), ctx, groupID) } @@ -104,7 +109,7 @@ func (m *MockGroupRepository) DeleteMembers(ctx context.Context, groupID uuid.UU } // DeleteMembers indicates an expected call of DeleteMembers. -func (mr *MockGroupRepositoryMockRecorder) DeleteMembers(ctx, groupID, userIDs interface{}) *gomock.Call { +func (mr *MockGroupRepositoryMockRecorder) DeleteMembers(ctx, groupID, userIDs any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteMembers", reflect.TypeOf((*MockGroupRepository)(nil).DeleteMembers), ctx, groupID, userIDs) } @@ -118,7 +123,7 @@ func (m *MockGroupRepository) DeleteOwners(ctx context.Context, groupID uuid.UUI } // DeleteOwners indicates an expected call of DeleteOwners. -func (mr *MockGroupRepositoryMockRecorder) DeleteOwners(ctx, groupID, ownerIDs interface{}) *gomock.Call { +func (mr *MockGroupRepositoryMockRecorder) DeleteOwners(ctx, groupID, ownerIDs any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteOwners", reflect.TypeOf((*MockGroupRepository)(nil).DeleteOwners), ctx, groupID, ownerIDs) } @@ -133,7 +138,7 @@ func (m *MockGroupRepository) GetGroup(ctx context.Context, groupID uuid.UUID) ( } // GetGroup indicates an expected call of GetGroup. -func (mr *MockGroupRepositoryMockRecorder) GetGroup(ctx, groupID interface{}) *gomock.Call { +func (mr *MockGroupRepositoryMockRecorder) GetGroup(ctx, groupID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGroup", reflect.TypeOf((*MockGroupRepository)(nil).GetGroup), ctx, groupID) } @@ -148,7 +153,7 @@ func (m *MockGroupRepository) GetGroups(ctx context.Context) ([]*model.Group, er } // GetGroups indicates an expected call of GetGroups. -func (mr *MockGroupRepositoryMockRecorder) GetGroups(ctx interface{}) *gomock.Call { +func (mr *MockGroupRepositoryMockRecorder) GetGroups(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetGroups", reflect.TypeOf((*MockGroupRepository)(nil).GetGroups), ctx) } @@ -163,7 +168,7 @@ func (m *MockGroupRepository) GetMembers(ctx context.Context, groupID uuid.UUID) } // GetMembers indicates an expected call of GetMembers. -func (mr *MockGroupRepositoryMockRecorder) GetMembers(ctx, groupID interface{}) *gomock.Call { +func (mr *MockGroupRepositoryMockRecorder) GetMembers(ctx, groupID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMembers", reflect.TypeOf((*MockGroupRepository)(nil).GetMembers), ctx, groupID) } @@ -178,7 +183,7 @@ func (m *MockGroupRepository) GetOwners(ctx context.Context, groupID uuid.UUID) } // GetOwners indicates an expected call of GetOwners. -func (mr *MockGroupRepositoryMockRecorder) GetOwners(ctx, groupID interface{}) *gomock.Call { +func (mr *MockGroupRepositoryMockRecorder) GetOwners(ctx, groupID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOwners", reflect.TypeOf((*MockGroupRepository)(nil).GetOwners), ctx, groupID) } @@ -193,7 +198,7 @@ func (m *MockGroupRepository) UpdateGroup(ctx context.Context, groupID uuid.UUID } // UpdateGroup indicates an expected call of UpdateGroup. -func (mr *MockGroupRepositoryMockRecorder) UpdateGroup(ctx, groupID, name, description, budget interface{}) *gomock.Call { +func (mr *MockGroupRepositoryMockRecorder) UpdateGroup(ctx, groupID, name, description, budget any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateGroup", reflect.TypeOf((*MockGroupRepository)(nil).UpdateGroup), ctx, groupID, name, description, budget) } diff --git a/model/mock_model/mock_group_budget.go b/model/mock_model/mock_group_budget.go index 1c63ff8b..bef38220 100644 --- a/model/mock_model/mock_group_budget.go +++ b/model/mock_model/mock_group_budget.go @@ -1,11 +1,16 @@ // Code generated by MockGen. DO NOT EDIT. // Source: group_budget.go +// +// Generated by this command: +// +// mockgen -source=group_budget.go -destination=mock_model/mock_group_budget.go -package=mock_model +// // Package mock_model is a generated GoMock package. package mock_model import ( - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockGroupBudgetRepository is a mock of GroupBudgetRepository interface. diff --git a/model/mock_model/mock_request.go b/model/mock_model/mock_request.go index b3938ace..e4a40c79 100644 --- a/model/mock_model/mock_request.go +++ b/model/mock_model/mock_request.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: request.go +// +// Generated by this command: +// +// mockgen -source=request.go -destination=mock_model/mock_request.go -package=mock_model +// // Package mock_model is a generated GoMock package. package mock_model @@ -8,9 +13,9 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" uuid "github.com/google/uuid" model "github.com/traPtitech/Jomon/model" + gomock "go.uber.org/mock/gomock" ) // MockRequestRepository is a mock of RequestRepository interface. @@ -46,7 +51,7 @@ func (m *MockRequestRepository) CreateRequest(ctx context.Context, title, conten } // CreateRequest indicates an expected call of CreateRequest. -func (mr *MockRequestRepositoryMockRecorder) CreateRequest(ctx, title, content, tags, targets, group, userID interface{}) *gomock.Call { +func (mr *MockRequestRepositoryMockRecorder) CreateRequest(ctx, title, content, tags, targets, group, userID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateRequest", reflect.TypeOf((*MockRequestRepository)(nil).CreateRequest), ctx, title, content, tags, targets, group, userID) } @@ -61,7 +66,7 @@ func (m *MockRequestRepository) GetRequest(ctx context.Context, requestID uuid.U } // GetRequest indicates an expected call of GetRequest. -func (mr *MockRequestRepositoryMockRecorder) GetRequest(ctx, requestID interface{}) *gomock.Call { +func (mr *MockRequestRepositoryMockRecorder) GetRequest(ctx, requestID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRequest", reflect.TypeOf((*MockRequestRepository)(nil).GetRequest), ctx, requestID) } @@ -76,7 +81,7 @@ func (m *MockRequestRepository) GetRequests(ctx context.Context, query model.Req } // GetRequests indicates an expected call of GetRequests. -func (mr *MockRequestRepositoryMockRecorder) GetRequests(ctx, query interface{}) *gomock.Call { +func (mr *MockRequestRepositoryMockRecorder) GetRequests(ctx, query any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRequests", reflect.TypeOf((*MockRequestRepository)(nil).GetRequests), ctx, query) } @@ -91,7 +96,7 @@ func (m *MockRequestRepository) UpdateRequest(ctx context.Context, requestID uui } // UpdateRequest indicates an expected call of UpdateRequest. -func (mr *MockRequestRepositoryMockRecorder) UpdateRequest(ctx, requestID, title, content, tags, targets, group interface{}) *gomock.Call { +func (mr *MockRequestRepositoryMockRecorder) UpdateRequest(ctx, requestID, title, content, tags, targets, group any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateRequest", reflect.TypeOf((*MockRequestRepository)(nil).UpdateRequest), ctx, requestID, title, content, tags, targets, group) } diff --git a/model/mock_model/mock_request_file.go b/model/mock_model/mock_request_file.go index 84c1ce95..2ea18670 100644 --- a/model/mock_model/mock_request_file.go +++ b/model/mock_model/mock_request_file.go @@ -1,11 +1,16 @@ // Code generated by MockGen. DO NOT EDIT. // Source: request_file.go +// +// Generated by this command: +// +// mockgen -source=request_file.go -destination=mock_model/mock_request_file.go -package=mock_model +// // Package mock_model is a generated GoMock package. package mock_model import ( - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockRequestFileRepository is a mock of RequestFileRepository interface. diff --git a/model/mock_model/mock_request_status.go b/model/mock_model/mock_request_status.go index 62bb0b95..d97399b3 100644 --- a/model/mock_model/mock_request_status.go +++ b/model/mock_model/mock_request_status.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: request_status.go +// +// Generated by this command: +// +// mockgen -source=request_status.go -destination=mock_model/mock_request_status.go -package=mock_model +// // Package mock_model is a generated GoMock package. package mock_model @@ -8,9 +13,9 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" uuid "github.com/google/uuid" model "github.com/traPtitech/Jomon/model" + gomock "go.uber.org/mock/gomock" ) // MockRequestStatusRepository is a mock of RequestStatusRepository interface. @@ -46,7 +51,7 @@ func (m *MockRequestStatusRepository) CreateStatus(ctx context.Context, requestI } // CreateStatus indicates an expected call of CreateStatus. -func (mr *MockRequestStatusRepositoryMockRecorder) CreateStatus(ctx, requestID, userID, status interface{}) *gomock.Call { +func (mr *MockRequestStatusRepositoryMockRecorder) CreateStatus(ctx, requestID, userID, status any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateStatus", reflect.TypeOf((*MockRequestStatusRepository)(nil).CreateStatus), ctx, requestID, userID, status) } diff --git a/model/mock_model/mock_request_tag.go b/model/mock_model/mock_request_tag.go index c75b9ddc..8a00f744 100644 --- a/model/mock_model/mock_request_tag.go +++ b/model/mock_model/mock_request_tag.go @@ -1,11 +1,16 @@ // Code generated by MockGen. DO NOT EDIT. // Source: request_tag.go +// +// Generated by this command: +// +// mockgen -source=request_tag.go -destination=mock_model/mock_request_tag.go -package=mock_model +// // Package mock_model is a generated GoMock package. package mock_model import ( - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockRequestTagRepository is a mock of RequestTagRepository interface. diff --git a/model/mock_model/mock_request_target.go b/model/mock_model/mock_request_target.go index 86a045a0..efe9c1ec 100644 --- a/model/mock_model/mock_request_target.go +++ b/model/mock_model/mock_request_target.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: request_target.go +// +// Generated by this command: +// +// mockgen -source=request_target.go -destination=mock_model/mock_request_target.go -package=mock_model +// // Package mock_model is a generated GoMock package. package mock_model @@ -8,9 +13,9 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" uuid "github.com/google/uuid" model "github.com/traPtitech/Jomon/model" + gomock "go.uber.org/mock/gomock" ) // MockRequestTargetRepository is a mock of RequestTargetRepository interface. @@ -46,7 +51,7 @@ func (m *MockRequestTargetRepository) GetRequestTargets(ctx context.Context, req } // GetRequestTargets indicates an expected call of GetRequestTargets. -func (mr *MockRequestTargetRepositoryMockRecorder) GetRequestTargets(ctx, requestID interface{}) *gomock.Call { +func (mr *MockRequestTargetRepositoryMockRecorder) GetRequestTargets(ctx, requestID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRequestTargets", reflect.TypeOf((*MockRequestTargetRepository)(nil).GetRequestTargets), ctx, requestID) } diff --git a/model/mock_model/mock_tag.go b/model/mock_model/mock_tag.go index e536a6bb..80a9b588 100644 --- a/model/mock_model/mock_tag.go +++ b/model/mock_model/mock_tag.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: tag.go +// +// Generated by this command: +// +// mockgen -source=tag.go -destination=mock_model/mock_tag.go -package=mock_model +// // Package mock_model is a generated GoMock package. package mock_model @@ -8,9 +13,9 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" uuid "github.com/google/uuid" model "github.com/traPtitech/Jomon/model" + gomock "go.uber.org/mock/gomock" ) // MockTagRepository is a mock of TagRepository interface. @@ -46,7 +51,7 @@ func (m *MockTagRepository) CreateTag(ctx context.Context, name string) (*model. } // CreateTag indicates an expected call of CreateTag. -func (mr *MockTagRepositoryMockRecorder) CreateTag(ctx, name interface{}) *gomock.Call { +func (mr *MockTagRepositoryMockRecorder) CreateTag(ctx, name any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateTag", reflect.TypeOf((*MockTagRepository)(nil).CreateTag), ctx, name) } @@ -60,7 +65,7 @@ func (m *MockTagRepository) DeleteTag(ctx context.Context, tagID uuid.UUID) erro } // DeleteTag indicates an expected call of DeleteTag. -func (mr *MockTagRepositoryMockRecorder) DeleteTag(ctx, tagID interface{}) *gomock.Call { +func (mr *MockTagRepositoryMockRecorder) DeleteTag(ctx, tagID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteTag", reflect.TypeOf((*MockTagRepository)(nil).DeleteTag), ctx, tagID) } @@ -75,7 +80,7 @@ func (m *MockTagRepository) GetTag(ctx context.Context, tagID uuid.UUID) (*model } // GetTag indicates an expected call of GetTag. -func (mr *MockTagRepositoryMockRecorder) GetTag(ctx, tagID interface{}) *gomock.Call { +func (mr *MockTagRepositoryMockRecorder) GetTag(ctx, tagID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTag", reflect.TypeOf((*MockTagRepository)(nil).GetTag), ctx, tagID) } @@ -90,7 +95,7 @@ func (m *MockTagRepository) GetTags(ctx context.Context) ([]*model.Tag, error) { } // GetTags indicates an expected call of GetTags. -func (mr *MockTagRepositoryMockRecorder) GetTags(ctx interface{}) *gomock.Call { +func (mr *MockTagRepositoryMockRecorder) GetTags(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTags", reflect.TypeOf((*MockTagRepository)(nil).GetTags), ctx) } @@ -105,7 +110,7 @@ func (m *MockTagRepository) UpdateTag(ctx context.Context, tagID uuid.UUID, name } // UpdateTag indicates an expected call of UpdateTag. -func (mr *MockTagRepositoryMockRecorder) UpdateTag(ctx, tagID, name interface{}) *gomock.Call { +func (mr *MockTagRepositoryMockRecorder) UpdateTag(ctx, tagID, name any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateTag", reflect.TypeOf((*MockTagRepository)(nil).UpdateTag), ctx, tagID, name) } diff --git a/model/mock_model/mock_transaction.go b/model/mock_model/mock_transaction.go index 512bf70c..8ed24d71 100644 --- a/model/mock_model/mock_transaction.go +++ b/model/mock_model/mock_transaction.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: transaction.go +// +// Generated by this command: +// +// mockgen -source=transaction.go -destination=mock_model/mock_transaction.go -package=mock_model +// // Package mock_model is a generated GoMock package. package mock_model @@ -8,9 +13,9 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" uuid "github.com/google/uuid" model "github.com/traPtitech/Jomon/model" + gomock "go.uber.org/mock/gomock" ) // MockTransactionRepository is a mock of TransactionRepository interface. @@ -46,7 +51,7 @@ func (m *MockTransactionRepository) CreateTransaction(ctx context.Context, Amoun } // CreateTransaction indicates an expected call of CreateTransaction. -func (mr *MockTransactionRepositoryMockRecorder) CreateTransaction(ctx, Amount, Target, tags, group, requestID interface{}) *gomock.Call { +func (mr *MockTransactionRepositoryMockRecorder) CreateTransaction(ctx, Amount, Target, tags, group, requestID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateTransaction", reflect.TypeOf((*MockTransactionRepository)(nil).CreateTransaction), ctx, Amount, Target, tags, group, requestID) } @@ -61,7 +66,7 @@ func (m *MockTransactionRepository) GetTransaction(ctx context.Context, transact } // GetTransaction indicates an expected call of GetTransaction. -func (mr *MockTransactionRepositoryMockRecorder) GetTransaction(ctx, transactionID interface{}) *gomock.Call { +func (mr *MockTransactionRepositoryMockRecorder) GetTransaction(ctx, transactionID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTransaction", reflect.TypeOf((*MockTransactionRepository)(nil).GetTransaction), ctx, transactionID) } @@ -76,7 +81,7 @@ func (m *MockTransactionRepository) GetTransactions(ctx context.Context, query m } // GetTransactions indicates an expected call of GetTransactions. -func (mr *MockTransactionRepositoryMockRecorder) GetTransactions(ctx, query interface{}) *gomock.Call { +func (mr *MockTransactionRepositoryMockRecorder) GetTransactions(ctx, query any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTransactions", reflect.TypeOf((*MockTransactionRepository)(nil).GetTransactions), ctx, query) } @@ -91,7 +96,7 @@ func (m *MockTransactionRepository) UpdateTransaction(ctx context.Context, trans } // UpdateTransaction indicates an expected call of UpdateTransaction. -func (mr *MockTransactionRepositoryMockRecorder) UpdateTransaction(ctx, transactionID, Amount, Target, tags, group, requestID interface{}) *gomock.Call { +func (mr *MockTransactionRepositoryMockRecorder) UpdateTransaction(ctx, transactionID, Amount, Target, tags, group, requestID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateTransaction", reflect.TypeOf((*MockTransactionRepository)(nil).UpdateTransaction), ctx, transactionID, Amount, Target, tags, group, requestID) } diff --git a/model/mock_model/mock_transaction_detail.go b/model/mock_model/mock_transaction_detail.go index 2b70f294..6f79266b 100644 --- a/model/mock_model/mock_transaction_detail.go +++ b/model/mock_model/mock_transaction_detail.go @@ -1,11 +1,16 @@ // Code generated by MockGen. DO NOT EDIT. // Source: transaction_detail.go +// +// Generated by this command: +// +// mockgen -source=transaction_detail.go -destination=mock_model/mock_transaction_detail.go -package=mock_model +// // Package mock_model is a generated GoMock package. package mock_model import ( - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockTransactionDetailRepository is a mock of TransactionDetailRepository interface. diff --git a/model/mock_model/mock_transaction_tag.go b/model/mock_model/mock_transaction_tag.go index 51d53d34..2d6e2839 100644 --- a/model/mock_model/mock_transaction_tag.go +++ b/model/mock_model/mock_transaction_tag.go @@ -1,11 +1,16 @@ // Code generated by MockGen. DO NOT EDIT. // Source: transaction_tag.go +// +// Generated by this command: +// +// mockgen -source=transaction_tag.go -destination=mock_model/mock_transaction_tag.go -package=mock_model +// // Package mock_model is a generated GoMock package. package mock_model import ( - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockTransactionTagRepository is a mock of TransactionTagRepository interface. diff --git a/model/mock_model/mock_user.go b/model/mock_model/mock_user.go index f93dfa37..26063dce 100644 --- a/model/mock_model/mock_user.go +++ b/model/mock_model/mock_user.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: user.go +// +// Generated by this command: +// +// mockgen -source=user.go -destination=mock_model/mock_user.go -package=mock_model +// // Package mock_model is a generated GoMock package. package mock_model @@ -8,9 +13,9 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" uuid "github.com/google/uuid" model "github.com/traPtitech/Jomon/model" + gomock "go.uber.org/mock/gomock" ) // MockUserRepository is a mock of UserRepository interface. @@ -46,7 +51,7 @@ func (m *MockUserRepository) CreateUser(ctx context.Context, name, dn string, ad } // CreateUser indicates an expected call of CreateUser. -func (mr *MockUserRepositoryMockRecorder) CreateUser(ctx, name, dn, admin interface{}) *gomock.Call { +func (mr *MockUserRepositoryMockRecorder) CreateUser(ctx, name, dn, admin any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateUser", reflect.TypeOf((*MockUserRepository)(nil).CreateUser), ctx, name, dn, admin) } @@ -61,7 +66,7 @@ func (m *MockUserRepository) GetUserByID(ctx context.Context, userID uuid.UUID) } // GetUserByID indicates an expected call of GetUserByID. -func (mr *MockUserRepositoryMockRecorder) GetUserByID(ctx, userID interface{}) *gomock.Call { +func (mr *MockUserRepositoryMockRecorder) GetUserByID(ctx, userID any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUserByID", reflect.TypeOf((*MockUserRepository)(nil).GetUserByID), ctx, userID) } @@ -76,7 +81,7 @@ func (m *MockUserRepository) GetUserByName(ctx context.Context, name string) (*m } // GetUserByName indicates an expected call of GetUserByName. -func (mr *MockUserRepositoryMockRecorder) GetUserByName(ctx, name interface{}) *gomock.Call { +func (mr *MockUserRepositoryMockRecorder) GetUserByName(ctx, name any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUserByName", reflect.TypeOf((*MockUserRepository)(nil).GetUserByName), ctx, name) } @@ -91,7 +96,7 @@ func (m *MockUserRepository) GetUsers(ctx context.Context) ([]*model.User, error } // GetUsers indicates an expected call of GetUsers. -func (mr *MockUserRepositoryMockRecorder) GetUsers(ctx interface{}) *gomock.Call { +func (mr *MockUserRepositoryMockRecorder) GetUsers(ctx any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUsers", reflect.TypeOf((*MockUserRepository)(nil).GetUsers), ctx) } @@ -106,7 +111,7 @@ func (m *MockUserRepository) UpdateUser(ctx context.Context, userID uuid.UUID, n } // UpdateUser indicates an expected call of UpdateUser. -func (mr *MockUserRepositoryMockRecorder) UpdateUser(ctx, userID, name, dn, admin interface{}) *gomock.Call { +func (mr *MockUserRepositoryMockRecorder) UpdateUser(ctx, userID, name, dn, admin any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateUser", reflect.TypeOf((*MockUserRepository)(nil).UpdateUser), ctx, userID, name, dn, admin) } diff --git a/router/admin_test.go b/router/admin_test.go index cca30cc1..d35df005 100644 --- a/router/admin_test.go +++ b/router/admin_test.go @@ -8,13 +8,13 @@ import ( "strings" "testing" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/labstack/echo/v4" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/traPtitech/Jomon/ent" "github.com/traPtitech/Jomon/model" + "go.uber.org/mock/gomock" ) func TestHandler_GetAdmins(t *testing.T) { diff --git a/router/file_test.go b/router/file_test.go index f03904a2..a41c8810 100644 --- a/router/file_test.go +++ b/router/file_test.go @@ -13,7 +13,6 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/gorilla/sessions" "github.com/labstack/echo-contrib/session" @@ -22,6 +21,7 @@ import ( "github.com/stretchr/testify/require" "github.com/traPtitech/Jomon/model" "github.com/traPtitech/Jomon/testutil/random" + "go.uber.org/mock/gomock" ) // nolint:lll diff --git a/router/group_test.go b/router/group_test.go index ab786c3d..7e6c9331 100644 --- a/router/group_test.go +++ b/router/group_test.go @@ -11,7 +11,6 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/labstack/echo/v4" "github.com/samber/lo" @@ -20,6 +19,7 @@ import ( "github.com/traPtitech/Jomon/ent" "github.com/traPtitech/Jomon/model" "github.com/traPtitech/Jomon/testutil/random" + "go.uber.org/mock/gomock" ) func TestHandlers_GetGroups(t *testing.T) { diff --git a/router/request_test.go b/router/request_test.go index b0f2a797..7bdac653 100644 --- a/router/request_test.go +++ b/router/request_test.go @@ -13,7 +13,6 @@ import ( "github.com/gorilla/sessions" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/labstack/echo-contrib/session" "github.com/labstack/echo/v4" @@ -23,6 +22,7 @@ import ( "github.com/traPtitech/Jomon/model" "github.com/traPtitech/Jomon/service" "github.com/traPtitech/Jomon/testutil/random" + "go.uber.org/mock/gomock" ) // To do diff --git a/router/router_test.go b/router/router_test.go index 6ab30dfe..10373336 100644 --- a/router/router_test.go +++ b/router/router_test.go @@ -7,11 +7,11 @@ import ( "github.com/traPtitech/Jomon/storage/mock_storage" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/traPtitech/Jomon/model" "github.com/traPtitech/Jomon/model/mock_model" "github.com/traPtitech/Jomon/testutil/random" + "go.uber.org/mock/gomock" "go.uber.org/zap" ) diff --git a/router/tag_test.go b/router/tag_test.go index 38140a7d..2bc6c642 100644 --- a/router/tag_test.go +++ b/router/tag_test.go @@ -11,7 +11,6 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/labstack/echo/v4" "github.com/samber/lo" @@ -19,6 +18,7 @@ import ( "github.com/stretchr/testify/require" "github.com/traPtitech/Jomon/model" "github.com/traPtitech/Jomon/testutil/random" + "go.uber.org/mock/gomock" ) func TestHandlers_GetTags(t *testing.T) { diff --git a/router/transaction_test.go b/router/transaction_test.go index 9f1b2a2d..0845023a 100644 --- a/router/transaction_test.go +++ b/router/transaction_test.go @@ -9,7 +9,6 @@ import ( "testing" "time" - "github.com/golang/mock/gomock" "github.com/google/uuid" "github.com/labstack/echo/v4" "github.com/samber/lo" @@ -18,6 +17,7 @@ import ( "github.com/traPtitech/Jomon/model" "github.com/traPtitech/Jomon/service" "github.com/traPtitech/Jomon/testutil/random" + "go.uber.org/mock/gomock" ) func TestHandlers_GetTransactions(t *testing.T) { diff --git a/router/user_test.go b/router/user_test.go index 685298e5..b5f28adb 100644 --- a/router/user_test.go +++ b/router/user_test.go @@ -12,11 +12,11 @@ import ( "github.com/gorilla/sessions" - "github.com/golang/mock/gomock" "github.com/labstack/echo-contrib/session" "github.com/labstack/echo/v4" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.uber.org/mock/gomock" "github.com/traPtitech/Jomon/model" "github.com/traPtitech/Jomon/testutil/random" diff --git a/service/webhook.go b/service/webhook.go index 6bd431cb..d1f8664f 100644 --- a/service/webhook.go +++ b/service/webhook.go @@ -127,7 +127,7 @@ func WebhookEventHandler(c echo.Context, reqBody, resBody []byte) { message += fmt.Sprintf("- 請求先グループ: %s\n", resApp.Group.Name) } - if resApp.Tags != nil && len(resApp.Tags) != 0 { + if len(resApp.Tags) != 0 { tags := lo.Map(resApp.Tags, func(tag *Tag, index int) string { return tag.Name }) @@ -188,7 +188,7 @@ func WebhookEventHandler(c echo.Context, reqBody, resBody []byte) { if resApp.Group != nil { message += fmt.Sprintf("- 関連するグループ: %s\n", resApp.Group.Name) } - if resApp.Tags != nil && len(resApp.Tags) != 0 { + if len(resApp.Tags) != 0 { tags := lo.Map(resApp.Tags, func(tag *Tag, index int) string { return tag.Name }) diff --git a/storage/mock_storage/mock_storage.go b/storage/mock_storage/mock_storage.go index c4ef5a21..f5e1c2d8 100644 --- a/storage/mock_storage/mock_storage.go +++ b/storage/mock_storage/mock_storage.go @@ -1,5 +1,10 @@ // Code generated by MockGen. DO NOT EDIT. // Source: storage.go +// +// Generated by this command: +// +// mockgen -source=storage.go -destination=mock_storage/mock_storage.go -package=mock_storage +// // Package mock_storage is a generated GoMock package. package mock_storage @@ -8,7 +13,7 @@ import ( io "io" reflect "reflect" - gomock "github.com/golang/mock/gomock" + gomock "go.uber.org/mock/gomock" ) // MockStorage is a mock of Storage interface. @@ -43,7 +48,7 @@ func (m *MockStorage) Delete(filename string) error { } // Delete indicates an expected call of Delete. -func (mr *MockStorageMockRecorder) Delete(filename interface{}) *gomock.Call { +func (mr *MockStorageMockRecorder) Delete(filename any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Delete", reflect.TypeOf((*MockStorage)(nil).Delete), filename) } @@ -58,7 +63,7 @@ func (m *MockStorage) Open(filename string) (io.ReadCloser, error) { } // Open indicates an expected call of Open. -func (mr *MockStorageMockRecorder) Open(filename interface{}) *gomock.Call { +func (mr *MockStorageMockRecorder) Open(filename any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Open", reflect.TypeOf((*MockStorage)(nil).Open), filename) } @@ -72,7 +77,7 @@ func (m *MockStorage) Save(filename string, src io.Reader) error { } // Save indicates an expected call of Save. -func (mr *MockStorageMockRecorder) Save(filename, src interface{}) *gomock.Call { +func (mr *MockStorageMockRecorder) Save(filename, src any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Save", reflect.TypeOf((*MockStorage)(nil).Save), filename, src) } diff --git a/testutil/random/ramdom.go b/testutil/random/ramdom.go index 4c1bca38..1b3645fc 100644 --- a/testutil/random/ramdom.go +++ b/testutil/random/ramdom.go @@ -3,8 +3,6 @@ package random import ( "math/rand/v2" "testing" - - "github.com/samber/lo" ) const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" @@ -22,33 +20,39 @@ func AlphaNumeric(t *testing.T, n int) string { return string(b) } -func Numeric(t *testing.T, max int) int { +func Numeric(t *testing.T, n int) int { t.Helper() - return rand.IntN(max) + return rand.IntN(n) } -func Numeric64(t *testing.T, max int64) int64 { +func Numeric64(t *testing.T, n int64) int64 { t.Helper() - return rand.Int64N(max) + return rand.Int64N(n) } -func AlphaNumericSlice(t *testing.T, length int, max int64) []string { +func AlphaNumericSlice(t *testing.T, length int, n int64) []string { t.Helper() - return lo.Times(length, func(index int) string { - return AlphaNumeric(t, int(max)) - }) + slice := []string{} + for range length { + slice = append(slice, AlphaNumeric(t, int(n))) + } + return slice } -func NumericSlice(t *testing.T, length int, max int) []int { +func NumericSlice(t *testing.T, length int, n int) []int { t.Helper() - return lo.Times(length, func(index int) int { - return Numeric(t, max) - }) + slice := []int{} + for range length { + slice = append(slice, Numeric(t, n)) + } + return slice } -func Numeric64Slice(t *testing.T, length int, max int64) []int64 { +func Numeric64Slice(t *testing.T, length int, n int64) []int64 { t.Helper() - return lo.Times(length, func(index int) int64 { - return Numeric64(t, max) - }) + slice := []int64{} + for range length { + slice = append(slice, Numeric64(t, n)) + } + return slice } From efc7ca423661258d58cffa3cdc82563048cfa804 Mon Sep 17 00:00:00 2001 From: Hueter Date: Wed, 2 Oct 2024 00:13:00 +0900 Subject: [PATCH 07/11] =?UTF-8?q?request=5Ftest.go=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E5=81=B4=E3=82=92nil=E3=81=8B=E3=82=89?= =?UTF-8?q?=E7=A9=BA=E8=A1=8C=E5=88=97=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router/request_test.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/router/request_test.go b/router/request_test.go index 7bdac653..0d5c1ae4 100644 --- a/router/request_test.go +++ b/router/request_test.go @@ -507,6 +507,8 @@ func TestHandlers_PostRequest(t *testing.T) { }, Title: request.Title, Content: request.Content, + Tags: []*TagOverview{}, + Targets: []*TargetOverview{}, } resBody, err := json.Marshal(res) require.NoError(t, err) @@ -603,6 +605,7 @@ func TestHandlers_PostRequest(t *testing.T) { CreatedAt: tag.CreatedAt, UpdatedAt: tag.UpdatedAt, }}, + Targets: []*TargetOverview{}, } resBody, err := json.Marshal(res) require.NoError(t, err) @@ -686,6 +689,8 @@ func TestHandlers_PostRequest(t *testing.T) { CreatedBy: request.CreatedBy, Title: request.Title, Content: request.Content, + Tags: []*TagOverview{}, + Targets: []*TargetOverview{}, Statuses: []*StatusResponseOverview{ { CreatedBy: request.Statuses[0].CreatedBy, @@ -803,6 +808,7 @@ func TestHandlers_PostRequest(t *testing.T) { }, Title: request.Title, Content: request.Content, + Tags: []*TagOverview{}, Targets: []*TargetOverview{tgov}, } resBody, err := json.Marshal(res) @@ -1431,7 +1437,10 @@ func TestHandlers_PutRequest(t *testing.T) { CreatedBy: updateRequest.Statuses[0].CreatedBy, }, }, - Content: updateRequest.Content, + Content: updateRequest.Content, + Tags: []*TagOverview{}, + Targets: []*TargetOverview{}, + Comments: []*CommentDetail{}, } resBody, err := json.Marshal(res) require.NoError(t, err) @@ -1568,6 +1577,8 @@ func TestHandlers_PutRequest(t *testing.T) { UpdatedAt: tag2.UpdatedAt, }, }, + Targets: []*TargetOverview{}, + Comments: []*CommentDetail{}, } resBody, err := json.Marshal(res) require.NoError(t, err) @@ -1717,6 +1728,8 @@ func TestHandlers_PutRequest(t *testing.T) { CreatedAt: target2.CreatedAt, }, }, + Tags: []*TagOverview{}, + Comments: []*CommentDetail{}, } resBody, err := json.Marshal(res) require.NoError(t, err) @@ -1839,6 +1852,9 @@ func TestHandlers_PutRequest(t *testing.T) { CreatedAt: group.CreatedAt, UpdatedAt: group.UpdatedAt, }, + Tags: []*TagOverview{}, + Targets: []*TargetOverview{}, + Comments: []*CommentDetail{}, } resBody, err := json.Marshal(res) require.NoError(t, err) @@ -1971,6 +1987,8 @@ func TestHandlers_PutRequest(t *testing.T) { Title: updateRequest.Title, Content: updateRequest.Content, Comments: resComments, + Tags: []*TagOverview{}, + Targets: []*TargetOverview{}, } resBody, err := json.Marshal(res) require.NoError(t, err) From 44d831785e8bef6167dde3f965f480172d1f42dc Mon Sep 17 00:00:00 2001 From: Hueter Date: Wed, 2 Oct 2024 01:28:19 +0900 Subject: [PATCH 08/11] =?UTF-8?q?for=E6=96=87=E3=82=92samber/lo=E3=81=A7?= =?UTF-8?q?=E7=BD=AE=E3=81=8D=E6=8F=9B=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router/group.go | 7 +++---- router/request.go | 9 ++++----- service/webhook.go | 15 +++++++-------- testutil/random/ramdom.go | 26 +++++++++++--------------- 4 files changed, 25 insertions(+), 32 deletions(-) diff --git a/router/group.go b/router/group.go index 4a719d3d..5022f35d 100644 --- a/router/group.go +++ b/router/group.go @@ -299,10 +299,9 @@ func (h Handlers) PostOwner(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - res := make([]uuid.UUID, len(added)) - for i, owner := range added { - res[i] = owner.ID - } + res := lo.Map(added, func(owner *model.Owner, index int) uuid.UUID { + return owner.ID + }) return c.JSON(http.StatusOK, res) } diff --git a/router/request.go b/router/request.go index 0777862a..89d77c93 100644 --- a/router/request.go +++ b/router/request.go @@ -715,13 +715,12 @@ func (h Handlers) PutStatus(c echo.Context) error { h.Logger.Error("failed to get request targets from repository", zap.Error(err)) return echo.NewHTTPError(http.StatusInternalServerError, err) } - var paid bool - for _, target := range targets { + paid := lo.Reduce(targets, func(p bool, target *model.RequestTargetDetail, _ int) bool { if target.PaidAt != nil { - paid = true - break + return true } - } + return p + }, false) if paid { h.Logger.Info("someone already paid") return echo.NewHTTPError(http.StatusBadRequest, errors.New("someone already paid")) diff --git a/service/webhook.go b/service/webhook.go index d1f8664f..d7801670 100644 --- a/service/webhook.go +++ b/service/webhook.go @@ -117,10 +117,9 @@ func WebhookEventHandler(c echo.Context, reqBody, resBody []byte) { "https://jomon.trap.jp", resApp.ID) - amount := 0 - for _, target := range resApp.Targets { - amount += target.Amount - } + amount := lo.Reduce(resApp.Targets, func(amo int, target *Target, _ int) int { + return amo + target.Amount + }, 0) message += fmt.Sprintf("- 支払金額: %d円\n", amount) if resApp.Group != nil { @@ -167,10 +166,10 @@ func WebhookEventHandler(c echo.Context, reqBody, resBody []byte) { resApp.Amount) } } else { - targets := make([]string, len(resApps)) - for i, resApp := range resApps { - targets[i] = resApp.Target - } + targets := lo.Map( + resApps, func(resApp TransactionRequestApplication, index int) string { + return resApp.Target + }) if resApp.Amount < 0 { message += fmt.Sprintf( "- %sへの支払い\n - 支払い金額: 計%d円(一人当たりへの支払い金額: %d円)\n", diff --git a/testutil/random/ramdom.go b/testutil/random/ramdom.go index 1b3645fc..b6dbd3c4 100644 --- a/testutil/random/ramdom.go +++ b/testutil/random/ramdom.go @@ -3,6 +3,8 @@ package random import ( "math/rand/v2" "testing" + + "github.com/samber/lo" ) const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" @@ -32,27 +34,21 @@ func Numeric64(t *testing.T, n int64) int64 { func AlphaNumericSlice(t *testing.T, length int, n int64) []string { t.Helper() - slice := []string{} - for range length { - slice = append(slice, AlphaNumeric(t, int(n))) - } - return slice + return lo.Times(length, func(index int) string { + return AlphaNumeric(t, int(n)) + }) } func NumericSlice(t *testing.T, length int, n int) []int { t.Helper() - slice := []int{} - for range length { - slice = append(slice, Numeric(t, n)) - } - return slice + return lo.Times(length, func(index int) int { + return Numeric(t, n) + }) } func Numeric64Slice(t *testing.T, length int, n int64) []int64 { t.Helper() - slice := []int64{} - for range length { - slice = append(slice, Numeric64(t, n)) - } - return slice + return lo.Times(length, func(index int) int64 { + return Numeric64(t, n) + }) } From d47fac896c9068a335959965edfbb95d0fe7939c Mon Sep 17 00:00:00 2001 From: Hueter Date: Wed, 2 Oct 2024 21:30:30 +0900 Subject: [PATCH 09/11] =?UTF-8?q?=E6=9C=AA=E4=BD=BF=E7=94=A8=E3=81=AEindex?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/admin_impl.go | 2 +- model/comment_impl.go | 2 +- model/group_impl.go | 10 +++++----- model/request_impl.go | 18 +++++++++--------- model/request_target_impl.go | 8 ++++---- model/tag_impl.go | 2 +- model/transaction_impl.go | 8 ++++---- model/user_impl.go | 2 +- router/admin.go | 2 +- router/group.go | 8 ++++---- router/group_test.go | 2 +- router/request.go | 32 ++++++++++++++++---------------- router/tag.go | 2 +- router/tag_test.go | 2 +- router/transaction.go | 10 +++++----- router/transaction_test.go | 32 ++++++++++++++++---------------- router/user.go | 2 +- service/webhook.go | 6 +++--- testutil/random/ramdom.go | 6 +++--- 19 files changed, 78 insertions(+), 78 deletions(-) diff --git a/model/admin_impl.go b/model/admin_impl.go index 90c30834..86556576 100644 --- a/model/admin_impl.go +++ b/model/admin_impl.go @@ -18,7 +18,7 @@ func (repo *EntRepository) GetAdmins(ctx context.Context) ([]*Admin, error) { return nil, err } - admins := lo.Map(users, func(u *ent.User, insex int) *Admin { + admins := lo.Map(users, func(u *ent.User, _ int) *Admin { return &Admin{ ID: u.ID, } diff --git a/model/comment_impl.go b/model/comment_impl.go index e63d545d..d37b93e4 100644 --- a/model/comment_impl.go +++ b/model/comment_impl.go @@ -34,7 +34,7 @@ func (repo *EntRepository) GetComments( if err != nil { return nil, err } - modelcomments := lo.Map(comments, func(c *ent.Comment, index int) *Comment { + modelcomments := lo.Map(comments, func(c *ent.Comment, _ int) *Comment { return ConvertEntCommentToModelComment(c, c.Edges.User.ID) }) return modelcomments, nil diff --git a/model/group_impl.go b/model/group_impl.go index cb354e07..c43d5d2e 100644 --- a/model/group_impl.go +++ b/model/group_impl.go @@ -17,7 +17,7 @@ func (repo *EntRepository) GetGroups(ctx context.Context) ([]*Group, error) { if err != nil { return nil, err } - modelgroups := lo.Map(groups, func(g *ent.Group, index int) *Group { + modelgroups := lo.Map(groups, func(g *ent.Group, _ int) *Group { return ConvertEntGroupToModelGroup(g) }) return modelgroups, nil @@ -85,7 +85,7 @@ func (repo *EntRepository) GetOwners(ctx context.Context, groupID uuid.UUID) ([] if err != nil { return nil, err } - owners := lo.Map(groupowners, func(groupowner *ent.User, index int) *Owner { + owners := lo.Map(groupowners, func(groupowner *ent.User, _ int) *Owner { return &Owner{ID: groupowner.ID} }) @@ -103,7 +103,7 @@ func (repo *EntRepository) AddOwners( if err != nil { return nil, err } - resowners := lo.Map(ownerIDs, func(owner uuid.UUID, index int) *Owner { + resowners := lo.Map(ownerIDs, func(owner uuid.UUID, _ int) *Owner { return &Owner{ID: owner} }) @@ -133,7 +133,7 @@ func (repo *EntRepository) GetMembers(ctx context.Context, groupID uuid.UUID) ([ if err != nil { return nil, err } - modelmembers := lo.Map(members, func(member *ent.User, index int) *Member { + modelmembers := lo.Map(members, func(member *ent.User, _ int) *Member { return &Member{member.ID} }) @@ -152,7 +152,7 @@ func (repo *EntRepository) AddMembers( if err != nil { return nil, err } - resMembers := lo.Map(userIDs, func(member uuid.UUID, index int) *Member { + resMembers := lo.Map(userIDs, func(member uuid.UUID, _ int) *Member { return &Member{member} }) diff --git a/model/request_impl.go b/model/request_impl.go index ea0d0796..acc17d54 100644 --- a/model/request_impl.go +++ b/model/request_impl.go @@ -116,7 +116,7 @@ func (repo *EntRepository) GetRequests( return nil, err } - reqres := lo.Map(requests, func(r *ent.Request, index int) *RequestResponse { + reqres := lo.Map(requests, func(r *ent.Request, _ int) *RequestResponse { return convertEntRequestResponseToModelRequestResponse( r, r.Edges.Tag, r.Edges.Group, r.Edges.Status[0], r.Edges.User) }) @@ -138,7 +138,7 @@ func (repo *EntRepository) CreateRequest( panic(v) } }() - tagIDs := lo.Map(tags, func(t *Tag, index int) uuid.UUID { + tagIDs := lo.Map(tags, func(t *Tag, _ int) uuid.UUID { return t.ID }) created, err := tx.Client().Request. @@ -235,17 +235,17 @@ func (repo *EntRepository) GetRequest( if err != nil { return nil, err } - tags := lo.Map(r.Edges.Tag, func(t *ent.Tag, index int) *Tag { + tags := lo.Map(r.Edges.Tag, func(t *ent.Tag, _ int) *Tag { return ConvertEntTagToModelTag(t) }) targets := lo.Map( r.Edges.Target, - func(target *ent.RequestTarget, index int) *RequestTargetDetail { + func(target *ent.RequestTarget, _ int) *RequestTargetDetail { return ConvertEntRequestTargetToModelRequestTargetDetail(target) }, ) modelGroup := ConvertEntGroupToModelGroup(r.Edges.Group) - statuses := lo.Map(r.Edges.Status, func(status *ent.RequestStatus, index int) *RequestStatus { + statuses := lo.Map(r.Edges.Status, func(status *ent.RequestStatus, _ int) *RequestStatus { return convertEntRequestStatusToModelRequestStatus(status) }) reqdetail := &RequestDetail{ @@ -278,7 +278,7 @@ func (repo *EntRepository) UpdateRequest( panic(v) } }() - tagIDs := lo.Map(tags, func(t *Tag, index int) uuid.UUID { + tagIDs := lo.Map(tags, func(t *Tag, _ int) uuid.UUID { return t.ID }) updated, err := tx.Client().Request. @@ -330,7 +330,7 @@ func (repo *EntRepository) UpdateRequest( err = RollbackWithError(tx, err) return nil, err } - modeltags := lo.Map(enttags, func(enttag *ent.Tag, index int) *Tag { + modeltags := lo.Map(enttags, func(enttag *ent.Tag, _ int) *Tag { return ConvertEntTagToModelTag(enttag) }) var entgroup *ent.Group @@ -356,7 +356,7 @@ func (repo *EntRepository) UpdateRequest( if err != nil { return nil, err } - statuses := lo.Map(entstatuses, func(s *ent.RequestStatus, index int) *RequestStatus { + statuses := lo.Map(entstatuses, func(s *ent.RequestStatus, _ int) *RequestStatus { return convertEntRequestStatusToModelRequestStatus(s) }) @@ -384,7 +384,7 @@ func convertEntRequestResponseToModelRequestResponse( if request == nil { return nil } - modeltags := lo.Map(tags, func(t *ent.Tag, index int) *Tag { + modeltags := lo.Map(tags, func(t *ent.Tag, _ int) *Tag { return ConvertEntTagToModelTag(t) }) return &RequestResponse{ diff --git a/model/request_target_impl.go b/model/request_target_impl.go index 6c0c6f39..e8eb2ef3 100644 --- a/model/request_target_impl.go +++ b/model/request_target_impl.go @@ -26,7 +26,7 @@ func (repo *EntRepository) GetRequestTargets( if err != nil { return nil, err } - targets := lo.Map(ts, func(t *ent.RequestTarget, index int) *RequestTargetDetail { + targets := lo.Map(ts, func(t *ent.RequestTarget, _ int) *RequestTargetDetail { return ConvertEntRequestTargetToModelRequestTargetDetail(t) }) return targets, err @@ -35,7 +35,7 @@ func (repo *EntRepository) GetRequestTargets( func (repo *EntRepository) createRequestTargets( ctx context.Context, tx *ent.Tx, requestID uuid.UUID, targets []*RequestTarget, ) ([]*RequestTargetDetail, error) { - bulk := lo.Map(targets, func(t *RequestTarget, index int) *ent.RequestTargetCreate { + bulk := lo.Map(targets, func(t *RequestTarget, _ int) *ent.RequestTargetCreate { return tx.Client().RequestTarget. Create(). SetAmount(t.Amount). @@ -47,7 +47,7 @@ func (repo *EntRepository) createRequestTargets( if err != nil { return nil, err } - ids := lo.Map(cs, func(c *ent.RequestTarget, index int) uuid.UUID { + ids := lo.Map(cs, func(c *ent.RequestTarget, _ int) uuid.UUID { return c.ID }) created, err := tx.Client().RequestTarget. @@ -61,7 +61,7 @@ func (repo *EntRepository) createRequestTargets( return nil, err } // []*ent.RequestTarget to []*RequestTargetDetail - ts := lo.Map(created, func(t *ent.RequestTarget, index int) *RequestTargetDetail { + ts := lo.Map(created, func(t *ent.RequestTarget, _ int) *RequestTargetDetail { return ConvertEntRequestTargetToModelRequestTargetDetail(t) }) return ts, nil diff --git a/model/tag_impl.go b/model/tag_impl.go index da7c2c67..93f2d21b 100644 --- a/model/tag_impl.go +++ b/model/tag_impl.go @@ -17,7 +17,7 @@ func (repo *EntRepository) GetTags(ctx context.Context) ([]*Tag, error) { if err != nil { return nil, err } - modeltags := lo.Map(tags, func(t *ent.Tag, index int) *Tag { + modeltags := lo.Map(tags, func(t *ent.Tag, _ int) *Tag { return ConvertEntTagToModelTag(t) }) diff --git a/model/transaction_impl.go b/model/transaction_impl.go index d0d6fd1c..a7b88b8e 100644 --- a/model/transaction_impl.go +++ b/model/transaction_impl.go @@ -117,7 +117,7 @@ func (repo *EntRepository) GetTransactions( } // Converting - res := lo.Map(txs, func(tx *ent.Transaction, index int) *TransactionResponse { + res := lo.Map(txs, func(tx *ent.Transaction, _ int) *TransactionResponse { return ConvertEntTransactionToModelTransactionResponse(tx) }) @@ -162,7 +162,7 @@ func (repo *EntRepository) CreateTransaction( }() // Get Tags - tagIDs := lo.Map(tags, func(t *uuid.UUID, index int) uuid.UUID { + tagIDs := lo.Map(tags, func(t *uuid.UUID, _ int) uuid.UUID { return *t }) @@ -270,7 +270,7 @@ func (repo *EntRepository) UpdateTransaction( } // Get Tags - tagIDs := lo.Map(tags, func(t *uuid.UUID, index int) uuid.UUID { + tagIDs := lo.Map(tags, func(t *uuid.UUID, _ int) uuid.UUID { return *t }) @@ -379,7 +379,7 @@ func ConvertEntTransactionToModelTransaction(transaction *ent.Transaction) *Tran func ConvertEntTransactionToModelTransactionResponse( transaction *ent.Transaction, ) *TransactionResponse { - tags := lo.Map(transaction.Edges.Tag, func(t *ent.Tag, index int) *Tag { + tags := lo.Map(transaction.Edges.Tag, func(t *ent.Tag, _ int) *Tag { return ConvertEntTagToModelTag(t) }) var g *Group diff --git a/model/user_impl.go b/model/user_impl.go index 99739d15..03e6633a 100644 --- a/model/user_impl.go +++ b/model/user_impl.go @@ -54,7 +54,7 @@ func (repo *EntRepository) GetUsers(ctx context.Context) ([]*User, error) { if err != nil { return nil, err } - modelusers := lo.Map(users, func(u *ent.User, index int) *User { + modelusers := lo.Map(users, func(u *ent.User, _ int) *User { return convertEntUserToModelUser(u) }) return modelusers, nil diff --git a/router/admin.go b/router/admin.go index df3035c0..0789f1cd 100644 --- a/router/admin.go +++ b/router/admin.go @@ -19,7 +19,7 @@ func (h Handlers) GetAdmins(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - res := lo.Map(admins, func(admin *model.Admin, index int) *uuid.UUID { + res := lo.Map(admins, func(admin *model.Admin, _ int) *uuid.UUID { return &admin.ID }) diff --git a/router/group.go b/router/group.go index 5022f35d..419ad0a5 100644 --- a/router/group.go +++ b/router/group.go @@ -63,7 +63,7 @@ func (h Handlers) GetGroups(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - res := lo.Map(groups, func(group *model.Group, index int) *GroupOverview { + res := lo.Map(groups, func(group *model.Group, _ int) *GroupOverview { return &GroupOverview{ ID: group.ID, Name: group.Name, @@ -144,7 +144,7 @@ func (h Handlers) GetGroupDetail(c echo.Context) error { h.Logger.Error("failed to get owners from repository", zap.Error(err)) return echo.NewHTTPError(http.StatusInternalServerError, err) } - res.Owners = lo.Map(owners, func(owner *model.Owner, index int) *uuid.UUID { + res.Owners = lo.Map(owners, func(owner *model.Owner, _ int) *uuid.UUID { return &owner.ID }) members, err := h.Repository.GetMembers(ctx, groupID) @@ -241,7 +241,7 @@ func (h Handlers) PostMember(c echo.Context) error { h.Logger.Error("failed to add member in repository", zap.Error(err)) return echo.NewHTTPError(http.StatusInternalServerError, err) } - res := lo.Map(added, func(m *model.Member, index int) *uuid.UUID { + res := lo.Map(added, func(m *model.Member, _ int) *uuid.UUID { return &m.ID }) return c.JSON(http.StatusOK, res) @@ -299,7 +299,7 @@ func (h Handlers) PostOwner(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - res := lo.Map(added, func(owner *model.Owner, index int) uuid.UUID { + res := lo.Map(added, func(owner *model.Owner, _ int) uuid.UUID { return owner.ID }) diff --git a/router/group_test.go b/router/group_test.go index 7e6c9331..4ca8482d 100644 --- a/router/group_test.go +++ b/router/group_test.go @@ -67,7 +67,7 @@ func TestHandlers_GetGroups(t *testing.T) { GetGroups(c.Request().Context()). Return(groups, nil) - resOverview := lo.Map(groups, func(group *model.Group, index int) *GroupOverview { + resOverview := lo.Map(groups, func(group *model.Group, _ int) *GroupOverview { return &GroupOverview{ ID: group.ID, Name: group.Name, diff --git a/router/request.go b/router/request.go index 89d77c93..ba709a1a 100644 --- a/router/request.go +++ b/router/request.go @@ -185,8 +185,8 @@ func (h Handlers) GetRequests(c echo.Context) error { requests := lo.Map( modelrequests, - func(request *model.RequestResponse, index int) *RequestResponse { - tags := lo.Map(request.Tags, func(tag *model.Tag, index int) *TagOverview { + func(request *model.RequestResponse, _ int) *RequestResponse { + tags := lo.Map(request.Tags, func(tag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: tag.ID, Name: tag.Name, @@ -197,7 +197,7 @@ func (h Handlers) GetRequests(c echo.Context) error { restargets := lo.Map( request.Targets, - func(target *model.RequestTargetDetail, index int) *TargetOverview { + func(target *model.RequestTargetDetail, _ int) *TargetOverview { return &TargetOverview{ ID: target.ID, Target: target.Target, @@ -259,7 +259,7 @@ func (h Handlers) PostRequest(c echo.Context) error { } tags = append(tags, tag) } - targets := lo.Map(req.Targets, func(target *Target, index int) *model.RequestTarget { + targets := lo.Map(req.Targets, func(target *Target, _ int) *model.RequestTarget { return &model.RequestTarget{ Target: target.Target, Amount: target.Amount, @@ -305,7 +305,7 @@ func (h Handlers) PostRequest(c echo.Context) error { } reqtargets := lo.Map( request.Targets, - func(target *model.RequestTargetDetail, index int) *TargetOverview { + func(target *model.RequestTargetDetail, _ int) *TargetOverview { return &TargetOverview{ ID: target.ID, Target: target.Target, @@ -315,7 +315,7 @@ func (h Handlers) PostRequest(c echo.Context) error { } }, ) - restags := lo.Map(request.Tags, func(tag *model.Tag, index int) *TagOverview { + restags := lo.Map(request.Tags, func(tag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: tag.ID, Name: tag.Name, @@ -325,7 +325,7 @@ func (h Handlers) PostRequest(c echo.Context) error { }) statuses := lo.Map( request.Statuses, - func(status *model.RequestStatus, index int) *StatusResponseOverview { + func(status *model.RequestStatus, _ int) *StatusResponseOverview { return &StatusResponseOverview{ Status: status.Status, CreatedAt: status.CreatedAt, @@ -379,7 +379,7 @@ func (h Handlers) GetRequest(c echo.Context) error { h.Logger.Error("failed to get comments from repository", zap.Error(err)) return echo.NewHTTPError(http.StatusInternalServerError, err) } - comments := lo.Map(modelcomments, func(modelcomment *model.Comment, index int) *CommentDetail { + comments := lo.Map(modelcomments, func(modelcomment *model.Comment, _ int) *CommentDetail { return &CommentDetail{ ID: modelcomment.ID, User: modelcomment.User, @@ -401,7 +401,7 @@ func (h Handlers) GetRequest(c echo.Context) error { } reqtargets := lo.Map( request.Targets, - func(target *model.RequestTargetDetail, index int) *TargetOverview { + func(target *model.RequestTargetDetail, _ int) *TargetOverview { return &TargetOverview{ ID: target.ID, Target: target.Target, @@ -411,7 +411,7 @@ func (h Handlers) GetRequest(c echo.Context) error { } }, ) - restags := lo.Map(request.Tags, func(tag *model.Tag, index int) *TagOverview { + restags := lo.Map(request.Tags, func(tag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: tag.ID, Name: tag.Name, @@ -422,7 +422,7 @@ func (h Handlers) GetRequest(c echo.Context) error { resstatuses := lo.Map( request.Statuses, - func(status *model.RequestStatus, index int) *StatusResponseOverview { + func(status *model.RequestStatus, _ int) *StatusResponseOverview { return &StatusResponseOverview{ CreatedBy: status.CreatedBy, Status: status.Status, @@ -479,7 +479,7 @@ func (h Handlers) PutRequest(c echo.Context) error { } tags = append(tags, tag) } - targets := lo.Map(req.Targets, func(target *Target, index int) *model.RequestTarget { + targets := lo.Map(req.Targets, func(target *Target, _ int) *model.RequestTarget { return &model.RequestTarget{ Target: target.Target, Amount: target.Amount, @@ -517,7 +517,7 @@ func (h Handlers) PutRequest(c echo.Context) error { h.Logger.Error("failed to get comments from repository", zap.Error(err)) return echo.NewHTTPError(http.StatusInternalServerError, err) } - comments := lo.Map(modelcomments, func(modelcomment *model.Comment, index int) *CommentDetail { + comments := lo.Map(modelcomments, func(modelcomment *model.Comment, _ int) *CommentDetail { return &CommentDetail{ ID: modelcomment.ID, User: modelcomment.User, @@ -538,7 +538,7 @@ func (h Handlers) PutRequest(c echo.Context) error { UpdatedAt: request.Group.UpdatedAt, } } - restags := lo.Map(request.Tags, func(tag *model.Tag, index int) *TagOverview { + restags := lo.Map(request.Tags, func(tag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: tag.ID, Name: tag.Name, @@ -549,7 +549,7 @@ func (h Handlers) PutRequest(c echo.Context) error { restargets := lo.Map( request.Targets, - func(target *model.RequestTargetDetail, index int) *TargetOverview { + func(target *model.RequestTargetDetail, _ int) *TargetOverview { return &TargetOverview{ ID: target.ID, Target: target.Target, @@ -562,7 +562,7 @@ func (h Handlers) PutRequest(c echo.Context) error { resstatuses := lo.Map( request.Statuses, - func(status *model.RequestStatus, index int) *StatusResponseOverview { + func(status *model.RequestStatus, _ int) *StatusResponseOverview { return &StatusResponseOverview{ CreatedBy: status.CreatedBy, Status: status.Status, diff --git a/router/tag.go b/router/tag.go index a8ba0b1e..49c60366 100644 --- a/router/tag.go +++ b/router/tag.go @@ -32,7 +32,7 @@ func (h Handlers) GetTags(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - res := lo.Map(tags, func(tag *model.Tag, index int) *TagOverview { + res := lo.Map(tags, func(tag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: tag.ID, Name: tag.Name, diff --git a/router/tag_test.go b/router/tag_test.go index 2bc6c642..93d831dd 100644 --- a/router/tag_test.go +++ b/router/tag_test.go @@ -58,7 +58,7 @@ func TestHandlers_GetTags(t *testing.T) { GetTags(c.Request().Context()). Return(tags, nil) - resOverview := lo.Map(tags, func(tag *model.Tag, index int) *TagOverview { + resOverview := lo.Map(tags, func(tag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: tag.ID, Name: tag.Name, diff --git a/router/transaction.go b/router/transaction.go index 819209c3..8e6e26b5 100644 --- a/router/transaction.go +++ b/router/transaction.go @@ -137,8 +137,8 @@ func (h Handlers) GetTransactions(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - res := lo.Map(txs, func(tx *model.TransactionResponse, index int) *Transaction { - tags := lo.Map(tx.Tags, func(tag *model.Tag, index int) *TagOverview { + res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *Transaction { + tags := lo.Map(tx.Tags, func(tag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: tag.ID, Name: tag.Name, @@ -195,7 +195,7 @@ func (h Handlers) PostTransaction(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - tags := lo.Map(created.Tags, func(tag *model.Tag, index int) *TagOverview { + tags := lo.Map(created.Tags, func(tag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: tag.ID, Name: tag.Name, @@ -245,7 +245,7 @@ func (h Handlers) GetTransaction(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - tags := lo.Map(tx.Tags, func(tag *model.Tag, index int) *TagOverview { + tags := lo.Map(tx.Tags, func(tag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: tag.ID, Name: tag.Name, @@ -303,7 +303,7 @@ func (h Handlers) PutTransaction(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - tags := lo.Map(updated.Tags, func(tag *model.Tag, index int) *TagOverview { + tags := lo.Map(updated.Tags, func(tag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: tag.ID, Name: tag.Name, diff --git a/router/transaction_test.go b/router/transaction_test.go index 0845023a..727f8fdf 100644 --- a/router/transaction_test.go +++ b/router/transaction_test.go @@ -100,8 +100,8 @@ func TestHandlers_GetTransactions(t *testing.T) { }). Return(txs, nil) - res := lo.Map(txs, func(tx *model.TransactionResponse, index int) *Transaction { - tag := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { + res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *Transaction { + tag := lo.Map(tx.Tags, func(modelTag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, @@ -213,8 +213,8 @@ func TestHandlers_GetTransactions(t *testing.T) { }). Return(txs, nil) - res := lo.Map(txs, func(tx *model.TransactionResponse, index int) *Transaction { - tag := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { + res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *Transaction { + tag := lo.Map(tx.Tags, func(modelTag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, @@ -327,8 +327,8 @@ func TestHandlers_GetTransactions(t *testing.T) { }). Return(txs, nil) - res := lo.Map(txs, func(tx *model.TransactionResponse, index int) *Transaction { - tag := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { + res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *Transaction { + tag := lo.Map(tx.Tags, func(modelTag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, @@ -446,8 +446,8 @@ func TestHandlers_GetTransactions(t *testing.T) { }). Return(txs, nil) - res := lo.Map(txs, func(tx *model.TransactionResponse, index int) *Transaction { - tag := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { + res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *Transaction { + tag := lo.Map(tx.Tags, func(modelTag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, @@ -549,8 +549,8 @@ func TestHandlers_GetTransactions(t *testing.T) { }). Return(txs, nil) - res := lo.Map(txs, func(tx *model.TransactionResponse, index int) *Transaction { - tag := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { + res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *Transaction { + tag := lo.Map(tx.Tags, func(modelTag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, @@ -655,8 +655,8 @@ func TestHandlers_PostTransaction(t *testing.T) { CreateTransaction(c.Request().Context(), tx1.Amount, tx1.Target, tags, &group, nil). Return(tx1, nil) - res := lo.Map(txs, func(tx *model.TransactionResponse, index int) *Transaction { - tag := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { + res := lo.Map(txs, func(tx *model.TransactionResponse, _ int) *Transaction { + tag := lo.Map(tx.Tags, func(modelTag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, @@ -773,7 +773,7 @@ func TestHandlers_PostTransaction(t *testing.T) { var resOverview Transaction res := []*Transaction{} - to := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { + to := lo.Map(tx.Tags, func(modelTag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, @@ -863,7 +863,7 @@ func TestHandlers_GetTransaction(t *testing.T) { Return(tx, nil) var resOverview Transaction - to := lo.Map(tx.Tags, func(modelTag *model.Tag, index int) *TagOverview { + to := lo.Map(tx.Tags, func(modelTag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, @@ -961,7 +961,7 @@ func TestHandlers_PutTransaction(t *testing.T) { UpdatedAt: time.Now(), } - updatedTags := lo.Map(updated.Tags, func(modelTag *model.Tag, index int) *uuid.UUID { + updatedTags := lo.Map(updated.Tags, func(modelTag *model.Tag, _ int) *uuid.UUID { return &modelTag.ID }) @@ -992,7 +992,7 @@ func TestHandlers_PutTransaction(t *testing.T) { Return(updated, nil) var resOverview Transaction - to := lo.Map(updated.Tags, func(modelTag *model.Tag, index int) *TagOverview { + to := lo.Map(updated.Tags, func(modelTag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: modelTag.ID, Name: modelTag.Name, diff --git a/router/user.go b/router/user.go index dcdbb32c..a14e59d4 100644 --- a/router/user.go +++ b/router/user.go @@ -29,7 +29,7 @@ func (h Handlers) GetUsers(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } - res := lo.Map(users, func(user *model.User, index int) User { + res := lo.Map(users, func(user *model.User, _ int) User { return User{ ID: user.ID, Name: user.Name, diff --git a/service/webhook.go b/service/webhook.go index d7801670..c2059158 100644 --- a/service/webhook.go +++ b/service/webhook.go @@ -127,7 +127,7 @@ func WebhookEventHandler(c echo.Context, reqBody, resBody []byte) { } if len(resApp.Tags) != 0 { - tags := lo.Map(resApp.Tags, func(tag *Tag, index int) string { + tags := lo.Map(resApp.Tags, func(tag *Tag, _ int) string { return tag.Name }) message += fmt.Sprintf("- タグ: %s", strings.Join(tags, ", ")) @@ -167,7 +167,7 @@ func WebhookEventHandler(c echo.Context, reqBody, resBody []byte) { } } else { targets := lo.Map( - resApps, func(resApp TransactionRequestApplication, index int) string { + resApps, func(resApp TransactionRequestApplication, _ int) string { return resApp.Target }) if resApp.Amount < 0 { @@ -188,7 +188,7 @@ func WebhookEventHandler(c echo.Context, reqBody, resBody []byte) { message += fmt.Sprintf("- 関連するグループ: %s\n", resApp.Group.Name) } if len(resApp.Tags) != 0 { - tags := lo.Map(resApp.Tags, func(tag *Tag, index int) string { + tags := lo.Map(resApp.Tags, func(tag *Tag, _ int) string { return tag.Name }) message += fmt.Sprintf("- タグ: %s", strings.Join(tags, ", ")) diff --git a/testutil/random/ramdom.go b/testutil/random/ramdom.go index b6dbd3c4..c5d69837 100644 --- a/testutil/random/ramdom.go +++ b/testutil/random/ramdom.go @@ -34,21 +34,21 @@ func Numeric64(t *testing.T, n int64) int64 { func AlphaNumericSlice(t *testing.T, length int, n int64) []string { t.Helper() - return lo.Times(length, func(index int) string { + return lo.Times(length, func(_ int) string { return AlphaNumeric(t, int(n)) }) } func NumericSlice(t *testing.T, length int, n int) []int { t.Helper() - return lo.Times(length, func(index int) int { + return lo.Times(length, func(_ int) int { return Numeric(t, n) }) } func Numeric64Slice(t *testing.T, length int, n int64) []int64 { t.Helper() - return lo.Times(length, func(index int) int64 { + return lo.Times(length, func(_ int) int64 { return Numeric64(t, n) }) } From 4bb7d1c6fdc14b69bcdf9d8a942a6efc42cb6c76 Mon Sep 17 00:00:00 2001 From: Hueter Date: Wed, 2 Oct 2024 21:41:58 +0900 Subject: [PATCH 10/11] =?UTF-8?q?lo.Reduce=E3=81=AE=E4=B8=AD=E8=BA=AB?= =?UTF-8?q?=E3=82=92=E7=B0=A1=E6=BD=94=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router/request.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/router/request.go b/router/request.go index ba709a1a..5ac87943 100644 --- a/router/request.go +++ b/router/request.go @@ -716,10 +716,7 @@ func (h Handlers) PutStatus(c echo.Context) error { return echo.NewHTTPError(http.StatusInternalServerError, err) } paid := lo.Reduce(targets, func(p bool, target *model.RequestTargetDetail, _ int) bool { - if target.PaidAt != nil { - return true - } - return p + return p || target.PaidAt != nil }, false) if paid { h.Logger.Info("someone already paid") From 28c2e0979700bf116c8a6d043802d2a8a4ad6325 Mon Sep 17 00:00:00 2001 From: Hueter Date: Wed, 2 Oct 2024 21:49:54 +0900 Subject: [PATCH 11/11] =?UTF-8?q?append=E3=81=AE=E6=9B=B8=E3=81=8D?= =?UTF-8?q?=E6=8F=9B=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router/transaction_test.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/router/transaction_test.go b/router/transaction_test.go index 727f8fdf..5897ee09 100644 --- a/router/transaction_test.go +++ b/router/transaction_test.go @@ -771,8 +771,6 @@ func TestHandlers_PostTransaction(t *testing.T) { tags, &group, &request.ID). Return(tx, nil) - var resOverview Transaction - res := []*Transaction{} to := lo.Map(tx.Tags, func(modelTag *model.Tag, _ int) *TagOverview { return &TagOverview{ ID: modelTag.ID, @@ -790,16 +788,17 @@ func TestHandlers_PostTransaction(t *testing.T) { CreatedAt: tx.Group.CreatedAt, UpdatedAt: tx.Group.UpdatedAt, } - resOverview = Transaction{ - ID: tx.ID, - Amount: tx.Amount, - Target: tx.Target, - Tags: to, - Group: grov, - CreatedAt: tx.CreatedAt, - UpdatedAt: tx.UpdatedAt, + res := []*Transaction{ + { + ID: tx.ID, + Amount: tx.Amount, + Target: tx.Target, + Tags: to, + Group: grov, + CreatedAt: tx.CreatedAt, + UpdatedAt: tx.UpdatedAt, + }, } - res = append(res, &resOverview) resBody, err := json.Marshal(res) require.NoError(t, err)