|
|
@ -12,7 +12,7 @@ type MockUserAgentRepository struct {
|
|
|
|
NextId int64
|
|
|
|
NextId int64
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewMockUserAgentRepository() domain.UserAgentRepository{
|
|
|
|
func NewMockUserAgentRepository() *MockUserAgentRepository {
|
|
|
|
r := new(MockUserAgentRepository)
|
|
|
|
r := new(MockUserAgentRepository)
|
|
|
|
r.NextId = 0
|
|
|
|
r.NextId = 0
|
|
|
|
r.IdIdx = make(map[int64]*domain.UserAgent)
|
|
|
|
r.IdIdx = make(map[int64]*domain.UserAgent)
|
|
|
@ -20,7 +20,7 @@ func NewMockUserAgentRepository() domain.UserAgentRepository{
|
|
|
|
return r
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (r MockUserAgentRepository) Create(useragent domain.UserAgent) (*domain.UserAgent, error) {
|
|
|
|
func (r *MockUserAgentRepository) Create(useragent domain.UserAgent) (*domain.UserAgent, error) {
|
|
|
|
r.NextId += 1
|
|
|
|
r.NextId += 1
|
|
|
|
useragent.ID = r.NextId
|
|
|
|
useragent.ID = r.NextId
|
|
|
|
|
|
|
|
|
|
|
@ -30,7 +30,7 @@ func (r MockUserAgentRepository) Create(useragent domain.UserAgent) (*domain.Use
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (r MockUserAgentRepository) All() ([]domain.UserAgent, error) {
|
|
|
|
func (r *MockUserAgentRepository) All() ([]domain.UserAgent, error) {
|
|
|
|
v := make([]domain.UserAgent, 0, len(r.IdIdx))
|
|
|
|
v := make([]domain.UserAgent, 0, len(r.IdIdx))
|
|
|
|
|
|
|
|
|
|
|
|
for _, value := range r.IdIdx {
|
|
|
|
for _, value := range r.IdIdx {
|
|
|
@ -40,7 +40,7 @@ func (r MockUserAgentRepository) All() ([]domain.UserAgent, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (r MockUserAgentRepository) GetByName(name string) (*domain.UserAgent, error) {
|
|
|
|
func (r *MockUserAgentRepository) GetByName(name string) (*domain.UserAgent, error) {
|
|
|
|
useragent, exists := r.NameIdx[name]
|
|
|
|
useragent, exists := r.NameIdx[name]
|
|
|
|
if exists {
|
|
|
|
if exists {
|
|
|
|
return useragent, nil
|
|
|
|
return useragent, nil
|
|
|
@ -49,7 +49,7 @@ func (r MockUserAgentRepository) GetByName(name string) (*domain.UserAgent, erro
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (r MockUserAgentRepository) Update(id int64, useragent domain.UserAgent) (*domain.UserAgent, error) {
|
|
|
|
func (r *MockUserAgentRepository) Update(id int64, useragent domain.UserAgent) (*domain.UserAgent, error) {
|
|
|
|
original := *r.IdIdx[id]
|
|
|
|
original := *r.IdIdx[id]
|
|
|
|
useragent.ID = id
|
|
|
|
useragent.ID = id
|
|
|
|
r.IdIdx[id] = &useragent
|
|
|
|
r.IdIdx[id] = &useragent
|
|
|
@ -58,7 +58,7 @@ func (r MockUserAgentRepository) Update(id int64, useragent domain.UserAgent) (*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (r MockUserAgentRepository) Delete(id int64) error {
|
|
|
|
func (r *MockUserAgentRepository) Delete(id int64) error {
|
|
|
|
original := *r.IdIdx[id]
|
|
|
|
original := *r.IdIdx[id]
|
|
|
|
delete(r.NameIdx, original.Name)
|
|
|
|
delete(r.NameIdx, original.Name)
|
|
|
|
delete(r.IdIdx, original.ID)
|
|
|
|
delete(r.IdIdx, original.ID)
|
|
|
|