github.com/lologarithm/mattermost-server@v5.3.2-0.20181002060438-c82a84ed765b+incompatible/app/service_terms.go (about)

     1  // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package app
     5  
     6  import (
     7  	"github.com/mattermost/mattermost-server/model"
     8  )
     9  
    10  func (a *App) CreateServiceTerms(text, userId string) (*model.ServiceTerms, *model.AppError) {
    11  	serviceTerms := &model.ServiceTerms{
    12  		Text:   text,
    13  		UserId: userId,
    14  	}
    15  
    16  	if _, err := a.GetUser(userId); err != nil {
    17  		return nil, err
    18  	}
    19  
    20  	result := <-a.Srv.Store.ServiceTerms().Save(serviceTerms)
    21  	if result.Err != nil {
    22  		return nil, result.Err
    23  	}
    24  
    25  	serviceTerms = result.Data.(*model.ServiceTerms)
    26  	return serviceTerms, nil
    27  }
    28  
    29  func (a *App) GetLatestServiceTerms() (*model.ServiceTerms, *model.AppError) {
    30  	if result := <-a.Srv.Store.ServiceTerms().GetLatest(true); result.Err != nil {
    31  		return nil, result.Err
    32  	} else {
    33  		serviceTerms := result.Data.(*model.ServiceTerms)
    34  		return serviceTerms, nil
    35  	}
    36  }
    37  
    38  func (a *App) GetServiceTerms(id string) (*model.ServiceTerms, *model.AppError) {
    39  	if result := <-a.Srv.Store.ServiceTerms().Get(id, true); result.Err != nil {
    40  		return nil, result.Err
    41  	} else {
    42  		serviceTerms := result.Data.(*model.ServiceTerms)
    43  		return serviceTerms, nil
    44  	}
    45  }