github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/model/team_search.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package model
     5  
     6  import (
     7  	"encoding/json"
     8  	"io"
     9  )
    10  
    11  type TeamSearch struct {
    12  	Term                    string `json:"term"`
    13  	Page                    *int   `json:"page,omitempty"`
    14  	PerPage                 *int   `json:"per_page,omitempty"`
    15  	AllowOpenInvite         *bool  `json:"allow_open_invite,omitempty"`
    16  	GroupConstrained        *bool  `json:"group_constrained,omitempty"`
    17  	IncludeGroupConstrained *bool  `json:"include_group_constrained,omitempty"`
    18  }
    19  
    20  func (t *TeamSearch) IsPaginated() bool {
    21  	return t.Page != nil && t.PerPage != nil
    22  }
    23  
    24  // ToJson convert a TeamSearch to json string
    25  func (t *TeamSearch) ToJson() string {
    26  	b, err := json.Marshal(t)
    27  	if err != nil {
    28  		return ""
    29  	}
    30  
    31  	return string(b)
    32  }
    33  
    34  // TeamSearchFromJson decodes the input and returns a TeamSearch
    35  func TeamSearchFromJson(data io.Reader) *TeamSearch {
    36  	decoder := json.NewDecoder(data)
    37  	var cs TeamSearch
    38  	err := decoder.Decode(&cs)
    39  	if err == nil {
    40  		return &cs
    41  	}
    42  
    43  	return nil
    44  }