@cryptotaxi247 / CoPilot / commits / 577472af

read from customers and customers_meta table for a given customer id (#69)

taylor_socfortress committed Jul 26, 2023 at 10:12 UTC 577472af4630bbdb5724bf660aaed31ceaf83fb2
2 files changed +67
backend/app/routes/customers.py
+19
@@ -256,3 +256,22 @@ def update_customer_meta(id: int):
256 )
257
258 return jsonify(updated_customer_meta), 201
259 +
260 +
261 +@bp.route("/customers/details/<int:id>", methods=["GET"])
262 +def read_customer_and_meta_details(id: int):
263 + """
264 + Endpoint to fetch a customer by their id and retrieve their details from the
265 + `customers` and `CustomersMeta` tables.
266 +
267 + Returns:
268 + Tuple[jsonify, int]: A Tuple where the first element is a JSON response
269 + containing the customer and customer meta details, and the second element is
270 + the HTTP status code.
271 + """
272 + logger.info(f"Received request to get customer and customer meta details with id {id}")
273 + customer = UniversalCustomers.read_by_id(id)
274 + customer_meta = UniversalCustomersMeta.read_by_id(id)
275 + if customer and customer_meta:
276 + return jsonify({"customer": customer, "customer_meta": customer_meta, "message": "Customer details fetched.", "success": True}), 200
277 + return jsonify({"message": "Customer or Customer Meta not found", "success": False}), 404
backend/app/static/swagger.json
+48
@@ -784,6 +784,54 @@
784 }
785 }
786 },
787 + "/customers/details/{id}": {
788 + "get": {
789 + "tags": ["Customers"],
790 + "summary": "Get a customer",
791 + "description": "Endpoint to retrieve a customer details from the `customers` and `customers_meta` tables.",
792 + "parameters": [
793 + {
794 + "name": "id",
795 + "in": "path",
796 + "description": "ID of the customer to retrieve",
797 + "required": true,
798 + "type": "integer"
799 + }
800 + ],
801 + "responses": {
802 + "200": {
803 + "description": "Successful operation",
804 + "content": {
805 + "application/json": {
806 + "schema": {
807 + "type": "object",
808 + "properties": {
809 + "message": { "type": "string", "example": "Customer retrieved successfully." },
810 + "success": { "type": "boolean", "example": true },
811 + "customer": { "$ref": "#/definitions/Customer" },
812 + "customerMeta": { "$ref": "#/definitions/CustomerMeta" }
813 + }
814 + }
815 + }
816 + }
817 + },
818 + "404": {
819 + "description": "Customer not found",
820 + "content": {
821 + "application/json": {
822 + "schema": {
823 + "type": "object",
824 + "properties": {
825 + "message": { "type": "string", "example": "Customer not found." },
826 + "success": { "type": "boolean", "example": false }
827 + }
828 + }
829 + }
830 + }
831 + }
832 + }
833 + }
834 + },
835 "/agents": {
836 "get": {
837 "tags": ["Agents"],