...

Source file src/codeberg.org/tslocum/sriracha/model/model_banner.go

Documentation: codeberg.org/tslocum/sriracha/model

     1  package model
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	. "codeberg.org/tslocum/sriracha/util"
     8  )
     9  
    10  type Banner struct {
    11  	ID        int
    12  	Name      string
    13  	Width     int
    14  	Height    int
    15  	Overboard bool
    16  	News      bool
    17  	Pages     bool
    18  	Boards    []*Board `diff:"-"`
    19  }
    20  
    21  func (b *Banner) Validate() error {
    22  	b.Name = strings.TrimSpace(b.Name)
    23  	switch {
    24  	case strings.TrimSpace(b.Name) == "" || !FilePathPattern.MatchString(b.Name) || strings.HasPrefix(b.Name, "."):
    25  		return fmt.Errorf("invalid banner name: %s", b.Name)
    26  	case b.Width <= 0:
    27  		return fmt.Errorf("invalid width")
    28  	case b.Height <= 0:
    29  		return fmt.Errorf("invalid height")
    30  	}
    31  	return nil
    32  }
    33  
    34  func (b *Banner) HasBoard(id int) bool {
    35  	for _, board := range b.Boards {
    36  		if board.ID == id {
    37  			return true
    38  		}
    39  	}
    40  	return false
    41  }
    42  

View as plain text