def showfood(request, id): if request.method == 'GET': user = Foods.objects.filter(id=id).first() if not user: return Response.badRequest(message='Pengguna tidak ditemukan!') user = transformer.foodTransform(user) return Response.badRequest(values=user) elif request.method == 'PUT': json_data = json.loads(request.body) user = Foods.objects.filter(id=id).first() if not user: return Response.badRequest(message="Pengguna tidak ditemukan") user.name = json_data['name'] user.price = json_data['harga'] user.isready = json_data['isready'] user.save() return Response.ok(values=transformer.foodTransform(user), message="Updated!") elif request.method == 'DELETE': user = Foods.objects.filter(id=id).first() if not user: return Response.badRequest(message="Pengguna tidak ditemukan") user.delete() return Response.ok(message="Deleted!") else: return Response.badRequest(message="Invalid method!")
def show(request, id): if request.method == 'GET': user = Users.objects.filter(id=id).first() if not user: return Response.badRequest(message='Pengguna tidak ditemukan!') user = transformer.singleTransform(user) return Response.badRequest(values=user) elif request.method == 'PUT': json_data = json.loads(request.body) user = Users.objects.filter(id=id).first() if not user: return Response.badRequest(message="Pengguna tidak ditemukan") user.jumlah = json_data['jumlah'] user.foods = Foods.objects.get(id=json_data["food"]) user.save() return Response.ok(values=transformer.singleTransform(user), message="Updated!") elif request.method == 'DELETE': user = Users.objects.filter(id=id).first() if not user: return Response.badRequest(message="Pengguna tidak ditemukan") user.delete() return Response.ok(message="Deleted!") else: return Response.badRequest(message="Invalid method!")
def pesanansshow(request, id): if request.method == 'GET': user = Pesanans.objects.filter(id=id).first() if not user: return Response.badRequest(message='Pengguna tidak ditemukan!') user = transformer.pesanansTransform(user) return Response.badRequest(values=user) elif request.method == 'PUT': json_data = json.loads(request.body) user = Pesanans.objects.filter(id=id).first() if not user: return Response.badRequest(message="Pengguna tidak ditemukan") user.nama = json_data['nama'] user.nomeja = json_data['nomor meja'] user.keranjang = Users.objects.all() user.save() return Response.ok(values=transformer.pesanansTransform(user), message="Updated!") elif request.method == 'DELETE': user = Pesanans.objects.filter(id=id).first() if not user: return Response.badRequest(message="Pengguna tidak ditemukan") user.delete() return Response.ok(message="Deleted!") else: return Response.badRequest(message="Invalid method!")
def show(request, id): if request.method == 'GET': user = Users.objects.filter(id=id).first() if not user: return Response.badRequest(message='Pengguna tidak ditemukan!') user = transformer.singleTransform(user) return Response.badRequest(values=user) elif request.method == 'PUT': json_data = json.loads(request.body) user = Users.objects.filter(id=id).first() if not user: return Response.badRequest(message="Pengguna tidak ditemukan") user.name = json_data['name'] user.email = json_data['email'] user.password = make_password(password=json_data['password']) user.save() return Response.ok(values=transformer.singleTransform(user), message="Updated!") elif request.method == 'DELETE': user = Users.objects.filter(id=id).first() if not user: return Response.badRequest(message="Pengguna tidak ditemukan") user.delete() return Response.ok(message="Deleted!") else: return Response.badRequest(message="Invalid method!")
def auth(request): if request.method == 'POST': json_data = json.loads(request.body) email = json_data['email'] user = Users.objects.filter(email=email).first() if not user: return Response.badRequest(message='Pengguna tidak ditemukan!') if not check_password(json_data['password'], user.password): return Response.badRequest( message="Password atau email yang kamu masukkan salah!") user = transformer.singleTransform(user) jwt = JWTAuth() user['token'] = jwt.encode({"id": user['id']}) return Response.ok(values=user, message="Berhasil masuk!")