Chore: Add context to org (#40685)
* Add context to org * Rebase * Fix rebase
This commit is contained in:
@@ -16,16 +16,16 @@ import (
|
||||
const MainOrgName = "Main Org."
|
||||
|
||||
func init() {
|
||||
bus.AddHandler("sql", GetOrgById)
|
||||
bus.AddHandler("sql", CreateOrg)
|
||||
bus.AddHandler("sql", UpdateOrg)
|
||||
bus.AddHandler("sql", UpdateOrgAddress)
|
||||
bus.AddHandler("sql", GetOrgByName)
|
||||
bus.AddHandler("sql", SearchOrgs)
|
||||
bus.AddHandler("sql", DeleteOrg)
|
||||
bus.AddHandlerCtx("sql", GetOrgById)
|
||||
bus.AddHandlerCtx("sql", CreateOrg)
|
||||
bus.AddHandlerCtx("sql", UpdateOrg)
|
||||
bus.AddHandlerCtx("sql", UpdateOrgAddress)
|
||||
bus.AddHandlerCtx("sql", GetOrgByName)
|
||||
bus.AddHandlerCtx("sql", SearchOrgs)
|
||||
bus.AddHandlerCtx("sql", DeleteOrg)
|
||||
}
|
||||
|
||||
func SearchOrgs(query *models.SearchOrgsQuery) error {
|
||||
func SearchOrgs(ctx context.Context, query *models.SearchOrgsQuery) error {
|
||||
query.Result = make([]*models.OrgDTO, 0)
|
||||
sess := x.Table("org")
|
||||
if query.Query != "" {
|
||||
@@ -48,7 +48,7 @@ func SearchOrgs(query *models.SearchOrgsQuery) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func GetOrgById(query *models.GetOrgByIdQuery) error {
|
||||
func GetOrgById(ctx context.Context, query *models.GetOrgByIdQuery) error {
|
||||
var org models.Org
|
||||
exists, err := x.Id(query.Id).Get(&org)
|
||||
if err != nil {
|
||||
@@ -63,7 +63,7 @@ func GetOrgById(query *models.GetOrgByIdQuery) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetOrgByName(query *models.GetOrgByNameQuery) error {
|
||||
func GetOrgByName(ctx context.Context, query *models.GetOrgByNameQuery) error {
|
||||
var org models.Org
|
||||
exists, err := x.Where("name=?", query.Name).Get(&org)
|
||||
if err != nil {
|
||||
@@ -154,7 +154,7 @@ func (ss *SQLStore) CreateOrgWithMember(name string, userID int64) (models.Org,
|
||||
return createOrg(name, userID, ss.engine)
|
||||
}
|
||||
|
||||
func CreateOrg(cmd *models.CreateOrgCommand) error {
|
||||
func CreateOrg(ctx context.Context, cmd *models.CreateOrgCommand) error {
|
||||
org, err := createOrg(cmd.Name, cmd.UserId, x)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -164,7 +164,7 @@ func CreateOrg(cmd *models.CreateOrgCommand) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateOrg(cmd *models.UpdateOrgCommand) error {
|
||||
func UpdateOrg(ctx context.Context, cmd *models.UpdateOrgCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
if isNameTaken, err := isOrgNameTaken(cmd.Name, cmd.OrgId, sess); err != nil {
|
||||
return err
|
||||
@@ -197,7 +197,7 @@ func UpdateOrg(cmd *models.UpdateOrgCommand) error {
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateOrgAddress(cmd *models.UpdateOrgAddressCommand) error {
|
||||
func UpdateOrgAddress(ctx context.Context, cmd *models.UpdateOrgAddressCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
org := models.Org{
|
||||
Address1: cmd.Address1,
|
||||
@@ -224,7 +224,7 @@ func UpdateOrgAddress(cmd *models.UpdateOrgAddressCommand) error {
|
||||
})
|
||||
}
|
||||
|
||||
func DeleteOrg(cmd *models.DeleteOrgCommand) error {
|
||||
func DeleteOrg(ctx context.Context, cmd *models.DeleteOrgCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
if res, err := sess.Query("SELECT 1 from org WHERE id=?", cmd.Id); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user