Example #1
0
async def http_server(db_connection, shared_obj, config):
    app = web.Application()

    user = User(db_connection, shared_obj, config, sendWSMessage)
    app.add_routes([
        web.get('/api/users', user.get),
        web.get('/api/users/{id}', user.get),
        web.post('/api/users', user.post),
        web.put('/api/users/{id}', user.put),
        web.delete('/api/users/{id}', user.delete),
    ])

    production = Production(db_connection, shared_obj, config, sendWSMessage)
    app.add_routes([
        web.post('/api/production', production.post),
        web.get('/api/production', production.get),
        web.get('/api/production/{id}', production.get),
        web.put('/api/production/{id}', production.put),
        web.delete('/api/production/{id}', production.delete),
    ])

    printer = Printer(db_connection, shared_obj, config, sendWSMessage)
    app.add_routes([
        web.get('/api/print/{action}', printer.get),
        web.post('/api/print/{action}', printer.post),
        web.get('/api/print/{action}/{subaction}', printer.get),
        web.post('/api/print/{action}/{subaction}', printer.post),
        web.put('/api/print/{action}/{subaction}', printer.put),
        web.delete('/api/print/{action}/{subaction}', printer.delete)
    ])

    index = Index(db_connection, shared_obj, config)
    app.add_routes([
        web.get('/', index.get),
        web.get('/users', index.get),
        web.get('/weighing', index.get),
        web.get('/templates', index.get),
        web.get('/production/list', index.get),
        web.get('/api/{action}', index.get)
    ])

    app.add_routes([
        web.static('/', './static'),
    ])

    setup_middlewares(app)
    runner = web.AppRunner(app, logger=LOGGER)
    await runner.setup()
    site = web.TCPSite(runner, '0.0.0.0', 8080)
    await site.start()
Example #2
0
 def user_info(self, user_id):
     (status, data) = self.get_data('users/%s.json' % user_id)
     if status:
         return User(data, api=self)