예제 #1
0
    def get(self):
        """
        Return all jobs
        """
        jobs = CoOpJobService.get_all()

        return Response.success(
            CoOpJobSchema().dump(jobs, many=True),
            HttpStatusCode.OK,
            message="List of jobs")
예제 #2
0
 def get(self, id):
     """
     get a job details
     """
     job = CoOpJobService.get_by_id(id)
     if job:
         return Response.success(
             CoOpJobSchema().dump(job),
             status_code=HttpStatusCode.OK,
             message="Detail of the job.")
     else:
         return Response.error({},
                               status_code=HttpStatusCode.NOT_FOUND,
                               message="Job does not exist")
예제 #3
0
 def delete(self, id):
     """
     soft deleting the Job.
     """
     deleted, error = CoOpJobService.delete_by_id(id)
     if deleted:
         return Response.success(
             {"id": id},
             status_code=HttpStatusCode.OK,
             message="Job Deleted Successful")
     else:
         return Response.error(
             error,
             status_code=HttpStatusCode.NOT_FOUND,
             message="Job does not exist.")
예제 #4
0
    def post(self):
        """
        create new job
        """
        payload = request.json
        schema = CoOpJobSchema()
        try:
            result = schema.load(payload)
        except ValidationError as err:
            return Response.error(err.messages,
                                  status_code=HttpStatusCode.BAD_REQUEST,
                                  message="Form validation error.")

        return Response.success(schema.dump(result),
                                status_code=HttpStatusCode.CREATED,
                                message="Job created successful.")
예제 #5
0
    def put(self, id):
        """
        update the given id job
        """
        payload = request.json
        schema = CoOpJobSchema()
        current_job = CoOpJobService.get_by_id(id)
        try:
            result = schema.load(payload, instance=current_job, partial=True)
        except ValidationError as err:
            return Response.error(err.messages,
                                  status_code=HttpStatusCode.BAD_REQUEST,
                                  message="Form validation error.")

        return Response.success(schema.dump(result),
                                status_code=HttpStatusCode.OK,
                                message="Job updated successful.")