mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Add preferences service API for products (#20869)
This commit is contained in:
@@ -226,6 +226,10 @@ func NewChannels(s *Server, services map[ServiceKey]any) (*Channels, error) {
|
||||
|
||||
services[UserKey] = &App{ch: ch}
|
||||
|
||||
services[PreferencesKey] = &preferencesServiceWrapper{
|
||||
app: &App{ch: ch},
|
||||
}
|
||||
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,29 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/product"
|
||||
)
|
||||
|
||||
// Ensure preferences service wrapper implements `product.PreferencesService`
|
||||
var _ product.PreferencesService = (*preferencesServiceWrapper)(nil)
|
||||
|
||||
// preferencesServiceWrapper provides an implementation of `product.PreferencesService` for use by products.
|
||||
type preferencesServiceWrapper struct {
|
||||
app AppIface
|
||||
}
|
||||
|
||||
func (w *preferencesServiceWrapper) GetPreferencesForUser(userID string) (model.Preferences, *model.AppError) {
|
||||
return w.app.GetPreferencesForUser(userID)
|
||||
}
|
||||
|
||||
func (w *preferencesServiceWrapper) UpdatePreferencesForUser(userID string, preferences model.Preferences) *model.AppError {
|
||||
return w.app.UpdatePreferences(userID, preferences)
|
||||
}
|
||||
|
||||
func (w *preferencesServiceWrapper) DeletePreferencesForUser(userID string, preferences model.Preferences) *model.AppError {
|
||||
return w.app.DeletePreferences(userID, preferences)
|
||||
}
|
||||
|
||||
func (a *App) GetPreferencesForUser(userID string) (model.Preferences, *model.AppError) {
|
||||
preferences, err := a.Srv().Store.Preference().GetAll(userID)
|
||||
if err != nil {
|
||||
|
||||
@@ -103,6 +103,7 @@ const (
|
||||
KVStoreKey ServiceKey = "kvstore"
|
||||
StoreKey ServiceKey = "storekey"
|
||||
SystemKey ServiceKey = "systemkey"
|
||||
PreferencesKey ServiceKey = "preferenceskey"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
|
||||
@@ -179,3 +179,12 @@ type StoreService interface {
|
||||
type SystemService interface {
|
||||
GetDiagnosticId() string
|
||||
}
|
||||
|
||||
// PreferencesService is the API for accessing the Preferences service APIs.
|
||||
//
|
||||
// The service shall be registered via app.PreferencesKey service key.
|
||||
type PreferencesService interface {
|
||||
GetPreferencesForUser(userID string) (model.Preferences, *model.AppError)
|
||||
UpdatePreferencesForUser(userID string, preferences model.Preferences) *model.AppError
|
||||
DeletePreferencesForUser(userID string, preferences model.Preferences) *model.AppError
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user