edgebox-iot / api

Edgebox API & Dashboard
https://docs.edgebox.io/usage/dashboard/
MIT License
0 stars 0 forks source link

Option JSON structures as native PHP types #37

Open paulotruta opened 3 years ago

paulotruta commented 3 years ago

Def thinking the way we're decoding these options into json arrays we should perhaps think about mapping these to real types... not sure what would be best as we could manually do it for the PHP side which would be sufficient but it's also from the go side right pushing them in.. opinions?

_Originally posted by @inverse in https://github.com/edgebox-iot/api/pull/34#discussion_r652104563_

paulotruta commented 3 years ago

Yeah, agree about decoding into native types, as we can potentially validate the data even before it gets into the controller.

Validation is happening on the Go side thanks to Marshall and Unmarshall requirement of having to define these json structures as go types.

I also agree that we can use pure PHP for this, and gain a few neat features such as data types and expected values validation, a better structured codebase and thus cleaner code, and way less confusion on the controller side.

My suggestion is that we create the types and a class for serializing and deserializing these types from and to json. Then we replace the current option calls in the codebase with the native types ones which return known structures to PHP. Will be fun 😉

I see a good potential improvement here. Let's open a new issue based on this as the scope of doing it is probably gonna touch more parts of the codebase.

_Originally posted by @paulotruta in https://github.com/edgebox-iot/api/pull/34#discussion_r652663178_