MCPcopy Index your code
hub / github.com/NdoleStudio/httpsms / Store

Method Store

api/pkg/services/discord_service.go:117–143  ·  view source on GitHub ↗

Store a new entities.Discord

(ctx context.Context, params *DiscordStoreParams)

Source from the content-addressed store, hash-verified

115
116// Store a new entities.Discord
117func (service *DiscordService) Store(ctx context.Context, params *DiscordStoreParams) (*entities.Discord, error) {
118 ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger)
119 defer span.End()
120
121 if err := service.createSlashCommand(ctx, params.ServerID); err != nil {
122 msg := fmt.Sprintf("cannot create slash command for server [%s]", params.ServerID)
123 return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
124 }
125
126 discordIntegration := &entities.Discord{
127 ID: uuid.New(),
128 UserID: params.UserID,
129 Name: params.Name,
130 ServerID: params.ServerID,
131 IncomingChannelID: params.IncomingChannelID,
132 CreatedAt: time.Now().UTC(),
133 UpdatedAt: time.Now().UTC(),
134 }
135
136 if err := service.repository.Save(ctx, discordIntegration); err != nil {
137 msg := fmt.Sprintf("cannot save discord integration with id [%s]", discordIntegration.ID)
138 return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg))
139 }
140
141 ctxLogger.Info(fmt.Sprintf("discord integration saved with id [%s] in the [%T]", discordIntegration.ID, service.repository))
142 return discordIntegration, nil
143}
144
145func (service *DiscordService) createSlashCommand(ctx context.Context, serverID string) error {
146 ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger)

Callers

nothing calls this directly

Calls 5

createSlashCommandMethod · 0.95
StartWithLoggerMethod · 0.65
WrapErrorSpanMethod · 0.65
SaveMethod · 0.65
InfoMethod · 0.65

Tested by

no test coverage detected