Skip to content

Commit

Permalink
basic get jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
tktaofik committed Jan 6, 2020
1 parent 31dc331 commit 0e4abd1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions services/job/job/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ async def get_job(id: int):
return dict(row)


async def get_jobs():
stm = job.select()
rows = await pg.query(stm)
jobs = map(lambda row: dict(row), rows)
return list(jobs)


async def delete_job(id: int):
stm = job.delete().where(job.c.id == id)
await pg.fetchrow(stm)
7 changes: 7 additions & 0 deletions services/job/job/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ async def post_handler(request: web.Request):
return web.json_response(body=job_json, status=201)


@routes.get('/api/job')
async def get_jobs_handler(request: web.Request):
jobs = await JobService.get_jobs()
jobs_json = json.dumps(jobs, default=json_serialize)
return web.json_response(body=jobs_json, status=200)


@routes.get('/api/job/{id}')
async def get_handler(request: web.Request):
id: int = int(request.match_info['id'])
Expand Down
5 changes: 5 additions & 0 deletions services/job/job/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ async def get_job(id: int):
job = await db.get_job(id)
return job

@staticmethod
async def get_jobs():
jobs = await db.get_jobs()
return jobs

@staticmethod
async def delete_job(id: int):
await db.delete_job(id)
Expand Down

0 comments on commit 0e4abd1

Please sign in to comment.