mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-01 13:48:56 +08:00

* MF-922 - Add User Update endpoint Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Revert Update function Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Update swagger Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix Things swagger Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix swagger Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * update Things swagger Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix users swagger Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix mocks Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix method name Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix swagger Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix swagger Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix swagger Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix typo Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Use User instead of metadata Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com> * Fix reviews Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
84 lines
1.6 KiB
Go
84 lines
1.6 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package mocks
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
"github.com/mainflux/mainflux/users"
|
|
)
|
|
|
|
var _ users.UserRepository = (*userRepositoryMock)(nil)
|
|
|
|
type userRepositoryMock struct {
|
|
mu sync.Mutex
|
|
users map[string]users.User
|
|
}
|
|
|
|
// NewUserRepository creates in-memory user repository
|
|
func NewUserRepository() users.UserRepository {
|
|
return &userRepositoryMock{
|
|
users: make(map[string]users.User),
|
|
}
|
|
}
|
|
|
|
func (urm *userRepositoryMock) Save(ctx context.Context, user users.User) error {
|
|
urm.mu.Lock()
|
|
defer urm.mu.Unlock()
|
|
|
|
if _, ok := urm.users[user.Email]; ok {
|
|
return users.ErrConflict
|
|
}
|
|
|
|
urm.users[user.Email] = user
|
|
return nil
|
|
}
|
|
|
|
func (urm *userRepositoryMock) Update(ctx context.Context, user users.User) error {
|
|
urm.mu.Lock()
|
|
defer urm.mu.Unlock()
|
|
|
|
if _, ok := urm.users[user.Email]; ok {
|
|
return users.ErrConflict
|
|
}
|
|
|
|
urm.users[user.Email] = user
|
|
return nil
|
|
}
|
|
|
|
func (urm *userRepositoryMock) UpdateUser(ctx context.Context, user users.User) error {
|
|
urm.mu.Lock()
|
|
defer urm.mu.Unlock()
|
|
|
|
if _, ok := urm.users[user.Email]; ok {
|
|
return users.ErrConflict
|
|
}
|
|
|
|
urm.users[user.Email] = user
|
|
return nil
|
|
}
|
|
|
|
func (urm *userRepositoryMock) RetrieveByID(ctx context.Context, email string) (users.User, error) {
|
|
urm.mu.Lock()
|
|
defer urm.mu.Unlock()
|
|
|
|
val, ok := urm.users[email]
|
|
if !ok {
|
|
return users.User{}, users.ErrNotFound
|
|
}
|
|
|
|
return val, nil
|
|
}
|
|
|
|
func (urm *userRepositoryMock) UpdatePassword(_ context.Context, token, password string) error {
|
|
urm.mu.Lock()
|
|
defer urm.mu.Unlock()
|
|
|
|
if _, ok := urm.users[token]; !ok {
|
|
return users.ErrNotFound
|
|
}
|
|
return nil
|
|
}
|