python-dependency-injector/examples/miniapps/services/example/services.py
2016-10-19 15:25:19 +03:00

48 lines
1.3 KiB
Python

"""Example business services module."""
class UsersService(object):
"""Users service."""
def __init__(self, logger, db):
"""Initializer."""
self.logger = logger
self.db = db
def get_user_by_id(self, uid):
"""Return user's information by login."""
self.logger.debug('User %s has been found in database', uid)
return {'uid': uid,
'password_hash': 'secret_hash'}
class AuthService(object):
"""Auth service."""
def __init__(self, logger, db, token_ttl):
"""Initializer."""
self.logger = logger
self.db = db
self.token_ttl = token_ttl
def authenticate(self, user, password):
"""Authenticate user."""
assert user['password_hash'] == '_'.join((password, 'hash'))
self.logger.debug('User %s has been successfully authenticated',
user['uid'])
class PhotosService(object):
"""Photos service."""
def __init__(self, logger, db, s3):
"""Initializer."""
self.logger = logger
self.db = db
self.s3 = s3
def upload_photo(self, uid, photo_path):
"""Upload user photo."""
self.logger.debug('Photo %s has been successfully uploaded by user %s',
photo_path, uid)