You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bog/domain/mock.go

60 lines
1.1 KiB
Go

package domain
type MockFileRepository struct {
IdIdx map[int64]*UserAgent
NameIdx map[string]*UserAgent
NextId int64
}
func (r MockFileRepository) Create(useragent UserAgent) (*UserAgent, error) {
r.NextId += 1
useragent.ID = r.NextId
r.IdIdx[useragent.ID] = &useragent
r.NameIdx[useragent.Name] = &useragent
return &useragent, nil
}
func (r MockFileRepository) All() ([]UserAgent, error) {
v := make([]UserAgent, 0, len(r.IdIdx))
for _, value := range r.IdIdx {
v = append(v, *value)
}
return v, nil
}
func (r MockFileRepository) GetByName(name string) (*UserAgent, error) {
useragent, exists := r.NameIdx[name]
if exists {
return useragent, nil
}
return nil, ErrNotExists
}
func (r MockFileRepository) Update(id int64, useragent UserAgent) (*UserAgent, error) {
original := *r.IdIdx[id]
useragent.ID = id
r.IdIdx[id] = &useragent
r.NameIdx[original.Name] = &useragent
return &useragent, nil
}
func (r MockFileRepository) Delete(id int64) error {
original := *r.IdIdx[id]
delete(r.NameIdx, original.Name)
delete(r.IdIdx, original.ID)
return nil
}
type MockUserAgentRepository struct {
}