2023-07-22 20:51:46 +08:00
|
|
|
package application
|
|
|
|
|
|
|
|
|
|
import (
|
2023-11-07 21:05:21 +08:00
|
|
|
"context"
|
2023-07-22 20:51:46 +08:00
|
|
|
"mayfly-go/internal/auth/domain/entity"
|
|
|
|
|
"mayfly-go/internal/auth/domain/repository"
|
2024-04-28 23:45:57 +08:00
|
|
|
"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 {
|
2024-04-28 23:45:57 +08:00
|
|
|
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 {
|
2023-10-26 17:15:49 +08:00
|
|
|
if e.Id == 0 {
|
2024-01-21 22:52:20 +08:00
|
|
|
return a.Oauth2AccountRepo.Insert(context.Background(), e)
|
2023-10-26 17:15:49 +08:00
|
|
|
}
|
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
|
|
|
}
|