12345678910111213141516171819202122232425262728293031323334353637383940 |
- package model
- import "go.mongodb.org/mongo-driver/bson/primitive"
- type Manufacturer struct {
- ID primitive.ObjectID `json:"-" bson:"_id,omitempty"`
- Name string `json:"name" bson:"name,omitempty"`
- Count int `json:"count" bson:"count,omitempty"`
- }
- type Manufacturers struct {
- List []Manufacturer
- }
- func NewManufacturers() Manufacturers {
- m := Manufacturers{
- List: make([]Manufacturer, 0),
- }
- return m
- }
- //Contains checking if the manufacturer name is present in the list of manufacturers
- func (m *Manufacturers) Contains(name string) bool {
- for _, a := range m.List {
- if a.Name == name {
- return true
- }
- }
- return false
- }
- //Add adding a new manufacturer to the list
- func (m *Manufacturers) Add(name string, count int) {
- if !m.Contains(name) {
- m.List = append(m.List, Manufacturer{
- Name: name,
- Count: count,
- })
- }
- }
|