Files
mayfly-go/server/internal/auth/application/oauth2.go

36 lines
977 B
Go
Raw Normal View History

2023-07-22 20:51:46 +08:00
package application
import (
"context"
2023-07-22 20:51:46 +08:00
"mayfly-go/internal/auth/domain/entity"
"mayfly-go/internal/auth/domain/repository"
"mayfly-go/pkg/model"
2023-07-22 20:51:46 +08:00
)
type Oauth2 interface {
GetOAuthAccount(condition *entity.Oauth2Account, cols ...string) error
BindOAuthAccount(e *entity.Oauth2Account) error
2023-07-24 22:36:07 +08:00
Unbind(accountId uint64)
2023-07-22 20:51:46 +08:00
}
type oauth2AppImpl struct {
2024-01-21 22:52:20 +08:00
Oauth2AccountRepo repository.Oauth2Account `inject:""`
2023-07-22 20:51:46 +08:00
}
func (a *oauth2AppImpl) GetOAuthAccount(condition *entity.Oauth2Account, cols ...string) error {
return a.Oauth2AccountRepo.GetByCond(model.NewModelCond(condition).Columns(cols...))
2023-07-22 20:51:46 +08:00
}
func (a *oauth2AppImpl) BindOAuthAccount(e *entity.Oauth2Account) error {
if e.Id == 0 {
2024-01-21 22:52:20 +08:00
return a.Oauth2AccountRepo.Insert(context.Background(), e)
}
2024-01-21 22:52:20 +08:00
return a.Oauth2AccountRepo.UpdateById(context.Background(), e)
2023-07-22 20:51:46 +08:00
}
2023-07-24 22:36:07 +08:00
func (a *oauth2AppImpl) Unbind(accountId uint64) {
2024-01-21 22:52:20 +08:00
a.Oauth2AccountRepo.DeleteByCond(context.Background(), &entity.Oauth2Account{AccountId: accountId})
2023-07-24 22:36:07 +08:00
}