manufacturer.go 916 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package model
  2. import "go.mongodb.org/mongo-driver/bson/primitive"
  3. type Manufacturer struct {
  4. ID primitive.ObjectID `json:"-" bson:"_id,omitempty"`
  5. Name string `json:"name" bson:"name,omitempty"`
  6. Count int `json:"count" bson:"count,omitempty"`
  7. }
  8. type Manufacturers struct {
  9. List []Manufacturer
  10. }
  11. func NewManufacturers() Manufacturers {
  12. m := Manufacturers{
  13. List: make([]Manufacturer, 0),
  14. }
  15. return m
  16. }
  17. //Contains checking if the manufacturer name is present in the list of manufacturers
  18. func (m *Manufacturers) Contains(name string) bool {
  19. for _, a := range m.List {
  20. if a.Name == name {
  21. return true
  22. }
  23. }
  24. return false
  25. }
  26. //Add adding a new manufacturer to the list
  27. func (m *Manufacturers) Add(name string, count int) {
  28. if !m.Contains(name) {
  29. m.List = append(m.List, Manufacturer{
  30. Name: name,
  31. Count: count,
  32. })
  33. }
  34. }