Beispiel #1
0
def ClothingItemView(request: WSGIRequest):
    if request.method == "GET":
        itemId = request.GET.get('id')
        itemSelected = ClothingItem.objects.get(id=itemId)
        return StandardResponse(200, [itemSelected])
    elif request.method == "POST":
        response_body = json.loads(request.body)
        return StandardResponse(200, ["Item created"])
    else:
        responseCode, response = 400, "Supported methods: GET"
        return StandardResponse(responseCode, response)
Beispiel #2
0
def Chores(request: WSGIRequest):
    if request.method == "GET":
        chores = list(ChoreDB.objects.values())
        responseCode = 200 if len(chores) > 0 else 204
        response = chores
    elif request.method == "POST":
        responseCode, response = 500, ["Not implemented yet"]
    else:
        responseCode, response = 405, []

    return StandardResponse(responseCode, response)
Beispiel #3
0
def ClothingItemBatchView(request: WSGIRequest):
    if request.method == "GET":
        items = []
        # Get Query Parameters
        # itemCategories = request.GET.get('category', default='')
        # onlyClean = request.GET.get('clean')
        # for category in itemCategories:
        #     if onlyClean and (onlyClean.lower() == "true"):
        #         [items.append(i) for i in ClothingItem.objects.filter(category=category, remaining_tolerance__gt=0)]
        #     else:
        #         [items.append(i) for i in ClothingItem.objects.filter(category=category)]

        # Form Response
        if (len(items) == 0):
            responseCode, response = 204, []
        else:
            responseCode, response = 200, items

        return StandardResponse(responseCode, response)
    else:
        responseCode, response = 400, "Supported methods: GET"
        return StandardResponse(responseCode, response)
Beispiel #4
0
def Reminders(request: WSGIRequest):
    if request.method == 'GET':
        try:
            if 'verbose' in request.GET:
                reminders = list(ReminderDB.objects.values())
            else:
                reminders = [r.text for r in ReminderDB.objects.all()]
            response = reminders
            responseCode = 200 if len(reminders) > 0 else 204
        except Exception as e:
            return StandardResponse(500, str(e))
    elif request.method == 'POST':
        try:
            request_body = json.loads(request.body)
        except:
            responseCode = 400
            response = ["Bad request: Malformed JSON Input"]
            return StandardResponse(responseCode, response)

        if 'text' not in request_body:
            responseCode = 400
            response = ["Bad Request: missing 'text' query parameter"]
        else:
            reminder_text = request_body['text']
            try:
                reminder_priority = int(request_body['priority'])
            except:
                reminder_priority = -1

            reminder = ReminderDB.objects.create(text=reminder_text,
                                                 priority=reminder_priority,
                                                 time=datetime.now())
            reminder.save()
            responseCode = 201
            response = [{"id": reminder.id}]

    return StandardResponse(responseCode, response)
Beispiel #5
0
def Reminder(request: WSGIRequest, id: int):
    if request.method == 'DELETE':

        try:
            ReminderDB.objects.get(id=id).delete()
            return StandardResponse(204, [])
        except ReminderDB.DoesNotExist as e:
            return StandardResponse(404, ["Resource does not exist"])
        except Exception as e:
            return StandardResponse(500, [str(e)])

    elif request.method == 'GET':
        try:
            obj = ReminderDB.objects.get(id=id)
            response = model_to_dict(obj)
            return StandardResponse(200, [response])
        except ReminderDB.DoesNotExist as e:
            return StandardResponse(404, ["Resource does not exist"])
        except Exception as e:
            return StandardResponse(500, [str(e)])

    else:
        return StandardResponse(405, [])
Beispiel #6
0
def LaundryView(request: WSGIRequest):
    message = "Checking Laundry"
    return StandardResponse(200, [message])
Beispiel #7
0
def OutfitRejected(request: WSGIRequest):
    return StandardResponse(200, ["Outfit Rejected"])
Beispiel #8
0
def healthCheck(request):
    return StandardResponse(200, ["Healthy"])