diff --git a/docs/concepts.md b/docs/concepts.md new file mode 100644 index 0000000000..a700f2a99c --- /dev/null +++ b/docs/concepts.md @@ -0,0 +1,25 @@ +# Achitectural concepts + +Vikunja was built with a maximum flexibility in mind while developing. To achive this, I built a set of easy-to-use +functions and respective web handlers, all represented through interfaces. + +## CRUDable + +This interface defines methods to Create/Read/ReadAll/Update/Delete something. In order to use the common web +handler, the struct mus implement this and the rights interface. + +Each of these methods is called on an instance of a struct like so: + +```go +func (l *List) ReadOne() (err error) { + *l, err = GetListByID(l.ID) + return +} +``` + +In that case, it takes the `ID` saved in the struct instance, gets the full list object and fills the original object with it. +(See parambinder to understand where that `ID` is coming from). + +All functions should behave like this, if they create or update something, they should return the created/updated struct +instance. The only exception is `ReadAll()` which returns an interface. Usually this is an array, because, well you cannot +make an array of a set type (If you know a way to do this, don't hesitate to drop me a message). \ No newline at end of file diff --git a/docs/parambinder.md b/docs/parambinder.md new file mode 100644 index 0000000000..4b29838ca5 --- /dev/null +++ b/docs/parambinder.md @@ -0,0 +1,7 @@ +# How the binder works + +The binder binds all values inside the url to their respective fields in a struct. Those fields need to have a tag +"param" with the name of the url placeholder which must be the same as in routes. + +Whenever one of the standard CRUD methods is invoked, this binder is called, which enables one handler method +to handle all kinds of different urls with different parameters. diff --git a/routes/crud/paramBinder.go b/routes/crud/paramBinder.go index 2c774be16a..5e349578ed 100644 --- a/routes/crud/paramBinder.go +++ b/routes/crud/paramBinder.go @@ -10,16 +10,6 @@ import ( const paramTagName = "param" -///////////////////////// -// HOW THIS BINDER WORKS -///////////////////////// -// This binder binds all values inside the url to their respective fields in a struct. Those fields need to have a tag -// "param" with the name of the url placeholder which must be the same as in routes. -// -// Whenever one of the standard CRUD methods is invoked, this binder is called, which enables one handler method -// to handle all kinds of different urls with different parameters. -///////////////////////// - // ParamBinder binds parameters to a struct. // Currently a working implementation, waiting to implement this officially into echo. func ParamBinder(i interface{}, c echo.Context) (err error) {