openboxes icon indicating copy to clipboard operation
openboxes copied to clipboard

Generic API should handle datetime attributes properly

Open jmiranda opened this issue 5 years ago • 3 comments

Request

curl -b cookies.txt -X POST -H "Accept: application/json" \
-H "Content-Type: application/json" \
--data-binary "@transaction.json" \
https://openboxes.ngrok.io/openboxes/api/generic/transaction

Data

{
    "inventory.id" : "1",
    "source.id" : "0065",
    "transactionDate": "04/14/2020 15:39 +02:00",
}

Response

{
	"data": {
		"class": "org.pih.warehouse.inventory.Transaction",
		"id": "ff80818171ad0c000171ad0d7f710001",
		"comment": null,
		"confirmed": false,
		"confirmedBy": null,
		"createdBy": {
			"class": "User",
			"id": "3"
		},
		"dateConfirmed": null,
		"dateCreated": "2020-04-24T16:37:55Z",
		"destination": null,
		"inboundTransfer": null,
		"incomingShipment": null,
		"inventory": {
			"class": "Inventory",
			"id": "1"
		},
		"lastUpdated": "2020-04-24T16:37:55Z",
		"order": null,
		"outboundTransfer": null,
		"outgoingShipment": null,
		"receipt": null,
		"requisition": null,
		"source": {
			"class": "Location",
			"id": "0065"
		},
		"transactionDate": "2020-04-24T06:00:00Z",
		"transactionEntries": null,
		"transactionNumber": null,
		"transactionType": {
			"class": "TransactionType",
			"id": "8"
		},
		"updatedBy": {
			"class": "User",
			"id": "3"
		}
	}
}

jmiranda avatar Apr 24 '20 16:04 jmiranda

One option here is to override the custom date binder to provide support for multiple date formats. This feature already exists in Grails 2 and 3, but we could add a small customization to provide this until we're done with the Grails 3 migration.

https://stackoverflow.com/questions/963922/grails-date-unmarshalling

jmiranda avatar Apr 24 '20 16:04 jmiranda

A few other resources:

  • https://stackoverflow.com/questions/12088519/how-use-registercustomeditors-for-multiple-dates
  • https://stackoverflow.com/questions/2871977/binding-a-grails-date-from-params-in-a-controller

jmiranda avatar Apr 24 '20 18:04 jmiranda

Best way to handle this until we migrate to Grails 3 (0.9.0) would probably to allow longs for timestamps.

jmiranda avatar Mar 04 '21 04:03 jmiranda