gitlab.com/evatix-go/core@v1.3.55/coredata/corepayload/PagingInfo.go (about)

     1  package corepayload
     2  
     3  type PagingInfo struct {
     4  	CurrentPageIndex                     int // -- 1 based index
     5  	TotalPages, PerPageItems, TotalItems int
     6  }
     7  
     8  func (it *PagingInfo) IsEmpty() bool {
     9  	return it == nil ||
    10  		it.TotalPages == 0 && it.TotalItems == 0
    11  }
    12  
    13  func (it *PagingInfo) IsEqual(right *PagingInfo) bool {
    14  	if it == nil && right == nil {
    15  		return true
    16  	}
    17  
    18  	if it == nil || right == nil {
    19  		return false
    20  	}
    21  
    22  	if it.TotalPages != right.TotalPages {
    23  		return false
    24  	}
    25  
    26  	if it.CurrentPageIndex != right.CurrentPageIndex {
    27  		return false
    28  	}
    29  
    30  	if it.PerPageItems != right.PerPageItems {
    31  		return false
    32  	}
    33  
    34  	return it.TotalItems == right.TotalItems
    35  }
    36  
    37  func (it *PagingInfo) HasTotalPages() bool {
    38  	return it != nil && it.TotalPages > 0
    39  }
    40  
    41  func (it *PagingInfo) HasCurrentPageIndex() bool {
    42  	return it != nil && it.CurrentPageIndex > 0
    43  }
    44  
    45  func (it *PagingInfo) HasPerPageItems() bool {
    46  	return it != nil && it.PerPageItems > 0
    47  }
    48  
    49  func (it *PagingInfo) HasTotalItems() bool {
    50  	return it != nil && it.TotalItems > 0
    51  }
    52  
    53  func (it *PagingInfo) IsInvalidTotalPages() bool {
    54  	return it == nil || it.TotalPages <= 0
    55  }
    56  
    57  func (it *PagingInfo) IsInvalidCurrentPageIndex() bool {
    58  	return it == nil || it.CurrentPageIndex <= 0
    59  }
    60  
    61  func (it *PagingInfo) IsInvalidPerPageItems() bool {
    62  	return it == nil || it.PerPageItems <= 0
    63  }
    64  
    65  func (it *PagingInfo) IsInvalidTotalItems() bool {
    66  	return it == nil || it.TotalItems <= 0
    67  }
    68  
    69  func (it PagingInfo) Clone() PagingInfo {
    70  	return PagingInfo{
    71  		TotalPages:       it.TotalPages,
    72  		CurrentPageIndex: it.CurrentPageIndex,
    73  		PerPageItems:     it.PerPageItems,
    74  		TotalItems:       it.TotalItems,
    75  	}
    76  }
    77  
    78  func (it *PagingInfo) ClonePtr() *PagingInfo {
    79  	if it == nil {
    80  		return nil
    81  	}
    82  
    83  	return &PagingInfo{
    84  		TotalPages:       it.TotalPages,
    85  		CurrentPageIndex: it.CurrentPageIndex,
    86  		PerPageItems:     it.PerPageItems,
    87  		TotalItems:       it.TotalItems,
    88  	}
    89  }