Refactor: Change sqlstore.inTransaction to SQLStore.WithTransactionalDBSession in misc files (#43926)
* Refactor: Change sqlstore.inTransaction to SQLStore.WithTransactionalDBSession in misc files * Refactor: Change .inTransaction in org.go file * Refactor: Update init() to proper SQLStore handlers * Refactor: Update funcs in tests to be sqlStore methods * Refactor: Update API funcs to receive HTTPServer * Fix: define methods on sqlstore * Adjust GetSignedInUser calls * Refactor: Add sqlStore to Service struct * Chore: Add back black spaces to remove file from PR Co-authored-by: Ida Furjesova <ida.furjesova@grafana.com>
This commit is contained in:
co-authored by
Ida Furjesova
parent
eed9e5543d
commit
92ca38bedf
@@ -15,14 +15,14 @@ import (
|
||||
// MainOrgName is the name of the main organization.
|
||||
const MainOrgName = "Main Org."
|
||||
|
||||
func init() {
|
||||
func (ss *SQLStore) addOrgQueryAndCommandHandlers() {
|
||||
bus.AddHandler("sql", GetOrgById)
|
||||
bus.AddHandler("sql", CreateOrg)
|
||||
bus.AddHandler("sql", UpdateOrg)
|
||||
bus.AddHandler("sql", UpdateOrgAddress)
|
||||
bus.AddHandler("sql", ss.UpdateOrg)
|
||||
bus.AddHandler("sql", ss.UpdateOrgAddress)
|
||||
bus.AddHandler("sql", GetOrgByName)
|
||||
bus.AddHandler("sql", SearchOrgs)
|
||||
bus.AddHandler("sql", DeleteOrg)
|
||||
bus.AddHandler("sql", ss.DeleteOrg)
|
||||
}
|
||||
|
||||
func SearchOrgs(ctx context.Context, query *models.SearchOrgsQuery) error {
|
||||
@@ -164,8 +164,8 @@ func CreateOrg(ctx context.Context, cmd *models.CreateOrgCommand) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateOrg(ctx context.Context, cmd *models.UpdateOrgCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
func (ss *SQLStore) UpdateOrg(ctx context.Context, cmd *models.UpdateOrgCommand) error {
|
||||
return ss.WithTransactionalDbSession(ctx, func(sess *DBSession) error {
|
||||
if isNameTaken, err := isOrgNameTaken(cmd.Name, cmd.OrgId, sess); err != nil {
|
||||
return err
|
||||
} else if isNameTaken {
|
||||
@@ -197,8 +197,8 @@ func UpdateOrg(ctx context.Context, cmd *models.UpdateOrgCommand) error {
|
||||
})
|
||||
}
|
||||
|
||||
func UpdateOrgAddress(ctx context.Context, cmd *models.UpdateOrgAddressCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
func (ss *SQLStore) UpdateOrgAddress(ctx context.Context, cmd *models.UpdateOrgAddressCommand) error {
|
||||
return ss.WithTransactionalDbSession(ctx, func(sess *DBSession) error {
|
||||
org := models.Org{
|
||||
Address1: cmd.Address1,
|
||||
Address2: cmd.Address2,
|
||||
@@ -224,8 +224,8 @@ func UpdateOrgAddress(ctx context.Context, cmd *models.UpdateOrgAddressCommand)
|
||||
})
|
||||
}
|
||||
|
||||
func DeleteOrg(ctx context.Context, cmd *models.DeleteOrgCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
func (ss *SQLStore) DeleteOrg(ctx context.Context, cmd *models.DeleteOrgCommand) error {
|
||||
return ss.WithTransactionalDbSession(ctx, func(sess *DBSession) error {
|
||||
if res, err := sess.Query("SELECT 1 from org WHERE id=?", cmd.Id); err != nil {
|
||||
return err
|
||||
} else if len(res) != 1 {
|
||||
|
||||
Reference in New Issue
Block a user