From 94f7c8d4963fd281c0f8d65167ca57ae00f6cb26 Mon Sep 17 00:00:00 2001 From: Neko Ayaka Date: Mon, 24 Jul 2023 17:31:30 +0800 Subject: [PATCH] feat: added reactions inline keyboard options (#163) * feat: added reactions inline keyboard options * chore: adjust ent lint --- .golangci.yml | 5 + ent/client.go | 276 ++- ent/ent.go | 4 + ent/feedbackchathistoriesrecapsreactions.go | 161 ++ .../feedbackchathistoriesrecapsreactions.go | 133 ++ .../where.go | 331 ++++ ...backchathistoriesrecapsreactions_create.go | 352 ++++ ...backchathistoriesrecapsreactions_delete.go | 91 + ...dbackchathistoriesrecapsreactions_query.go | 535 ++++++ ...backchathistoriesrecapsreactions_update.go | 456 +++++ ent/feedbacksummarizationsreactions.go | 161 ++ .../feedbacksummarizationsreactions.go | 133 ++ ent/feedbacksummarizationsreactions/where.go | 331 ++++ ent/feedbacksummarizationsreactions_create.go | 352 ++++ ent/feedbacksummarizationsreactions_delete.go | 91 + ent/feedbacksummarizationsreactions_query.go | 535 ++++++ ent/feedbacksummarizationsreactions_update.go | 456 +++++ ent/hook/hook.go | 24 + ent/internal/schemaconfig.go | 2 + ent/migrate/schema.go | 34 + ent/mutation.go | 1478 +++++++++++++++++ ent/predicate/predicate.go | 6 + ent/runtime.go | 54 + .../feedbackchathistoriesrecapsreactions.go | 32 + ent/schema/feedbacksummarizationsreactions.go | 32 + ent/tx.go | 6 + .../telegram/handlers/recap/callback_query.go | 128 +- .../handlers/recap/feedback_callback_query.go | 137 ++ .../bots/telegram/handlers/recap/recap.go | 1 + .../handlers/recap/recap_callback_query.go | 143 ++ .../summarize/feedback_callback_query.go | 94 ++ .../telegram/handlers/summarize/summarize.go | 1 + .../models/chathistories/chat_histories.go | 15 +- internal/models/chathistories/feedbacks.go | 195 +++ internal/models/smr/feedbacks.go | 181 ++ internal/models/smr/smr.go | 7 +- internal/services/autorecap/autorecap.go | 40 +- internal/services/smr/processor.go | 49 +- pkg/bots/tgbot/dispatcher.go | 25 +- pkg/bots/tgbot/tgbot.go | 44 + .../bot/handlers/recap/configure_recap.go | 18 +- 41 files changed, 6985 insertions(+), 164 deletions(-) create mode 100644 ent/feedbackchathistoriesrecapsreactions.go create mode 100644 ent/feedbackchathistoriesrecapsreactions/feedbackchathistoriesrecapsreactions.go create mode 100644 ent/feedbackchathistoriesrecapsreactions/where.go create mode 100644 ent/feedbackchathistoriesrecapsreactions_create.go create mode 100644 ent/feedbackchathistoriesrecapsreactions_delete.go create mode 100644 ent/feedbackchathistoriesrecapsreactions_query.go create mode 100644 ent/feedbackchathistoriesrecapsreactions_update.go create mode 100644 ent/feedbacksummarizationsreactions.go create mode 100644 ent/feedbacksummarizationsreactions/feedbacksummarizationsreactions.go create mode 100644 ent/feedbacksummarizationsreactions/where.go create mode 100644 ent/feedbacksummarizationsreactions_create.go create mode 100644 ent/feedbacksummarizationsreactions_delete.go create mode 100644 ent/feedbacksummarizationsreactions_query.go create mode 100644 ent/feedbacksummarizationsreactions_update.go create mode 100644 ent/schema/feedbackchathistoriesrecapsreactions.go create mode 100644 ent/schema/feedbacksummarizationsreactions.go create mode 100644 internal/bots/telegram/handlers/recap/feedback_callback_query.go create mode 100644 internal/bots/telegram/handlers/recap/recap_callback_query.go create mode 100644 internal/bots/telegram/handlers/summarize/feedback_callback_query.go create mode 100644 internal/models/chathistories/feedbacks.go create mode 100644 internal/models/smr/feedbacks.go diff --git a/.golangci.yml b/.golangci.yml index 436b8ee..14207db 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -57,4 +57,9 @@ issues: - "if statements should only be cuddled with assignments used in the if statement itself" # from wsl - "assignments should only be cuddled with other assignments" # from wsl. false positive case: var a bool\nb := true - "declarations should never be cuddled" # from wsl + exclude-rules: + # Exclude some linters from running on tests files. + - path: ent/.*\.go + linters: + - dupl diff --git a/ent/client.go b/ent/client.go index e9b9600..7acd072 100644 --- a/ent/client.go +++ b/ent/client.go @@ -15,6 +15,8 @@ import ( "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "github.com/nekomeowww/insights-bot/ent/chathistories" + "github.com/nekomeowww/insights-bot/ent/feedbackchathistoriesrecapsreactions" + "github.com/nekomeowww/insights-bot/ent/feedbacksummarizationsreactions" "github.com/nekomeowww/insights-bot/ent/logchathistoriesrecap" "github.com/nekomeowww/insights-bot/ent/logsummarizations" "github.com/nekomeowww/insights-bot/ent/metricopenaichatcompletiontokenusage" @@ -33,6 +35,10 @@ type Client struct { Schema *migrate.Schema // ChatHistories is the client for interacting with the ChatHistories builders. ChatHistories *ChatHistoriesClient + // FeedbackChatHistoriesRecapsReactions is the client for interacting with the FeedbackChatHistoriesRecapsReactions builders. + FeedbackChatHistoriesRecapsReactions *FeedbackChatHistoriesRecapsReactionsClient + // FeedbackSummarizationsReactions is the client for interacting with the FeedbackSummarizationsReactions builders. + FeedbackSummarizationsReactions *FeedbackSummarizationsReactionsClient // LogChatHistoriesRecap is the client for interacting with the LogChatHistoriesRecap builders. LogChatHistoriesRecap *LogChatHistoriesRecapClient // LogSummarizations is the client for interacting with the LogSummarizations builders. @@ -61,6 +67,8 @@ func NewClient(opts ...Option) *Client { func (c *Client) init() { c.Schema = migrate.NewSchema(c.driver) c.ChatHistories = NewChatHistoriesClient(c.config) + c.FeedbackChatHistoriesRecapsReactions = NewFeedbackChatHistoriesRecapsReactionsClient(c.config) + c.FeedbackSummarizationsReactions = NewFeedbackSummarizationsReactionsClient(c.config) c.LogChatHistoriesRecap = NewLogChatHistoriesRecapClient(c.config) c.LogSummarizations = NewLogSummarizationsClient(c.config) c.MetricOpenAIChatCompletionTokenUsage = NewMetricOpenAIChatCompletionTokenUsageClient(c.config) @@ -153,6 +161,8 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { ctx: ctx, config: cfg, ChatHistories: NewChatHistoriesClient(cfg), + FeedbackChatHistoriesRecapsReactions: NewFeedbackChatHistoriesRecapsReactionsClient(cfg), + FeedbackSummarizationsReactions: NewFeedbackSummarizationsReactionsClient(cfg), LogChatHistoriesRecap: NewLogChatHistoriesRecapClient(cfg), LogSummarizations: NewLogSummarizationsClient(cfg), MetricOpenAIChatCompletionTokenUsage: NewMetricOpenAIChatCompletionTokenUsageClient(cfg), @@ -180,6 +190,8 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) ctx: ctx, config: cfg, ChatHistories: NewChatHistoriesClient(cfg), + FeedbackChatHistoriesRecapsReactions: NewFeedbackChatHistoriesRecapsReactionsClient(cfg), + FeedbackSummarizationsReactions: NewFeedbackSummarizationsReactionsClient(cfg), LogChatHistoriesRecap: NewLogChatHistoriesRecapClient(cfg), LogSummarizations: NewLogSummarizationsClient(cfg), MetricOpenAIChatCompletionTokenUsage: NewMetricOpenAIChatCompletionTokenUsageClient(cfg), @@ -216,10 +228,11 @@ func (c *Client) Close() error { // In order to add hooks to a specific client, call: `client.Node.Use(...)`. func (c *Client) Use(hooks ...Hook) { for _, n := range []interface{ Use(...Hook) }{ - c.ChatHistories, c.LogChatHistoriesRecap, c.LogSummarizations, - c.MetricOpenAIChatCompletionTokenUsage, c.SlackOAuthCredentials, - c.TelegramChatAutoRecapsSubscribers, c.TelegramChatFeatureFlags, - c.TelegramChatRecapsOptions, + c.ChatHistories, c.FeedbackChatHistoriesRecapsReactions, + c.FeedbackSummarizationsReactions, c.LogChatHistoriesRecap, + c.LogSummarizations, c.MetricOpenAIChatCompletionTokenUsage, + c.SlackOAuthCredentials, c.TelegramChatAutoRecapsSubscribers, + c.TelegramChatFeatureFlags, c.TelegramChatRecapsOptions, } { n.Use(hooks...) } @@ -229,10 +242,11 @@ func (c *Client) Use(hooks ...Hook) { // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. func (c *Client) Intercept(interceptors ...Interceptor) { for _, n := range []interface{ Intercept(...Interceptor) }{ - c.ChatHistories, c.LogChatHistoriesRecap, c.LogSummarizations, - c.MetricOpenAIChatCompletionTokenUsage, c.SlackOAuthCredentials, - c.TelegramChatAutoRecapsSubscribers, c.TelegramChatFeatureFlags, - c.TelegramChatRecapsOptions, + c.ChatHistories, c.FeedbackChatHistoriesRecapsReactions, + c.FeedbackSummarizationsReactions, c.LogChatHistoriesRecap, + c.LogSummarizations, c.MetricOpenAIChatCompletionTokenUsage, + c.SlackOAuthCredentials, c.TelegramChatAutoRecapsSubscribers, + c.TelegramChatFeatureFlags, c.TelegramChatRecapsOptions, } { n.Intercept(interceptors...) } @@ -243,6 +257,10 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { switch m := m.(type) { case *ChatHistoriesMutation: return c.ChatHistories.mutate(ctx, m) + case *FeedbackChatHistoriesRecapsReactionsMutation: + return c.FeedbackChatHistoriesRecapsReactions.mutate(ctx, m) + case *FeedbackSummarizationsReactionsMutation: + return c.FeedbackSummarizationsReactions.mutate(ctx, m) case *LogChatHistoriesRecapMutation: return c.LogChatHistoriesRecap.mutate(ctx, m) case *LogSummarizationsMutation: @@ -380,6 +398,242 @@ func (c *ChatHistoriesClient) mutate(ctx context.Context, m *ChatHistoriesMutati } } +// FeedbackChatHistoriesRecapsReactionsClient is a client for the FeedbackChatHistoriesRecapsReactions schema. +type FeedbackChatHistoriesRecapsReactionsClient struct { + config +} + +// NewFeedbackChatHistoriesRecapsReactionsClient returns a client for the FeedbackChatHistoriesRecapsReactions from the given config. +func NewFeedbackChatHistoriesRecapsReactionsClient(c config) *FeedbackChatHistoriesRecapsReactionsClient { + return &FeedbackChatHistoriesRecapsReactionsClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `feedbackchathistoriesrecapsreactions.Hooks(f(g(h())))`. +func (c *FeedbackChatHistoriesRecapsReactionsClient) Use(hooks ...Hook) { + c.hooks.FeedbackChatHistoriesRecapsReactions = append(c.hooks.FeedbackChatHistoriesRecapsReactions, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `feedbackchathistoriesrecapsreactions.Intercept(f(g(h())))`. +func (c *FeedbackChatHistoriesRecapsReactionsClient) Intercept(interceptors ...Interceptor) { + c.inters.FeedbackChatHistoriesRecapsReactions = append(c.inters.FeedbackChatHistoriesRecapsReactions, interceptors...) +} + +// Create returns a builder for creating a FeedbackChatHistoriesRecapsReactions entity. +func (c *FeedbackChatHistoriesRecapsReactionsClient) Create() *FeedbackChatHistoriesRecapsReactionsCreate { + mutation := newFeedbackChatHistoriesRecapsReactionsMutation(c.config, OpCreate) + return &FeedbackChatHistoriesRecapsReactionsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of FeedbackChatHistoriesRecapsReactions entities. +func (c *FeedbackChatHistoriesRecapsReactionsClient) CreateBulk(builders ...*FeedbackChatHistoriesRecapsReactionsCreate) *FeedbackChatHistoriesRecapsReactionsCreateBulk { + return &FeedbackChatHistoriesRecapsReactionsCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for FeedbackChatHistoriesRecapsReactions. +func (c *FeedbackChatHistoriesRecapsReactionsClient) Update() *FeedbackChatHistoriesRecapsReactionsUpdate { + mutation := newFeedbackChatHistoriesRecapsReactionsMutation(c.config, OpUpdate) + return &FeedbackChatHistoriesRecapsReactionsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *FeedbackChatHistoriesRecapsReactionsClient) UpdateOne(fchrr *FeedbackChatHistoriesRecapsReactions) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + mutation := newFeedbackChatHistoriesRecapsReactionsMutation(c.config, OpUpdateOne, withFeedbackChatHistoriesRecapsReactions(fchrr)) + return &FeedbackChatHistoriesRecapsReactionsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *FeedbackChatHistoriesRecapsReactionsClient) UpdateOneID(id uuid.UUID) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + mutation := newFeedbackChatHistoriesRecapsReactionsMutation(c.config, OpUpdateOne, withFeedbackChatHistoriesRecapsReactionsID(id)) + return &FeedbackChatHistoriesRecapsReactionsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for FeedbackChatHistoriesRecapsReactions. +func (c *FeedbackChatHistoriesRecapsReactionsClient) Delete() *FeedbackChatHistoriesRecapsReactionsDelete { + mutation := newFeedbackChatHistoriesRecapsReactionsMutation(c.config, OpDelete) + return &FeedbackChatHistoriesRecapsReactionsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *FeedbackChatHistoriesRecapsReactionsClient) DeleteOne(fchrr *FeedbackChatHistoriesRecapsReactions) *FeedbackChatHistoriesRecapsReactionsDeleteOne { + return c.DeleteOneID(fchrr.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *FeedbackChatHistoriesRecapsReactionsClient) DeleteOneID(id uuid.UUID) *FeedbackChatHistoriesRecapsReactionsDeleteOne { + builder := c.Delete().Where(feedbackchathistoriesrecapsreactions.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &FeedbackChatHistoriesRecapsReactionsDeleteOne{builder} +} + +// Query returns a query builder for FeedbackChatHistoriesRecapsReactions. +func (c *FeedbackChatHistoriesRecapsReactionsClient) Query() *FeedbackChatHistoriesRecapsReactionsQuery { + return &FeedbackChatHistoriesRecapsReactionsQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeFeedbackChatHistoriesRecapsReactions}, + inters: c.Interceptors(), + } +} + +// Get returns a FeedbackChatHistoriesRecapsReactions entity by its id. +func (c *FeedbackChatHistoriesRecapsReactionsClient) Get(ctx context.Context, id uuid.UUID) (*FeedbackChatHistoriesRecapsReactions, error) { + return c.Query().Where(feedbackchathistoriesrecapsreactions.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *FeedbackChatHistoriesRecapsReactionsClient) GetX(ctx context.Context, id uuid.UUID) *FeedbackChatHistoriesRecapsReactions { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *FeedbackChatHistoriesRecapsReactionsClient) Hooks() []Hook { + return c.hooks.FeedbackChatHistoriesRecapsReactions +} + +// Interceptors returns the client interceptors. +func (c *FeedbackChatHistoriesRecapsReactionsClient) Interceptors() []Interceptor { + return c.inters.FeedbackChatHistoriesRecapsReactions +} + +func (c *FeedbackChatHistoriesRecapsReactionsClient) mutate(ctx context.Context, m *FeedbackChatHistoriesRecapsReactionsMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&FeedbackChatHistoriesRecapsReactionsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&FeedbackChatHistoriesRecapsReactionsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&FeedbackChatHistoriesRecapsReactionsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&FeedbackChatHistoriesRecapsReactionsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown FeedbackChatHistoriesRecapsReactions mutation op: %q", m.Op()) + } +} + +// FeedbackSummarizationsReactionsClient is a client for the FeedbackSummarizationsReactions schema. +type FeedbackSummarizationsReactionsClient struct { + config +} + +// NewFeedbackSummarizationsReactionsClient returns a client for the FeedbackSummarizationsReactions from the given config. +func NewFeedbackSummarizationsReactionsClient(c config) *FeedbackSummarizationsReactionsClient { + return &FeedbackSummarizationsReactionsClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `feedbacksummarizationsreactions.Hooks(f(g(h())))`. +func (c *FeedbackSummarizationsReactionsClient) Use(hooks ...Hook) { + c.hooks.FeedbackSummarizationsReactions = append(c.hooks.FeedbackSummarizationsReactions, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `feedbacksummarizationsreactions.Intercept(f(g(h())))`. +func (c *FeedbackSummarizationsReactionsClient) Intercept(interceptors ...Interceptor) { + c.inters.FeedbackSummarizationsReactions = append(c.inters.FeedbackSummarizationsReactions, interceptors...) +} + +// Create returns a builder for creating a FeedbackSummarizationsReactions entity. +func (c *FeedbackSummarizationsReactionsClient) Create() *FeedbackSummarizationsReactionsCreate { + mutation := newFeedbackSummarizationsReactionsMutation(c.config, OpCreate) + return &FeedbackSummarizationsReactionsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of FeedbackSummarizationsReactions entities. +func (c *FeedbackSummarizationsReactionsClient) CreateBulk(builders ...*FeedbackSummarizationsReactionsCreate) *FeedbackSummarizationsReactionsCreateBulk { + return &FeedbackSummarizationsReactionsCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for FeedbackSummarizationsReactions. +func (c *FeedbackSummarizationsReactionsClient) Update() *FeedbackSummarizationsReactionsUpdate { + mutation := newFeedbackSummarizationsReactionsMutation(c.config, OpUpdate) + return &FeedbackSummarizationsReactionsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *FeedbackSummarizationsReactionsClient) UpdateOne(fsr *FeedbackSummarizationsReactions) *FeedbackSummarizationsReactionsUpdateOne { + mutation := newFeedbackSummarizationsReactionsMutation(c.config, OpUpdateOne, withFeedbackSummarizationsReactions(fsr)) + return &FeedbackSummarizationsReactionsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *FeedbackSummarizationsReactionsClient) UpdateOneID(id uuid.UUID) *FeedbackSummarizationsReactionsUpdateOne { + mutation := newFeedbackSummarizationsReactionsMutation(c.config, OpUpdateOne, withFeedbackSummarizationsReactionsID(id)) + return &FeedbackSummarizationsReactionsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for FeedbackSummarizationsReactions. +func (c *FeedbackSummarizationsReactionsClient) Delete() *FeedbackSummarizationsReactionsDelete { + mutation := newFeedbackSummarizationsReactionsMutation(c.config, OpDelete) + return &FeedbackSummarizationsReactionsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *FeedbackSummarizationsReactionsClient) DeleteOne(fsr *FeedbackSummarizationsReactions) *FeedbackSummarizationsReactionsDeleteOne { + return c.DeleteOneID(fsr.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *FeedbackSummarizationsReactionsClient) DeleteOneID(id uuid.UUID) *FeedbackSummarizationsReactionsDeleteOne { + builder := c.Delete().Where(feedbacksummarizationsreactions.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &FeedbackSummarizationsReactionsDeleteOne{builder} +} + +// Query returns a query builder for FeedbackSummarizationsReactions. +func (c *FeedbackSummarizationsReactionsClient) Query() *FeedbackSummarizationsReactionsQuery { + return &FeedbackSummarizationsReactionsQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeFeedbackSummarizationsReactions}, + inters: c.Interceptors(), + } +} + +// Get returns a FeedbackSummarizationsReactions entity by its id. +func (c *FeedbackSummarizationsReactionsClient) Get(ctx context.Context, id uuid.UUID) (*FeedbackSummarizationsReactions, error) { + return c.Query().Where(feedbacksummarizationsreactions.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *FeedbackSummarizationsReactionsClient) GetX(ctx context.Context, id uuid.UUID) *FeedbackSummarizationsReactions { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *FeedbackSummarizationsReactionsClient) Hooks() []Hook { + return c.hooks.FeedbackSummarizationsReactions +} + +// Interceptors returns the client interceptors. +func (c *FeedbackSummarizationsReactionsClient) Interceptors() []Interceptor { + return c.inters.FeedbackSummarizationsReactions +} + +func (c *FeedbackSummarizationsReactionsClient) mutate(ctx context.Context, m *FeedbackSummarizationsReactionsMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&FeedbackSummarizationsReactionsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&FeedbackSummarizationsReactionsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&FeedbackSummarizationsReactionsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&FeedbackSummarizationsReactionsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown FeedbackSummarizationsReactions mutation op: %q", m.Op()) + } +} + // LogChatHistoriesRecapClient is a client for the LogChatHistoriesRecap schema. type LogChatHistoriesRecapClient struct { config @@ -1209,13 +1463,15 @@ func (c *TelegramChatRecapsOptionsClient) mutate(ctx context.Context, m *Telegra // hooks and interceptors per client, for fast access. type ( hooks struct { - ChatHistories, LogChatHistoriesRecap, LogSummarizations, + ChatHistories, FeedbackChatHistoriesRecapsReactions, + FeedbackSummarizationsReactions, LogChatHistoriesRecap, LogSummarizations, MetricOpenAIChatCompletionTokenUsage, SlackOAuthCredentials, TelegramChatAutoRecapsSubscribers, TelegramChatFeatureFlags, TelegramChatRecapsOptions []ent.Hook } inters struct { - ChatHistories, LogChatHistoriesRecap, LogSummarizations, + ChatHistories, FeedbackChatHistoriesRecapsReactions, + FeedbackSummarizationsReactions, LogChatHistoriesRecap, LogSummarizations, MetricOpenAIChatCompletionTokenUsage, SlackOAuthCredentials, TelegramChatAutoRecapsSubscribers, TelegramChatFeatureFlags, TelegramChatRecapsOptions []ent.Interceptor diff --git a/ent/ent.go b/ent/ent.go index c594807..c227d6c 100644 --- a/ent/ent.go +++ b/ent/ent.go @@ -13,6 +13,8 @@ import ( "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "github.com/nekomeowww/insights-bot/ent/chathistories" + "github.com/nekomeowww/insights-bot/ent/feedbackchathistoriesrecapsreactions" + "github.com/nekomeowww/insights-bot/ent/feedbacksummarizationsreactions" "github.com/nekomeowww/insights-bot/ent/logchathistoriesrecap" "github.com/nekomeowww/insights-bot/ent/logsummarizations" "github.com/nekomeowww/insights-bot/ent/metricopenaichatcompletiontokenusage" @@ -81,6 +83,8 @@ func checkColumn(table, column string) error { initCheck.Do(func() { columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ chathistories.Table: chathistories.ValidColumn, + feedbackchathistoriesrecapsreactions.Table: feedbackchathistoriesrecapsreactions.ValidColumn, + feedbacksummarizationsreactions.Table: feedbacksummarizationsreactions.ValidColumn, logchathistoriesrecap.Table: logchathistoriesrecap.ValidColumn, logsummarizations.Table: logsummarizations.ValidColumn, metricopenaichatcompletiontokenusage.Table: metricopenaichatcompletiontokenusage.ValidColumn, diff --git a/ent/feedbackchathistoriesrecapsreactions.go b/ent/feedbackchathistoriesrecapsreactions.go new file mode 100644 index 0000000..17f52b5 --- /dev/null +++ b/ent/feedbackchathistoriesrecapsreactions.go @@ -0,0 +1,161 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" + "github.com/nekomeowww/insights-bot/ent/feedbackchathistoriesrecapsreactions" +) + +// FeedbackChatHistoriesRecapsReactions is the model entity for the FeedbackChatHistoriesRecapsReactions schema. +type FeedbackChatHistoriesRecapsReactions struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // ChatID holds the value of the "chat_id" field. + ChatID int64 `json:"chat_id,omitempty"` + // LogID holds the value of the "log_id" field. + LogID uuid.UUID `json:"log_id,omitempty"` + // UserID holds the value of the "user_id" field. + UserID int64 `json:"user_id,omitempty"` + // Type holds the value of the "type" field. + Type feedbackchathistoriesrecapsreactions.Type `json:"type,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt int64 `json:"created_at,omitempty"` + // UpdatedAt holds the value of the "updated_at" field. + UpdatedAt int64 `json:"updated_at,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*FeedbackChatHistoriesRecapsReactions) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case feedbackchathistoriesrecapsreactions.FieldChatID, feedbackchathistoriesrecapsreactions.FieldUserID, feedbackchathistoriesrecapsreactions.FieldCreatedAt, feedbackchathistoriesrecapsreactions.FieldUpdatedAt: + values[i] = new(sql.NullInt64) + case feedbackchathistoriesrecapsreactions.FieldType: + values[i] = new(sql.NullString) + case feedbackchathistoriesrecapsreactions.FieldID, feedbackchathistoriesrecapsreactions.FieldLogID: + values[i] = new(uuid.UUID) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the FeedbackChatHistoriesRecapsReactions fields. +func (fchrr *FeedbackChatHistoriesRecapsReactions) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case feedbackchathistoriesrecapsreactions.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + fchrr.ID = *value + } + case feedbackchathistoriesrecapsreactions.FieldChatID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field chat_id", values[i]) + } else if value.Valid { + fchrr.ChatID = value.Int64 + } + case feedbackchathistoriesrecapsreactions.FieldLogID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field log_id", values[i]) + } else if value != nil { + fchrr.LogID = *value + } + case feedbackchathistoriesrecapsreactions.FieldUserID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field user_id", values[i]) + } else if value.Valid { + fchrr.UserID = value.Int64 + } + case feedbackchathistoriesrecapsreactions.FieldType: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field type", values[i]) + } else if value.Valid { + fchrr.Type = feedbackchathistoriesrecapsreactions.Type(value.String) + } + case feedbackchathistoriesrecapsreactions.FieldCreatedAt: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + fchrr.CreatedAt = value.Int64 + } + case feedbackchathistoriesrecapsreactions.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + fchrr.UpdatedAt = value.Int64 + } + default: + fchrr.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the FeedbackChatHistoriesRecapsReactions. +// This includes values selected through modifiers, order, etc. +func (fchrr *FeedbackChatHistoriesRecapsReactions) Value(name string) (ent.Value, error) { + return fchrr.selectValues.Get(name) +} + +// Update returns a builder for updating this FeedbackChatHistoriesRecapsReactions. +// Note that you need to call FeedbackChatHistoriesRecapsReactions.Unwrap() before calling this method if this FeedbackChatHistoriesRecapsReactions +// was returned from a transaction, and the transaction was committed or rolled back. +func (fchrr *FeedbackChatHistoriesRecapsReactions) Update() *FeedbackChatHistoriesRecapsReactionsUpdateOne { + return NewFeedbackChatHistoriesRecapsReactionsClient(fchrr.config).UpdateOne(fchrr) +} + +// Unwrap unwraps the FeedbackChatHistoriesRecapsReactions entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (fchrr *FeedbackChatHistoriesRecapsReactions) Unwrap() *FeedbackChatHistoriesRecapsReactions { + _tx, ok := fchrr.config.driver.(*txDriver) + if !ok { + panic("ent: FeedbackChatHistoriesRecapsReactions is not a transactional entity") + } + fchrr.config.driver = _tx.drv + return fchrr +} + +// String implements the fmt.Stringer. +func (fchrr *FeedbackChatHistoriesRecapsReactions) String() string { + var builder strings.Builder + builder.WriteString("FeedbackChatHistoriesRecapsReactions(") + builder.WriteString(fmt.Sprintf("id=%v, ", fchrr.ID)) + builder.WriteString("chat_id=") + builder.WriteString(fmt.Sprintf("%v", fchrr.ChatID)) + builder.WriteString(", ") + builder.WriteString("log_id=") + builder.WriteString(fmt.Sprintf("%v", fchrr.LogID)) + builder.WriteString(", ") + builder.WriteString("user_id=") + builder.WriteString(fmt.Sprintf("%v", fchrr.UserID)) + builder.WriteString(", ") + builder.WriteString("type=") + builder.WriteString(fmt.Sprintf("%v", fchrr.Type)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(fmt.Sprintf("%v", fchrr.CreatedAt)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(fmt.Sprintf("%v", fchrr.UpdatedAt)) + builder.WriteByte(')') + return builder.String() +} + +// FeedbackChatHistoriesRecapsReactionsSlice is a parsable slice of FeedbackChatHistoriesRecapsReactions. +type FeedbackChatHistoriesRecapsReactionsSlice []*FeedbackChatHistoriesRecapsReactions diff --git a/ent/feedbackchathistoriesrecapsreactions/feedbackchathistoriesrecapsreactions.go b/ent/feedbackchathistoriesrecapsreactions/feedbackchathistoriesrecapsreactions.go new file mode 100644 index 0000000..1db0464 --- /dev/null +++ b/ent/feedbackchathistoriesrecapsreactions/feedbackchathistoriesrecapsreactions.go @@ -0,0 +1,133 @@ +// Code generated by ent, DO NOT EDIT. + +package feedbackchathistoriesrecapsreactions + +import ( + "fmt" + + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the feedbackchathistoriesrecapsreactions type in the database. + Label = "feedback_chat_histories_recaps_reactions" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldChatID holds the string denoting the chat_id field in the database. + FieldChatID = "chat_id" + // FieldLogID holds the string denoting the log_id field in the database. + FieldLogID = "log_id" + // FieldUserID holds the string denoting the user_id field in the database. + FieldUserID = "user_id" + // FieldType holds the string denoting the type field in the database. + FieldType = "type" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // Table holds the table name of the feedbackchathistoriesrecapsreactions in the database. + Table = "feedback_chat_histories_recaps_reactions" +) + +// Columns holds all SQL columns for feedbackchathistoriesrecapsreactions fields. +var Columns = []string{ + FieldID, + FieldChatID, + FieldLogID, + FieldUserID, + FieldType, + FieldCreatedAt, + FieldUpdatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultChatID holds the default value on creation for the "chat_id" field. + DefaultChatID int64 + // DefaultLogID holds the default value on creation for the "log_id" field. + DefaultLogID func() uuid.UUID + // DefaultUserID holds the default value on creation for the "user_id" field. + DefaultUserID int64 + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() int64 + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() int64 + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// Type defines the type for the "type" enum field. +type Type string + +// TypeNone is the default value of the Type enum. +const DefaultType = TypeNone + +// Type values. +const ( + TypeNone Type = "none" + TypeUpVote Type = "up_vote" + TypeDownVote Type = "down_vote" + TypeLmao Type = "lmao" +) + +func (_type Type) String() string { + return string(_type) +} + +// TypeValidator is a validator for the "type" field enum values. It is called by the builders before save. +func TypeValidator(_type Type) error { + switch _type { + case TypeNone, TypeUpVote, TypeDownVote, TypeLmao: + return nil + default: + return fmt.Errorf("feedbackchathistoriesrecapsreactions: invalid enum value for type field: %q", _type) + } +} + +// OrderOption defines the ordering options for the FeedbackChatHistoriesRecapsReactions 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() +} + +// ByChatID orders the results by the chat_id field. +func ByChatID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldChatID, opts...).ToFunc() +} + +// ByLogID orders the results by the log_id field. +func ByLogID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldLogID, opts...).ToFunc() +} + +// ByUserID orders the results by the user_id field. +func ByUserID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUserID, opts...).ToFunc() +} + +// ByType orders the results by the type field. +func ByType(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldType, 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() +} diff --git a/ent/feedbackchathistoriesrecapsreactions/where.go b/ent/feedbackchathistoriesrecapsreactions/where.go new file mode 100644 index 0000000..4eeff4a --- /dev/null +++ b/ent/feedbackchathistoriesrecapsreactions/where.go @@ -0,0 +1,331 @@ +// Code generated by ent, DO NOT EDIT. + +package feedbackchathistoriesrecapsreactions + +import ( + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" + "github.com/nekomeowww/insights-bot/ent/predicate" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldLTE(FieldID, id)) +} + +// ChatID applies equality check predicate on the "chat_id" field. It's identical to ChatIDEQ. +func ChatID(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldEQ(FieldChatID, v)) +} + +// LogID applies equality check predicate on the "log_id" field. It's identical to LogIDEQ. +func LogID(v uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldEQ(FieldLogID, v)) +} + +// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ. +func UserID(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldEQ(FieldUserID, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// ChatIDEQ applies the EQ predicate on the "chat_id" field. +func ChatIDEQ(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldEQ(FieldChatID, v)) +} + +// ChatIDNEQ applies the NEQ predicate on the "chat_id" field. +func ChatIDNEQ(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldNEQ(FieldChatID, v)) +} + +// ChatIDIn applies the In predicate on the "chat_id" field. +func ChatIDIn(vs ...int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldIn(FieldChatID, vs...)) +} + +// ChatIDNotIn applies the NotIn predicate on the "chat_id" field. +func ChatIDNotIn(vs ...int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldNotIn(FieldChatID, vs...)) +} + +// ChatIDGT applies the GT predicate on the "chat_id" field. +func ChatIDGT(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldGT(FieldChatID, v)) +} + +// ChatIDGTE applies the GTE predicate on the "chat_id" field. +func ChatIDGTE(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldGTE(FieldChatID, v)) +} + +// ChatIDLT applies the LT predicate on the "chat_id" field. +func ChatIDLT(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldLT(FieldChatID, v)) +} + +// ChatIDLTE applies the LTE predicate on the "chat_id" field. +func ChatIDLTE(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldLTE(FieldChatID, v)) +} + +// LogIDEQ applies the EQ predicate on the "log_id" field. +func LogIDEQ(v uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldEQ(FieldLogID, v)) +} + +// LogIDNEQ applies the NEQ predicate on the "log_id" field. +func LogIDNEQ(v uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldNEQ(FieldLogID, v)) +} + +// LogIDIn applies the In predicate on the "log_id" field. +func LogIDIn(vs ...uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldIn(FieldLogID, vs...)) +} + +// LogIDNotIn applies the NotIn predicate on the "log_id" field. +func LogIDNotIn(vs ...uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldNotIn(FieldLogID, vs...)) +} + +// LogIDGT applies the GT predicate on the "log_id" field. +func LogIDGT(v uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldGT(FieldLogID, v)) +} + +// LogIDGTE applies the GTE predicate on the "log_id" field. +func LogIDGTE(v uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldGTE(FieldLogID, v)) +} + +// LogIDLT applies the LT predicate on the "log_id" field. +func LogIDLT(v uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldLT(FieldLogID, v)) +} + +// LogIDLTE applies the LTE predicate on the "log_id" field. +func LogIDLTE(v uuid.UUID) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldLTE(FieldLogID, v)) +} + +// UserIDEQ applies the EQ predicate on the "user_id" field. +func UserIDEQ(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldEQ(FieldUserID, v)) +} + +// UserIDNEQ applies the NEQ predicate on the "user_id" field. +func UserIDNEQ(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldNEQ(FieldUserID, v)) +} + +// UserIDIn applies the In predicate on the "user_id" field. +func UserIDIn(vs ...int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldIn(FieldUserID, vs...)) +} + +// UserIDNotIn applies the NotIn predicate on the "user_id" field. +func UserIDNotIn(vs ...int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldNotIn(FieldUserID, vs...)) +} + +// UserIDGT applies the GT predicate on the "user_id" field. +func UserIDGT(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldGT(FieldUserID, v)) +} + +// UserIDGTE applies the GTE predicate on the "user_id" field. +func UserIDGTE(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldGTE(FieldUserID, v)) +} + +// UserIDLT applies the LT predicate on the "user_id" field. +func UserIDLT(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldLT(FieldUserID, v)) +} + +// UserIDLTE applies the LTE predicate on the "user_id" field. +func UserIDLTE(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldLTE(FieldUserID, v)) +} + +// TypeEQ applies the EQ predicate on the "type" field. +func TypeEQ(v Type) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldEQ(FieldType, v)) +} + +// TypeNEQ applies the NEQ predicate on the "type" field. +func TypeNEQ(v Type) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldNEQ(FieldType, v)) +} + +// TypeIn applies the In predicate on the "type" field. +func TypeIn(vs ...Type) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldIn(FieldType, vs...)) +} + +// TypeNotIn applies the NotIn predicate on the "type" field. +func TypeNotIn(vs ...Type) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldNotIn(FieldType, vs...)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v int64) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.FeedbackChatHistoriesRecapsReactions) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for _, p := range predicates { + p(s1) + } + s.Where(s1.P()) + }) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.FeedbackChatHistoriesRecapsReactions) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(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()) + }) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.FeedbackChatHistoriesRecapsReactions) predicate.FeedbackChatHistoriesRecapsReactions { + return predicate.FeedbackChatHistoriesRecapsReactions(func(s *sql.Selector) { + p(s.Not()) + }) +} diff --git a/ent/feedbackchathistoriesrecapsreactions_create.go b/ent/feedbackchathistoriesrecapsreactions_create.go new file mode 100644 index 0000000..ce29db8 --- /dev/null +++ b/ent/feedbackchathistoriesrecapsreactions_create.go @@ -0,0 +1,352 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/nekomeowww/insights-bot/ent/feedbackchathistoriesrecapsreactions" +) + +// FeedbackChatHistoriesRecapsReactionsCreate is the builder for creating a FeedbackChatHistoriesRecapsReactions entity. +type FeedbackChatHistoriesRecapsReactionsCreate struct { + config + mutation *FeedbackChatHistoriesRecapsReactionsMutation + hooks []Hook +} + +// SetChatID sets the "chat_id" field. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) SetChatID(i int64) *FeedbackChatHistoriesRecapsReactionsCreate { + fchrrc.mutation.SetChatID(i) + return fchrrc +} + +// SetNillableChatID sets the "chat_id" field if the given value is not nil. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) SetNillableChatID(i *int64) *FeedbackChatHistoriesRecapsReactionsCreate { + if i != nil { + fchrrc.SetChatID(*i) + } + return fchrrc +} + +// SetLogID sets the "log_id" field. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) SetLogID(u uuid.UUID) *FeedbackChatHistoriesRecapsReactionsCreate { + fchrrc.mutation.SetLogID(u) + return fchrrc +} + +// SetNillableLogID sets the "log_id" field if the given value is not nil. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) SetNillableLogID(u *uuid.UUID) *FeedbackChatHistoriesRecapsReactionsCreate { + if u != nil { + fchrrc.SetLogID(*u) + } + return fchrrc +} + +// SetUserID sets the "user_id" field. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) SetUserID(i int64) *FeedbackChatHistoriesRecapsReactionsCreate { + fchrrc.mutation.SetUserID(i) + return fchrrc +} + +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) SetNillableUserID(i *int64) *FeedbackChatHistoriesRecapsReactionsCreate { + if i != nil { + fchrrc.SetUserID(*i) + } + return fchrrc +} + +// SetType sets the "type" field. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) SetType(f feedbackchathistoriesrecapsreactions.Type) *FeedbackChatHistoriesRecapsReactionsCreate { + fchrrc.mutation.SetType(f) + return fchrrc +} + +// SetNillableType sets the "type" field if the given value is not nil. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) SetNillableType(f *feedbackchathistoriesrecapsreactions.Type) *FeedbackChatHistoriesRecapsReactionsCreate { + if f != nil { + fchrrc.SetType(*f) + } + return fchrrc +} + +// SetCreatedAt sets the "created_at" field. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) SetCreatedAt(i int64) *FeedbackChatHistoriesRecapsReactionsCreate { + fchrrc.mutation.SetCreatedAt(i) + return fchrrc +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) SetNillableCreatedAt(i *int64) *FeedbackChatHistoriesRecapsReactionsCreate { + if i != nil { + fchrrc.SetCreatedAt(*i) + } + return fchrrc +} + +// SetUpdatedAt sets the "updated_at" field. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) SetUpdatedAt(i int64) *FeedbackChatHistoriesRecapsReactionsCreate { + fchrrc.mutation.SetUpdatedAt(i) + return fchrrc +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) SetNillableUpdatedAt(i *int64) *FeedbackChatHistoriesRecapsReactionsCreate { + if i != nil { + fchrrc.SetUpdatedAt(*i) + } + return fchrrc +} + +// SetID sets the "id" field. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) SetID(u uuid.UUID) *FeedbackChatHistoriesRecapsReactionsCreate { + fchrrc.mutation.SetID(u) + return fchrrc +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) SetNillableID(u *uuid.UUID) *FeedbackChatHistoriesRecapsReactionsCreate { + if u != nil { + fchrrc.SetID(*u) + } + return fchrrc +} + +// Mutation returns the FeedbackChatHistoriesRecapsReactionsMutation object of the builder. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) Mutation() *FeedbackChatHistoriesRecapsReactionsMutation { + return fchrrc.mutation +} + +// Save creates the FeedbackChatHistoriesRecapsReactions in the database. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) Save(ctx context.Context) (*FeedbackChatHistoriesRecapsReactions, error) { + fchrrc.defaults() + return withHooks(ctx, fchrrc.sqlSave, fchrrc.mutation, fchrrc.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) SaveX(ctx context.Context) *FeedbackChatHistoriesRecapsReactions { + v, err := fchrrc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) Exec(ctx context.Context) error { + _, err := fchrrc.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) ExecX(ctx context.Context) { + if err := fchrrc.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) defaults() { + if _, ok := fchrrc.mutation.ChatID(); !ok { + v := feedbackchathistoriesrecapsreactions.DefaultChatID + fchrrc.mutation.SetChatID(v) + } + if _, ok := fchrrc.mutation.LogID(); !ok { + v := feedbackchathistoriesrecapsreactions.DefaultLogID() + fchrrc.mutation.SetLogID(v) + } + if _, ok := fchrrc.mutation.UserID(); !ok { + v := feedbackchathistoriesrecapsreactions.DefaultUserID + fchrrc.mutation.SetUserID(v) + } + if _, ok := fchrrc.mutation.GetType(); !ok { + v := feedbackchathistoriesrecapsreactions.DefaultType + fchrrc.mutation.SetType(v) + } + if _, ok := fchrrc.mutation.CreatedAt(); !ok { + v := feedbackchathistoriesrecapsreactions.DefaultCreatedAt() + fchrrc.mutation.SetCreatedAt(v) + } + if _, ok := fchrrc.mutation.UpdatedAt(); !ok { + v := feedbackchathistoriesrecapsreactions.DefaultUpdatedAt() + fchrrc.mutation.SetUpdatedAt(v) + } + if _, ok := fchrrc.mutation.ID(); !ok { + v := feedbackchathistoriesrecapsreactions.DefaultID() + fchrrc.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) check() error { + if _, ok := fchrrc.mutation.ChatID(); !ok { + return &ValidationError{Name: "chat_id", err: errors.New(`ent: missing required field "FeedbackChatHistoriesRecapsReactions.chat_id"`)} + } + if _, ok := fchrrc.mutation.LogID(); !ok { + return &ValidationError{Name: "log_id", err: errors.New(`ent: missing required field "FeedbackChatHistoriesRecapsReactions.log_id"`)} + } + if _, ok := fchrrc.mutation.UserID(); !ok { + return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "FeedbackChatHistoriesRecapsReactions.user_id"`)} + } + if _, ok := fchrrc.mutation.GetType(); !ok { + return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "FeedbackChatHistoriesRecapsReactions.type"`)} + } + if v, ok := fchrrc.mutation.GetType(); ok { + if err := feedbackchathistoriesrecapsreactions.TypeValidator(v); err != nil { + return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "FeedbackChatHistoriesRecapsReactions.type": %w`, err)} + } + } + if _, ok := fchrrc.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "FeedbackChatHistoriesRecapsReactions.created_at"`)} + } + if _, ok := fchrrc.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "FeedbackChatHistoriesRecapsReactions.updated_at"`)} + } + return nil +} + +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) sqlSave(ctx context.Context) (*FeedbackChatHistoriesRecapsReactions, error) { + if err := fchrrc.check(); err != nil { + return nil, err + } + _node, _spec := fchrrc.createSpec() + if err := sqlgraph.CreateNode(ctx, fchrrc.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + fchrrc.mutation.id = &_node.ID + fchrrc.mutation.done = true + return _node, nil +} + +func (fchrrc *FeedbackChatHistoriesRecapsReactionsCreate) createSpec() (*FeedbackChatHistoriesRecapsReactions, *sqlgraph.CreateSpec) { + var ( + _node = &FeedbackChatHistoriesRecapsReactions{config: fchrrc.config} + _spec = sqlgraph.NewCreateSpec(feedbackchathistoriesrecapsreactions.Table, sqlgraph.NewFieldSpec(feedbackchathistoriesrecapsreactions.FieldID, field.TypeUUID)) + ) + _spec.Schema = fchrrc.schemaConfig.FeedbackChatHistoriesRecapsReactions + if id, ok := fchrrc.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := fchrrc.mutation.ChatID(); ok { + _spec.SetField(feedbackchathistoriesrecapsreactions.FieldChatID, field.TypeInt64, value) + _node.ChatID = value + } + if value, ok := fchrrc.mutation.LogID(); ok { + _spec.SetField(feedbackchathistoriesrecapsreactions.FieldLogID, field.TypeUUID, value) + _node.LogID = value + } + if value, ok := fchrrc.mutation.UserID(); ok { + _spec.SetField(feedbackchathistoriesrecapsreactions.FieldUserID, field.TypeInt64, value) + _node.UserID = value + } + if value, ok := fchrrc.mutation.GetType(); ok { + _spec.SetField(feedbackchathistoriesrecapsreactions.FieldType, field.TypeEnum, value) + _node.Type = value + } + if value, ok := fchrrc.mutation.CreatedAt(); ok { + _spec.SetField(feedbackchathistoriesrecapsreactions.FieldCreatedAt, field.TypeInt64, value) + _node.CreatedAt = value + } + if value, ok := fchrrc.mutation.UpdatedAt(); ok { + _spec.SetField(feedbackchathistoriesrecapsreactions.FieldUpdatedAt, field.TypeInt64, value) + _node.UpdatedAt = value + } + return _node, _spec +} + +// FeedbackChatHistoriesRecapsReactionsCreateBulk is the builder for creating many FeedbackChatHistoriesRecapsReactions entities in bulk. +type FeedbackChatHistoriesRecapsReactionsCreateBulk struct { + config + builders []*FeedbackChatHistoriesRecapsReactionsCreate +} + +// Save creates the FeedbackChatHistoriesRecapsReactions entities in the database. +func (fchrrcb *FeedbackChatHistoriesRecapsReactionsCreateBulk) Save(ctx context.Context) ([]*FeedbackChatHistoriesRecapsReactions, error) { + specs := make([]*sqlgraph.CreateSpec, len(fchrrcb.builders)) + nodes := make([]*FeedbackChatHistoriesRecapsReactions, len(fchrrcb.builders)) + mutators := make([]Mutator, len(fchrrcb.builders)) + for i := range fchrrcb.builders { + func(i int, root context.Context) { + builder := fchrrcb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*FeedbackChatHistoriesRecapsReactionsMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, fchrrcb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, fchrrcb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, fchrrcb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (fchrrcb *FeedbackChatHistoriesRecapsReactionsCreateBulk) SaveX(ctx context.Context) []*FeedbackChatHistoriesRecapsReactions { + v, err := fchrrcb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (fchrrcb *FeedbackChatHistoriesRecapsReactionsCreateBulk) Exec(ctx context.Context) error { + _, err := fchrrcb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (fchrrcb *FeedbackChatHistoriesRecapsReactionsCreateBulk) ExecX(ctx context.Context) { + if err := fchrrcb.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/feedbackchathistoriesrecapsreactions_delete.go b/ent/feedbackchathistoriesrecapsreactions_delete.go new file mode 100644 index 0000000..e6c0251 --- /dev/null +++ b/ent/feedbackchathistoriesrecapsreactions_delete.go @@ -0,0 +1,91 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/nekomeowww/insights-bot/ent/feedbackchathistoriesrecapsreactions" + "github.com/nekomeowww/insights-bot/ent/internal" + "github.com/nekomeowww/insights-bot/ent/predicate" +) + +// FeedbackChatHistoriesRecapsReactionsDelete is the builder for deleting a FeedbackChatHistoriesRecapsReactions entity. +type FeedbackChatHistoriesRecapsReactionsDelete struct { + config + hooks []Hook + mutation *FeedbackChatHistoriesRecapsReactionsMutation +} + +// Where appends a list predicates to the FeedbackChatHistoriesRecapsReactionsDelete builder. +func (fchrrd *FeedbackChatHistoriesRecapsReactionsDelete) Where(ps ...predicate.FeedbackChatHistoriesRecapsReactions) *FeedbackChatHistoriesRecapsReactionsDelete { + fchrrd.mutation.Where(ps...) + return fchrrd +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (fchrrd *FeedbackChatHistoriesRecapsReactionsDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, fchrrd.sqlExec, fchrrd.mutation, fchrrd.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (fchrrd *FeedbackChatHistoriesRecapsReactionsDelete) ExecX(ctx context.Context) int { + n, err := fchrrd.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (fchrrd *FeedbackChatHistoriesRecapsReactionsDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(feedbackchathistoriesrecapsreactions.Table, sqlgraph.NewFieldSpec(feedbackchathistoriesrecapsreactions.FieldID, field.TypeUUID)) + _spec.Node.Schema = fchrrd.schemaConfig.FeedbackChatHistoriesRecapsReactions + ctx = internal.NewSchemaConfigContext(ctx, fchrrd.schemaConfig) + if ps := fchrrd.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, fchrrd.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + fchrrd.mutation.done = true + return affected, err +} + +// FeedbackChatHistoriesRecapsReactionsDeleteOne is the builder for deleting a single FeedbackChatHistoriesRecapsReactions entity. +type FeedbackChatHistoriesRecapsReactionsDeleteOne struct { + fchrrd *FeedbackChatHistoriesRecapsReactionsDelete +} + +// Where appends a list predicates to the FeedbackChatHistoriesRecapsReactionsDelete builder. +func (fchrrdo *FeedbackChatHistoriesRecapsReactionsDeleteOne) Where(ps ...predicate.FeedbackChatHistoriesRecapsReactions) *FeedbackChatHistoriesRecapsReactionsDeleteOne { + fchrrdo.fchrrd.mutation.Where(ps...) + return fchrrdo +} + +// Exec executes the deletion query. +func (fchrrdo *FeedbackChatHistoriesRecapsReactionsDeleteOne) Exec(ctx context.Context) error { + n, err := fchrrdo.fchrrd.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{feedbackchathistoriesrecapsreactions.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (fchrrdo *FeedbackChatHistoriesRecapsReactionsDeleteOne) ExecX(ctx context.Context) { + if err := fchrrdo.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/feedbackchathistoriesrecapsreactions_query.go b/ent/feedbackchathistoriesrecapsreactions_query.go new file mode 100644 index 0000000..c0e8b9b --- /dev/null +++ b/ent/feedbackchathistoriesrecapsreactions_query.go @@ -0,0 +1,535 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "math" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/nekomeowww/insights-bot/ent/feedbackchathistoriesrecapsreactions" + "github.com/nekomeowww/insights-bot/ent/internal" + "github.com/nekomeowww/insights-bot/ent/predicate" +) + +// FeedbackChatHistoriesRecapsReactionsQuery is the builder for querying FeedbackChatHistoriesRecapsReactions entities. +type FeedbackChatHistoriesRecapsReactionsQuery struct { + config + ctx *QueryContext + order []feedbackchathistoriesrecapsreactions.OrderOption + inters []Interceptor + predicates []predicate.FeedbackChatHistoriesRecapsReactions + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the FeedbackChatHistoriesRecapsReactionsQuery builder. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) Where(ps ...predicate.FeedbackChatHistoriesRecapsReactions) *FeedbackChatHistoriesRecapsReactionsQuery { + fchrrq.predicates = append(fchrrq.predicates, ps...) + return fchrrq +} + +// Limit the number of records to be returned by this query. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) Limit(limit int) *FeedbackChatHistoriesRecapsReactionsQuery { + fchrrq.ctx.Limit = &limit + return fchrrq +} + +// Offset to start from. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) Offset(offset int) *FeedbackChatHistoriesRecapsReactionsQuery { + fchrrq.ctx.Offset = &offset + return fchrrq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) Unique(unique bool) *FeedbackChatHistoriesRecapsReactionsQuery { + fchrrq.ctx.Unique = &unique + return fchrrq +} + +// Order specifies how the records should be ordered. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) Order(o ...feedbackchathistoriesrecapsreactions.OrderOption) *FeedbackChatHistoriesRecapsReactionsQuery { + fchrrq.order = append(fchrrq.order, o...) + return fchrrq +} + +// First returns the first FeedbackChatHistoriesRecapsReactions entity from the query. +// Returns a *NotFoundError when no FeedbackChatHistoriesRecapsReactions was found. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) First(ctx context.Context) (*FeedbackChatHistoriesRecapsReactions, error) { + nodes, err := fchrrq.Limit(1).All(setContextOp(ctx, fchrrq.ctx, "First")) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{feedbackchathistoriesrecapsreactions.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) FirstX(ctx context.Context) *FeedbackChatHistoriesRecapsReactions { + node, err := fchrrq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first FeedbackChatHistoriesRecapsReactions ID from the query. +// Returns a *NotFoundError when no FeedbackChatHistoriesRecapsReactions ID was found. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = fchrrq.Limit(1).IDs(setContextOp(ctx, fchrrq.ctx, "FirstID")); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{feedbackchathistoriesrecapsreactions.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := fchrrq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single FeedbackChatHistoriesRecapsReactions entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one FeedbackChatHistoriesRecapsReactions entity is found. +// Returns a *NotFoundError when no FeedbackChatHistoriesRecapsReactions entities are found. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) Only(ctx context.Context) (*FeedbackChatHistoriesRecapsReactions, error) { + nodes, err := fchrrq.Limit(2).All(setContextOp(ctx, fchrrq.ctx, "Only")) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{feedbackchathistoriesrecapsreactions.Label} + default: + return nil, &NotSingularError{feedbackchathistoriesrecapsreactions.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) OnlyX(ctx context.Context) *FeedbackChatHistoriesRecapsReactions { + node, err := fchrrq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only FeedbackChatHistoriesRecapsReactions ID in the query. +// Returns a *NotSingularError when more than one FeedbackChatHistoriesRecapsReactions ID is found. +// Returns a *NotFoundError when no entities are found. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = fchrrq.Limit(2).IDs(setContextOp(ctx, fchrrq.ctx, "OnlyID")); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{feedbackchathistoriesrecapsreactions.Label} + default: + err = &NotSingularError{feedbackchathistoriesrecapsreactions.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := fchrrq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of FeedbackChatHistoriesRecapsReactionsSlice. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) All(ctx context.Context) ([]*FeedbackChatHistoriesRecapsReactions, error) { + ctx = setContextOp(ctx, fchrrq.ctx, "All") + if err := fchrrq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*FeedbackChatHistoriesRecapsReactions, *FeedbackChatHistoriesRecapsReactionsQuery]() + return withInterceptors[[]*FeedbackChatHistoriesRecapsReactions](ctx, fchrrq, qr, fchrrq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) AllX(ctx context.Context) []*FeedbackChatHistoriesRecapsReactions { + nodes, err := fchrrq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of FeedbackChatHistoriesRecapsReactions IDs. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if fchrrq.ctx.Unique == nil && fchrrq.path != nil { + fchrrq.Unique(true) + } + ctx = setContextOp(ctx, fchrrq.ctx, "IDs") + if err = fchrrq.Select(feedbackchathistoriesrecapsreactions.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := fchrrq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, fchrrq.ctx, "Count") + if err := fchrrq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, fchrrq, querierCount[*FeedbackChatHistoriesRecapsReactionsQuery](), fchrrq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) CountX(ctx context.Context) int { + count, err := fchrrq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, fchrrq.ctx, "Exist") + switch _, err := fchrrq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) ExistX(ctx context.Context) bool { + exist, err := fchrrq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the FeedbackChatHistoriesRecapsReactionsQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) Clone() *FeedbackChatHistoriesRecapsReactionsQuery { + if fchrrq == nil { + return nil + } + return &FeedbackChatHistoriesRecapsReactionsQuery{ + config: fchrrq.config, + ctx: fchrrq.ctx.Clone(), + order: append([]feedbackchathistoriesrecapsreactions.OrderOption{}, fchrrq.order...), + inters: append([]Interceptor{}, fchrrq.inters...), + predicates: append([]predicate.FeedbackChatHistoriesRecapsReactions{}, fchrrq.predicates...), + // clone intermediate query. + sql: fchrrq.sql.Clone(), + path: fchrrq.path, + } +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// ChatID int64 `json:"chat_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.FeedbackChatHistoriesRecapsReactions.Query(). +// GroupBy(feedbackchathistoriesrecapsreactions.FieldChatID). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) GroupBy(field string, fields ...string) *FeedbackChatHistoriesRecapsReactionsGroupBy { + fchrrq.ctx.Fields = append([]string{field}, fields...) + grbuild := &FeedbackChatHistoriesRecapsReactionsGroupBy{build: fchrrq} + grbuild.flds = &fchrrq.ctx.Fields + grbuild.label = feedbackchathistoriesrecapsreactions.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// ChatID int64 `json:"chat_id,omitempty"` +// } +// +// client.FeedbackChatHistoriesRecapsReactions.Query(). +// Select(feedbackchathistoriesrecapsreactions.FieldChatID). +// Scan(ctx, &v) +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) Select(fields ...string) *FeedbackChatHistoriesRecapsReactionsSelect { + fchrrq.ctx.Fields = append(fchrrq.ctx.Fields, fields...) + sbuild := &FeedbackChatHistoriesRecapsReactionsSelect{FeedbackChatHistoriesRecapsReactionsQuery: fchrrq} + sbuild.label = feedbackchathistoriesrecapsreactions.Label + sbuild.flds, sbuild.scan = &fchrrq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a FeedbackChatHistoriesRecapsReactionsSelect configured with the given aggregations. +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) Aggregate(fns ...AggregateFunc) *FeedbackChatHistoriesRecapsReactionsSelect { + return fchrrq.Select().Aggregate(fns...) +} + +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) prepareQuery(ctx context.Context) error { + for _, inter := range fchrrq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, fchrrq); err != nil { + return err + } + } + } + for _, f := range fchrrq.ctx.Fields { + if !feedbackchathistoriesrecapsreactions.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if fchrrq.path != nil { + prev, err := fchrrq.path(ctx) + if err != nil { + return err + } + fchrrq.sql = prev + } + return nil +} + +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*FeedbackChatHistoriesRecapsReactions, error) { + var ( + nodes = []*FeedbackChatHistoriesRecapsReactions{} + _spec = fchrrq.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*FeedbackChatHistoriesRecapsReactions).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &FeedbackChatHistoriesRecapsReactions{config: fchrrq.config} + nodes = append(nodes, node) + return node.assignValues(columns, values) + } + _spec.Node.Schema = fchrrq.schemaConfig.FeedbackChatHistoriesRecapsReactions + ctx = internal.NewSchemaConfigContext(ctx, fchrrq.schemaConfig) + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, fchrrq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + return nodes, nil +} + +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) sqlCount(ctx context.Context) (int, error) { + _spec := fchrrq.querySpec() + _spec.Node.Schema = fchrrq.schemaConfig.FeedbackChatHistoriesRecapsReactions + ctx = internal.NewSchemaConfigContext(ctx, fchrrq.schemaConfig) + _spec.Node.Columns = fchrrq.ctx.Fields + if len(fchrrq.ctx.Fields) > 0 { + _spec.Unique = fchrrq.ctx.Unique != nil && *fchrrq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, fchrrq.driver, _spec) +} + +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(feedbackchathistoriesrecapsreactions.Table, feedbackchathistoriesrecapsreactions.Columns, sqlgraph.NewFieldSpec(feedbackchathistoriesrecapsreactions.FieldID, field.TypeUUID)) + _spec.From = fchrrq.sql + if unique := fchrrq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if fchrrq.path != nil { + _spec.Unique = true + } + if fields := fchrrq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, feedbackchathistoriesrecapsreactions.FieldID) + for i := range fields { + if fields[i] != feedbackchathistoriesrecapsreactions.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := fchrrq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := fchrrq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := fchrrq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := fchrrq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (fchrrq *FeedbackChatHistoriesRecapsReactionsQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(fchrrq.driver.Dialect()) + t1 := builder.Table(feedbackchathistoriesrecapsreactions.Table) + columns := fchrrq.ctx.Fields + if len(columns) == 0 { + columns = feedbackchathistoriesrecapsreactions.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if fchrrq.sql != nil { + selector = fchrrq.sql + selector.Select(selector.Columns(columns...)...) + } + if fchrrq.ctx.Unique != nil && *fchrrq.ctx.Unique { + selector.Distinct() + } + t1.Schema(fchrrq.schemaConfig.FeedbackChatHistoriesRecapsReactions) + ctx = internal.NewSchemaConfigContext(ctx, fchrrq.schemaConfig) + selector.WithContext(ctx) + for _, p := range fchrrq.predicates { + p(selector) + } + for _, p := range fchrrq.order { + p(selector) + } + if offset := fchrrq.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := fchrrq.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// FeedbackChatHistoriesRecapsReactionsGroupBy is the group-by builder for FeedbackChatHistoriesRecapsReactions entities. +type FeedbackChatHistoriesRecapsReactionsGroupBy struct { + selector + build *FeedbackChatHistoriesRecapsReactionsQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (fchrrgb *FeedbackChatHistoriesRecapsReactionsGroupBy) Aggregate(fns ...AggregateFunc) *FeedbackChatHistoriesRecapsReactionsGroupBy { + fchrrgb.fns = append(fchrrgb.fns, fns...) + return fchrrgb +} + +// Scan applies the selector query and scans the result into the given value. +func (fchrrgb *FeedbackChatHistoriesRecapsReactionsGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, fchrrgb.build.ctx, "GroupBy") + if err := fchrrgb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*FeedbackChatHistoriesRecapsReactionsQuery, *FeedbackChatHistoriesRecapsReactionsGroupBy](ctx, fchrrgb.build, fchrrgb, fchrrgb.build.inters, v) +} + +func (fchrrgb *FeedbackChatHistoriesRecapsReactionsGroupBy) sqlScan(ctx context.Context, root *FeedbackChatHistoriesRecapsReactionsQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(fchrrgb.fns)) + for _, fn := range fchrrgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*fchrrgb.flds)+len(fchrrgb.fns)) + for _, f := range *fchrrgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*fchrrgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := fchrrgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// FeedbackChatHistoriesRecapsReactionsSelect is the builder for selecting fields of FeedbackChatHistoriesRecapsReactions entities. +type FeedbackChatHistoriesRecapsReactionsSelect struct { + *FeedbackChatHistoriesRecapsReactionsQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (fchrrs *FeedbackChatHistoriesRecapsReactionsSelect) Aggregate(fns ...AggregateFunc) *FeedbackChatHistoriesRecapsReactionsSelect { + fchrrs.fns = append(fchrrs.fns, fns...) + return fchrrs +} + +// Scan applies the selector query and scans the result into the given value. +func (fchrrs *FeedbackChatHistoriesRecapsReactionsSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, fchrrs.ctx, "Select") + if err := fchrrs.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*FeedbackChatHistoriesRecapsReactionsQuery, *FeedbackChatHistoriesRecapsReactionsSelect](ctx, fchrrs.FeedbackChatHistoriesRecapsReactionsQuery, fchrrs, fchrrs.inters, v) +} + +func (fchrrs *FeedbackChatHistoriesRecapsReactionsSelect) sqlScan(ctx context.Context, root *FeedbackChatHistoriesRecapsReactionsQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(fchrrs.fns)) + for _, fn := range fchrrs.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*fchrrs.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := fchrrs.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/ent/feedbackchathistoriesrecapsreactions_update.go b/ent/feedbackchathistoriesrecapsreactions_update.go new file mode 100644 index 0000000..421cd87 --- /dev/null +++ b/ent/feedbackchathistoriesrecapsreactions_update.go @@ -0,0 +1,456 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/nekomeowww/insights-bot/ent/feedbackchathistoriesrecapsreactions" + "github.com/nekomeowww/insights-bot/ent/internal" + "github.com/nekomeowww/insights-bot/ent/predicate" +) + +// FeedbackChatHistoriesRecapsReactionsUpdate is the builder for updating FeedbackChatHistoriesRecapsReactions entities. +type FeedbackChatHistoriesRecapsReactionsUpdate struct { + config + hooks []Hook + mutation *FeedbackChatHistoriesRecapsReactionsMutation +} + +// Where appends a list predicates to the FeedbackChatHistoriesRecapsReactionsUpdate builder. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) Where(ps ...predicate.FeedbackChatHistoriesRecapsReactions) *FeedbackChatHistoriesRecapsReactionsUpdate { + fchrru.mutation.Where(ps...) + return fchrru +} + +// SetChatID sets the "chat_id" field. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) SetChatID(i int64) *FeedbackChatHistoriesRecapsReactionsUpdate { + fchrru.mutation.ResetChatID() + fchrru.mutation.SetChatID(i) + return fchrru +} + +// SetNillableChatID sets the "chat_id" field if the given value is not nil. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) SetNillableChatID(i *int64) *FeedbackChatHistoriesRecapsReactionsUpdate { + if i != nil { + fchrru.SetChatID(*i) + } + return fchrru +} + +// AddChatID adds i to the "chat_id" field. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) AddChatID(i int64) *FeedbackChatHistoriesRecapsReactionsUpdate { + fchrru.mutation.AddChatID(i) + return fchrru +} + +// SetUserID sets the "user_id" field. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) SetUserID(i int64) *FeedbackChatHistoriesRecapsReactionsUpdate { + fchrru.mutation.ResetUserID() + fchrru.mutation.SetUserID(i) + return fchrru +} + +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) SetNillableUserID(i *int64) *FeedbackChatHistoriesRecapsReactionsUpdate { + if i != nil { + fchrru.SetUserID(*i) + } + return fchrru +} + +// AddUserID adds i to the "user_id" field. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) AddUserID(i int64) *FeedbackChatHistoriesRecapsReactionsUpdate { + fchrru.mutation.AddUserID(i) + return fchrru +} + +// SetType sets the "type" field. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) SetType(f feedbackchathistoriesrecapsreactions.Type) *FeedbackChatHistoriesRecapsReactionsUpdate { + fchrru.mutation.SetType(f) + return fchrru +} + +// SetNillableType sets the "type" field if the given value is not nil. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) SetNillableType(f *feedbackchathistoriesrecapsreactions.Type) *FeedbackChatHistoriesRecapsReactionsUpdate { + if f != nil { + fchrru.SetType(*f) + } + return fchrru +} + +// SetCreatedAt sets the "created_at" field. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) SetCreatedAt(i int64) *FeedbackChatHistoriesRecapsReactionsUpdate { + fchrru.mutation.ResetCreatedAt() + fchrru.mutation.SetCreatedAt(i) + return fchrru +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) SetNillableCreatedAt(i *int64) *FeedbackChatHistoriesRecapsReactionsUpdate { + if i != nil { + fchrru.SetCreatedAt(*i) + } + return fchrru +} + +// AddCreatedAt adds i to the "created_at" field. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) AddCreatedAt(i int64) *FeedbackChatHistoriesRecapsReactionsUpdate { + fchrru.mutation.AddCreatedAt(i) + return fchrru +} + +// SetUpdatedAt sets the "updated_at" field. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) SetUpdatedAt(i int64) *FeedbackChatHistoriesRecapsReactionsUpdate { + fchrru.mutation.ResetUpdatedAt() + fchrru.mutation.SetUpdatedAt(i) + return fchrru +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) SetNillableUpdatedAt(i *int64) *FeedbackChatHistoriesRecapsReactionsUpdate { + if i != nil { + fchrru.SetUpdatedAt(*i) + } + return fchrru +} + +// AddUpdatedAt adds i to the "updated_at" field. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) AddUpdatedAt(i int64) *FeedbackChatHistoriesRecapsReactionsUpdate { + fchrru.mutation.AddUpdatedAt(i) + return fchrru +} + +// Mutation returns the FeedbackChatHistoriesRecapsReactionsMutation object of the builder. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) Mutation() *FeedbackChatHistoriesRecapsReactionsMutation { + return fchrru.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) Save(ctx context.Context) (int, error) { + return withHooks(ctx, fchrru.sqlSave, fchrru.mutation, fchrru.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) SaveX(ctx context.Context) int { + affected, err := fchrru.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) Exec(ctx context.Context) error { + _, err := fchrru.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) ExecX(ctx context.Context) { + if err := fchrru.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) check() error { + if v, ok := fchrru.mutation.GetType(); ok { + if err := feedbackchathistoriesrecapsreactions.TypeValidator(v); err != nil { + return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "FeedbackChatHistoriesRecapsReactions.type": %w`, err)} + } + } + return nil +} + +func (fchrru *FeedbackChatHistoriesRecapsReactionsUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := fchrru.check(); err != nil { + return n, err + } + _spec := sqlgraph.NewUpdateSpec(feedbackchathistoriesrecapsreactions.Table, feedbackchathistoriesrecapsreactions.Columns, sqlgraph.NewFieldSpec(feedbackchathistoriesrecapsreactions.FieldID, field.TypeUUID)) + if ps := fchrru.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := fchrru.mutation.ChatID(); ok { + _spec.SetField(feedbackchathistoriesrecapsreactions.FieldChatID, field.TypeInt64, value) + } + if value, ok := fchrru.mutation.AddedChatID(); ok { + _spec.AddField(feedbackchathistoriesrecapsreactions.FieldChatID, field.TypeInt64, value) + } + if value, ok := fchrru.mutation.UserID(); ok { + _spec.SetField(feedbackchathistoriesrecapsreactions.FieldUserID, field.TypeInt64, value) + } + if value, ok := fchrru.mutation.AddedUserID(); ok { + _spec.AddField(feedbackchathistoriesrecapsreactions.FieldUserID, field.TypeInt64, value) + } + if value, ok := fchrru.mutation.GetType(); ok { + _spec.SetField(feedbackchathistoriesrecapsreactions.FieldType, field.TypeEnum, value) + } + if value, ok := fchrru.mutation.CreatedAt(); ok { + _spec.SetField(feedbackchathistoriesrecapsreactions.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := fchrru.mutation.AddedCreatedAt(); ok { + _spec.AddField(feedbackchathistoriesrecapsreactions.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := fchrru.mutation.UpdatedAt(); ok { + _spec.SetField(feedbackchathistoriesrecapsreactions.FieldUpdatedAt, field.TypeInt64, value) + } + if value, ok := fchrru.mutation.AddedUpdatedAt(); ok { + _spec.AddField(feedbackchathistoriesrecapsreactions.FieldUpdatedAt, field.TypeInt64, value) + } + _spec.Node.Schema = fchrru.schemaConfig.FeedbackChatHistoriesRecapsReactions + ctx = internal.NewSchemaConfigContext(ctx, fchrru.schemaConfig) + if n, err = sqlgraph.UpdateNodes(ctx, fchrru.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{feedbackchathistoriesrecapsreactions.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + fchrru.mutation.done = true + return n, nil +} + +// FeedbackChatHistoriesRecapsReactionsUpdateOne is the builder for updating a single FeedbackChatHistoriesRecapsReactions entity. +type FeedbackChatHistoriesRecapsReactionsUpdateOne struct { + config + fields []string + hooks []Hook + mutation *FeedbackChatHistoriesRecapsReactionsMutation +} + +// SetChatID sets the "chat_id" field. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) SetChatID(i int64) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + fchrruo.mutation.ResetChatID() + fchrruo.mutation.SetChatID(i) + return fchrruo +} + +// SetNillableChatID sets the "chat_id" field if the given value is not nil. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) SetNillableChatID(i *int64) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + if i != nil { + fchrruo.SetChatID(*i) + } + return fchrruo +} + +// AddChatID adds i to the "chat_id" field. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) AddChatID(i int64) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + fchrruo.mutation.AddChatID(i) + return fchrruo +} + +// SetUserID sets the "user_id" field. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) SetUserID(i int64) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + fchrruo.mutation.ResetUserID() + fchrruo.mutation.SetUserID(i) + return fchrruo +} + +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) SetNillableUserID(i *int64) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + if i != nil { + fchrruo.SetUserID(*i) + } + return fchrruo +} + +// AddUserID adds i to the "user_id" field. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) AddUserID(i int64) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + fchrruo.mutation.AddUserID(i) + return fchrruo +} + +// SetType sets the "type" field. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) SetType(f feedbackchathistoriesrecapsreactions.Type) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + fchrruo.mutation.SetType(f) + return fchrruo +} + +// SetNillableType sets the "type" field if the given value is not nil. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) SetNillableType(f *feedbackchathistoriesrecapsreactions.Type) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + if f != nil { + fchrruo.SetType(*f) + } + return fchrruo +} + +// SetCreatedAt sets the "created_at" field. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) SetCreatedAt(i int64) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + fchrruo.mutation.ResetCreatedAt() + fchrruo.mutation.SetCreatedAt(i) + return fchrruo +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) SetNillableCreatedAt(i *int64) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + if i != nil { + fchrruo.SetCreatedAt(*i) + } + return fchrruo +} + +// AddCreatedAt adds i to the "created_at" field. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) AddCreatedAt(i int64) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + fchrruo.mutation.AddCreatedAt(i) + return fchrruo +} + +// SetUpdatedAt sets the "updated_at" field. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) SetUpdatedAt(i int64) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + fchrruo.mutation.ResetUpdatedAt() + fchrruo.mutation.SetUpdatedAt(i) + return fchrruo +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) SetNillableUpdatedAt(i *int64) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + if i != nil { + fchrruo.SetUpdatedAt(*i) + } + return fchrruo +} + +// AddUpdatedAt adds i to the "updated_at" field. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) AddUpdatedAt(i int64) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + fchrruo.mutation.AddUpdatedAt(i) + return fchrruo +} + +// Mutation returns the FeedbackChatHistoriesRecapsReactionsMutation object of the builder. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) Mutation() *FeedbackChatHistoriesRecapsReactionsMutation { + return fchrruo.mutation +} + +// Where appends a list predicates to the FeedbackChatHistoriesRecapsReactionsUpdate builder. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) Where(ps ...predicate.FeedbackChatHistoriesRecapsReactions) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + fchrruo.mutation.Where(ps...) + return fchrruo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) Select(field string, fields ...string) *FeedbackChatHistoriesRecapsReactionsUpdateOne { + fchrruo.fields = append([]string{field}, fields...) + return fchrruo +} + +// Save executes the query and returns the updated FeedbackChatHistoriesRecapsReactions entity. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) Save(ctx context.Context) (*FeedbackChatHistoriesRecapsReactions, error) { + return withHooks(ctx, fchrruo.sqlSave, fchrruo.mutation, fchrruo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) SaveX(ctx context.Context) *FeedbackChatHistoriesRecapsReactions { + node, err := fchrruo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) Exec(ctx context.Context) error { + _, err := fchrruo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) ExecX(ctx context.Context) { + if err := fchrruo.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) check() error { + if v, ok := fchrruo.mutation.GetType(); ok { + if err := feedbackchathistoriesrecapsreactions.TypeValidator(v); err != nil { + return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "FeedbackChatHistoriesRecapsReactions.type": %w`, err)} + } + } + return nil +} + +func (fchrruo *FeedbackChatHistoriesRecapsReactionsUpdateOne) sqlSave(ctx context.Context) (_node *FeedbackChatHistoriesRecapsReactions, err error) { + if err := fchrruo.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(feedbackchathistoriesrecapsreactions.Table, feedbackchathistoriesrecapsreactions.Columns, sqlgraph.NewFieldSpec(feedbackchathistoriesrecapsreactions.FieldID, field.TypeUUID)) + id, ok := fchrruo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "FeedbackChatHistoriesRecapsReactions.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := fchrruo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, feedbackchathistoriesrecapsreactions.FieldID) + for _, f := range fields { + if !feedbackchathistoriesrecapsreactions.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != feedbackchathistoriesrecapsreactions.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := fchrruo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := fchrruo.mutation.ChatID(); ok { + _spec.SetField(feedbackchathistoriesrecapsreactions.FieldChatID, field.TypeInt64, value) + } + if value, ok := fchrruo.mutation.AddedChatID(); ok { + _spec.AddField(feedbackchathistoriesrecapsreactions.FieldChatID, field.TypeInt64, value) + } + if value, ok := fchrruo.mutation.UserID(); ok { + _spec.SetField(feedbackchathistoriesrecapsreactions.FieldUserID, field.TypeInt64, value) + } + if value, ok := fchrruo.mutation.AddedUserID(); ok { + _spec.AddField(feedbackchathistoriesrecapsreactions.FieldUserID, field.TypeInt64, value) + } + if value, ok := fchrruo.mutation.GetType(); ok { + _spec.SetField(feedbackchathistoriesrecapsreactions.FieldType, field.TypeEnum, value) + } + if value, ok := fchrruo.mutation.CreatedAt(); ok { + _spec.SetField(feedbackchathistoriesrecapsreactions.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := fchrruo.mutation.AddedCreatedAt(); ok { + _spec.AddField(feedbackchathistoriesrecapsreactions.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := fchrruo.mutation.UpdatedAt(); ok { + _spec.SetField(feedbackchathistoriesrecapsreactions.FieldUpdatedAt, field.TypeInt64, value) + } + if value, ok := fchrruo.mutation.AddedUpdatedAt(); ok { + _spec.AddField(feedbackchathistoriesrecapsreactions.FieldUpdatedAt, field.TypeInt64, value) + } + _spec.Node.Schema = fchrruo.schemaConfig.FeedbackChatHistoriesRecapsReactions + ctx = internal.NewSchemaConfigContext(ctx, fchrruo.schemaConfig) + _node = &FeedbackChatHistoriesRecapsReactions{config: fchrruo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, fchrruo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{feedbackchathistoriesrecapsreactions.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + fchrruo.mutation.done = true + return _node, nil +} diff --git a/ent/feedbacksummarizationsreactions.go b/ent/feedbacksummarizationsreactions.go new file mode 100644 index 0000000..5b7d652 --- /dev/null +++ b/ent/feedbacksummarizationsreactions.go @@ -0,0 +1,161 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" + "github.com/nekomeowww/insights-bot/ent/feedbacksummarizationsreactions" +) + +// FeedbackSummarizationsReactions is the model entity for the FeedbackSummarizationsReactions schema. +type FeedbackSummarizationsReactions struct { + config `json:"-"` + // ID of the ent. + ID uuid.UUID `json:"id,omitempty"` + // ChatID holds the value of the "chat_id" field. + ChatID int64 `json:"chat_id,omitempty"` + // LogID holds the value of the "log_id" field. + LogID uuid.UUID `json:"log_id,omitempty"` + // UserID holds the value of the "user_id" field. + UserID int64 `json:"user_id,omitempty"` + // Type holds the value of the "type" field. + Type feedbacksummarizationsreactions.Type `json:"type,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt int64 `json:"created_at,omitempty"` + // UpdatedAt holds the value of the "updated_at" field. + UpdatedAt int64 `json:"updated_at,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*FeedbackSummarizationsReactions) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case feedbacksummarizationsreactions.FieldChatID, feedbacksummarizationsreactions.FieldUserID, feedbacksummarizationsreactions.FieldCreatedAt, feedbacksummarizationsreactions.FieldUpdatedAt: + values[i] = new(sql.NullInt64) + case feedbacksummarizationsreactions.FieldType: + values[i] = new(sql.NullString) + case feedbacksummarizationsreactions.FieldID, feedbacksummarizationsreactions.FieldLogID: + values[i] = new(uuid.UUID) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the FeedbackSummarizationsReactions fields. +func (fsr *FeedbackSummarizationsReactions) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case feedbacksummarizationsreactions.FieldID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field id", values[i]) + } else if value != nil { + fsr.ID = *value + } + case feedbacksummarizationsreactions.FieldChatID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field chat_id", values[i]) + } else if value.Valid { + fsr.ChatID = value.Int64 + } + case feedbacksummarizationsreactions.FieldLogID: + if value, ok := values[i].(*uuid.UUID); !ok { + return fmt.Errorf("unexpected type %T for field log_id", values[i]) + } else if value != nil { + fsr.LogID = *value + } + case feedbacksummarizationsreactions.FieldUserID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field user_id", values[i]) + } else if value.Valid { + fsr.UserID = value.Int64 + } + case feedbacksummarizationsreactions.FieldType: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field type", values[i]) + } else if value.Valid { + fsr.Type = feedbacksummarizationsreactions.Type(value.String) + } + case feedbacksummarizationsreactions.FieldCreatedAt: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + fsr.CreatedAt = value.Int64 + } + case feedbacksummarizationsreactions.FieldUpdatedAt: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field updated_at", values[i]) + } else if value.Valid { + fsr.UpdatedAt = value.Int64 + } + default: + fsr.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the FeedbackSummarizationsReactions. +// This includes values selected through modifiers, order, etc. +func (fsr *FeedbackSummarizationsReactions) Value(name string) (ent.Value, error) { + return fsr.selectValues.Get(name) +} + +// Update returns a builder for updating this FeedbackSummarizationsReactions. +// Note that you need to call FeedbackSummarizationsReactions.Unwrap() before calling this method if this FeedbackSummarizationsReactions +// was returned from a transaction, and the transaction was committed or rolled back. +func (fsr *FeedbackSummarizationsReactions) Update() *FeedbackSummarizationsReactionsUpdateOne { + return NewFeedbackSummarizationsReactionsClient(fsr.config).UpdateOne(fsr) +} + +// Unwrap unwraps the FeedbackSummarizationsReactions entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (fsr *FeedbackSummarizationsReactions) Unwrap() *FeedbackSummarizationsReactions { + _tx, ok := fsr.config.driver.(*txDriver) + if !ok { + panic("ent: FeedbackSummarizationsReactions is not a transactional entity") + } + fsr.config.driver = _tx.drv + return fsr +} + +// String implements the fmt.Stringer. +func (fsr *FeedbackSummarizationsReactions) String() string { + var builder strings.Builder + builder.WriteString("FeedbackSummarizationsReactions(") + builder.WriteString(fmt.Sprintf("id=%v, ", fsr.ID)) + builder.WriteString("chat_id=") + builder.WriteString(fmt.Sprintf("%v", fsr.ChatID)) + builder.WriteString(", ") + builder.WriteString("log_id=") + builder.WriteString(fmt.Sprintf("%v", fsr.LogID)) + builder.WriteString(", ") + builder.WriteString("user_id=") + builder.WriteString(fmt.Sprintf("%v", fsr.UserID)) + builder.WriteString(", ") + builder.WriteString("type=") + builder.WriteString(fmt.Sprintf("%v", fsr.Type)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(fmt.Sprintf("%v", fsr.CreatedAt)) + builder.WriteString(", ") + builder.WriteString("updated_at=") + builder.WriteString(fmt.Sprintf("%v", fsr.UpdatedAt)) + builder.WriteByte(')') + return builder.String() +} + +// FeedbackSummarizationsReactionsSlice is a parsable slice of FeedbackSummarizationsReactions. +type FeedbackSummarizationsReactionsSlice []*FeedbackSummarizationsReactions diff --git a/ent/feedbacksummarizationsreactions/feedbacksummarizationsreactions.go b/ent/feedbacksummarizationsreactions/feedbacksummarizationsreactions.go new file mode 100644 index 0000000..96d8008 --- /dev/null +++ b/ent/feedbacksummarizationsreactions/feedbacksummarizationsreactions.go @@ -0,0 +1,133 @@ +// Code generated by ent, DO NOT EDIT. + +package feedbacksummarizationsreactions + +import ( + "fmt" + + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" +) + +const ( + // Label holds the string label denoting the feedbacksummarizationsreactions type in the database. + Label = "feedback_summarizations_reactions" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldChatID holds the string denoting the chat_id field in the database. + FieldChatID = "chat_id" + // FieldLogID holds the string denoting the log_id field in the database. + FieldLogID = "log_id" + // FieldUserID holds the string denoting the user_id field in the database. + FieldUserID = "user_id" + // FieldType holds the string denoting the type field in the database. + FieldType = "type" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // FieldUpdatedAt holds the string denoting the updated_at field in the database. + FieldUpdatedAt = "updated_at" + // Table holds the table name of the feedbacksummarizationsreactions in the database. + Table = "feedback_summarizations_reactions" +) + +// Columns holds all SQL columns for feedbacksummarizationsreactions fields. +var Columns = []string{ + FieldID, + FieldChatID, + FieldLogID, + FieldUserID, + FieldType, + FieldCreatedAt, + FieldUpdatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultChatID holds the default value on creation for the "chat_id" field. + DefaultChatID int64 + // DefaultLogID holds the default value on creation for the "log_id" field. + DefaultLogID func() uuid.UUID + // DefaultUserID holds the default value on creation for the "user_id" field. + DefaultUserID int64 + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() int64 + // DefaultUpdatedAt holds the default value on creation for the "updated_at" field. + DefaultUpdatedAt func() int64 + // DefaultID holds the default value on creation for the "id" field. + DefaultID func() uuid.UUID +) + +// Type defines the type for the "type" enum field. +type Type string + +// TypeNone is the default value of the Type enum. +const DefaultType = TypeNone + +// Type values. +const ( + TypeNone Type = "none" + TypeUpVote Type = "up_vote" + TypeDownVote Type = "down_vote" + TypeLmao Type = "lmao" +) + +func (_type Type) String() string { + return string(_type) +} + +// TypeValidator is a validator for the "type" field enum values. It is called by the builders before save. +func TypeValidator(_type Type) error { + switch _type { + case TypeNone, TypeUpVote, TypeDownVote, TypeLmao: + return nil + default: + return fmt.Errorf("feedbacksummarizationsreactions: invalid enum value for type field: %q", _type) + } +} + +// OrderOption defines the ordering options for the FeedbackSummarizationsReactions 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() +} + +// ByChatID orders the results by the chat_id field. +func ByChatID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldChatID, opts...).ToFunc() +} + +// ByLogID orders the results by the log_id field. +func ByLogID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldLogID, opts...).ToFunc() +} + +// ByUserID orders the results by the user_id field. +func ByUserID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUserID, opts...).ToFunc() +} + +// ByType orders the results by the type field. +func ByType(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldType, 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() +} diff --git a/ent/feedbacksummarizationsreactions/where.go b/ent/feedbacksummarizationsreactions/where.go new file mode 100644 index 0000000..20d0aa2 --- /dev/null +++ b/ent/feedbacksummarizationsreactions/where.go @@ -0,0 +1,331 @@ +// Code generated by ent, DO NOT EDIT. + +package feedbacksummarizationsreactions + +import ( + "entgo.io/ent/dialect/sql" + "github.com/google/uuid" + "github.com/nekomeowww/insights-bot/ent/predicate" +) + +// ID filters vertices based on their ID field. +func ID(id uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldLTE(FieldID, id)) +} + +// ChatID applies equality check predicate on the "chat_id" field. It's identical to ChatIDEQ. +func ChatID(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldEQ(FieldChatID, v)) +} + +// LogID applies equality check predicate on the "log_id" field. It's identical to LogIDEQ. +func LogID(v uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldEQ(FieldLogID, v)) +} + +// UserID applies equality check predicate on the "user_id" field. It's identical to UserIDEQ. +func UserID(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldEQ(FieldUserID, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldEQ(FieldCreatedAt, v)) +} + +// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ. +func UpdatedAt(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// ChatIDEQ applies the EQ predicate on the "chat_id" field. +func ChatIDEQ(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldEQ(FieldChatID, v)) +} + +// ChatIDNEQ applies the NEQ predicate on the "chat_id" field. +func ChatIDNEQ(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldNEQ(FieldChatID, v)) +} + +// ChatIDIn applies the In predicate on the "chat_id" field. +func ChatIDIn(vs ...int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldIn(FieldChatID, vs...)) +} + +// ChatIDNotIn applies the NotIn predicate on the "chat_id" field. +func ChatIDNotIn(vs ...int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldNotIn(FieldChatID, vs...)) +} + +// ChatIDGT applies the GT predicate on the "chat_id" field. +func ChatIDGT(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldGT(FieldChatID, v)) +} + +// ChatIDGTE applies the GTE predicate on the "chat_id" field. +func ChatIDGTE(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldGTE(FieldChatID, v)) +} + +// ChatIDLT applies the LT predicate on the "chat_id" field. +func ChatIDLT(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldLT(FieldChatID, v)) +} + +// ChatIDLTE applies the LTE predicate on the "chat_id" field. +func ChatIDLTE(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldLTE(FieldChatID, v)) +} + +// LogIDEQ applies the EQ predicate on the "log_id" field. +func LogIDEQ(v uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldEQ(FieldLogID, v)) +} + +// LogIDNEQ applies the NEQ predicate on the "log_id" field. +func LogIDNEQ(v uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldNEQ(FieldLogID, v)) +} + +// LogIDIn applies the In predicate on the "log_id" field. +func LogIDIn(vs ...uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldIn(FieldLogID, vs...)) +} + +// LogIDNotIn applies the NotIn predicate on the "log_id" field. +func LogIDNotIn(vs ...uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldNotIn(FieldLogID, vs...)) +} + +// LogIDGT applies the GT predicate on the "log_id" field. +func LogIDGT(v uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldGT(FieldLogID, v)) +} + +// LogIDGTE applies the GTE predicate on the "log_id" field. +func LogIDGTE(v uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldGTE(FieldLogID, v)) +} + +// LogIDLT applies the LT predicate on the "log_id" field. +func LogIDLT(v uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldLT(FieldLogID, v)) +} + +// LogIDLTE applies the LTE predicate on the "log_id" field. +func LogIDLTE(v uuid.UUID) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldLTE(FieldLogID, v)) +} + +// UserIDEQ applies the EQ predicate on the "user_id" field. +func UserIDEQ(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldEQ(FieldUserID, v)) +} + +// UserIDNEQ applies the NEQ predicate on the "user_id" field. +func UserIDNEQ(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldNEQ(FieldUserID, v)) +} + +// UserIDIn applies the In predicate on the "user_id" field. +func UserIDIn(vs ...int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldIn(FieldUserID, vs...)) +} + +// UserIDNotIn applies the NotIn predicate on the "user_id" field. +func UserIDNotIn(vs ...int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldNotIn(FieldUserID, vs...)) +} + +// UserIDGT applies the GT predicate on the "user_id" field. +func UserIDGT(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldGT(FieldUserID, v)) +} + +// UserIDGTE applies the GTE predicate on the "user_id" field. +func UserIDGTE(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldGTE(FieldUserID, v)) +} + +// UserIDLT applies the LT predicate on the "user_id" field. +func UserIDLT(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldLT(FieldUserID, v)) +} + +// UserIDLTE applies the LTE predicate on the "user_id" field. +func UserIDLTE(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldLTE(FieldUserID, v)) +} + +// TypeEQ applies the EQ predicate on the "type" field. +func TypeEQ(v Type) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldEQ(FieldType, v)) +} + +// TypeNEQ applies the NEQ predicate on the "type" field. +func TypeNEQ(v Type) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldNEQ(FieldType, v)) +} + +// TypeIn applies the In predicate on the "type" field. +func TypeIn(vs ...Type) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldIn(FieldType, vs...)) +} + +// TypeNotIn applies the NotIn predicate on the "type" field. +func TypeNotIn(vs ...Type) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldNotIn(FieldType, vs...)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldLTE(FieldCreatedAt, v)) +} + +// UpdatedAtEQ applies the EQ predicate on the "updated_at" field. +func UpdatedAtEQ(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field. +func UpdatedAtNEQ(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldNEQ(FieldUpdatedAt, v)) +} + +// UpdatedAtIn applies the In predicate on the "updated_at" field. +func UpdatedAtIn(vs ...int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field. +func UpdatedAtNotIn(vs ...int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldNotIn(FieldUpdatedAt, vs...)) +} + +// UpdatedAtGT applies the GT predicate on the "updated_at" field. +func UpdatedAtGT(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldGT(FieldUpdatedAt, v)) +} + +// UpdatedAtGTE applies the GTE predicate on the "updated_at" field. +func UpdatedAtGTE(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldGTE(FieldUpdatedAt, v)) +} + +// UpdatedAtLT applies the LT predicate on the "updated_at" field. +func UpdatedAtLT(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldLT(FieldUpdatedAt, v)) +} + +// UpdatedAtLTE applies the LTE predicate on the "updated_at" field. +func UpdatedAtLTE(v int64) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(sql.FieldLTE(FieldUpdatedAt, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.FeedbackSummarizationsReactions) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for _, p := range predicates { + p(s1) + } + s.Where(s1.P()) + }) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.FeedbackSummarizationsReactions) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(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()) + }) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.FeedbackSummarizationsReactions) predicate.FeedbackSummarizationsReactions { + return predicate.FeedbackSummarizationsReactions(func(s *sql.Selector) { + p(s.Not()) + }) +} diff --git a/ent/feedbacksummarizationsreactions_create.go b/ent/feedbacksummarizationsreactions_create.go new file mode 100644 index 0000000..018fab1 --- /dev/null +++ b/ent/feedbacksummarizationsreactions_create.go @@ -0,0 +1,352 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/nekomeowww/insights-bot/ent/feedbacksummarizationsreactions" +) + +// FeedbackSummarizationsReactionsCreate is the builder for creating a FeedbackSummarizationsReactions entity. +type FeedbackSummarizationsReactionsCreate struct { + config + mutation *FeedbackSummarizationsReactionsMutation + hooks []Hook +} + +// SetChatID sets the "chat_id" field. +func (fsrc *FeedbackSummarizationsReactionsCreate) SetChatID(i int64) *FeedbackSummarizationsReactionsCreate { + fsrc.mutation.SetChatID(i) + return fsrc +} + +// SetNillableChatID sets the "chat_id" field if the given value is not nil. +func (fsrc *FeedbackSummarizationsReactionsCreate) SetNillableChatID(i *int64) *FeedbackSummarizationsReactionsCreate { + if i != nil { + fsrc.SetChatID(*i) + } + return fsrc +} + +// SetLogID sets the "log_id" field. +func (fsrc *FeedbackSummarizationsReactionsCreate) SetLogID(u uuid.UUID) *FeedbackSummarizationsReactionsCreate { + fsrc.mutation.SetLogID(u) + return fsrc +} + +// SetNillableLogID sets the "log_id" field if the given value is not nil. +func (fsrc *FeedbackSummarizationsReactionsCreate) SetNillableLogID(u *uuid.UUID) *FeedbackSummarizationsReactionsCreate { + if u != nil { + fsrc.SetLogID(*u) + } + return fsrc +} + +// SetUserID sets the "user_id" field. +func (fsrc *FeedbackSummarizationsReactionsCreate) SetUserID(i int64) *FeedbackSummarizationsReactionsCreate { + fsrc.mutation.SetUserID(i) + return fsrc +} + +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (fsrc *FeedbackSummarizationsReactionsCreate) SetNillableUserID(i *int64) *FeedbackSummarizationsReactionsCreate { + if i != nil { + fsrc.SetUserID(*i) + } + return fsrc +} + +// SetType sets the "type" field. +func (fsrc *FeedbackSummarizationsReactionsCreate) SetType(f feedbacksummarizationsreactions.Type) *FeedbackSummarizationsReactionsCreate { + fsrc.mutation.SetType(f) + return fsrc +} + +// SetNillableType sets the "type" field if the given value is not nil. +func (fsrc *FeedbackSummarizationsReactionsCreate) SetNillableType(f *feedbacksummarizationsreactions.Type) *FeedbackSummarizationsReactionsCreate { + if f != nil { + fsrc.SetType(*f) + } + return fsrc +} + +// SetCreatedAt sets the "created_at" field. +func (fsrc *FeedbackSummarizationsReactionsCreate) SetCreatedAt(i int64) *FeedbackSummarizationsReactionsCreate { + fsrc.mutation.SetCreatedAt(i) + return fsrc +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (fsrc *FeedbackSummarizationsReactionsCreate) SetNillableCreatedAt(i *int64) *FeedbackSummarizationsReactionsCreate { + if i != nil { + fsrc.SetCreatedAt(*i) + } + return fsrc +} + +// SetUpdatedAt sets the "updated_at" field. +func (fsrc *FeedbackSummarizationsReactionsCreate) SetUpdatedAt(i int64) *FeedbackSummarizationsReactionsCreate { + fsrc.mutation.SetUpdatedAt(i) + return fsrc +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (fsrc *FeedbackSummarizationsReactionsCreate) SetNillableUpdatedAt(i *int64) *FeedbackSummarizationsReactionsCreate { + if i != nil { + fsrc.SetUpdatedAt(*i) + } + return fsrc +} + +// SetID sets the "id" field. +func (fsrc *FeedbackSummarizationsReactionsCreate) SetID(u uuid.UUID) *FeedbackSummarizationsReactionsCreate { + fsrc.mutation.SetID(u) + return fsrc +} + +// SetNillableID sets the "id" field if the given value is not nil. +func (fsrc *FeedbackSummarizationsReactionsCreate) SetNillableID(u *uuid.UUID) *FeedbackSummarizationsReactionsCreate { + if u != nil { + fsrc.SetID(*u) + } + return fsrc +} + +// Mutation returns the FeedbackSummarizationsReactionsMutation object of the builder. +func (fsrc *FeedbackSummarizationsReactionsCreate) Mutation() *FeedbackSummarizationsReactionsMutation { + return fsrc.mutation +} + +// Save creates the FeedbackSummarizationsReactions in the database. +func (fsrc *FeedbackSummarizationsReactionsCreate) Save(ctx context.Context) (*FeedbackSummarizationsReactions, error) { + fsrc.defaults() + return withHooks(ctx, fsrc.sqlSave, fsrc.mutation, fsrc.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (fsrc *FeedbackSummarizationsReactionsCreate) SaveX(ctx context.Context) *FeedbackSummarizationsReactions { + v, err := fsrc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (fsrc *FeedbackSummarizationsReactionsCreate) Exec(ctx context.Context) error { + _, err := fsrc.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (fsrc *FeedbackSummarizationsReactionsCreate) ExecX(ctx context.Context) { + if err := fsrc.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (fsrc *FeedbackSummarizationsReactionsCreate) defaults() { + if _, ok := fsrc.mutation.ChatID(); !ok { + v := feedbacksummarizationsreactions.DefaultChatID + fsrc.mutation.SetChatID(v) + } + if _, ok := fsrc.mutation.LogID(); !ok { + v := feedbacksummarizationsreactions.DefaultLogID() + fsrc.mutation.SetLogID(v) + } + if _, ok := fsrc.mutation.UserID(); !ok { + v := feedbacksummarizationsreactions.DefaultUserID + fsrc.mutation.SetUserID(v) + } + if _, ok := fsrc.mutation.GetType(); !ok { + v := feedbacksummarizationsreactions.DefaultType + fsrc.mutation.SetType(v) + } + if _, ok := fsrc.mutation.CreatedAt(); !ok { + v := feedbacksummarizationsreactions.DefaultCreatedAt() + fsrc.mutation.SetCreatedAt(v) + } + if _, ok := fsrc.mutation.UpdatedAt(); !ok { + v := feedbacksummarizationsreactions.DefaultUpdatedAt() + fsrc.mutation.SetUpdatedAt(v) + } + if _, ok := fsrc.mutation.ID(); !ok { + v := feedbacksummarizationsreactions.DefaultID() + fsrc.mutation.SetID(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (fsrc *FeedbackSummarizationsReactionsCreate) check() error { + if _, ok := fsrc.mutation.ChatID(); !ok { + return &ValidationError{Name: "chat_id", err: errors.New(`ent: missing required field "FeedbackSummarizationsReactions.chat_id"`)} + } + if _, ok := fsrc.mutation.LogID(); !ok { + return &ValidationError{Name: "log_id", err: errors.New(`ent: missing required field "FeedbackSummarizationsReactions.log_id"`)} + } + if _, ok := fsrc.mutation.UserID(); !ok { + return &ValidationError{Name: "user_id", err: errors.New(`ent: missing required field "FeedbackSummarizationsReactions.user_id"`)} + } + if _, ok := fsrc.mutation.GetType(); !ok { + return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "FeedbackSummarizationsReactions.type"`)} + } + if v, ok := fsrc.mutation.GetType(); ok { + if err := feedbacksummarizationsreactions.TypeValidator(v); err != nil { + return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "FeedbackSummarizationsReactions.type": %w`, err)} + } + } + if _, ok := fsrc.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "FeedbackSummarizationsReactions.created_at"`)} + } + if _, ok := fsrc.mutation.UpdatedAt(); !ok { + return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "FeedbackSummarizationsReactions.updated_at"`)} + } + return nil +} + +func (fsrc *FeedbackSummarizationsReactionsCreate) sqlSave(ctx context.Context) (*FeedbackSummarizationsReactions, error) { + if err := fsrc.check(); err != nil { + return nil, err + } + _node, _spec := fsrc.createSpec() + if err := sqlgraph.CreateNode(ctx, fsrc.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + if _spec.ID.Value != nil { + if id, ok := _spec.ID.Value.(*uuid.UUID); ok { + _node.ID = *id + } else if err := _node.ID.Scan(_spec.ID.Value); err != nil { + return nil, err + } + } + fsrc.mutation.id = &_node.ID + fsrc.mutation.done = true + return _node, nil +} + +func (fsrc *FeedbackSummarizationsReactionsCreate) createSpec() (*FeedbackSummarizationsReactions, *sqlgraph.CreateSpec) { + var ( + _node = &FeedbackSummarizationsReactions{config: fsrc.config} + _spec = sqlgraph.NewCreateSpec(feedbacksummarizationsreactions.Table, sqlgraph.NewFieldSpec(feedbacksummarizationsreactions.FieldID, field.TypeUUID)) + ) + _spec.Schema = fsrc.schemaConfig.FeedbackSummarizationsReactions + if id, ok := fsrc.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = &id + } + if value, ok := fsrc.mutation.ChatID(); ok { + _spec.SetField(feedbacksummarizationsreactions.FieldChatID, field.TypeInt64, value) + _node.ChatID = value + } + if value, ok := fsrc.mutation.LogID(); ok { + _spec.SetField(feedbacksummarizationsreactions.FieldLogID, field.TypeUUID, value) + _node.LogID = value + } + if value, ok := fsrc.mutation.UserID(); ok { + _spec.SetField(feedbacksummarizationsreactions.FieldUserID, field.TypeInt64, value) + _node.UserID = value + } + if value, ok := fsrc.mutation.GetType(); ok { + _spec.SetField(feedbacksummarizationsreactions.FieldType, field.TypeEnum, value) + _node.Type = value + } + if value, ok := fsrc.mutation.CreatedAt(); ok { + _spec.SetField(feedbacksummarizationsreactions.FieldCreatedAt, field.TypeInt64, value) + _node.CreatedAt = value + } + if value, ok := fsrc.mutation.UpdatedAt(); ok { + _spec.SetField(feedbacksummarizationsreactions.FieldUpdatedAt, field.TypeInt64, value) + _node.UpdatedAt = value + } + return _node, _spec +} + +// FeedbackSummarizationsReactionsCreateBulk is the builder for creating many FeedbackSummarizationsReactions entities in bulk. +type FeedbackSummarizationsReactionsCreateBulk struct { + config + builders []*FeedbackSummarizationsReactionsCreate +} + +// Save creates the FeedbackSummarizationsReactions entities in the database. +func (fsrcb *FeedbackSummarizationsReactionsCreateBulk) Save(ctx context.Context) ([]*FeedbackSummarizationsReactions, error) { + specs := make([]*sqlgraph.CreateSpec, len(fsrcb.builders)) + nodes := make([]*FeedbackSummarizationsReactions, len(fsrcb.builders)) + mutators := make([]Mutator, len(fsrcb.builders)) + for i := range fsrcb.builders { + func(i int, root context.Context) { + builder := fsrcb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*FeedbackSummarizationsReactionsMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, fsrcb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, fsrcb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, fsrcb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (fsrcb *FeedbackSummarizationsReactionsCreateBulk) SaveX(ctx context.Context) []*FeedbackSummarizationsReactions { + v, err := fsrcb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (fsrcb *FeedbackSummarizationsReactionsCreateBulk) Exec(ctx context.Context) error { + _, err := fsrcb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (fsrcb *FeedbackSummarizationsReactionsCreateBulk) ExecX(ctx context.Context) { + if err := fsrcb.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/feedbacksummarizationsreactions_delete.go b/ent/feedbacksummarizationsreactions_delete.go new file mode 100644 index 0000000..729e1f0 --- /dev/null +++ b/ent/feedbacksummarizationsreactions_delete.go @@ -0,0 +1,91 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/nekomeowww/insights-bot/ent/feedbacksummarizationsreactions" + "github.com/nekomeowww/insights-bot/ent/internal" + "github.com/nekomeowww/insights-bot/ent/predicate" +) + +// FeedbackSummarizationsReactionsDelete is the builder for deleting a FeedbackSummarizationsReactions entity. +type FeedbackSummarizationsReactionsDelete struct { + config + hooks []Hook + mutation *FeedbackSummarizationsReactionsMutation +} + +// Where appends a list predicates to the FeedbackSummarizationsReactionsDelete builder. +func (fsrd *FeedbackSummarizationsReactionsDelete) Where(ps ...predicate.FeedbackSummarizationsReactions) *FeedbackSummarizationsReactionsDelete { + fsrd.mutation.Where(ps...) + return fsrd +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (fsrd *FeedbackSummarizationsReactionsDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, fsrd.sqlExec, fsrd.mutation, fsrd.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (fsrd *FeedbackSummarizationsReactionsDelete) ExecX(ctx context.Context) int { + n, err := fsrd.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (fsrd *FeedbackSummarizationsReactionsDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(feedbacksummarizationsreactions.Table, sqlgraph.NewFieldSpec(feedbacksummarizationsreactions.FieldID, field.TypeUUID)) + _spec.Node.Schema = fsrd.schemaConfig.FeedbackSummarizationsReactions + ctx = internal.NewSchemaConfigContext(ctx, fsrd.schemaConfig) + if ps := fsrd.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, fsrd.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + fsrd.mutation.done = true + return affected, err +} + +// FeedbackSummarizationsReactionsDeleteOne is the builder for deleting a single FeedbackSummarizationsReactions entity. +type FeedbackSummarizationsReactionsDeleteOne struct { + fsrd *FeedbackSummarizationsReactionsDelete +} + +// Where appends a list predicates to the FeedbackSummarizationsReactionsDelete builder. +func (fsrdo *FeedbackSummarizationsReactionsDeleteOne) Where(ps ...predicate.FeedbackSummarizationsReactions) *FeedbackSummarizationsReactionsDeleteOne { + fsrdo.fsrd.mutation.Where(ps...) + return fsrdo +} + +// Exec executes the deletion query. +func (fsrdo *FeedbackSummarizationsReactionsDeleteOne) Exec(ctx context.Context) error { + n, err := fsrdo.fsrd.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{feedbacksummarizationsreactions.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (fsrdo *FeedbackSummarizationsReactionsDeleteOne) ExecX(ctx context.Context) { + if err := fsrdo.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/feedbacksummarizationsreactions_query.go b/ent/feedbacksummarizationsreactions_query.go new file mode 100644 index 0000000..8cbd084 --- /dev/null +++ b/ent/feedbacksummarizationsreactions_query.go @@ -0,0 +1,535 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "math" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/google/uuid" + "github.com/nekomeowww/insights-bot/ent/feedbacksummarizationsreactions" + "github.com/nekomeowww/insights-bot/ent/internal" + "github.com/nekomeowww/insights-bot/ent/predicate" +) + +// FeedbackSummarizationsReactionsQuery is the builder for querying FeedbackSummarizationsReactions entities. +type FeedbackSummarizationsReactionsQuery struct { + config + ctx *QueryContext + order []feedbacksummarizationsreactions.OrderOption + inters []Interceptor + predicates []predicate.FeedbackSummarizationsReactions + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the FeedbackSummarizationsReactionsQuery builder. +func (fsrq *FeedbackSummarizationsReactionsQuery) Where(ps ...predicate.FeedbackSummarizationsReactions) *FeedbackSummarizationsReactionsQuery { + fsrq.predicates = append(fsrq.predicates, ps...) + return fsrq +} + +// Limit the number of records to be returned by this query. +func (fsrq *FeedbackSummarizationsReactionsQuery) Limit(limit int) *FeedbackSummarizationsReactionsQuery { + fsrq.ctx.Limit = &limit + return fsrq +} + +// Offset to start from. +func (fsrq *FeedbackSummarizationsReactionsQuery) Offset(offset int) *FeedbackSummarizationsReactionsQuery { + fsrq.ctx.Offset = &offset + return fsrq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (fsrq *FeedbackSummarizationsReactionsQuery) Unique(unique bool) *FeedbackSummarizationsReactionsQuery { + fsrq.ctx.Unique = &unique + return fsrq +} + +// Order specifies how the records should be ordered. +func (fsrq *FeedbackSummarizationsReactionsQuery) Order(o ...feedbacksummarizationsreactions.OrderOption) *FeedbackSummarizationsReactionsQuery { + fsrq.order = append(fsrq.order, o...) + return fsrq +} + +// First returns the first FeedbackSummarizationsReactions entity from the query. +// Returns a *NotFoundError when no FeedbackSummarizationsReactions was found. +func (fsrq *FeedbackSummarizationsReactionsQuery) First(ctx context.Context) (*FeedbackSummarizationsReactions, error) { + nodes, err := fsrq.Limit(1).All(setContextOp(ctx, fsrq.ctx, "First")) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{feedbacksummarizationsreactions.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (fsrq *FeedbackSummarizationsReactionsQuery) FirstX(ctx context.Context) *FeedbackSummarizationsReactions { + node, err := fsrq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first FeedbackSummarizationsReactions ID from the query. +// Returns a *NotFoundError when no FeedbackSummarizationsReactions ID was found. +func (fsrq *FeedbackSummarizationsReactionsQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = fsrq.Limit(1).IDs(setContextOp(ctx, fsrq.ctx, "FirstID")); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{feedbacksummarizationsreactions.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (fsrq *FeedbackSummarizationsReactionsQuery) FirstIDX(ctx context.Context) uuid.UUID { + id, err := fsrq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single FeedbackSummarizationsReactions entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one FeedbackSummarizationsReactions entity is found. +// Returns a *NotFoundError when no FeedbackSummarizationsReactions entities are found. +func (fsrq *FeedbackSummarizationsReactionsQuery) Only(ctx context.Context) (*FeedbackSummarizationsReactions, error) { + nodes, err := fsrq.Limit(2).All(setContextOp(ctx, fsrq.ctx, "Only")) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{feedbacksummarizationsreactions.Label} + default: + return nil, &NotSingularError{feedbacksummarizationsreactions.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (fsrq *FeedbackSummarizationsReactionsQuery) OnlyX(ctx context.Context) *FeedbackSummarizationsReactions { + node, err := fsrq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only FeedbackSummarizationsReactions ID in the query. +// Returns a *NotSingularError when more than one FeedbackSummarizationsReactions ID is found. +// Returns a *NotFoundError when no entities are found. +func (fsrq *FeedbackSummarizationsReactionsQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { + var ids []uuid.UUID + if ids, err = fsrq.Limit(2).IDs(setContextOp(ctx, fsrq.ctx, "OnlyID")); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{feedbacksummarizationsreactions.Label} + default: + err = &NotSingularError{feedbacksummarizationsreactions.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (fsrq *FeedbackSummarizationsReactionsQuery) OnlyIDX(ctx context.Context) uuid.UUID { + id, err := fsrq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of FeedbackSummarizationsReactionsSlice. +func (fsrq *FeedbackSummarizationsReactionsQuery) All(ctx context.Context) ([]*FeedbackSummarizationsReactions, error) { + ctx = setContextOp(ctx, fsrq.ctx, "All") + if err := fsrq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*FeedbackSummarizationsReactions, *FeedbackSummarizationsReactionsQuery]() + return withInterceptors[[]*FeedbackSummarizationsReactions](ctx, fsrq, qr, fsrq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (fsrq *FeedbackSummarizationsReactionsQuery) AllX(ctx context.Context) []*FeedbackSummarizationsReactions { + nodes, err := fsrq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of FeedbackSummarizationsReactions IDs. +func (fsrq *FeedbackSummarizationsReactionsQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { + if fsrq.ctx.Unique == nil && fsrq.path != nil { + fsrq.Unique(true) + } + ctx = setContextOp(ctx, fsrq.ctx, "IDs") + if err = fsrq.Select(feedbacksummarizationsreactions.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (fsrq *FeedbackSummarizationsReactionsQuery) IDsX(ctx context.Context) []uuid.UUID { + ids, err := fsrq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (fsrq *FeedbackSummarizationsReactionsQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, fsrq.ctx, "Count") + if err := fsrq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, fsrq, querierCount[*FeedbackSummarizationsReactionsQuery](), fsrq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (fsrq *FeedbackSummarizationsReactionsQuery) CountX(ctx context.Context) int { + count, err := fsrq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (fsrq *FeedbackSummarizationsReactionsQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, fsrq.ctx, "Exist") + switch _, err := fsrq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (fsrq *FeedbackSummarizationsReactionsQuery) ExistX(ctx context.Context) bool { + exist, err := fsrq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the FeedbackSummarizationsReactionsQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (fsrq *FeedbackSummarizationsReactionsQuery) Clone() *FeedbackSummarizationsReactionsQuery { + if fsrq == nil { + return nil + } + return &FeedbackSummarizationsReactionsQuery{ + config: fsrq.config, + ctx: fsrq.ctx.Clone(), + order: append([]feedbacksummarizationsreactions.OrderOption{}, fsrq.order...), + inters: append([]Interceptor{}, fsrq.inters...), + predicates: append([]predicate.FeedbackSummarizationsReactions{}, fsrq.predicates...), + // clone intermediate query. + sql: fsrq.sql.Clone(), + path: fsrq.path, + } +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// ChatID int64 `json:"chat_id,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.FeedbackSummarizationsReactions.Query(). +// GroupBy(feedbacksummarizationsreactions.FieldChatID). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (fsrq *FeedbackSummarizationsReactionsQuery) GroupBy(field string, fields ...string) *FeedbackSummarizationsReactionsGroupBy { + fsrq.ctx.Fields = append([]string{field}, fields...) + grbuild := &FeedbackSummarizationsReactionsGroupBy{build: fsrq} + grbuild.flds = &fsrq.ctx.Fields + grbuild.label = feedbacksummarizationsreactions.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// ChatID int64 `json:"chat_id,omitempty"` +// } +// +// client.FeedbackSummarizationsReactions.Query(). +// Select(feedbacksummarizationsreactions.FieldChatID). +// Scan(ctx, &v) +func (fsrq *FeedbackSummarizationsReactionsQuery) Select(fields ...string) *FeedbackSummarizationsReactionsSelect { + fsrq.ctx.Fields = append(fsrq.ctx.Fields, fields...) + sbuild := &FeedbackSummarizationsReactionsSelect{FeedbackSummarizationsReactionsQuery: fsrq} + sbuild.label = feedbacksummarizationsreactions.Label + sbuild.flds, sbuild.scan = &fsrq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a FeedbackSummarizationsReactionsSelect configured with the given aggregations. +func (fsrq *FeedbackSummarizationsReactionsQuery) Aggregate(fns ...AggregateFunc) *FeedbackSummarizationsReactionsSelect { + return fsrq.Select().Aggregate(fns...) +} + +func (fsrq *FeedbackSummarizationsReactionsQuery) prepareQuery(ctx context.Context) error { + for _, inter := range fsrq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, fsrq); err != nil { + return err + } + } + } + for _, f := range fsrq.ctx.Fields { + if !feedbacksummarizationsreactions.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if fsrq.path != nil { + prev, err := fsrq.path(ctx) + if err != nil { + return err + } + fsrq.sql = prev + } + return nil +} + +func (fsrq *FeedbackSummarizationsReactionsQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*FeedbackSummarizationsReactions, error) { + var ( + nodes = []*FeedbackSummarizationsReactions{} + _spec = fsrq.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*FeedbackSummarizationsReactions).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &FeedbackSummarizationsReactions{config: fsrq.config} + nodes = append(nodes, node) + return node.assignValues(columns, values) + } + _spec.Node.Schema = fsrq.schemaConfig.FeedbackSummarizationsReactions + ctx = internal.NewSchemaConfigContext(ctx, fsrq.schemaConfig) + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, fsrq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + return nodes, nil +} + +func (fsrq *FeedbackSummarizationsReactionsQuery) sqlCount(ctx context.Context) (int, error) { + _spec := fsrq.querySpec() + _spec.Node.Schema = fsrq.schemaConfig.FeedbackSummarizationsReactions + ctx = internal.NewSchemaConfigContext(ctx, fsrq.schemaConfig) + _spec.Node.Columns = fsrq.ctx.Fields + if len(fsrq.ctx.Fields) > 0 { + _spec.Unique = fsrq.ctx.Unique != nil && *fsrq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, fsrq.driver, _spec) +} + +func (fsrq *FeedbackSummarizationsReactionsQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(feedbacksummarizationsreactions.Table, feedbacksummarizationsreactions.Columns, sqlgraph.NewFieldSpec(feedbacksummarizationsreactions.FieldID, field.TypeUUID)) + _spec.From = fsrq.sql + if unique := fsrq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if fsrq.path != nil { + _spec.Unique = true + } + if fields := fsrq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, feedbacksummarizationsreactions.FieldID) + for i := range fields { + if fields[i] != feedbacksummarizationsreactions.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := fsrq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := fsrq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := fsrq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := fsrq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (fsrq *FeedbackSummarizationsReactionsQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(fsrq.driver.Dialect()) + t1 := builder.Table(feedbacksummarizationsreactions.Table) + columns := fsrq.ctx.Fields + if len(columns) == 0 { + columns = feedbacksummarizationsreactions.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if fsrq.sql != nil { + selector = fsrq.sql + selector.Select(selector.Columns(columns...)...) + } + if fsrq.ctx.Unique != nil && *fsrq.ctx.Unique { + selector.Distinct() + } + t1.Schema(fsrq.schemaConfig.FeedbackSummarizationsReactions) + ctx = internal.NewSchemaConfigContext(ctx, fsrq.schemaConfig) + selector.WithContext(ctx) + for _, p := range fsrq.predicates { + p(selector) + } + for _, p := range fsrq.order { + p(selector) + } + if offset := fsrq.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := fsrq.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// FeedbackSummarizationsReactionsGroupBy is the group-by builder for FeedbackSummarizationsReactions entities. +type FeedbackSummarizationsReactionsGroupBy struct { + selector + build *FeedbackSummarizationsReactionsQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (fsrgb *FeedbackSummarizationsReactionsGroupBy) Aggregate(fns ...AggregateFunc) *FeedbackSummarizationsReactionsGroupBy { + fsrgb.fns = append(fsrgb.fns, fns...) + return fsrgb +} + +// Scan applies the selector query and scans the result into the given value. +func (fsrgb *FeedbackSummarizationsReactionsGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, fsrgb.build.ctx, "GroupBy") + if err := fsrgb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*FeedbackSummarizationsReactionsQuery, *FeedbackSummarizationsReactionsGroupBy](ctx, fsrgb.build, fsrgb, fsrgb.build.inters, v) +} + +func (fsrgb *FeedbackSummarizationsReactionsGroupBy) sqlScan(ctx context.Context, root *FeedbackSummarizationsReactionsQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(fsrgb.fns)) + for _, fn := range fsrgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*fsrgb.flds)+len(fsrgb.fns)) + for _, f := range *fsrgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*fsrgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := fsrgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// FeedbackSummarizationsReactionsSelect is the builder for selecting fields of FeedbackSummarizationsReactions entities. +type FeedbackSummarizationsReactionsSelect struct { + *FeedbackSummarizationsReactionsQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (fsrs *FeedbackSummarizationsReactionsSelect) Aggregate(fns ...AggregateFunc) *FeedbackSummarizationsReactionsSelect { + fsrs.fns = append(fsrs.fns, fns...) + return fsrs +} + +// Scan applies the selector query and scans the result into the given value. +func (fsrs *FeedbackSummarizationsReactionsSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, fsrs.ctx, "Select") + if err := fsrs.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*FeedbackSummarizationsReactionsQuery, *FeedbackSummarizationsReactionsSelect](ctx, fsrs.FeedbackSummarizationsReactionsQuery, fsrs, fsrs.inters, v) +} + +func (fsrs *FeedbackSummarizationsReactionsSelect) sqlScan(ctx context.Context, root *FeedbackSummarizationsReactionsQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(fsrs.fns)) + for _, fn := range fsrs.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*fsrs.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := fsrs.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/ent/feedbacksummarizationsreactions_update.go b/ent/feedbacksummarizationsreactions_update.go new file mode 100644 index 0000000..77ffc6c --- /dev/null +++ b/ent/feedbacksummarizationsreactions_update.go @@ -0,0 +1,456 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" + "github.com/nekomeowww/insights-bot/ent/feedbacksummarizationsreactions" + "github.com/nekomeowww/insights-bot/ent/internal" + "github.com/nekomeowww/insights-bot/ent/predicate" +) + +// FeedbackSummarizationsReactionsUpdate is the builder for updating FeedbackSummarizationsReactions entities. +type FeedbackSummarizationsReactionsUpdate struct { + config + hooks []Hook + mutation *FeedbackSummarizationsReactionsMutation +} + +// Where appends a list predicates to the FeedbackSummarizationsReactionsUpdate builder. +func (fsru *FeedbackSummarizationsReactionsUpdate) Where(ps ...predicate.FeedbackSummarizationsReactions) *FeedbackSummarizationsReactionsUpdate { + fsru.mutation.Where(ps...) + return fsru +} + +// SetChatID sets the "chat_id" field. +func (fsru *FeedbackSummarizationsReactionsUpdate) SetChatID(i int64) *FeedbackSummarizationsReactionsUpdate { + fsru.mutation.ResetChatID() + fsru.mutation.SetChatID(i) + return fsru +} + +// SetNillableChatID sets the "chat_id" field if the given value is not nil. +func (fsru *FeedbackSummarizationsReactionsUpdate) SetNillableChatID(i *int64) *FeedbackSummarizationsReactionsUpdate { + if i != nil { + fsru.SetChatID(*i) + } + return fsru +} + +// AddChatID adds i to the "chat_id" field. +func (fsru *FeedbackSummarizationsReactionsUpdate) AddChatID(i int64) *FeedbackSummarizationsReactionsUpdate { + fsru.mutation.AddChatID(i) + return fsru +} + +// SetUserID sets the "user_id" field. +func (fsru *FeedbackSummarizationsReactionsUpdate) SetUserID(i int64) *FeedbackSummarizationsReactionsUpdate { + fsru.mutation.ResetUserID() + fsru.mutation.SetUserID(i) + return fsru +} + +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (fsru *FeedbackSummarizationsReactionsUpdate) SetNillableUserID(i *int64) *FeedbackSummarizationsReactionsUpdate { + if i != nil { + fsru.SetUserID(*i) + } + return fsru +} + +// AddUserID adds i to the "user_id" field. +func (fsru *FeedbackSummarizationsReactionsUpdate) AddUserID(i int64) *FeedbackSummarizationsReactionsUpdate { + fsru.mutation.AddUserID(i) + return fsru +} + +// SetType sets the "type" field. +func (fsru *FeedbackSummarizationsReactionsUpdate) SetType(f feedbacksummarizationsreactions.Type) *FeedbackSummarizationsReactionsUpdate { + fsru.mutation.SetType(f) + return fsru +} + +// SetNillableType sets the "type" field if the given value is not nil. +func (fsru *FeedbackSummarizationsReactionsUpdate) SetNillableType(f *feedbacksummarizationsreactions.Type) *FeedbackSummarizationsReactionsUpdate { + if f != nil { + fsru.SetType(*f) + } + return fsru +} + +// SetCreatedAt sets the "created_at" field. +func (fsru *FeedbackSummarizationsReactionsUpdate) SetCreatedAt(i int64) *FeedbackSummarizationsReactionsUpdate { + fsru.mutation.ResetCreatedAt() + fsru.mutation.SetCreatedAt(i) + return fsru +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (fsru *FeedbackSummarizationsReactionsUpdate) SetNillableCreatedAt(i *int64) *FeedbackSummarizationsReactionsUpdate { + if i != nil { + fsru.SetCreatedAt(*i) + } + return fsru +} + +// AddCreatedAt adds i to the "created_at" field. +func (fsru *FeedbackSummarizationsReactionsUpdate) AddCreatedAt(i int64) *FeedbackSummarizationsReactionsUpdate { + fsru.mutation.AddCreatedAt(i) + return fsru +} + +// SetUpdatedAt sets the "updated_at" field. +func (fsru *FeedbackSummarizationsReactionsUpdate) SetUpdatedAt(i int64) *FeedbackSummarizationsReactionsUpdate { + fsru.mutation.ResetUpdatedAt() + fsru.mutation.SetUpdatedAt(i) + return fsru +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (fsru *FeedbackSummarizationsReactionsUpdate) SetNillableUpdatedAt(i *int64) *FeedbackSummarizationsReactionsUpdate { + if i != nil { + fsru.SetUpdatedAt(*i) + } + return fsru +} + +// AddUpdatedAt adds i to the "updated_at" field. +func (fsru *FeedbackSummarizationsReactionsUpdate) AddUpdatedAt(i int64) *FeedbackSummarizationsReactionsUpdate { + fsru.mutation.AddUpdatedAt(i) + return fsru +} + +// Mutation returns the FeedbackSummarizationsReactionsMutation object of the builder. +func (fsru *FeedbackSummarizationsReactionsUpdate) Mutation() *FeedbackSummarizationsReactionsMutation { + return fsru.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (fsru *FeedbackSummarizationsReactionsUpdate) Save(ctx context.Context) (int, error) { + return withHooks(ctx, fsru.sqlSave, fsru.mutation, fsru.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (fsru *FeedbackSummarizationsReactionsUpdate) SaveX(ctx context.Context) int { + affected, err := fsru.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (fsru *FeedbackSummarizationsReactionsUpdate) Exec(ctx context.Context) error { + _, err := fsru.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (fsru *FeedbackSummarizationsReactionsUpdate) ExecX(ctx context.Context) { + if err := fsru.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (fsru *FeedbackSummarizationsReactionsUpdate) check() error { + if v, ok := fsru.mutation.GetType(); ok { + if err := feedbacksummarizationsreactions.TypeValidator(v); err != nil { + return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "FeedbackSummarizationsReactions.type": %w`, err)} + } + } + return nil +} + +func (fsru *FeedbackSummarizationsReactionsUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := fsru.check(); err != nil { + return n, err + } + _spec := sqlgraph.NewUpdateSpec(feedbacksummarizationsreactions.Table, feedbacksummarizationsreactions.Columns, sqlgraph.NewFieldSpec(feedbacksummarizationsreactions.FieldID, field.TypeUUID)) + if ps := fsru.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := fsru.mutation.ChatID(); ok { + _spec.SetField(feedbacksummarizationsreactions.FieldChatID, field.TypeInt64, value) + } + if value, ok := fsru.mutation.AddedChatID(); ok { + _spec.AddField(feedbacksummarizationsreactions.FieldChatID, field.TypeInt64, value) + } + if value, ok := fsru.mutation.UserID(); ok { + _spec.SetField(feedbacksummarizationsreactions.FieldUserID, field.TypeInt64, value) + } + if value, ok := fsru.mutation.AddedUserID(); ok { + _spec.AddField(feedbacksummarizationsreactions.FieldUserID, field.TypeInt64, value) + } + if value, ok := fsru.mutation.GetType(); ok { + _spec.SetField(feedbacksummarizationsreactions.FieldType, field.TypeEnum, value) + } + if value, ok := fsru.mutation.CreatedAt(); ok { + _spec.SetField(feedbacksummarizationsreactions.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := fsru.mutation.AddedCreatedAt(); ok { + _spec.AddField(feedbacksummarizationsreactions.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := fsru.mutation.UpdatedAt(); ok { + _spec.SetField(feedbacksummarizationsreactions.FieldUpdatedAt, field.TypeInt64, value) + } + if value, ok := fsru.mutation.AddedUpdatedAt(); ok { + _spec.AddField(feedbacksummarizationsreactions.FieldUpdatedAt, field.TypeInt64, value) + } + _spec.Node.Schema = fsru.schemaConfig.FeedbackSummarizationsReactions + ctx = internal.NewSchemaConfigContext(ctx, fsru.schemaConfig) + if n, err = sqlgraph.UpdateNodes(ctx, fsru.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{feedbacksummarizationsreactions.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + fsru.mutation.done = true + return n, nil +} + +// FeedbackSummarizationsReactionsUpdateOne is the builder for updating a single FeedbackSummarizationsReactions entity. +type FeedbackSummarizationsReactionsUpdateOne struct { + config + fields []string + hooks []Hook + mutation *FeedbackSummarizationsReactionsMutation +} + +// SetChatID sets the "chat_id" field. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) SetChatID(i int64) *FeedbackSummarizationsReactionsUpdateOne { + fsruo.mutation.ResetChatID() + fsruo.mutation.SetChatID(i) + return fsruo +} + +// SetNillableChatID sets the "chat_id" field if the given value is not nil. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) SetNillableChatID(i *int64) *FeedbackSummarizationsReactionsUpdateOne { + if i != nil { + fsruo.SetChatID(*i) + } + return fsruo +} + +// AddChatID adds i to the "chat_id" field. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) AddChatID(i int64) *FeedbackSummarizationsReactionsUpdateOne { + fsruo.mutation.AddChatID(i) + return fsruo +} + +// SetUserID sets the "user_id" field. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) SetUserID(i int64) *FeedbackSummarizationsReactionsUpdateOne { + fsruo.mutation.ResetUserID() + fsruo.mutation.SetUserID(i) + return fsruo +} + +// SetNillableUserID sets the "user_id" field if the given value is not nil. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) SetNillableUserID(i *int64) *FeedbackSummarizationsReactionsUpdateOne { + if i != nil { + fsruo.SetUserID(*i) + } + return fsruo +} + +// AddUserID adds i to the "user_id" field. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) AddUserID(i int64) *FeedbackSummarizationsReactionsUpdateOne { + fsruo.mutation.AddUserID(i) + return fsruo +} + +// SetType sets the "type" field. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) SetType(f feedbacksummarizationsreactions.Type) *FeedbackSummarizationsReactionsUpdateOne { + fsruo.mutation.SetType(f) + return fsruo +} + +// SetNillableType sets the "type" field if the given value is not nil. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) SetNillableType(f *feedbacksummarizationsreactions.Type) *FeedbackSummarizationsReactionsUpdateOne { + if f != nil { + fsruo.SetType(*f) + } + return fsruo +} + +// SetCreatedAt sets the "created_at" field. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) SetCreatedAt(i int64) *FeedbackSummarizationsReactionsUpdateOne { + fsruo.mutation.ResetCreatedAt() + fsruo.mutation.SetCreatedAt(i) + return fsruo +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) SetNillableCreatedAt(i *int64) *FeedbackSummarizationsReactionsUpdateOne { + if i != nil { + fsruo.SetCreatedAt(*i) + } + return fsruo +} + +// AddCreatedAt adds i to the "created_at" field. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) AddCreatedAt(i int64) *FeedbackSummarizationsReactionsUpdateOne { + fsruo.mutation.AddCreatedAt(i) + return fsruo +} + +// SetUpdatedAt sets the "updated_at" field. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) SetUpdatedAt(i int64) *FeedbackSummarizationsReactionsUpdateOne { + fsruo.mutation.ResetUpdatedAt() + fsruo.mutation.SetUpdatedAt(i) + return fsruo +} + +// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) SetNillableUpdatedAt(i *int64) *FeedbackSummarizationsReactionsUpdateOne { + if i != nil { + fsruo.SetUpdatedAt(*i) + } + return fsruo +} + +// AddUpdatedAt adds i to the "updated_at" field. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) AddUpdatedAt(i int64) *FeedbackSummarizationsReactionsUpdateOne { + fsruo.mutation.AddUpdatedAt(i) + return fsruo +} + +// Mutation returns the FeedbackSummarizationsReactionsMutation object of the builder. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) Mutation() *FeedbackSummarizationsReactionsMutation { + return fsruo.mutation +} + +// Where appends a list predicates to the FeedbackSummarizationsReactionsUpdate builder. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) Where(ps ...predicate.FeedbackSummarizationsReactions) *FeedbackSummarizationsReactionsUpdateOne { + fsruo.mutation.Where(ps...) + return fsruo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) Select(field string, fields ...string) *FeedbackSummarizationsReactionsUpdateOne { + fsruo.fields = append([]string{field}, fields...) + return fsruo +} + +// Save executes the query and returns the updated FeedbackSummarizationsReactions entity. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) Save(ctx context.Context) (*FeedbackSummarizationsReactions, error) { + return withHooks(ctx, fsruo.sqlSave, fsruo.mutation, fsruo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) SaveX(ctx context.Context) *FeedbackSummarizationsReactions { + node, err := fsruo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) Exec(ctx context.Context) error { + _, err := fsruo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) ExecX(ctx context.Context) { + if err := fsruo.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) check() error { + if v, ok := fsruo.mutation.GetType(); ok { + if err := feedbacksummarizationsreactions.TypeValidator(v); err != nil { + return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "FeedbackSummarizationsReactions.type": %w`, err)} + } + } + return nil +} + +func (fsruo *FeedbackSummarizationsReactionsUpdateOne) sqlSave(ctx context.Context) (_node *FeedbackSummarizationsReactions, err error) { + if err := fsruo.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(feedbacksummarizationsreactions.Table, feedbacksummarizationsreactions.Columns, sqlgraph.NewFieldSpec(feedbacksummarizationsreactions.FieldID, field.TypeUUID)) + id, ok := fsruo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "FeedbackSummarizationsReactions.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := fsruo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, feedbacksummarizationsreactions.FieldID) + for _, f := range fields { + if !feedbacksummarizationsreactions.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != feedbacksummarizationsreactions.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := fsruo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := fsruo.mutation.ChatID(); ok { + _spec.SetField(feedbacksummarizationsreactions.FieldChatID, field.TypeInt64, value) + } + if value, ok := fsruo.mutation.AddedChatID(); ok { + _spec.AddField(feedbacksummarizationsreactions.FieldChatID, field.TypeInt64, value) + } + if value, ok := fsruo.mutation.UserID(); ok { + _spec.SetField(feedbacksummarizationsreactions.FieldUserID, field.TypeInt64, value) + } + if value, ok := fsruo.mutation.AddedUserID(); ok { + _spec.AddField(feedbacksummarizationsreactions.FieldUserID, field.TypeInt64, value) + } + if value, ok := fsruo.mutation.GetType(); ok { + _spec.SetField(feedbacksummarizationsreactions.FieldType, field.TypeEnum, value) + } + if value, ok := fsruo.mutation.CreatedAt(); ok { + _spec.SetField(feedbacksummarizationsreactions.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := fsruo.mutation.AddedCreatedAt(); ok { + _spec.AddField(feedbacksummarizationsreactions.FieldCreatedAt, field.TypeInt64, value) + } + if value, ok := fsruo.mutation.UpdatedAt(); ok { + _spec.SetField(feedbacksummarizationsreactions.FieldUpdatedAt, field.TypeInt64, value) + } + if value, ok := fsruo.mutation.AddedUpdatedAt(); ok { + _spec.AddField(feedbacksummarizationsreactions.FieldUpdatedAt, field.TypeInt64, value) + } + _spec.Node.Schema = fsruo.schemaConfig.FeedbackSummarizationsReactions + ctx = internal.NewSchemaConfigContext(ctx, fsruo.schemaConfig) + _node = &FeedbackSummarizationsReactions{config: fsruo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, fsruo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{feedbacksummarizationsreactions.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + fsruo.mutation.done = true + return _node, nil +} diff --git a/ent/hook/hook.go b/ent/hook/hook.go index 4ec76f1..b12f8d6 100644 --- a/ent/hook/hook.go +++ b/ent/hook/hook.go @@ -21,6 +21,30 @@ func (f ChatHistoriesFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Valu return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ChatHistoriesMutation", m) } +// The FeedbackChatHistoriesRecapsReactionsFunc type is an adapter to allow the use of ordinary +// function as FeedbackChatHistoriesRecapsReactions mutator. +type FeedbackChatHistoriesRecapsReactionsFunc func(context.Context, *ent.FeedbackChatHistoriesRecapsReactionsMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f FeedbackChatHistoriesRecapsReactionsFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.FeedbackChatHistoriesRecapsReactionsMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.FeedbackChatHistoriesRecapsReactionsMutation", m) +} + +// The FeedbackSummarizationsReactionsFunc type is an adapter to allow the use of ordinary +// function as FeedbackSummarizationsReactions mutator. +type FeedbackSummarizationsReactionsFunc func(context.Context, *ent.FeedbackSummarizationsReactionsMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f FeedbackSummarizationsReactionsFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.FeedbackSummarizationsReactionsMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.FeedbackSummarizationsReactionsMutation", m) +} + // The LogChatHistoriesRecapFunc type is an adapter to allow the use of ordinary // function as LogChatHistoriesRecap mutator. type LogChatHistoriesRecapFunc func(context.Context, *ent.LogChatHistoriesRecapMutation) (ent.Value, error) diff --git a/ent/internal/schemaconfig.go b/ent/internal/schemaconfig.go index ef4b3eb..5791780 100644 --- a/ent/internal/schemaconfig.go +++ b/ent/internal/schemaconfig.go @@ -8,6 +8,8 @@ import "context" // that can be passed at runtime. type SchemaConfig struct { ChatHistories string // ChatHistories table. + FeedbackChatHistoriesRecapsReactions string // FeedbackChatHistoriesRecapsReactions table. + FeedbackSummarizationsReactions string // FeedbackSummarizationsReactions table. LogChatHistoriesRecap string // LogChatHistoriesRecap table. LogSummarizations string // LogSummarizations table. MetricOpenAIChatCompletionTokenUsage string // MetricOpenAIChatCompletionTokenUsage table. diff --git a/ent/migrate/schema.go b/ent/migrate/schema.go index 1006e8a..df5c894 100644 --- a/ent/migrate/schema.go +++ b/ent/migrate/schema.go @@ -37,6 +37,38 @@ var ( Columns: ChatHistoriesColumns, PrimaryKey: []*schema.Column{ChatHistoriesColumns[0]}, } + // FeedbackChatHistoriesRecapsReactionsColumns holds the columns for the "feedback_chat_histories_recaps_reactions" table. + FeedbackChatHistoriesRecapsReactionsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID, Unique: true}, + {Name: "chat_id", Type: field.TypeInt64, Default: 0}, + {Name: "log_id", Type: field.TypeUUID}, + {Name: "user_id", Type: field.TypeInt64, Default: 0}, + {Name: "type", Type: field.TypeEnum, Enums: []string{"none", "up_vote", "down_vote", "lmao"}, Default: "none"}, + {Name: "created_at", Type: field.TypeInt64}, + {Name: "updated_at", Type: field.TypeInt64}, + } + // FeedbackChatHistoriesRecapsReactionsTable holds the schema information for the "feedback_chat_histories_recaps_reactions" table. + FeedbackChatHistoriesRecapsReactionsTable = &schema.Table{ + Name: "feedback_chat_histories_recaps_reactions", + Columns: FeedbackChatHistoriesRecapsReactionsColumns, + PrimaryKey: []*schema.Column{FeedbackChatHistoriesRecapsReactionsColumns[0]}, + } + // FeedbackSummarizationsReactionsColumns holds the columns for the "feedback_summarizations_reactions" table. + FeedbackSummarizationsReactionsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeUUID, Unique: true}, + {Name: "chat_id", Type: field.TypeInt64, Default: 0}, + {Name: "log_id", Type: field.TypeUUID}, + {Name: "user_id", Type: field.TypeInt64, Default: 0}, + {Name: "type", Type: field.TypeEnum, Enums: []string{"none", "up_vote", "down_vote", "lmao"}, Default: "none"}, + {Name: "created_at", Type: field.TypeInt64}, + {Name: "updated_at", Type: field.TypeInt64}, + } + // FeedbackSummarizationsReactionsTable holds the schema information for the "feedback_summarizations_reactions" table. + FeedbackSummarizationsReactionsTable = &schema.Table{ + Name: "feedback_summarizations_reactions", + Columns: FeedbackSummarizationsReactionsColumns, + PrimaryKey: []*schema.Column{FeedbackSummarizationsReactionsColumns[0]}, + } // LogChatHistoriesRecapsColumns holds the columns for the "log_chat_histories_recaps" table. LogChatHistoriesRecapsColumns = []*schema.Column{ {Name: "id", Type: field.TypeUUID, Unique: true}, @@ -161,6 +193,8 @@ var ( // Tables holds all the tables in the schema. Tables = []*schema.Table{ ChatHistoriesTable, + FeedbackChatHistoriesRecapsReactionsTable, + FeedbackSummarizationsReactionsTable, LogChatHistoriesRecapsTable, LogSummarizationsTable, MetricOpenAiChatCompletionTokenUsagesTable, diff --git a/ent/mutation.go b/ent/mutation.go index 5175aea..2fab4fc 100644 --- a/ent/mutation.go +++ b/ent/mutation.go @@ -12,6 +12,8 @@ import ( "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/nekomeowww/insights-bot/ent/chathistories" + "github.com/nekomeowww/insights-bot/ent/feedbackchathistoriesrecapsreactions" + "github.com/nekomeowww/insights-bot/ent/feedbacksummarizationsreactions" "github.com/nekomeowww/insights-bot/ent/logchathistoriesrecap" "github.com/nekomeowww/insights-bot/ent/logsummarizations" "github.com/nekomeowww/insights-bot/ent/metricopenaichatcompletiontokenusage" @@ -32,6 +34,8 @@ const ( // Node types. TypeChatHistories = "ChatHistories" + TypeFeedbackChatHistoriesRecapsReactions = "FeedbackChatHistoriesRecapsReactions" + TypeFeedbackSummarizationsReactions = "FeedbackSummarizationsReactions" TypeLogChatHistoriesRecap = "LogChatHistoriesRecap" TypeLogSummarizations = "LogSummarizations" TypeMetricOpenAIChatCompletionTokenUsage = "MetricOpenAIChatCompletionTokenUsage" @@ -1645,6 +1649,1480 @@ func (m *ChatHistoriesMutation) ResetEdge(name string) error { return fmt.Errorf("unknown ChatHistories edge %s", name) } +// FeedbackChatHistoriesRecapsReactionsMutation represents an operation that mutates the FeedbackChatHistoriesRecapsReactions nodes in the graph. +type FeedbackChatHistoriesRecapsReactionsMutation struct { + config + op Op + typ string + id *uuid.UUID + chat_id *int64 + addchat_id *int64 + log_id *uuid.UUID + user_id *int64 + adduser_id *int64 + _type *feedbackchathistoriesrecapsreactions.Type + created_at *int64 + addcreated_at *int64 + updated_at *int64 + addupdated_at *int64 + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*FeedbackChatHistoriesRecapsReactions, error) + predicates []predicate.FeedbackChatHistoriesRecapsReactions +} + +var _ ent.Mutation = (*FeedbackChatHistoriesRecapsReactionsMutation)(nil) + +// feedbackchathistoriesrecapsreactionsOption allows management of the mutation configuration using functional options. +type feedbackchathistoriesrecapsreactionsOption func(*FeedbackChatHistoriesRecapsReactionsMutation) + +// newFeedbackChatHistoriesRecapsReactionsMutation creates new mutation for the FeedbackChatHistoriesRecapsReactions entity. +func newFeedbackChatHistoriesRecapsReactionsMutation(c config, op Op, opts ...feedbackchathistoriesrecapsreactionsOption) *FeedbackChatHistoriesRecapsReactionsMutation { + m := &FeedbackChatHistoriesRecapsReactionsMutation{ + config: c, + op: op, + typ: TypeFeedbackChatHistoriesRecapsReactions, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withFeedbackChatHistoriesRecapsReactionsID sets the ID field of the mutation. +func withFeedbackChatHistoriesRecapsReactionsID(id uuid.UUID) feedbackchathistoriesrecapsreactionsOption { + return func(m *FeedbackChatHistoriesRecapsReactionsMutation) { + var ( + err error + once sync.Once + value *FeedbackChatHistoriesRecapsReactions + ) + m.oldValue = func(ctx context.Context) (*FeedbackChatHistoriesRecapsReactions, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().FeedbackChatHistoriesRecapsReactions.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withFeedbackChatHistoriesRecapsReactions sets the old FeedbackChatHistoriesRecapsReactions of the mutation. +func withFeedbackChatHistoriesRecapsReactions(node *FeedbackChatHistoriesRecapsReactions) feedbackchathistoriesrecapsreactionsOption { + return func(m *FeedbackChatHistoriesRecapsReactionsMutation) { + m.oldValue = func(context.Context) (*FeedbackChatHistoriesRecapsReactions, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m FeedbackChatHistoriesRecapsReactionsMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m FeedbackChatHistoriesRecapsReactionsMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of FeedbackChatHistoriesRecapsReactions entities. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().FeedbackChatHistoriesRecapsReactions.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetChatID sets the "chat_id" field. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) SetChatID(i int64) { + m.chat_id = &i + m.addchat_id = nil +} + +// ChatID returns the value of the "chat_id" field in the mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) ChatID() (r int64, exists bool) { + v := m.chat_id + if v == nil { + return + } + return *v, true +} + +// OldChatID returns the old "chat_id" field's value of the FeedbackChatHistoriesRecapsReactions entity. +// If the FeedbackChatHistoriesRecapsReactions object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) OldChatID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldChatID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldChatID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldChatID: %w", err) + } + return oldValue.ChatID, nil +} + +// AddChatID adds i to the "chat_id" field. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) AddChatID(i int64) { + if m.addchat_id != nil { + *m.addchat_id += i + } else { + m.addchat_id = &i + } +} + +// AddedChatID returns the value that was added to the "chat_id" field in this mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) AddedChatID() (r int64, exists bool) { + v := m.addchat_id + if v == nil { + return + } + return *v, true +} + +// ResetChatID resets all changes to the "chat_id" field. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) ResetChatID() { + m.chat_id = nil + m.addchat_id = nil +} + +// SetLogID sets the "log_id" field. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) SetLogID(u uuid.UUID) { + m.log_id = &u +} + +// LogID returns the value of the "log_id" field in the mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) LogID() (r uuid.UUID, exists bool) { + v := m.log_id + if v == nil { + return + } + return *v, true +} + +// OldLogID returns the old "log_id" field's value of the FeedbackChatHistoriesRecapsReactions entity. +// If the FeedbackChatHistoriesRecapsReactions object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) OldLogID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldLogID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldLogID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldLogID: %w", err) + } + return oldValue.LogID, nil +} + +// ResetLogID resets all changes to the "log_id" field. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) ResetLogID() { + m.log_id = nil +} + +// SetUserID sets the "user_id" field. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) SetUserID(i int64) { + m.user_id = &i + m.adduser_id = nil +} + +// UserID returns the value of the "user_id" field in the mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) UserID() (r int64, exists bool) { + v := m.user_id + if v == nil { + return + } + return *v, true +} + +// OldUserID returns the old "user_id" field's value of the FeedbackChatHistoriesRecapsReactions entity. +// If the FeedbackChatHistoriesRecapsReactions object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) OldUserID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUserID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUserID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUserID: %w", err) + } + return oldValue.UserID, nil +} + +// AddUserID adds i to the "user_id" field. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) AddUserID(i int64) { + if m.adduser_id != nil { + *m.adduser_id += i + } else { + m.adduser_id = &i + } +} + +// AddedUserID returns the value that was added to the "user_id" field in this mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) AddedUserID() (r int64, exists bool) { + v := m.adduser_id + if v == nil { + return + } + return *v, true +} + +// ResetUserID resets all changes to the "user_id" field. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) ResetUserID() { + m.user_id = nil + m.adduser_id = nil +} + +// SetType sets the "type" field. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) SetType(f feedbackchathistoriesrecapsreactions.Type) { + m._type = &f +} + +// GetType returns the value of the "type" field in the mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) GetType() (r feedbackchathistoriesrecapsreactions.Type, exists bool) { + v := m._type + if v == nil { + return + } + return *v, true +} + +// OldType returns the old "type" field's value of the FeedbackChatHistoriesRecapsReactions entity. +// If the FeedbackChatHistoriesRecapsReactions object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) OldType(ctx context.Context) (v feedbackchathistoriesrecapsreactions.Type, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldType: %w", err) + } + return oldValue.Type, nil +} + +// ResetType resets all changes to the "type" field. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) ResetType() { + m._type = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) SetCreatedAt(i int64) { + m.created_at = &i + m.addcreated_at = nil +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) CreatedAt() (r int64, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the FeedbackChatHistoriesRecapsReactions entity. +// If the FeedbackChatHistoriesRecapsReactions object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) OldCreatedAt(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// AddCreatedAt adds i to the "created_at" field. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) AddCreatedAt(i int64) { + if m.addcreated_at != nil { + *m.addcreated_at += i + } else { + m.addcreated_at = &i + } +} + +// AddedCreatedAt returns the value that was added to the "created_at" field in this mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) AddedCreatedAt() (r int64, exists bool) { + v := m.addcreated_at + if v == nil { + return + } + return *v, true +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) ResetCreatedAt() { + m.created_at = nil + m.addcreated_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) SetUpdatedAt(i int64) { + m.updated_at = &i + m.addupdated_at = nil +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) UpdatedAt() (r int64, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the FeedbackChatHistoriesRecapsReactions entity. +// If the FeedbackChatHistoriesRecapsReactions object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) OldUpdatedAt(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// AddUpdatedAt adds i to the "updated_at" field. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) AddUpdatedAt(i int64) { + if m.addupdated_at != nil { + *m.addupdated_at += i + } else { + m.addupdated_at = &i + } +} + +// AddedUpdatedAt returns the value that was added to the "updated_at" field in this mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) AddedUpdatedAt() (r int64, exists bool) { + v := m.addupdated_at + if v == nil { + return + } + return *v, true +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) ResetUpdatedAt() { + m.updated_at = nil + m.addupdated_at = nil +} + +// Where appends a list predicates to the FeedbackChatHistoriesRecapsReactionsMutation builder. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) Where(ps ...predicate.FeedbackChatHistoriesRecapsReactions) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the FeedbackChatHistoriesRecapsReactionsMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.FeedbackChatHistoriesRecapsReactions, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (FeedbackChatHistoriesRecapsReactions). +func (m *FeedbackChatHistoriesRecapsReactionsMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *FeedbackChatHistoriesRecapsReactionsMutation) Fields() []string { + fields := make([]string, 0, 6) + if m.chat_id != nil { + fields = append(fields, feedbackchathistoriesrecapsreactions.FieldChatID) + } + if m.log_id != nil { + fields = append(fields, feedbackchathistoriesrecapsreactions.FieldLogID) + } + if m.user_id != nil { + fields = append(fields, feedbackchathistoriesrecapsreactions.FieldUserID) + } + if m._type != nil { + fields = append(fields, feedbackchathistoriesrecapsreactions.FieldType) + } + if m.created_at != nil { + fields = append(fields, feedbackchathistoriesrecapsreactions.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, feedbackchathistoriesrecapsreactions.FieldUpdatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) Field(name string) (ent.Value, bool) { + switch name { + case feedbackchathistoriesrecapsreactions.FieldChatID: + return m.ChatID() + case feedbackchathistoriesrecapsreactions.FieldLogID: + return m.LogID() + case feedbackchathistoriesrecapsreactions.FieldUserID: + return m.UserID() + case feedbackchathistoriesrecapsreactions.FieldType: + return m.GetType() + case feedbackchathistoriesrecapsreactions.FieldCreatedAt: + return m.CreatedAt() + case feedbackchathistoriesrecapsreactions.FieldUpdatedAt: + return m.UpdatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case feedbackchathistoriesrecapsreactions.FieldChatID: + return m.OldChatID(ctx) + case feedbackchathistoriesrecapsreactions.FieldLogID: + return m.OldLogID(ctx) + case feedbackchathistoriesrecapsreactions.FieldUserID: + return m.OldUserID(ctx) + case feedbackchathistoriesrecapsreactions.FieldType: + return m.OldType(ctx) + case feedbackchathistoriesrecapsreactions.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case feedbackchathistoriesrecapsreactions.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown FeedbackChatHistoriesRecapsReactions field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) SetField(name string, value ent.Value) error { + switch name { + case feedbackchathistoriesrecapsreactions.FieldChatID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetChatID(v) + return nil + case feedbackchathistoriesrecapsreactions.FieldLogID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLogID(v) + return nil + case feedbackchathistoriesrecapsreactions.FieldUserID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUserID(v) + return nil + case feedbackchathistoriesrecapsreactions.FieldType: + v, ok := value.(feedbackchathistoriesrecapsreactions.Type) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetType(v) + return nil + case feedbackchathistoriesrecapsreactions.FieldCreatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case feedbackchathistoriesrecapsreactions.FieldUpdatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown FeedbackChatHistoriesRecapsReactions field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) AddedFields() []string { + var fields []string + if m.addchat_id != nil { + fields = append(fields, feedbackchathistoriesrecapsreactions.FieldChatID) + } + if m.adduser_id != nil { + fields = append(fields, feedbackchathistoriesrecapsreactions.FieldUserID) + } + if m.addcreated_at != nil { + fields = append(fields, feedbackchathistoriesrecapsreactions.FieldCreatedAt) + } + if m.addupdated_at != nil { + fields = append(fields, feedbackchathistoriesrecapsreactions.FieldUpdatedAt) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case feedbackchathistoriesrecapsreactions.FieldChatID: + return m.AddedChatID() + case feedbackchathistoriesrecapsreactions.FieldUserID: + return m.AddedUserID() + case feedbackchathistoriesrecapsreactions.FieldCreatedAt: + return m.AddedCreatedAt() + case feedbackchathistoriesrecapsreactions.FieldUpdatedAt: + return m.AddedUpdatedAt() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) AddField(name string, value ent.Value) error { + switch name { + case feedbackchathistoriesrecapsreactions.FieldChatID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddChatID(v) + return nil + case feedbackchathistoriesrecapsreactions.FieldUserID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddUserID(v) + return nil + case feedbackchathistoriesrecapsreactions.FieldCreatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddCreatedAt(v) + return nil + case feedbackchathistoriesrecapsreactions.FieldUpdatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown FeedbackChatHistoriesRecapsReactions numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) ClearField(name string) error { + return fmt.Errorf("unknown FeedbackChatHistoriesRecapsReactions nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) ResetField(name string) error { + switch name { + case feedbackchathistoriesrecapsreactions.FieldChatID: + m.ResetChatID() + return nil + case feedbackchathistoriesrecapsreactions.FieldLogID: + m.ResetLogID() + return nil + case feedbackchathistoriesrecapsreactions.FieldUserID: + m.ResetUserID() + return nil + case feedbackchathistoriesrecapsreactions.FieldType: + m.ResetType() + return nil + case feedbackchathistoriesrecapsreactions.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case feedbackchathistoriesrecapsreactions.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown FeedbackChatHistoriesRecapsReactions field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown FeedbackChatHistoriesRecapsReactions unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *FeedbackChatHistoriesRecapsReactionsMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown FeedbackChatHistoriesRecapsReactions edge %s", name) +} + +// FeedbackSummarizationsReactionsMutation represents an operation that mutates the FeedbackSummarizationsReactions nodes in the graph. +type FeedbackSummarizationsReactionsMutation struct { + config + op Op + typ string + id *uuid.UUID + chat_id *int64 + addchat_id *int64 + log_id *uuid.UUID + user_id *int64 + adduser_id *int64 + _type *feedbacksummarizationsreactions.Type + created_at *int64 + addcreated_at *int64 + updated_at *int64 + addupdated_at *int64 + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*FeedbackSummarizationsReactions, error) + predicates []predicate.FeedbackSummarizationsReactions +} + +var _ ent.Mutation = (*FeedbackSummarizationsReactionsMutation)(nil) + +// feedbacksummarizationsreactionsOption allows management of the mutation configuration using functional options. +type feedbacksummarizationsreactionsOption func(*FeedbackSummarizationsReactionsMutation) + +// newFeedbackSummarizationsReactionsMutation creates new mutation for the FeedbackSummarizationsReactions entity. +func newFeedbackSummarizationsReactionsMutation(c config, op Op, opts ...feedbacksummarizationsreactionsOption) *FeedbackSummarizationsReactionsMutation { + m := &FeedbackSummarizationsReactionsMutation{ + config: c, + op: op, + typ: TypeFeedbackSummarizationsReactions, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withFeedbackSummarizationsReactionsID sets the ID field of the mutation. +func withFeedbackSummarizationsReactionsID(id uuid.UUID) feedbacksummarizationsreactionsOption { + return func(m *FeedbackSummarizationsReactionsMutation) { + var ( + err error + once sync.Once + value *FeedbackSummarizationsReactions + ) + m.oldValue = func(ctx context.Context) (*FeedbackSummarizationsReactions, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().FeedbackSummarizationsReactions.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withFeedbackSummarizationsReactions sets the old FeedbackSummarizationsReactions of the mutation. +func withFeedbackSummarizationsReactions(node *FeedbackSummarizationsReactions) feedbacksummarizationsreactionsOption { + return func(m *FeedbackSummarizationsReactionsMutation) { + m.oldValue = func(context.Context) (*FeedbackSummarizationsReactions, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m FeedbackSummarizationsReactionsMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m FeedbackSummarizationsReactionsMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// SetID sets the value of the id field. Note that this +// operation is only accepted on creation of FeedbackSummarizationsReactions entities. +func (m *FeedbackSummarizationsReactionsMutation) SetID(id uuid.UUID) { + m.id = &id +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *FeedbackSummarizationsReactionsMutation) ID() (id uuid.UUID, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *FeedbackSummarizationsReactionsMutation) IDs(ctx context.Context) ([]uuid.UUID, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []uuid.UUID{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().FeedbackSummarizationsReactions.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetChatID sets the "chat_id" field. +func (m *FeedbackSummarizationsReactionsMutation) SetChatID(i int64) { + m.chat_id = &i + m.addchat_id = nil +} + +// ChatID returns the value of the "chat_id" field in the mutation. +func (m *FeedbackSummarizationsReactionsMutation) ChatID() (r int64, exists bool) { + v := m.chat_id + if v == nil { + return + } + return *v, true +} + +// OldChatID returns the old "chat_id" field's value of the FeedbackSummarizationsReactions entity. +// If the FeedbackSummarizationsReactions object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *FeedbackSummarizationsReactionsMutation) OldChatID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldChatID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldChatID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldChatID: %w", err) + } + return oldValue.ChatID, nil +} + +// AddChatID adds i to the "chat_id" field. +func (m *FeedbackSummarizationsReactionsMutation) AddChatID(i int64) { + if m.addchat_id != nil { + *m.addchat_id += i + } else { + m.addchat_id = &i + } +} + +// AddedChatID returns the value that was added to the "chat_id" field in this mutation. +func (m *FeedbackSummarizationsReactionsMutation) AddedChatID() (r int64, exists bool) { + v := m.addchat_id + if v == nil { + return + } + return *v, true +} + +// ResetChatID resets all changes to the "chat_id" field. +func (m *FeedbackSummarizationsReactionsMutation) ResetChatID() { + m.chat_id = nil + m.addchat_id = nil +} + +// SetLogID sets the "log_id" field. +func (m *FeedbackSummarizationsReactionsMutation) SetLogID(u uuid.UUID) { + m.log_id = &u +} + +// LogID returns the value of the "log_id" field in the mutation. +func (m *FeedbackSummarizationsReactionsMutation) LogID() (r uuid.UUID, exists bool) { + v := m.log_id + if v == nil { + return + } + return *v, true +} + +// OldLogID returns the old "log_id" field's value of the FeedbackSummarizationsReactions entity. +// If the FeedbackSummarizationsReactions object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *FeedbackSummarizationsReactionsMutation) OldLogID(ctx context.Context) (v uuid.UUID, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldLogID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldLogID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldLogID: %w", err) + } + return oldValue.LogID, nil +} + +// ResetLogID resets all changes to the "log_id" field. +func (m *FeedbackSummarizationsReactionsMutation) ResetLogID() { + m.log_id = nil +} + +// SetUserID sets the "user_id" field. +func (m *FeedbackSummarizationsReactionsMutation) SetUserID(i int64) { + m.user_id = &i + m.adduser_id = nil +} + +// UserID returns the value of the "user_id" field in the mutation. +func (m *FeedbackSummarizationsReactionsMutation) UserID() (r int64, exists bool) { + v := m.user_id + if v == nil { + return + } + return *v, true +} + +// OldUserID returns the old "user_id" field's value of the FeedbackSummarizationsReactions entity. +// If the FeedbackSummarizationsReactions object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *FeedbackSummarizationsReactionsMutation) OldUserID(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUserID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUserID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUserID: %w", err) + } + return oldValue.UserID, nil +} + +// AddUserID adds i to the "user_id" field. +func (m *FeedbackSummarizationsReactionsMutation) AddUserID(i int64) { + if m.adduser_id != nil { + *m.adduser_id += i + } else { + m.adduser_id = &i + } +} + +// AddedUserID returns the value that was added to the "user_id" field in this mutation. +func (m *FeedbackSummarizationsReactionsMutation) AddedUserID() (r int64, exists bool) { + v := m.adduser_id + if v == nil { + return + } + return *v, true +} + +// ResetUserID resets all changes to the "user_id" field. +func (m *FeedbackSummarizationsReactionsMutation) ResetUserID() { + m.user_id = nil + m.adduser_id = nil +} + +// SetType sets the "type" field. +func (m *FeedbackSummarizationsReactionsMutation) SetType(f feedbacksummarizationsreactions.Type) { + m._type = &f +} + +// GetType returns the value of the "type" field in the mutation. +func (m *FeedbackSummarizationsReactionsMutation) GetType() (r feedbacksummarizationsreactions.Type, exists bool) { + v := m._type + if v == nil { + return + } + return *v, true +} + +// OldType returns the old "type" field's value of the FeedbackSummarizationsReactions entity. +// If the FeedbackSummarizationsReactions object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *FeedbackSummarizationsReactionsMutation) OldType(ctx context.Context) (v feedbacksummarizationsreactions.Type, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldType: %w", err) + } + return oldValue.Type, nil +} + +// ResetType resets all changes to the "type" field. +func (m *FeedbackSummarizationsReactionsMutation) ResetType() { + m._type = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *FeedbackSummarizationsReactionsMutation) SetCreatedAt(i int64) { + m.created_at = &i + m.addcreated_at = nil +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *FeedbackSummarizationsReactionsMutation) CreatedAt() (r int64, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the FeedbackSummarizationsReactions entity. +// If the FeedbackSummarizationsReactions object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *FeedbackSummarizationsReactionsMutation) OldCreatedAt(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// AddCreatedAt adds i to the "created_at" field. +func (m *FeedbackSummarizationsReactionsMutation) AddCreatedAt(i int64) { + if m.addcreated_at != nil { + *m.addcreated_at += i + } else { + m.addcreated_at = &i + } +} + +// AddedCreatedAt returns the value that was added to the "created_at" field in this mutation. +func (m *FeedbackSummarizationsReactionsMutation) AddedCreatedAt() (r int64, exists bool) { + v := m.addcreated_at + if v == nil { + return + } + return *v, true +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *FeedbackSummarizationsReactionsMutation) ResetCreatedAt() { + m.created_at = nil + m.addcreated_at = nil +} + +// SetUpdatedAt sets the "updated_at" field. +func (m *FeedbackSummarizationsReactionsMutation) SetUpdatedAt(i int64) { + m.updated_at = &i + m.addupdated_at = nil +} + +// UpdatedAt returns the value of the "updated_at" field in the mutation. +func (m *FeedbackSummarizationsReactionsMutation) UpdatedAt() (r int64, exists bool) { + v := m.updated_at + if v == nil { + return + } + return *v, true +} + +// OldUpdatedAt returns the old "updated_at" field's value of the FeedbackSummarizationsReactions entity. +// If the FeedbackSummarizationsReactions object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *FeedbackSummarizationsReactionsMutation) OldUpdatedAt(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldUpdatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err) + } + return oldValue.UpdatedAt, nil +} + +// AddUpdatedAt adds i to the "updated_at" field. +func (m *FeedbackSummarizationsReactionsMutation) AddUpdatedAt(i int64) { + if m.addupdated_at != nil { + *m.addupdated_at += i + } else { + m.addupdated_at = &i + } +} + +// AddedUpdatedAt returns the value that was added to the "updated_at" field in this mutation. +func (m *FeedbackSummarizationsReactionsMutation) AddedUpdatedAt() (r int64, exists bool) { + v := m.addupdated_at + if v == nil { + return + } + return *v, true +} + +// ResetUpdatedAt resets all changes to the "updated_at" field. +func (m *FeedbackSummarizationsReactionsMutation) ResetUpdatedAt() { + m.updated_at = nil + m.addupdated_at = nil +} + +// Where appends a list predicates to the FeedbackSummarizationsReactionsMutation builder. +func (m *FeedbackSummarizationsReactionsMutation) Where(ps ...predicate.FeedbackSummarizationsReactions) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the FeedbackSummarizationsReactionsMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *FeedbackSummarizationsReactionsMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.FeedbackSummarizationsReactions, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *FeedbackSummarizationsReactionsMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *FeedbackSummarizationsReactionsMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (FeedbackSummarizationsReactions). +func (m *FeedbackSummarizationsReactionsMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *FeedbackSummarizationsReactionsMutation) Fields() []string { + fields := make([]string, 0, 6) + if m.chat_id != nil { + fields = append(fields, feedbacksummarizationsreactions.FieldChatID) + } + if m.log_id != nil { + fields = append(fields, feedbacksummarizationsreactions.FieldLogID) + } + if m.user_id != nil { + fields = append(fields, feedbacksummarizationsreactions.FieldUserID) + } + if m._type != nil { + fields = append(fields, feedbacksummarizationsreactions.FieldType) + } + if m.created_at != nil { + fields = append(fields, feedbacksummarizationsreactions.FieldCreatedAt) + } + if m.updated_at != nil { + fields = append(fields, feedbacksummarizationsreactions.FieldUpdatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *FeedbackSummarizationsReactionsMutation) Field(name string) (ent.Value, bool) { + switch name { + case feedbacksummarizationsreactions.FieldChatID: + return m.ChatID() + case feedbacksummarizationsreactions.FieldLogID: + return m.LogID() + case feedbacksummarizationsreactions.FieldUserID: + return m.UserID() + case feedbacksummarizationsreactions.FieldType: + return m.GetType() + case feedbacksummarizationsreactions.FieldCreatedAt: + return m.CreatedAt() + case feedbacksummarizationsreactions.FieldUpdatedAt: + return m.UpdatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *FeedbackSummarizationsReactionsMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case feedbacksummarizationsreactions.FieldChatID: + return m.OldChatID(ctx) + case feedbacksummarizationsreactions.FieldLogID: + return m.OldLogID(ctx) + case feedbacksummarizationsreactions.FieldUserID: + return m.OldUserID(ctx) + case feedbacksummarizationsreactions.FieldType: + return m.OldType(ctx) + case feedbacksummarizationsreactions.FieldCreatedAt: + return m.OldCreatedAt(ctx) + case feedbacksummarizationsreactions.FieldUpdatedAt: + return m.OldUpdatedAt(ctx) + } + return nil, fmt.Errorf("unknown FeedbackSummarizationsReactions field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *FeedbackSummarizationsReactionsMutation) SetField(name string, value ent.Value) error { + switch name { + case feedbacksummarizationsreactions.FieldChatID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetChatID(v) + return nil + case feedbacksummarizationsreactions.FieldLogID: + v, ok := value.(uuid.UUID) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLogID(v) + return nil + case feedbacksummarizationsreactions.FieldUserID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUserID(v) + return nil + case feedbacksummarizationsreactions.FieldType: + v, ok := value.(feedbacksummarizationsreactions.Type) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetType(v) + return nil + case feedbacksummarizationsreactions.FieldCreatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + case feedbacksummarizationsreactions.FieldUpdatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown FeedbackSummarizationsReactions field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *FeedbackSummarizationsReactionsMutation) AddedFields() []string { + var fields []string + if m.addchat_id != nil { + fields = append(fields, feedbacksummarizationsreactions.FieldChatID) + } + if m.adduser_id != nil { + fields = append(fields, feedbacksummarizationsreactions.FieldUserID) + } + if m.addcreated_at != nil { + fields = append(fields, feedbacksummarizationsreactions.FieldCreatedAt) + } + if m.addupdated_at != nil { + fields = append(fields, feedbacksummarizationsreactions.FieldUpdatedAt) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *FeedbackSummarizationsReactionsMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case feedbacksummarizationsreactions.FieldChatID: + return m.AddedChatID() + case feedbacksummarizationsreactions.FieldUserID: + return m.AddedUserID() + case feedbacksummarizationsreactions.FieldCreatedAt: + return m.AddedCreatedAt() + case feedbacksummarizationsreactions.FieldUpdatedAt: + return m.AddedUpdatedAt() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *FeedbackSummarizationsReactionsMutation) AddField(name string, value ent.Value) error { + switch name { + case feedbacksummarizationsreactions.FieldChatID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddChatID(v) + return nil + case feedbacksummarizationsreactions.FieldUserID: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddUserID(v) + return nil + case feedbacksummarizationsreactions.FieldCreatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddCreatedAt(v) + return nil + case feedbacksummarizationsreactions.FieldUpdatedAt: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddUpdatedAt(v) + return nil + } + return fmt.Errorf("unknown FeedbackSummarizationsReactions numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *FeedbackSummarizationsReactionsMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *FeedbackSummarizationsReactionsMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *FeedbackSummarizationsReactionsMutation) ClearField(name string) error { + return fmt.Errorf("unknown FeedbackSummarizationsReactions nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *FeedbackSummarizationsReactionsMutation) ResetField(name string) error { + switch name { + case feedbacksummarizationsreactions.FieldChatID: + m.ResetChatID() + return nil + case feedbacksummarizationsreactions.FieldLogID: + m.ResetLogID() + return nil + case feedbacksummarizationsreactions.FieldUserID: + m.ResetUserID() + return nil + case feedbacksummarizationsreactions.FieldType: + m.ResetType() + return nil + case feedbacksummarizationsreactions.FieldCreatedAt: + m.ResetCreatedAt() + return nil + case feedbacksummarizationsreactions.FieldUpdatedAt: + m.ResetUpdatedAt() + return nil + } + return fmt.Errorf("unknown FeedbackSummarizationsReactions field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *FeedbackSummarizationsReactionsMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *FeedbackSummarizationsReactionsMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *FeedbackSummarizationsReactionsMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *FeedbackSummarizationsReactionsMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *FeedbackSummarizationsReactionsMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *FeedbackSummarizationsReactionsMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *FeedbackSummarizationsReactionsMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown FeedbackSummarizationsReactions unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *FeedbackSummarizationsReactionsMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown FeedbackSummarizationsReactions edge %s", name) +} + // LogChatHistoriesRecapMutation represents an operation that mutates the LogChatHistoriesRecap nodes in the graph. type LogChatHistoriesRecapMutation struct { config diff --git a/ent/predicate/predicate.go b/ent/predicate/predicate.go index d87aedc..1c848ef 100644 --- a/ent/predicate/predicate.go +++ b/ent/predicate/predicate.go @@ -9,6 +9,12 @@ import ( // ChatHistories is the predicate function for chathistories builders. type ChatHistories func(*sql.Selector) +// FeedbackChatHistoriesRecapsReactions is the predicate function for feedbackchathistoriesrecapsreactions builders. +type FeedbackChatHistoriesRecapsReactions func(*sql.Selector) + +// FeedbackSummarizationsReactions is the predicate function for feedbacksummarizationsreactions builders. +type FeedbackSummarizationsReactions func(*sql.Selector) + // LogChatHistoriesRecap is the predicate function for logchathistoriesrecap builders. type LogChatHistoriesRecap func(*sql.Selector) diff --git a/ent/runtime.go b/ent/runtime.go index 9cd9dbb..7b2d3a8 100644 --- a/ent/runtime.go +++ b/ent/runtime.go @@ -5,6 +5,8 @@ package ent import ( "github.com/google/uuid" "github.com/nekomeowww/insights-bot/ent/chathistories" + "github.com/nekomeowww/insights-bot/ent/feedbackchathistoriesrecapsreactions" + "github.com/nekomeowww/insights-bot/ent/feedbacksummarizationsreactions" "github.com/nekomeowww/insights-bot/ent/logchathistoriesrecap" "github.com/nekomeowww/insights-bot/ent/logsummarizations" "github.com/nekomeowww/insights-bot/ent/metricopenaichatcompletiontokenusage" @@ -101,6 +103,58 @@ func init() { chathistoriesDescID := chathistoriesFields[0].Descriptor() // chathistories.DefaultID holds the default value on creation for the id field. chathistories.DefaultID = chathistoriesDescID.Default.(func() uuid.UUID) + feedbackchathistoriesrecapsreactionsFields := schema.FeedbackChatHistoriesRecapsReactions{}.Fields() + _ = feedbackchathistoriesrecapsreactionsFields + // feedbackchathistoriesrecapsreactionsDescChatID is the schema descriptor for chat_id field. + feedbackchathistoriesrecapsreactionsDescChatID := feedbackchathistoriesrecapsreactionsFields[1].Descriptor() + // feedbackchathistoriesrecapsreactions.DefaultChatID holds the default value on creation for the chat_id field. + feedbackchathistoriesrecapsreactions.DefaultChatID = feedbackchathistoriesrecapsreactionsDescChatID.Default.(int64) + // feedbackchathistoriesrecapsreactionsDescLogID is the schema descriptor for log_id field. + feedbackchathistoriesrecapsreactionsDescLogID := feedbackchathistoriesrecapsreactionsFields[2].Descriptor() + // feedbackchathistoriesrecapsreactions.DefaultLogID holds the default value on creation for the log_id field. + feedbackchathistoriesrecapsreactions.DefaultLogID = feedbackchathistoriesrecapsreactionsDescLogID.Default.(func() uuid.UUID) + // feedbackchathistoriesrecapsreactionsDescUserID is the schema descriptor for user_id field. + feedbackchathistoriesrecapsreactionsDescUserID := feedbackchathistoriesrecapsreactionsFields[3].Descriptor() + // feedbackchathistoriesrecapsreactions.DefaultUserID holds the default value on creation for the user_id field. + feedbackchathistoriesrecapsreactions.DefaultUserID = feedbackchathistoriesrecapsreactionsDescUserID.Default.(int64) + // feedbackchathistoriesrecapsreactionsDescCreatedAt is the schema descriptor for created_at field. + feedbackchathistoriesrecapsreactionsDescCreatedAt := feedbackchathistoriesrecapsreactionsFields[5].Descriptor() + // feedbackchathistoriesrecapsreactions.DefaultCreatedAt holds the default value on creation for the created_at field. + feedbackchathistoriesrecapsreactions.DefaultCreatedAt = feedbackchathistoriesrecapsreactionsDescCreatedAt.Default.(func() int64) + // feedbackchathistoriesrecapsreactionsDescUpdatedAt is the schema descriptor for updated_at field. + feedbackchathistoriesrecapsreactionsDescUpdatedAt := feedbackchathistoriesrecapsreactionsFields[6].Descriptor() + // feedbackchathistoriesrecapsreactions.DefaultUpdatedAt holds the default value on creation for the updated_at field. + feedbackchathistoriesrecapsreactions.DefaultUpdatedAt = feedbackchathistoriesrecapsreactionsDescUpdatedAt.Default.(func() int64) + // feedbackchathistoriesrecapsreactionsDescID is the schema descriptor for id field. + feedbackchathistoriesrecapsreactionsDescID := feedbackchathistoriesrecapsreactionsFields[0].Descriptor() + // feedbackchathistoriesrecapsreactions.DefaultID holds the default value on creation for the id field. + feedbackchathistoriesrecapsreactions.DefaultID = feedbackchathistoriesrecapsreactionsDescID.Default.(func() uuid.UUID) + feedbacksummarizationsreactionsFields := schema.FeedbackSummarizationsReactions{}.Fields() + _ = feedbacksummarizationsreactionsFields + // feedbacksummarizationsreactionsDescChatID is the schema descriptor for chat_id field. + feedbacksummarizationsreactionsDescChatID := feedbacksummarizationsreactionsFields[1].Descriptor() + // feedbacksummarizationsreactions.DefaultChatID holds the default value on creation for the chat_id field. + feedbacksummarizationsreactions.DefaultChatID = feedbacksummarizationsreactionsDescChatID.Default.(int64) + // feedbacksummarizationsreactionsDescLogID is the schema descriptor for log_id field. + feedbacksummarizationsreactionsDescLogID := feedbacksummarizationsreactionsFields[2].Descriptor() + // feedbacksummarizationsreactions.DefaultLogID holds the default value on creation for the log_id field. + feedbacksummarizationsreactions.DefaultLogID = feedbacksummarizationsreactionsDescLogID.Default.(func() uuid.UUID) + // feedbacksummarizationsreactionsDescUserID is the schema descriptor for user_id field. + feedbacksummarizationsreactionsDescUserID := feedbacksummarizationsreactionsFields[3].Descriptor() + // feedbacksummarizationsreactions.DefaultUserID holds the default value on creation for the user_id field. + feedbacksummarizationsreactions.DefaultUserID = feedbacksummarizationsreactionsDescUserID.Default.(int64) + // feedbacksummarizationsreactionsDescCreatedAt is the schema descriptor for created_at field. + feedbacksummarizationsreactionsDescCreatedAt := feedbacksummarizationsreactionsFields[5].Descriptor() + // feedbacksummarizationsreactions.DefaultCreatedAt holds the default value on creation for the created_at field. + feedbacksummarizationsreactions.DefaultCreatedAt = feedbacksummarizationsreactionsDescCreatedAt.Default.(func() int64) + // feedbacksummarizationsreactionsDescUpdatedAt is the schema descriptor for updated_at field. + feedbacksummarizationsreactionsDescUpdatedAt := feedbacksummarizationsreactionsFields[6].Descriptor() + // feedbacksummarizationsreactions.DefaultUpdatedAt holds the default value on creation for the updated_at field. + feedbacksummarizationsreactions.DefaultUpdatedAt = feedbacksummarizationsreactionsDescUpdatedAt.Default.(func() int64) + // feedbacksummarizationsreactionsDescID is the schema descriptor for id field. + feedbacksummarizationsreactionsDescID := feedbacksummarizationsreactionsFields[0].Descriptor() + // feedbacksummarizationsreactions.DefaultID holds the default value on creation for the id field. + feedbacksummarizationsreactions.DefaultID = feedbacksummarizationsreactionsDescID.Default.(func() uuid.UUID) logchathistoriesrecapFields := schema.LogChatHistoriesRecap{}.Fields() _ = logchathistoriesrecapFields // logchathistoriesrecapDescChatID is the schema descriptor for chat_id field. diff --git a/ent/schema/feedbackchathistoriesrecapsreactions.go b/ent/schema/feedbackchathistoriesrecapsreactions.go new file mode 100644 index 0000000..ca48091 --- /dev/null +++ b/ent/schema/feedbackchathistoriesrecapsreactions.go @@ -0,0 +1,32 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/schema/field" + "github.com/google/uuid" +) + +// FeedbackChatHistoriesRecapsReactions holds the schema definition for the FeedbackChatHistoriesRecapsReactions entity. +type FeedbackChatHistoriesRecapsReactions struct { + ent.Schema +} + +// Fields of the FeedbackChatHistoriesRecapsReactions. +func (FeedbackChatHistoriesRecapsReactions) Fields() []ent.Field { + return []ent.Field{ + field.UUID("id", uuid.UUID{}).Default(uuid.New).Unique().Immutable(), + field.Int64("chat_id").Default(0), + field.UUID("log_id", uuid.UUID{}).Default(uuid.New).Immutable(), + field.Int64("user_id").Default(0), + field.Enum("type").Values("none", "up_vote", "down_vote", "lmao").Default("none"), + field.Int64("created_at").DefaultFunc(func() int64 { return time.Now().UnixMilli() }), + field.Int64("updated_at").DefaultFunc(func() int64 { return time.Now().UnixMilli() }), + } +} + +// Edges of the FeedbackChatHistoriesRecapsReactions. +func (FeedbackChatHistoriesRecapsReactions) Edges() []ent.Edge { + return nil +} diff --git a/ent/schema/feedbacksummarizationsreactions.go b/ent/schema/feedbacksummarizationsreactions.go new file mode 100644 index 0000000..23b56ca --- /dev/null +++ b/ent/schema/feedbacksummarizationsreactions.go @@ -0,0 +1,32 @@ +package schema + +import ( + "time" + + "entgo.io/ent" + "entgo.io/ent/schema/field" + "github.com/google/uuid" +) + +// FeedbackSummarizationsReactions holds the schema definition for the FeedbackSummarizationsReactions entity. +type FeedbackSummarizationsReactions struct { + ent.Schema +} + +// Fields of the FeedbackSummarizationsReactions. +func (FeedbackSummarizationsReactions) Fields() []ent.Field { + return []ent.Field{ + field.UUID("id", uuid.UUID{}).Default(uuid.New).Unique().Immutable(), + field.Int64("chat_id").Default(0), + field.UUID("log_id", uuid.UUID{}).Default(uuid.New).Immutable(), + field.Int64("user_id").Default(0), + field.Enum("type").Values("none", "up_vote", "down_vote", "lmao").Default("none"), + field.Int64("created_at").DefaultFunc(func() int64 { return time.Now().UnixMilli() }), + field.Int64("updated_at").DefaultFunc(func() int64 { return time.Now().UnixMilli() }), + } +} + +// Edges of the FeedbackSummarizationsReactions. +func (FeedbackSummarizationsReactions) Edges() []ent.Edge { + return nil +} diff --git a/ent/tx.go b/ent/tx.go index 4679bf2..cc1cde6 100644 --- a/ent/tx.go +++ b/ent/tx.go @@ -14,6 +14,10 @@ type Tx struct { config // ChatHistories is the client for interacting with the ChatHistories builders. ChatHistories *ChatHistoriesClient + // FeedbackChatHistoriesRecapsReactions is the client for interacting with the FeedbackChatHistoriesRecapsReactions builders. + FeedbackChatHistoriesRecapsReactions *FeedbackChatHistoriesRecapsReactionsClient + // FeedbackSummarizationsReactions is the client for interacting with the FeedbackSummarizationsReactions builders. + FeedbackSummarizationsReactions *FeedbackSummarizationsReactionsClient // LogChatHistoriesRecap is the client for interacting with the LogChatHistoriesRecap builders. LogChatHistoriesRecap *LogChatHistoriesRecapClient // LogSummarizations is the client for interacting with the LogSummarizations builders. @@ -160,6 +164,8 @@ func (tx *Tx) Client() *Client { func (tx *Tx) init() { tx.ChatHistories = NewChatHistoriesClient(tx.config) + tx.FeedbackChatHistoriesRecapsReactions = NewFeedbackChatHistoriesRecapsReactionsClient(tx.config) + tx.FeedbackSummarizationsReactions = NewFeedbackSummarizationsReactionsClient(tx.config) tx.LogChatHistoriesRecap = NewLogChatHistoriesRecapClient(tx.config) tx.LogSummarizations = NewLogSummarizationsClient(tx.config) tx.MetricOpenAIChatCompletionTokenUsage = NewMetricOpenAIChatCompletionTokenUsageClient(tx.config) diff --git a/internal/bots/telegram/handlers/recap/callback_query.go b/internal/bots/telegram/handlers/recap/callback_query.go index 2c36109..fd07323 100644 --- a/internal/bots/telegram/handlers/recap/callback_query.go +++ b/internal/bots/telegram/handlers/recap/callback_query.go @@ -3,8 +3,6 @@ package recap import ( "errors" "fmt" - "strings" - "time" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" "github.com/samber/lo" @@ -88,119 +86,6 @@ func shouldSkipCallbackQueryHandlingByCheckingActionData[ return false } -func (h *CallbackQueryHandler) handleCallbackQuerySelectHours(c *tgbot.Context) (tgbot.Response, error) { - messageID := c.Update.CallbackQuery.Message.MessageID - - replyToMessage := c.Update.CallbackQuery.Message.ReplyToMessage - - var data recap.SelectHourCallbackQueryData - - err := c.BindFromCallbackQueryData(&data) - if err != nil { - return nil, tgbot. - NewExceptionError(err). - WithMessage("聊天记录回顾生成失败,请稍后再试!"). - WithReply(replyToMessage) - } - if !lo.Contains(RecapSelectHourAvailable, data.Hour) { - return nil, tgbot. - NewExceptionError(fmt.Errorf("invalid hour: %d", data.Hour)). - WithReply(replyToMessage) - } - - var inProgressText string - - switch data.RecapMode { - case tgchat.AutoRecapSendModePublicly: - inProgressText = fmt.Sprintf("正在为过去 %d 个小时的聊天记录生成回顾,请稍等...", data.Hour) - case tgchat.AutoRecapSendModeOnlyPrivateSubscriptions: - inProgressText = fmt.Sprintf("正在为 %s 过去 %d 个小时的聊天记录生成回顾,请稍等...", tgbot.EscapeHTMLSymbols(data.ChatTitle), data.Hour) - default: - inProgressText = fmt.Sprintf("正在为过去 %d 个小时的聊天记录生成回顾,请稍等...", data.Hour) - } - - editConfig := tgbotapi.NewEditMessageTextAndMarkup( - c.Update.CallbackQuery.Message.Chat.ID, - messageID, - inProgressText, - tgbotapi.NewInlineKeyboardMarkup([]tgbotapi.InlineKeyboardButton{}), - ) - - editConfig.ParseMode = tgbotapi.ModeHTML - - _, err = c.Bot.Request(editConfig) - if err != nil { - h.logger.Error("failed to edit message", zap.Error(err)) - } - - histories, err := h.chatHistories.FindChatHistoriesByTimeBefore(data.ChatID, time.Duration(data.Hour)*time.Hour) - if err != nil { - return nil, tgbot. - NewExceptionError(err).WithMessage("聊天记录回顾生成失败,请稍后再试!"). - WithReply(replyToMessage) - } - if len(histories) <= 5 { - var errMessage string - - switch data.RecapMode { - case tgchat.AutoRecapSendModePublicly: - errMessage = fmt.Sprintf("最近 %d 小时内暂时没有超过 5 条的聊天记录可以生成聊天回顾哦,要再多聊点之后再试试吗?", data.Hour) - case tgchat.AutoRecapSendModeOnlyPrivateSubscriptions: - errMessage = fmt.Sprintf("最近 %d 小时内暂时没有超过 5 条的聊天记录可以生成聊天回顾哦,要再等待群内成员多聊点之后再试试吗?", data.Hour) - default: - errMessage = fmt.Sprintf("最近 %d 小时内暂时没有超过 5 条的聊天记录可以生成聊天回顾哦,要再多聊点之后再试试吗?", data.Hour) - } - - return nil, tgbot. - NewMessageError(errMessage). - WithReply(replyToMessage) - } - - summarizations, err := h.chatHistories.SummarizeChatHistories(data.ChatID, histories) - if err != nil { - return nil, tgbot. - NewExceptionError(err).WithMessage("聊天记录回顾生成失败,请稍后再试!"). - WithReply(replyToMessage) - } - - summarizations = lo.Filter(summarizations, func(item string, _ int) bool { return item != "" }) - if len(summarizations) == 0 { - return nil, tgbot. - NewMessageError("聊天记录回顾生成失败,请稍后再试!"). - WithReply(replyToMessage) - } - - for i, s := range summarizations { - summarizations[i] = tgbot.ReplaceMarkdownTitlesToTelegramBoldElement(s) - } - - summarizationBatches := tgbot.SplitMessagesAgainstLengthLimitIntoMessageGroups(summarizations) - for i, s := range summarizationBatches { - var content string - if len(summarizationBatches) > 1 { - content = fmt.Sprintf("%s\n\n(%d/%d)\n#recap\n🤖️ Generated by chatGPT", strings.Join(s, "\n\n"), i+1, len(summarizationBatches)) - } else { - content = fmt.Sprintf("%s\n\n#recap\n🤖️ Generated by chatGPT", strings.Join(s, "\n\n")) - } - - msg := tgbotapi.NewMessage(c.Update.CallbackQuery.Message.Chat.ID, content) - msg.ParseMode = tgbotapi.ModeHTML - - if c.Update.CallbackQuery.Message.ReplyToMessage != nil { - msg.ReplyToMessageID = c.Update.CallbackQuery.Message.ReplyToMessage.MessageID - } - - h.logger.Info("sending chat histories recap for chat", - zap.Int64("chat_id", c.Update.CallbackQuery.Message.Chat.ID), - zap.String("text", msg.Text), - ) - - c.Bot.MaySend(msg) - } - - return nil, nil -} - func (h *CallbackQueryHandler) handleCallbackQueryToggle(c *tgbot.Context) (tgbot.Response, error) { msg := c.Update.CallbackQuery.Message @@ -474,6 +359,7 @@ func (h *CallbackQueryHandler) handleCallbackQueryUnsubscribe(c *tgbot.Context) WithReplyMarkup(tgbotapi.NewInlineKeyboardMarkup(msg.ReplyMarkup.InlineKeyboard...)) } if actionData.ChatID != chatID || actionData.FromID != fromID { + h.logger.Warn("action skipped, callback query is not from the same actor or the same chat", zap.Int64("from_id", fromID), zap.Int64("chat_id", chatID)) return nil, nil } @@ -486,9 +372,15 @@ func (h *CallbackQueryHandler) handleCallbackQueryUnsubscribe(c *tgbot.Context) WithReplyMarkup(tgbotapi.NewInlineKeyboardMarkup(msg.ReplyMarkup.InlineKeyboard...)) } - c.Bot.MayRequest(tgbotapi.NewEditMessageReplyMarkup(chatID, msg.MessageID, tgbotapi.InlineKeyboardMarkup{ - InlineKeyboard: make([][]tgbotapi.InlineKeyboardButton, 0), - })) + var inlineKeyboardMarkup tgbotapi.InlineKeyboardMarkup + if msg.ReplyMarkup == nil { + inlineKeyboardMarkup = tgbotapi.NewInlineKeyboardMarkup() + } else { + inlineKeyboardMarkup = *msg.ReplyMarkup + inlineKeyboardMarkup = c.Bot.RemoveInlineKeyboardButtonFromInlineKeyboardMarkupThatMatchesDataWith(inlineKeyboardMarkup, c.Update.CallbackQuery.Data) + } + + c.Bot.MayRequest(tgbotapi.NewEditMessageReplyMarkup(chatID, msg.MessageID, inlineKeyboardMarkup)) return c.NewMessage(fmt.Sprintf("已成功取消订阅群组 %s 的定时聊天回顾。", tgbot.EscapeHTMLSymbols(actionData.ChatTitle))).WithParseModeHTML(), nil } diff --git a/internal/bots/telegram/handlers/recap/feedback_callback_query.go b/internal/bots/telegram/handlers/recap/feedback_callback_query.go new file mode 100644 index 0000000..a15fe3e --- /dev/null +++ b/internal/bots/telegram/handlers/recap/feedback_callback_query.go @@ -0,0 +1,137 @@ +package recap + +import ( + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" + "github.com/google/uuid" + "github.com/nekomeowww/insights-bot/ent/feedbackchathistoriesrecapsreactions" + "github.com/nekomeowww/insights-bot/pkg/bots/tgbot" + "github.com/nekomeowww/insights-bot/pkg/types/bot/handlers/recap" + "go.uber.org/zap" +) + +func (h *CallbackQueryHandler) handleCallbackQueryReact(c *tgbot.Context) (tgbot.Response, error) { + messageID := c.Update.CallbackQuery.Message.MessageID + + var data recap.FeedbackRecapReactionActionData + + err := c.BindFromCallbackQueryData(&data) + if err != nil { + h.logger.Error("failed to bind callback query data", + zap.Error(err), + zap.Int("message_id", messageID), + zap.Int64("chat_id", c.Update.CallbackQuery.Message.Chat.ID), + zap.Int64("from_id", c.Update.CallbackQuery.From.ID), + zap.String("data", c.Update.CallbackQuery.Data), + ) + + return nil, nil + } + + logID, err := uuid.Parse(data.LogID) + if err != nil { + h.logger.Error("failed to parse log id", + zap.Error(err), + zap.Int("message_id", messageID), + zap.Int64("chat_id", data.ChatID), + zap.Int64("from_id", c.Update.CallbackQuery.From.ID), + zap.String("log_id", data.LogID), + ) + + return nil, nil + } + + switch data.Type { + case feedbackchathistoriesrecapsreactions.TypeNone: + return nil, nil + case feedbackchathistoriesrecapsreactions.TypeUpVote, feedbackchathistoriesrecapsreactions.TypeDownVote, feedbackchathistoriesrecapsreactions.TypeLmao: + err = h.chatHistories.FeedbackRecapsReactToChatIDAndLogID(data.ChatID, logID, c.Update.CallbackQuery.From.ID, data.Type) + default: + return nil, nil + } + if err != nil { + h.logger.Error("failed to react to recap of chat id and log id", + zap.Error(err), + zap.Int("message_id", messageID), + zap.Int64("from_id", c.Update.CallbackQuery.From.ID), + zap.Int64("chat_id", data.ChatID), + zap.String("log_id", data.LogID), + zap.String("action", "up vote"), + ) + + return nil, nil + } + + counts, err := h.chatHistories.FindFeedbackRecapsReactionCountsForChatIDAndLogID(data.ChatID, logID) + if err != nil { + h.logger.Error("failed to find feedback recaps reactions for chat id and log id", + zap.Error(err), + zap.Int("message_id", messageID), + zap.Int64("from_id", c.Update.CallbackQuery.From.ID), + zap.Int64("chat_id", data.ChatID), + zap.String("log_id", data.LogID), + ) + + return nil, nil + } + + upVoteButton, err := h.chatHistories.NewFeedbackRecapsUpVoteButton(c.Bot, data.ChatID, logID, counts.UpVotes) + if err != nil { + h.logger.Error("failed to new up vote recap inline keyboard markup", + zap.Error(err), + zap.Int("message_id", messageID), + zap.Int64("from_id", c.Update.CallbackQuery.From.ID), + zap.Int64("chat_id", data.ChatID), + zap.String("log_id", data.LogID), + ) + + return nil, nil + } + + downVoteButton, err := h.chatHistories.NewFeedbackRecapsDownVoteButton(c.Bot, data.ChatID, logID, counts.DownVotes) + if err != nil { + h.logger.Error("failed to new down vote recap inline keyboard markup", + zap.Error(err), + zap.Int("message_id", messageID), + zap.Int64("from_id", c.Update.CallbackQuery.From.ID), + zap.Int64("chat_id", data.ChatID), + zap.String("log_id", data.LogID), + ) + + return nil, nil + } + + lmaoButton, err := h.chatHistories.NewFeedbackRecapsLmaoButton(c.Bot, data.ChatID, logID, counts.Lmao) + if err != nil { + h.logger.Error("failed to new lmao recap inline keyboard markup", + zap.Error(err), + zap.Int("message_id", messageID), + zap.Int64("from_id", c.Update.CallbackQuery.From.ID), + zap.Int64("chat_id", data.ChatID), + zap.String("log_id", data.LogID), + ) + + return nil, nil + } + + inlineKeyboardMarkup := c.Update.CallbackQuery.Message.ReplyMarkup + if inlineKeyboardMarkup == nil || len(inlineKeyboardMarkup.InlineKeyboard) == 0 { + return nil, nil + } + + for i := range inlineKeyboardMarkup.InlineKeyboard { + for j := range inlineKeyboardMarkup.InlineKeyboard[i] { + if inlineKeyboardMarkup.InlineKeyboard[i][j].CallbackData == nil { + continue + } + if *inlineKeyboardMarkup.InlineKeyboard[i][j].CallbackData != c.Update.CallbackQuery.Data { + continue + } + + inlineKeyboardMarkup.InlineKeyboard[i] = tgbotapi.NewInlineKeyboardRow(upVoteButton, downVoteButton, lmaoButton) + } + } + + c.Bot.MayRequest(tgbotapi.NewEditMessageReplyMarkup(data.ChatID, messageID, *inlineKeyboardMarkup)) + + return nil, nil +} diff --git a/internal/bots/telegram/handlers/recap/recap.go b/internal/bots/telegram/handlers/recap/recap.go index 8fdb3d5..e15e5aa 100644 --- a/internal/bots/telegram/handlers/recap/recap.go +++ b/internal/bots/telegram/handlers/recap/recap.go @@ -56,6 +56,7 @@ func (h *Handlers) Install(dispatcher *tgbot.Dispatcher) { dispatcher.OnCallbackQuery("recap/configure/assign_mode", tgbot.NewHandler(h.callbackQuery.handleCallbackQueryAssignMode)) dispatcher.OnCallbackQuery("recap/configure/complete", tgbot.NewHandler(h.callbackQuery.handleCallbackQueryComplete)) dispatcher.OnCallbackQuery("recap/unsubscribe_recap", tgbot.NewHandler(h.callbackQuery.handleCallbackQueryUnsubscribe)) + dispatcher.OnCallbackQuery("recap/recap/feedback/react", tgbot.NewHandler(h.callbackQuery.handleCallbackQueryReact)) dispatcher.OnLeftChatMember(tgbot.NewHandler(h.command.handleChatMemberLeft)) } diff --git a/internal/bots/telegram/handlers/recap/recap_callback_query.go b/internal/bots/telegram/handlers/recap/recap_callback_query.go new file mode 100644 index 0000000..d955a2b --- /dev/null +++ b/internal/bots/telegram/handlers/recap/recap_callback_query.go @@ -0,0 +1,143 @@ +package recap + +import ( + "fmt" + "strings" + "time" + + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" + "github.com/samber/lo" + "go.uber.org/zap" + + "github.com/nekomeowww/insights-bot/pkg/bots/tgbot" + "github.com/nekomeowww/insights-bot/pkg/types/bot/handlers/recap" + "github.com/nekomeowww/insights-bot/pkg/types/tgchat" +) + +func (h *CallbackQueryHandler) handleCallbackQuerySelectHours(c *tgbot.Context) (tgbot.Response, error) { + messageID := c.Update.CallbackQuery.Message.MessageID + + replyToMessage := c.Update.CallbackQuery.Message.ReplyToMessage + + var data recap.SelectHourCallbackQueryData + + err := c.BindFromCallbackQueryData(&data) + if err != nil { + return nil, tgbot. + NewExceptionError(err). + WithMessage("聊天记录回顾生成失败,请稍后再试!"). + WithReply(replyToMessage) + } + if !lo.Contains(RecapSelectHourAvailable, data.Hour) { + return nil, tgbot. + NewExceptionError(fmt.Errorf("invalid hour: %d", data.Hour)). + WithReply(replyToMessage) + } + + var inProgressText string + + switch data.RecapMode { + case tgchat.AutoRecapSendModePublicly: + inProgressText = fmt.Sprintf("正在为过去 %d 个小时的聊天记录生成回顾,请稍等...", data.Hour) + case tgchat.AutoRecapSendModeOnlyPrivateSubscriptions: + inProgressText = fmt.Sprintf("正在为 %s 过去 %d 个小时的聊天记录生成回顾,请稍等...", tgbot.EscapeHTMLSymbols(data.ChatTitle), data.Hour) + default: + inProgressText = fmt.Sprintf("正在为过去 %d 个小时的聊天记录生成回顾,请稍等...", data.Hour) + } + + editConfig := tgbotapi.NewEditMessageTextAndMarkup( + c.Update.CallbackQuery.Message.Chat.ID, + messageID, + inProgressText, + tgbotapi.NewInlineKeyboardMarkup([]tgbotapi.InlineKeyboardButton{}), + ) + + editConfig.ParseMode = tgbotapi.ModeHTML + + _, err = c.Bot.Request(editConfig) + if err != nil { + h.logger.Error("failed to edit message", zap.Error(err)) + } + + histories, err := h.chatHistories.FindChatHistoriesByTimeBefore(data.ChatID, time.Duration(data.Hour)*time.Hour) + if err != nil { + return nil, tgbot. + NewExceptionError(err).WithMessage("聊天记录回顾生成失败,请稍后再试!"). + WithReply(replyToMessage) + } + if len(histories) <= 5 { + var errMessage string + + switch data.RecapMode { + case tgchat.AutoRecapSendModePublicly: + errMessage = fmt.Sprintf("最近 %d 小时内暂时没有超过 5 条的聊天记录可以生成聊天回顾哦,要再多聊点之后再试试吗?", data.Hour) + case tgchat.AutoRecapSendModeOnlyPrivateSubscriptions: + errMessage = fmt.Sprintf("最近 %d 小时内暂时没有超过 5 条的聊天记录可以生成聊天回顾哦,要再等待群内成员多聊点之后再试试吗?", data.Hour) + default: + errMessage = fmt.Sprintf("最近 %d 小时内暂时没有超过 5 条的聊天记录可以生成聊天回顾哦,要再多聊点之后再试试吗?", data.Hour) + } + + return nil, tgbot. + NewMessageError(errMessage). + WithReply(replyToMessage) + } + + logID, summarizations, err := h.chatHistories.SummarizeChatHistories(data.ChatID, histories) + if err != nil { + return nil, tgbot. + NewExceptionError(err).WithMessage("聊天记录回顾生成失败,请稍后再试!"). + WithReply(replyToMessage) + } + + counts, err := h.chatHistories.FindFeedbackRecapsReactionCountsForChatIDAndLogID(data.ChatID, logID) + if err != nil { + return nil, tgbot. + NewExceptionError(err).WithMessage("聊天记录回顾生成失败,请稍后再试!"). + WithReply(replyToMessage) + } + + inlineKeyboardMarkup, err := h.chatHistories.NewVoteRecapInlineKeyboardMarkup(c.Bot, data.ChatID, logID, counts.UpVotes, counts.DownVotes, counts.Lmao) + if err != nil { + return nil, tgbot. + NewExceptionError(err).WithMessage("聊天记录回顾生成失败,请稍后再试!"). + WithReply(replyToMessage) + } + + summarizations = lo.Filter(summarizations, func(item string, _ int) bool { return item != "" }) + if len(summarizations) == 0 { + return nil, tgbot. + NewMessageError("聊天记录回顾生成失败,请稍后再试!"). + WithReply(replyToMessage) + } + + for i, s := range summarizations { + summarizations[i] = tgbot.ReplaceMarkdownTitlesToTelegramBoldElement(s) + } + + summarizationBatches := tgbot.SplitMessagesAgainstLengthLimitIntoMessageGroups(summarizations) + for i, s := range summarizationBatches { + var content string + if len(summarizationBatches) > 1 { + content = fmt.Sprintf("%s\n\n(%d/%d)\n#recap\n🤖️ Generated by chatGPT", strings.Join(s, "\n\n"), i+1, len(summarizationBatches)) + } else { + content = fmt.Sprintf("%s\n\n#recap\n🤖️ Generated by chatGPT", strings.Join(s, "\n\n")) + } + + msg := tgbotapi.NewMessage(c.Update.CallbackQuery.Message.Chat.ID, content) + msg.ParseMode = tgbotapi.ModeHTML + msg.ReplyMarkup = inlineKeyboardMarkup + + if c.Update.CallbackQuery.Message.ReplyToMessage != nil { + msg.ReplyToMessageID = c.Update.CallbackQuery.Message.ReplyToMessage.MessageID + } + + h.logger.Info("sending chat histories recap for chat", + zap.Int64("chat_id", c.Update.CallbackQuery.Message.Chat.ID), + zap.String("text", msg.Text), + ) + + c.Bot.MaySend(msg) + } + + return nil, nil +} diff --git a/internal/bots/telegram/handlers/summarize/feedback_callback_query.go b/internal/bots/telegram/handlers/summarize/feedback_callback_query.go new file mode 100644 index 0000000..ec15b51 --- /dev/null +++ b/internal/bots/telegram/handlers/summarize/feedback_callback_query.go @@ -0,0 +1,94 @@ +package summarize + +import ( + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" + "github.com/google/uuid" + "github.com/nekomeowww/insights-bot/ent/feedbacksummarizationsreactions" + "github.com/nekomeowww/insights-bot/pkg/bots/tgbot" + "github.com/nekomeowww/insights-bot/pkg/types/bot/handlers/recap" + "go.uber.org/zap" +) + +func (h *Handlers) handleCallbackQueryReact(c *tgbot.Context) (tgbot.Response, error) { + h.logger.Info("handling callback query react") + messageID := c.Update.CallbackQuery.Message.MessageID + + var data recap.FeedbackSummarizationReactionActionData + + err := c.BindFromCallbackQueryData(&data) + if err != nil { + h.logger.Error("failed to bind callback query data", + zap.Error(err), + zap.Int("message_id", messageID), + zap.Int64("chat_id", c.Update.CallbackQuery.Message.Chat.ID), + zap.Int64("from_id", c.Update.CallbackQuery.From.ID), + zap.String("data", c.Update.CallbackQuery.Data), + ) + + return nil, nil + } + + logID, err := uuid.Parse(data.LogID) + if err != nil { + h.logger.Error("failed to parse log id", + zap.Error(err), + zap.Int("message_id", messageID), + zap.Int64("chat_id", data.ChatID), + zap.Int64("from_id", c.Update.CallbackQuery.From.ID), + zap.String("log_id", data.LogID), + ) + + return nil, nil + } + + switch data.Type { + case feedbacksummarizationsreactions.TypeNone: + return nil, nil + case feedbacksummarizationsreactions.TypeUpVote, feedbacksummarizationsreactions.TypeDownVote, feedbacksummarizationsreactions.TypeLmao: + err = h.smr.FeedbackReactSummarizationsToChatIDAndLogID(data.ChatID, logID, c.Update.CallbackQuery.From.ID, data.Type) + default: + return nil, nil + } + if err != nil { + h.logger.Error("failed to react to recap of chat id and log id", + zap.Error(err), + zap.Int("message_id", messageID), + zap.Int64("from_id", c.Update.CallbackQuery.From.ID), + zap.Int64("chat_id", data.ChatID), + zap.String("log_id", data.LogID), + zap.String("action", "up vote"), + ) + + return nil, nil + } + + counts, err := h.smr.FindFeedbackSummarizationsReactionCountsForChatIDAndLogID(data.ChatID, logID) + if err != nil { + h.logger.Error("failed to find feedback recaps reactions for chat id and log id", + zap.Error(err), + zap.Int("message_id", messageID), + zap.Int64("from_id", c.Update.CallbackQuery.From.ID), + zap.Int64("chat_id", data.ChatID), + zap.String("log_id", data.LogID), + ) + + return nil, nil + } + + inlineKeyboardMarkup, err := h.smr.NewVoteSummarizationsReactionsInlineKeyboardMarkup(c.Bot, data.ChatID, logID, counts.UpVotes, counts.DownVotes, counts.Lmao) + if err != nil { + h.logger.Error("failed to new up vote recap inline keyboard markup", + zap.Error(err), + zap.Int("message_id", messageID), + zap.Int64("from_id", c.Update.CallbackQuery.From.ID), + zap.Int64("chat_id", data.ChatID), + zap.String("log_id", data.LogID), + ) + + return nil, nil + } + + c.Bot.MayRequest(tgbotapi.NewEditMessageReplyMarkup(data.ChatID, messageID, inlineKeyboardMarkup)) + + return nil, nil +} diff --git a/internal/bots/telegram/handlers/summarize/summarize.go b/internal/bots/telegram/handlers/summarize/summarize.go index e4a83ca..36b1a9b 100644 --- a/internal/bots/telegram/handlers/summarize/summarize.go +++ b/internal/bots/telegram/handlers/summarize/summarize.go @@ -48,4 +48,5 @@ func (h *Handlers) Install(dispatcher *tgbot.Dispatcher) { }) dispatcher.OnChannelPost(tgbot.NewHandler(h.HandleChannelPost)) + dispatcher.OnCallbackQuery("smr/summarization/feedback/react", tgbot.NewHandler(h.handleCallbackQueryReact)) } diff --git a/internal/models/chathistories/chat_histories.go b/internal/models/chathistories/chat_histories.go index 61349b6..5a0943b 100644 --- a/internal/models/chathistories/chat_histories.go +++ b/internal/models/chathistories/chat_histories.go @@ -11,6 +11,7 @@ import ( "entgo.io/ent/dialect/sql" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" + "github.com/google/uuid" "github.com/samber/lo" lop "github.com/samber/lo/parallel" "go.uber.org/fx" @@ -341,7 +342,7 @@ func formatFullNameAndUsername(fullName, username string) string { return strings.ReplaceAll(fullName, "#", "") } -func (m *Model) SummarizeChatHistories(chatID int64, histories []*ent.ChatHistories) ([]string, error) { +func (m *Model) SummarizeChatHistories(chatID int64, histories []*ent.ChatHistories) (uuid.UUID, []string, error) { historiesLLMFriendly := make([]string, 0, len(histories)) historiesIncludedMessageIDs := make([]int64, 0) @@ -377,15 +378,15 @@ func (m *Model) SummarizeChatHistories(chatID int64, histories []*ent.ChatHistor summarizations, statusUsage, err := m.summarizeChatHistories(chatID, historiesIncludedMessageIDs, chatHistories) if err != nil { - return make([]string, 0), err + return uuid.Nil, make([]string, 0), err } ss, err := m.renderRecapTemplates(chatID, summarizations) if err != nil { - return make([]string, 0), err + return uuid.Nil, make([]string, 0), err } - err = m.ent.LogChatHistoriesRecap. + saved, err := m.ent.LogChatHistoriesRecap. Create(). SetChatID(chatID). SetRecapInputs(chatHistories). @@ -396,10 +397,10 @@ func (m *Model) SummarizeChatHistories(chatID int64, histories []*ent.ChatHistor SetFromPlatform(int(FromPlatformTelegram)). SetRecapType(int(RecapTypeForGroup)). SetModelName(m.openAI.GetModelName()). - Exec(context.Background()) + Save(context.Background()) if err != nil { - return make([]string, 0), err + return uuid.Nil, make([]string, 0), err } - return ss, nil + return saved.ID, ss, nil } diff --git a/internal/models/chathistories/feedbacks.go b/internal/models/chathistories/feedbacks.go new file mode 100644 index 0000000..aa53d03 --- /dev/null +++ b/internal/models/chathistories/feedbacks.go @@ -0,0 +1,195 @@ +package chathistories + +import ( + "context" + "fmt" + + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" + "github.com/google/uuid" + "github.com/samber/lo" + + "github.com/nekomeowww/insights-bot/ent" + "github.com/nekomeowww/insights-bot/ent/feedbackchathistoriesrecapsreactions" + "github.com/nekomeowww/insights-bot/pkg/bots/tgbot" + "github.com/nekomeowww/insights-bot/pkg/types/bot/handlers/recap" +) + +type FeedbackChatHistoriesRecapsReactionsCounts struct { + UpVotes int + DownVotes int + Lmao int +} + +func (m *Model) FindFeedbackRecapsReactionCountsForChatIDAndLogID(chatID int64, logID uuid.UUID) (FeedbackChatHistoriesRecapsReactionsCounts, error) { + votes, err := m.ent.FeedbackChatHistoriesRecapsReactions. + Query(). + Where( + feedbackchathistoriesrecapsreactions.ChatIDEQ(chatID), + feedbackchathistoriesrecapsreactions.LogIDEQ(logID), + ). + All(context.TODO()) + if err != nil { + return FeedbackChatHistoriesRecapsReactionsCounts{}, err + } + + upVotes := len(lo.Filter(votes, func(item *ent.FeedbackChatHistoriesRecapsReactions, _ int) bool { + return item.Type == feedbackchathistoriesrecapsreactions.TypeUpVote + })) + downVotes := len(lo.Filter(votes, func(item *ent.FeedbackChatHistoriesRecapsReactions, _ int) bool { + return item.Type == feedbackchathistoriesrecapsreactions.TypeDownVote + })) + lmaos := len(lo.Filter(votes, func(item *ent.FeedbackChatHistoriesRecapsReactions, _ int) bool { + return item.Type == feedbackchathistoriesrecapsreactions.TypeLmao + })) + + return FeedbackChatHistoriesRecapsReactionsCounts{ + UpVotes: upVotes, + DownVotes: downVotes, + Lmao: lmaos, + }, nil +} + +func (m *Model) FeedbackRecapsReactToChatIDAndLogID(chatID int64, logID uuid.UUID, userID int64, reactionType feedbackchathistoriesrecapsreactions.Type) error { + affectedRows, err := m.ent.FeedbackChatHistoriesRecapsReactions. + Delete(). + Where( + feedbackchathistoriesrecapsreactions.ChatIDEQ(chatID), + feedbackchathistoriesrecapsreactions.LogIDEQ(logID), + feedbackchathistoriesrecapsreactions.UserIDEQ(userID), + feedbackchathistoriesrecapsreactions.TypeEQ(reactionType), + ). + Exec(context.Background()) + if err != nil { + return err + } + if affectedRows > 0 { + return nil + } + + _, err = m.ent.FeedbackChatHistoriesRecapsReactions. + Delete(). + Where( + feedbackchathistoriesrecapsreactions.ChatIDEQ(chatID), + feedbackchathistoriesrecapsreactions.LogIDEQ(logID), + feedbackchathistoriesrecapsreactions.UserIDEQ(userID), + ). + Exec(context.Background()) + if err != nil { + return err + } + + err = m.ent.FeedbackChatHistoriesRecapsReactions. + Create(). + SetChatID(chatID). + SetLogID(logID). + SetUserID(userID). + SetType(reactionType). + Exec(context.Background()) + if err != nil { + return err + } + + return nil +} + +func (m *Model) NewFeedbackRecapsUpVoteButton(bot *tgbot.Bot, chatID int64, logID uuid.UUID, upVoteCount int) (tgbotapi.InlineKeyboardButton, error) { + upVoteData, err := bot.AssignOneCallbackQueryData("smr/summarization/feedback/react", recap.FeedbackRecapReactionActionData{ChatID: chatID, Type: feedbackchathistoriesrecapsreactions.TypeUpVote, LogID: logID.String()}) + if err != nil { + return tgbotapi.InlineKeyboardButton{}, err + } + + upVoteButtonText := fmt.Sprintf("👍 %d", upVoteCount) + if upVoteCount <= 0 { + upVoteButtonText = "👍" + } + + return tgbotapi.NewInlineKeyboardButtonData(upVoteButtonText, upVoteData), nil +} + +func (m *Model) NewFeedbackRecapsDownVoteButton(bot *tgbot.Bot, chatID int64, logID uuid.UUID, downVoteCount int) (tgbotapi.InlineKeyboardButton, error) { + downVoteData, err := bot.AssignOneCallbackQueryData("smr/summarization/feedback/react", recap.FeedbackRecapReactionActionData{ChatID: chatID, Type: feedbackchathistoriesrecapsreactions.TypeDownVote, LogID: logID.String()}) + if err != nil { + return tgbotapi.InlineKeyboardButton{}, err + } + + downVoteButtonText := fmt.Sprintf("👎 %d", downVoteCount) + if downVoteCount <= 0 { + downVoteButtonText = "👎" + } + + return tgbotapi.NewInlineKeyboardButtonData(downVoteButtonText, downVoteData), nil +} + +func (m *Model) NewFeedbackRecapsLmaoButton(bot *tgbot.Bot, chatID int64, logID uuid.UUID, downVoteCount int) (tgbotapi.InlineKeyboardButton, error) { + lmaoData, err := bot.AssignOneCallbackQueryData("smr/summarization/feedback/react", recap.FeedbackRecapReactionActionData{ChatID: chatID, Type: feedbackchathistoriesrecapsreactions.TypeLmao, LogID: logID.String()}) + if err != nil { + return tgbotapi.InlineKeyboardButton{}, err + } + + lmaoButtonText := fmt.Sprintf("🤣 %d", downVoteCount) + if downVoteCount <= 0 { + lmaoButtonText = "🤣" + } + + return tgbotapi.NewInlineKeyboardButtonData(lmaoButtonText, lmaoData), nil +} + +func (m *Model) NewVoteRecapInlineKeyboardMarkup(bot *tgbot.Bot, chatID int64, logID uuid.UUID, upVoteCount int, downVoteCount int, lmaoCount int) (tgbotapi.InlineKeyboardMarkup, error) { + upVoteButton, err := m.NewFeedbackRecapsUpVoteButton(bot, chatID, logID, upVoteCount) + if err != nil { + return tgbotapi.InlineKeyboardMarkup{}, err + } + + downVoteButton, err := m.NewFeedbackRecapsDownVoteButton(bot, chatID, logID, downVoteCount) + if err != nil { + return tgbotapi.InlineKeyboardMarkup{}, err + } + + lmaoButton, err := m.NewFeedbackRecapsLmaoButton(bot, chatID, logID, lmaoCount) + if err != nil { + return tgbotapi.InlineKeyboardMarkup{}, err + } + + return tgbotapi.NewInlineKeyboardMarkup( + tgbotapi.NewInlineKeyboardRow( + upVoteButton, + downVoteButton, + lmaoButton, + ), + ), nil +} + +func (m *Model) NewVoteRecapWithUnsubscribeInlineKeyboardMarkup(bot *tgbot.Bot, chatID int64, chatTitle string, fromID int64, logID uuid.UUID, upVoteCount int, downVoteCount int, lmaoCount int) (tgbotapi.InlineKeyboardMarkup, error) { + upVoteButton, err := m.NewFeedbackRecapsUpVoteButton(bot, chatID, logID, upVoteCount) + if err != nil { + return tgbotapi.InlineKeyboardMarkup{}, err + } + + downVoteButton, err := m.NewFeedbackRecapsDownVoteButton(bot, chatID, logID, downVoteCount) + if err != nil { + return tgbotapi.InlineKeyboardMarkup{}, err + } + + lmaoButton, err := m.NewFeedbackRecapsLmaoButton(bot, chatID, logID, lmaoCount) + if err != nil { + return tgbotapi.InlineKeyboardMarkup{}, err + } + + buttonData, err := bot.AssignOneCallbackQueryData("recap/unsubscribe_recap", recap.UnsubscribeRecapActionData{ + ChatID: chatID, + ChatTitle: chatTitle, + FromID: fromID, + }) + if err != nil { + return tgbotapi.InlineKeyboardMarkup{}, err + } + + return tgbotapi.NewInlineKeyboardMarkup( + tgbotapi.NewInlineKeyboardRow( + upVoteButton, + downVoteButton, + lmaoButton, + ), + tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData("取消订阅", buttonData)), + ), nil +} diff --git a/internal/models/smr/feedbacks.go b/internal/models/smr/feedbacks.go new file mode 100644 index 0000000..e23733c --- /dev/null +++ b/internal/models/smr/feedbacks.go @@ -0,0 +1,181 @@ +package smr + +import ( + "context" + "fmt" + + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" + "github.com/google/uuid" + "github.com/samber/lo" + + "github.com/nekomeowww/insights-bot/ent" + "github.com/nekomeowww/insights-bot/ent/feedbacksummarizationsreactions" + "github.com/nekomeowww/insights-bot/pkg/bots/tgbot" + "github.com/nekomeowww/insights-bot/pkg/types/bot/handlers/recap" +) + +type FeedbackSummarizationsReactionsCounts struct { + UpVotes int + DownVotes int + Lmao int +} + +func (m *Model) FindFeedbackSummarizationsReactionCountsForChatIDAndLogID(chatID int64, logID uuid.UUID) (FeedbackSummarizationsReactionsCounts, error) { + votes, err := m.ent.FeedbackSummarizationsReactions. + Query(). + Where( + feedbacksummarizationsreactions.ChatIDEQ(chatID), + feedbacksummarizationsreactions.LogIDEQ(logID), + ). + All(context.TODO()) + if err != nil { + return FeedbackSummarizationsReactionsCounts{}, err + } + + upVotes := len(lo.Filter(votes, func(item *ent.FeedbackSummarizationsReactions, _ int) bool { + return item.Type == feedbacksummarizationsreactions.TypeUpVote + })) + downVotes := len(lo.Filter(votes, func(item *ent.FeedbackSummarizationsReactions, _ int) bool { + return item.Type == feedbacksummarizationsreactions.TypeDownVote + })) + lmaos := len(lo.Filter(votes, func(item *ent.FeedbackSummarizationsReactions, _ int) bool { + return item.Type == feedbacksummarizationsreactions.TypeLmao + })) + + return FeedbackSummarizationsReactionsCounts{ + UpVotes: upVotes, + DownVotes: downVotes, + Lmao: lmaos, + }, nil +} + +func (m *Model) HasFeedbackReactSummarizationsToChatIDAndLogID(chatID int64, logID uuid.UUID, userID int64, reactionType feedbacksummarizationsreactions.Type) (bool, error) { + existing, err := m.ent.FeedbackSummarizationsReactions. + Query(). + Where( + feedbacksummarizationsreactions.ChatIDEQ(chatID), + feedbacksummarizationsreactions.LogIDEQ(logID), + feedbacksummarizationsreactions.UserIDEQ(userID), + feedbacksummarizationsreactions.TypeEQ(reactionType), + ). + First(context.Background()) + if err != nil { + if ent.IsNotFound(err) { + return false, nil + } + + return false, err + } + + return existing != nil, nil +} + +func (m *Model) FeedbackReactSummarizationsToChatIDAndLogID(chatID int64, logID uuid.UUID, userID int64, reactionType feedbacksummarizationsreactions.Type) error { + affectedRows, err := m.ent.FeedbackSummarizationsReactions. + Delete(). + Where( + feedbacksummarizationsreactions.ChatIDEQ(chatID), + feedbacksummarizationsreactions.LogIDEQ(logID), + feedbacksummarizationsreactions.UserIDEQ(userID), + feedbacksummarizationsreactions.TypeEQ(reactionType), + ). + Exec(context.Background()) + if err != nil { + return err + } + if affectedRows > 0 { + return nil + } + + _, err = m.ent.FeedbackSummarizationsReactions. + Delete(). + Where( + feedbacksummarizationsreactions.ChatIDEQ(chatID), + feedbacksummarizationsreactions.LogIDEQ(logID), + feedbacksummarizationsreactions.UserIDEQ(userID), + ). + Exec(context.Background()) + if err != nil { + return err + } + + err = m.ent.FeedbackSummarizationsReactions. + Create(). + SetChatID(chatID). + SetLogID(logID). + SetUserID(userID). + SetType(reactionType). + Exec(context.Background()) + if err != nil { + return err + } + + return nil +} + +func (m *Model) NewFeedbackSummarizationsUpVoteReactionButton(bot *tgbot.Bot, chatID int64, logID uuid.UUID, upVoteCount int) (tgbotapi.InlineKeyboardButton, error) { + upVoteData, err := bot.AssignOneCallbackQueryData("smr/summarization/feedback/react", recap.FeedbackSummarizationReactionActionData{ChatID: chatID, Type: feedbacksummarizationsreactions.TypeUpVote, LogID: logID.String()}) + if err != nil { + return tgbotapi.InlineKeyboardButton{}, err + } + + upVoteButtonText := fmt.Sprintf("👍 %d", upVoteCount) + if upVoteCount <= 0 { + upVoteButtonText = "👍" + } + + return tgbotapi.NewInlineKeyboardButtonData(upVoteButtonText, upVoteData), nil +} + +func (m *Model) NewFeedbackSummarizationsDownVoteReactionButton(bot *tgbot.Bot, chatID int64, logID uuid.UUID, downVoteCount int) (tgbotapi.InlineKeyboardButton, error) { + downVoteData, err := bot.AssignOneCallbackQueryData("smr/summarization/feedback/react", recap.FeedbackSummarizationReactionActionData{ChatID: chatID, Type: feedbacksummarizationsreactions.TypeDownVote, LogID: logID.String()}) + if err != nil { + return tgbotapi.InlineKeyboardButton{}, err + } + + downVoteButtonText := fmt.Sprintf("👎 %d", downVoteCount) + if downVoteCount <= 0 { + downVoteButtonText = "👎" + } + + return tgbotapi.NewInlineKeyboardButtonData(downVoteButtonText, downVoteData), nil +} + +func (m *Model) NewFeedbackSummarizationsLmaoReactionButton(bot *tgbot.Bot, chatID int64, logID uuid.UUID, downVoteCount int) (tgbotapi.InlineKeyboardButton, error) { + lmaoData, err := bot.AssignOneCallbackQueryData("smr/summarization/feedback/react", recap.FeedbackSummarizationReactionActionData{ChatID: chatID, Type: feedbacksummarizationsreactions.TypeLmao, LogID: logID.String()}) + if err != nil { + return tgbotapi.InlineKeyboardButton{}, err + } + + lmaoButtonText := fmt.Sprintf("🤣 %d", downVoteCount) + if downVoteCount <= 0 { + lmaoButtonText = "🤣" + } + + return tgbotapi.NewInlineKeyboardButtonData(lmaoButtonText, lmaoData), nil +} + +func (m *Model) NewVoteSummarizationsReactionsInlineKeyboardMarkup(bot *tgbot.Bot, chatID int64, logID uuid.UUID, upVoteCount int, downVoteCount int, lmaoCount int) (tgbotapi.InlineKeyboardMarkup, error) { + upVoteButton, err := m.NewFeedbackSummarizationsUpVoteReactionButton(bot, chatID, logID, upVoteCount) + if err != nil { + return tgbotapi.InlineKeyboardMarkup{}, err + } + + downVoteButton, err := m.NewFeedbackSummarizationsDownVoteReactionButton(bot, chatID, logID, downVoteCount) + if err != nil { + return tgbotapi.InlineKeyboardMarkup{}, err + } + + lmaoButton, err := m.NewFeedbackSummarizationsLmaoReactionButton(bot, chatID, logID, lmaoCount) + if err != nil { + return tgbotapi.InlineKeyboardMarkup{}, err + } + + return tgbotapi.NewInlineKeyboardMarkup( + tgbotapi.NewInlineKeyboardRow( + upVoteButton, + downVoteButton, + lmaoButton, + ), + ), nil +} diff --git a/internal/models/smr/smr.go b/internal/models/smr/smr.go index 51e23f3..cf6a47c 100644 --- a/internal/models/smr/smr.go +++ b/internal/models/smr/smr.go @@ -10,6 +10,7 @@ import ( "strings" "time" + "github.com/google/uuid" "github.com/imroc/req/v3" "github.com/go-shiori/go-readability" @@ -64,6 +65,7 @@ var ( ) type URLSummarizationOutput struct { + ID uuid.UUID URL string Title string Msg string @@ -112,7 +114,7 @@ func (m *Model) SummarizeInputURL(ctx context.Context, url string, fromPlatform m.logger.Info("✅ summarizing article done", zap.String("title", article.Title), zap.String("url", url)) - err = m.ent.LogSummarizations. + saved, err := m.ent.LogSummarizations. Create(). SetContentURL(url). SetContentTitle(article.Title). @@ -124,13 +126,14 @@ func (m *Model) SummarizeInputURL(ctx context.Context, url string, fromPlatform SetPromptTokenUsage(resp.Usage.PromptTokens). SetTotalTokenUsage(resp.Usage.TotalTokens). SetModelName(m.openai.GetModelName()). - Exec(context.Background()) + Save(context.Background()) if err != nil { m.logger.Error("failed to create log", zap.Error(err)) return nil, err } return &URLSummarizationOutput{ + ID: saved.ID, URL: url, Title: article.Title, Msg: respMessages[0], diff --git a/internal/services/autorecap/autorecap.go b/internal/services/autorecap/autorecap.go index e8c712b..3f63d56 100644 --- a/internal/services/autorecap/autorecap.go +++ b/internal/services/autorecap/autorecap.go @@ -22,7 +22,6 @@ import ( "github.com/nekomeowww/insights-bot/internal/models/tgchats" "github.com/nekomeowww/insights-bot/pkg/bots/tgbot" "github.com/nekomeowww/insights-bot/pkg/logger" - "github.com/nekomeowww/insights-bot/pkg/types/bot/handlers/recap" "github.com/nekomeowww/insights-bot/pkg/types/telegram" "github.com/nekomeowww/insights-bot/pkg/types/tgchat" "github.com/nekomeowww/insights-bot/pkg/types/timecapsules" @@ -157,7 +156,7 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca histories, err := m.chathistories.FindLastSixHourChatHistories(chatID) if err != nil { - m.logger.Error("failed to find last six hour chat histories", zap.Error(err)) + m.logger.Error("failed to find last six hour chat histories", zap.Error(err), zap.Int64("chat_id", chatID)) return } if len(histories) <= 5 { @@ -167,15 +166,27 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca chatTitle := histories[len(histories)-1].ChatTitle - summarizations, err := m.chathistories.SummarizeChatHistories(chatID, histories) + logID, summarizations, err := m.chathistories.SummarizeChatHistories(chatID, histories) if err != nil { - m.logger.Error("failed to summarize last six hour chat histories", zap.Error(err)) + m.logger.Error("failed to summarize last six hour chat histories", zap.Error(err), zap.Int64("chat_id", chatID)) + return + } + + counts, err := m.chathistories.FindFeedbackRecapsReactionCountsForChatIDAndLogID(chatID, logID) + if err != nil { + m.logger.Error("failed to find feedback recaps votes for chat", zap.Error(err), zap.Int64("chat_id", chatID)) + return + } + + inlineKeyboardMarkup, err := m.chathistories.NewVoteRecapInlineKeyboardMarkup(m.botService.Bot(), chatID, logID, counts.UpVotes, counts.DownVotes, counts.Lmao) + if err != nil { + m.logger.Error("failed to create vote recap inline keyboard markup", zap.Error(err), zap.Int64("chat_id", chatID), zap.String("log_id", logID.String())) return } summarizations = lo.Filter(summarizations, func(item string, _ int) bool { return item != "" }) if len(summarizations) == 0 { - m.logger.Warn("summarization is empty") + m.logger.Warn("summarization is empty", zap.Int64("chat_id", chatID)) return } @@ -209,7 +220,7 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca }, }) if err != nil { - m.logger.Error("failed to get chat member", zap.Error(err)) + m.logger.Error("failed to get chat member", zap.Error(err), zap.Int64("chat_id", chatID)) continue } if !lo.Contains([]telegram.MemberStatus{ @@ -242,7 +253,7 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca return nil }) if err != nil { - m.logger.Error("failed to unsubscribe to auto recaps", zap.Error(err)) + m.logger.Error("failed to unsubscribe to auto recaps", zap.Error(err), zap.Int64("chat_id", chatID)) } msg := tgbotapi.NewMessage(subscriber.UserID, fmt.Sprintf("由于您已不再是 %s 的成员,因此已自动帮您取消了您所订阅的聊天记录回顾。", tgbot.EscapeHTMLSymbols(chatTitle))) @@ -250,7 +261,7 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca _, err = m.botService.Send(msg) if err != nil { - m.logger.Error("failed to send the auto un-subscription message", zap.Error(err), zap.Int64("user_id", subscriber.UserID)) + m.logger.Error("failed to send the auto un-subscription message", zap.Error(err), zap.Int64("user_id", subscriber.UserID), zap.Int64("chat_id", chatID)) } continue @@ -280,24 +291,21 @@ func (m *AutoRecapService) summarize(chatID int64, options *ent.TelegramChatReca if targetChat.isPrivateSubscriber { msg.Text = fmt.Sprintf("您好,这是您订阅的 %s 群组的定时聊天回顾。\n\n%s", tgbot.EscapeHTMLSymbols(chatTitle), content) - buttonData, err := m.botService.Bot().AssignOneCallbackQueryData("recap/unsubscribe_recap", recap.UnsubscribeRecapActionData{ - ChatID: chatID, - ChatTitle: chatTitle, - FromID: targetChat.chatID, - }) + inlineKeyboardMarkup, err := m.chathistories.NewVoteRecapWithUnsubscribeInlineKeyboardMarkup(m.botService.Bot(), targetChat.chatID, chatTitle, targetChat.chatID, logID, counts.UpVotes, counts.DownVotes, counts.Lmao) if err != nil { - m.logger.Error("failed to assign callback query data", zap.Error(err)) + m.logger.Error("failed to assign callback query data", zap.Error(err), zap.Int64("chat_id", chatID)) continue } - msg.ReplyMarkup = tgbotapi.NewInlineKeyboardMarkup(tgbotapi.NewInlineKeyboardRow(tgbotapi.NewInlineKeyboardButtonData("取消订阅", buttonData))) + msg.ReplyMarkup = inlineKeyboardMarkup } else { msg.Text = content + msg.ReplyMarkup = inlineKeyboardMarkup } _, err = m.botService.Send(msg) if err != nil { - m.logger.Error("failed to send chat histories recap", zap.Error(err)) + m.logger.Error("failed to send chat histories recap", zap.Error(err), zap.Int64("chat_id", chatID)) } } } diff --git a/internal/services/smr/processor.go b/internal/services/smr/processor.go index baffd1d..b7c6ab4 100644 --- a/internal/services/smr/processor.go +++ b/internal/services/smr/processor.go @@ -8,11 +8,13 @@ import ( "github.com/disgoorg/disgo/discord" "github.com/disgoorg/snowflake/v2" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" + "github.com/google/uuid" "github.com/nekomeowww/insights-bot/ent/slackoauthcredentials" "github.com/nekomeowww/insights-bot/internal/models/smr" "github.com/nekomeowww/insights-bot/pkg/bots/slackbot" "github.com/nekomeowww/insights-bot/pkg/types/bot" types "github.com/nekomeowww/insights-bot/pkg/types/smr" + "github.com/samber/lo" "github.com/slack-go/slack" "go.uber.org/zap" ) @@ -40,20 +42,51 @@ func (s *Service) processError(err error) string { return "量子速读失败了。可以再试试?" } -func (s *Service) sendResult(info types.TaskInfo, result string) { +func (s *Service) sendResult(output *smr.URLSummarizationOutput, info types.TaskInfo, result string) { switch info.Platform { case bot.FromPlatformTelegram: + logID := uuid.Nil + if output != nil { + logID = output.ID + } + + counts, err := s.model.FindFeedbackSummarizationsReactionCountsForChatIDAndLogID(info.ChatID, logID) + if err != nil { + s.logger.Warn("smr service: failed to send result message", + zap.Error(err), + zap.Int64("chat_id", info.ChatID), + zap.String("platform", info.Platform.String()), + ) + + return + } + + inlineKeyboardMarkup, err := s.model.NewVoteSummarizationsReactionsInlineKeyboardMarkup(s.tgBot.Bot(), info.ChatID, logID, counts.UpVotes, counts.DownVotes, counts.Lmao) + if err != nil { + s.logger.Warn("smr service: failed to send result message", + zap.Error(err), + zap.Int64("chat_id", info.ChatID), + zap.String("platform", info.Platform.String()), + ) + + return + } + msgEdit := tgbotapi.EditMessageTextConfig{ - Text: result, + BaseEdit: tgbotapi.BaseEdit{ + ChatID: info.ChatID, + MessageID: info.MessageID, + ReplyMarkup: lo.ToPtr(inlineKeyboardMarkup), + }, + Text: result, + ParseMode: tgbotapi.ModeHTML, } - msgEdit.ChatID = info.ChatID - msgEdit.MessageID = info.MessageID - msgEdit.ParseMode = tgbotapi.ModeHTML - _, err := s.tgBot.Send(msgEdit) + _, err = s.tgBot.Send(msgEdit) if err != nil { s.logger.Warn("smr service: failed to send result message", zap.Error(err), + zap.Int64("chat_id", msgEdit.ChatID), zap.String("platform", info.Platform.String()), ) } @@ -134,11 +167,11 @@ func (s *Service) processor(info types.TaskInfo) { if err != nil { s.logger.Warn("smr service: summarization failed", zap.Error(err)) errStr := s.processError(err) - s.sendResult(info, errStr) + s.sendResult(nil, info, errStr) return } finalResult := s.processOutput(info, smrResult) - s.sendResult(info, finalResult) + s.sendResult(smrResult, info, finalResult) } diff --git a/pkg/bots/tgbot/dispatcher.go b/pkg/bots/tgbot/dispatcher.go index 13ee57b..1a345d9 100644 --- a/pkg/bots/tgbot/dispatcher.go +++ b/pkg/bots/tgbot/dispatcher.go @@ -162,14 +162,35 @@ func (d *Dispatcher) dispatchCallbackQuery(c *Context) { identityStrings = append(identityStrings, "@"+c.Update.CallbackQuery.From.UserName) } - if c.callbackQueryHandlerRoute == "" || c.callbackQueryHandlerActionData == "" { - d.Logger.Debug(fmt.Sprintf("[回调查询|%s] [%s (%s)] %s (%s) : %s (Raw Data, missing route or action data)", + if c.callbackQueryHandlerRoute == "" { + d.Logger.Error(fmt.Sprintf("[回调查询|%s] [%s (%s)] %s (%s) : %s (Raw Data) \n%s\n%s\n\n%s\n%s\n", MapChatTypeToChineseText(telegram.ChatType(c.Update.CallbackQuery.Message.Chat.Type)), color.FgGreen.Render(c.Update.CallbackQuery.Message.Chat.Title), color.FgYellow.Render(c.Update.CallbackQuery.Message.Chat.ID), strings.Join(identityStrings, " "), color.FgYellow.Render(c.Update.CallbackQuery.From.ID), c.Update.CallbackData(), + color.FgRed.Render("无法调度 Callback Query,监测到缺少路由。"), + color.FgRed.Render("Unable to dispatch Callback Query due to missing route DETECTED."), + color.FgRed.Render("大多数情况下,发生这种情况的原因是相应的处理程序没有通过 OnCallbackQuery(...) 方法正确注册,或者内部派发器未能与之匹配,请检查已注册的处理程序及其路由,然后再试一次。"), + color.FgRed.Render("For most of the time, this happens when the corresponding handler wasn't registered properly through OnCallbackQuery(...) method or internal dispatcher failed to match it, please check registered handlers and the route of them and then try again."), + ), + zap.String("route", c.callbackQueryHandlerRoute), + zap.String("route_hash", c.callbackQueryHandlerRouteHash), + zap.String("action_data_hash", c.callbackQueryHandlerActionDataHash), + ) + } else if c.callbackQueryHandlerActionData == "" { + d.Logger.Error(fmt.Sprintf("[回调查询|%s] [%s (%s)] %s (%s) : %s (Raw Data) \n%s\n%s\n\n%s\n%s\n", + MapChatTypeToChineseText(telegram.ChatType(c.Update.CallbackQuery.Message.Chat.Type)), + color.FgGreen.Render(c.Update.CallbackQuery.Message.Chat.Title), + color.FgYellow.Render(c.Update.CallbackQuery.Message.Chat.ID), + strings.Join(identityStrings, " "), + color.FgYellow.Render(c.Update.CallbackQuery.From.ID), + c.Update.CallbackData(), + color.FgRed.Render("无法调度 Callback Query,检测到缺少操作数据。"), + color.FgRed.Render("Unable to dispatch Callback Query due to missing action data DETECTED."), + color.FgRed.Render("大多数情况下,当存储在回调查询数据中的操作数据为空、不存在于缓存中或无法从缓存中获取时会出现这种情况,请尝试刷新相应的缓存键并重试。"), + color.FgRed.Render("For most of the time, this happens when the action data that stored into callback query data is either empty, not exist on cache, or failed to fetch from cache, please try to flush any corresponding cache keys and try again."), ), zap.String("route", c.callbackQueryHandlerRoute), zap.String("route_hash", c.callbackQueryHandlerRouteHash), diff --git a/pkg/bots/tgbot/tgbot.go b/pkg/bots/tgbot/tgbot.go index 453ad01..2b9514f 100644 --- a/pkg/bots/tgbot/tgbot.go +++ b/pkg/bots/tgbot/tgbot.go @@ -478,3 +478,47 @@ func (b *Bot) fetchCallbackQueryActionData(route string, dataHash string) (strin return str, nil } + +func (b *Bot) RemoveInlineKeyboardButtonFromInlineKeyboardMarkupThatMatchesDataWith(inlineKeyboardMarkup tgbotapi.InlineKeyboardMarkup, callbackData string) tgbotapi.InlineKeyboardMarkup { + if len(inlineKeyboardMarkup.InlineKeyboard) == 0 { + return inlineKeyboardMarkup + } + + for i := range inlineKeyboardMarkup.InlineKeyboard { + for j := range inlineKeyboardMarkup.InlineKeyboard[i] { + if inlineKeyboardMarkup.InlineKeyboard[i][j].CallbackData == nil { + continue + } + if *inlineKeyboardMarkup.InlineKeyboard[i][j].CallbackData == callbackData { + inlineKeyboardMarkup.InlineKeyboard[i] = append(inlineKeyboardMarkup.InlineKeyboard[i][:j], inlineKeyboardMarkup.InlineKeyboard[i][j+1:]...) + break + } + } + } + + inlineKeyboardMarkup.InlineKeyboard = lo.Filter(inlineKeyboardMarkup.InlineKeyboard, func(row []tgbotapi.InlineKeyboardButton, _ int) bool { + return len(row) > 0 + }) + + return inlineKeyboardMarkup +} + +func (b *Bot) ReplaceInlineKeyboardButtonFromInlineKeyboardMarkupThatMatchesDataWith(inlineKeyboardMarkup tgbotapi.InlineKeyboardMarkup, callbackData string, replacedButton tgbotapi.InlineKeyboardButton) tgbotapi.InlineKeyboardMarkup { + if len(inlineKeyboardMarkup.InlineKeyboard) == 0 { + return inlineKeyboardMarkup + } + + for i := range inlineKeyboardMarkup.InlineKeyboard { + for j := range inlineKeyboardMarkup.InlineKeyboard[i] { + if inlineKeyboardMarkup.InlineKeyboard[i][j].CallbackData == nil { + continue + } + if *inlineKeyboardMarkup.InlineKeyboard[i][j].CallbackData == callbackData { + inlineKeyboardMarkup.InlineKeyboard[i][j] = replacedButton + break + } + } + } + + return inlineKeyboardMarkup +} diff --git a/pkg/types/bot/handlers/recap/configure_recap.go b/pkg/types/bot/handlers/recap/configure_recap.go index 1493d95..127fb97 100644 --- a/pkg/types/bot/handlers/recap/configure_recap.go +++ b/pkg/types/bot/handlers/recap/configure_recap.go @@ -1,6 +1,10 @@ package recap -import "github.com/nekomeowww/insights-bot/pkg/types/tgchat" +import ( + "github.com/nekomeowww/insights-bot/ent/feedbackchathistoriesrecapsreactions" + "github.com/nekomeowww/insights-bot/ent/feedbacksummarizationsreactions" + "github.com/nekomeowww/insights-bot/pkg/types/tgchat" +) type ConfigureRecapToggleActionData struct { Status bool `json:"status"` @@ -18,3 +22,15 @@ type ConfigureRecapCompleteActionData struct { ChatID int64 `json:"chatId"` FromID int64 `json:"fromId"` } + +type FeedbackRecapReactionActionData struct { + ChatID int64 `json:"chatId"` + LogID string `json:"logId"` + Type feedbackchathistoriesrecapsreactions.Type `json:"type"` +} + +type FeedbackSummarizationReactionActionData struct { + ChatID int64 `json:"chatId"` + LogID string `json:"logId"` + Type feedbacksummarizationsreactions.Type `json:"type"` +}