Skip to content

Commit

Permalink
Working post rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
1nv8rzim committed Dec 6, 2023
1 parent 575eedc commit 9f46a4d
Show file tree
Hide file tree
Showing 26 changed files with 3,055 additions and 19 deletions.
2 changes: 2 additions & 0 deletions commands/enabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func populateSlashCommands(ctx ddtrace.SpanContext) {
SlashCommands["update"] = slash.Update
SlashCommands["query"] = slash.Query
SlashCommands["scoreboard"] = slash.Scoreboard
SlashCommands["birthday"] = slash.Birthday
}

// populateHandlers populates the Handlers map with all of the handlers
Expand Down Expand Up @@ -68,4 +69,5 @@ func populateScheduledEvents(ctx ddtrace.SpanContext) {
ScheduledEvents["heartbeat"] = scheduled.Heartbeat
ScheduledEvents["status"] = scheduled.Status
ScheduledEvents["update"] = scheduled.Update
ScheduledEvents["birthday"] = scheduled.Birthday
}
108 changes: 108 additions & 0 deletions data/birthday.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package data

import (
"github.com/ritsec/ops-bot-iii/ent"
"github.com/ritsec/ops-bot-iii/ent/birthday"
"github.com/ritsec/ops-bot-iii/ent/user"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)

// Birthday is the interface for interacting with the birthday table
type birthday_s struct{}

// Exists checks if a birthday exists for a user
func (*birthday_s) Exists(user_id string, ctx ddtrace.SpanContext) (bool, error) {
span := tracer.StartSpan(
"data.birthday:Exists",
tracer.ResourceName("Data.Birthday.Exists"),
tracer.ChildOf(ctx),
)
defer span.Finish()

return Client.Birthday.Query().
Where(
birthday.HasUserWith(
user.ID(user_id),
),
).
Exist(Ctx)
}

// GetBirthdays gets all birthdays for a given day and month
func (*birthday_s) GetBirthdays(day int, month int, ctx ddtrace.SpanContext) ([]*ent.Birthday, error) {
span := tracer.StartSpan(
"data.birthday:GetBirthdays",
tracer.ResourceName("Data.Birthday.GetBirthdays"),
tracer.ChildOf(ctx),
)
defer span.Finish()

return Client.Birthday.Query().
Where(
birthday.Day(day),
birthday.Month(month),
).
WithUser().
All(Ctx)
}

// Create creates a new birthday for a user
func (*birthday_s) Create(user_id string, day int, month int, ctx ddtrace.SpanContext) (*ent.Birthday, error) {
span := tracer.StartSpan(
"data.birthday:Create",
tracer.ResourceName("Data.Birthday.Create"),
tracer.ChildOf(ctx),
)
defer span.Finish()

entUser, err := User.Get(user_id, ctx)
if err != nil {
return nil, err
}

return Client.Birthday.Create().
SetDay(day).
SetMonth(month).
SetUser(
entUser,
).
Save(Ctx)
}

// Get gets a birthday for a user
func (*birthday_s) Get(user_id string, ctx ddtrace.SpanContext) (*ent.Birthday, error) {
span := tracer.StartSpan(
"data.birthday:Get",
tracer.ResourceName("Data.Birthday.Get"),
tracer.ChildOf(ctx),
)
defer span.Finish()

return Client.Birthday.Query().
Where(
birthday.HasUserWith(
user.ID(user_id),
),
).
WithUser().
Only(Ctx)
}

// Delete deletes a birthday for a user
func (*birthday_s) Delete(user_id string, ctx ddtrace.SpanContext) (int, error) {
span := tracer.StartSpan(
"data.birthday:Delete",
tracer.ResourceName("Data.Birthday.Delete"),
tracer.ChildOf(ctx),
)
defer span.Finish()

return Client.Birthday.Delete().
Where(
birthday.HasUserWith(
user.ID(user_id),
),
).
Exec(Ctx)
}
3 changes: 3 additions & 0 deletions data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ var (

// Shitposts is the struct reference shitposts
Shitposts *shitpost_s = &shitpost_s{}

// Birthday is the struct reference birthday
Birthday *birthday_s = &birthday_s{}
)

func init() {
Expand Down
153 changes: 153 additions & 0 deletions ent/birthday.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 97 additions & 0 deletions ent/birthday/birthday.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9f46a4d

Please sign in to comment.