implement new appointement method

This commit is contained in:
vincent 2021-06-21 22:34:59 +02:00
parent 5ea127e080
commit 5f98a0a7bf
2 changed files with 59 additions and 2 deletions

View File

@ -62,7 +62,43 @@ def get_appointment_by_ticket(id):
@api.route("/appointment", methods=["POST"]) @api.route("/appointment", methods=["POST"])
def new_appointment(): def new_appointment():
raise NotImplementedError book_datetime = datetime.now()
start_datetime = request.values.get("start_datetime")
service = request.values.get("service")
planning = request.values.get("planning")
ticket = request.values.get("ticket")
customer = request.values.get("customer")
is_unavaillable = request.values.get("is_unavaillable")
notes = request.values.get("notes")
if start_datetime is None or service is None or planning is None:
return GenericError("missing parameter")
if is_unavaillable is None:
is_unavaillable = False
service = Service[service]
planning = Planning[planning]
start_datetime = datetime.strptime(start_datetime, "%Y-%m-%dT%H%M")
end_datetime = start_datetime + timedelta(minutes=service.service_category.duration)
if customer:
customer = Customer[customer]
if ticket:
ticket = Ticket[ticket]
if notes is None:
notes = ""
newappointment = Appointment(
book_datetime=book_datetime,
start_datetime=start_datetime,
end_datetime=end_datetime,
is_unavaillable=is_unavaillable,
service=service,
planning=planning,
ticket=ticket,
customer=customer,
notes="",
)
rv = jsonify(newappointment.to_dict())
rv.status_code = 201
return rv
@api.route("/appointment", methods=["PUT"]) @api.route("/appointment", methods=["PUT"])

View File

@ -1,5 +1,9 @@
from ..testBase import APITestBase from datetime import datetime, timedelta
from pony.orm import db_session from pony.orm import db_session
from ITPlanning.db import Appointment
from json import loads
from ..testBase import APITestBase
from ..assets.filldb import filldatabase
class AppointmentTestCase(APITestBase): class AppointmentTestCase(APITestBase):
@ -63,3 +67,20 @@ class AppointmentTestCase(APITestBase):
req, data = self.make_request("appointment/customer/1", 200) req, data = self.make_request("appointment/customer/1", 200)
req, data = self.make_request("appointment/ticket/1", 200) req, data = self.make_request("appointment/ticket/1", 200)
def test_post_appointment(self):
with db_session:
service = filldatabase.create_service()
customer = filldatabase.create_Customer()
planning = filldatabase.create_planning()
planning.services.add(service)
req = self.make_request(
"appointment",
201,
{
"start_datetime": datetime.now().strftime("%Y-%m-%dT%H%M"),
"planning": planning.id,
"service": service.id,
},
"post",
)
print(req)