Files
neo-blog/internal/repo/oidc_config.go
Snowykami cb3f602663 Refactor comment components and update OIDC configuration
- Updated OIDC configuration to include additional fields in the UpdateOidcConfig method.
- Enhanced CommentService to include IsPrivate field in the comment DTO.
- Refactored comment components: renamed neo-comment to comment, and moved related files.
- Implemented new CommentInput and CommentItem components for better structure and readability.
- Removed obsolete files related to the old comment system.
- Added CSS animations for comment components to improve user experience.
2025-09-09 22:37:27 +08:00

73 lines
1.7 KiB
Go

package repo
import (
"net/http"
"github.com/snowykami/neo-blog/internal/model"
"github.com/snowykami/neo-blog/pkg/errs"
)
type oidcRepo struct {
}
var Oidc = &oidcRepo{}
func (o *oidcRepo) CreateOidcConfig(oidcConfig *model.OidcConfig) error {
if err := GetDB().Create(oidcConfig).Error; err != nil {
return err
}
return nil
}
func (o *oidcRepo) DeleteOidcConfig(id string) error {
if id == "" {
return errs.New(http.StatusBadRequest, "invalid OIDC config ID", nil)
}
if err := GetDB().Where("id = ?", id).Delete(&model.OidcConfig{}).Error; err != nil {
return err
}
return nil
}
func (o *oidcRepo) ListOidcConfigs(onlyEnabled bool) ([]model.OidcConfig, error) {
var configs []model.OidcConfig
if onlyEnabled {
if err := GetDB().Where("enabled = ?", true).Find(&configs).Error; err != nil {
return nil, err
}
} else {
if err := GetDB().Find(&configs).Error; err != nil {
return nil, err
}
}
return configs, nil
}
func (o *oidcRepo) GetOidcConfigByName(name string) (*model.OidcConfig, error) {
var config model.OidcConfig
if err := GetDB().Where("name = ?", name).First(&config).Error; err != nil {
return nil, err
}
return &config, nil
}
func (o *oidcRepo) GetOidcConfigByID(id string) (*model.OidcConfig, error) {
var config model.OidcConfig
if err := GetDB().Where("id = ?", id).First(&config).Error; err != nil {
return nil, err
}
return &config, nil
}
func (o *oidcRepo) UpdateOidcConfig(oidcConfig *model.OidcConfig) error {
if oidcConfig.ID == 0 {
return errs.New(http.StatusBadRequest, "invalid OIDC config ID", nil)
}
if err := GetDB().Select("Name", "ClientID", "ClientSecret",
"DisplayName", "Icon", "OidcDiscoveryUrl",
"Enabled", "Type").Updates(oidcConfig).Error; err != nil {
return err
}
return nil
}