Add preferences service API for products (#20869)

This commit is contained in:
Doug Lauder
2022-08-23 11:57:07 -04:00
committed by GitHub
parent 3138543d10
commit 6a6e05073e
4 changed files with 35 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -103,6 +103,7 @@ const (
KVStoreKey ServiceKey = "kvstore"
StoreKey ServiceKey = "storekey"
SystemKey ServiceKey = "systemkey"
PreferencesKey ServiceKey = "preferenceskey"
)
type Server struct {

View File

@@ -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
}