summaryrefslogtreecommitdiffstats
path: root/cmd (unfollow)
Commit message (Collapse)AuthorFilesLines
2024-02-15Implementing the templateCache in organisations listMatthew Lemon2-13/+12
The render() function at the moment requires a templateData struct to be passed to it, but prior to this commit, that struct only had an Operations field in it. We have now added an Organisations field too - the thinking being that we only add the data we need for the page in question and the other fields remain as nil values. As of this commit - the slice of Organisations passed is not rendered correctly by the template - just a raw data dump to prove it works.
2024-02-15Implemented template cacheMatthew Lemon4-22/+73
This is not perfect. At the moment, the new render() function, introduced in this commit, expects a templateData{} struct which contains an Operations field. This will need to be made generic, or we have multiple render() functions to accommdate the different types of data struct we want to be able to pass to templates. Also, in this commit I had to get rid of the /pages/operations and /pages/organisation sub directories for now. This does not fit the newTemplateCache() function - also introduced here. This needs to be refactored if we want to have subdirectories of templates - or else we stick to putting them inside pages/ and we name them appropriately, as we have done here with operations_list and organisation_list templates.
2024-02-12Operations list shows ESs for each entityMatthew Lemon1-4/+9
This was about two hours of learning, and getting confused - and it needs to be refactored. We need to be able to generate the list of EPs for the Operation also. At the moment this only prints the object representation. More work to be done writing a method that gives us the id and textual representation for the link in the table.
2024-02-12wip: mating EPs with OperationsMatthew Lemon2-7/+20
2024-02-12An Operations list page now renders data in tableMatthew Lemon2-4/+2
The data is fetched from the database and uses html/template to render the rows in a list. A critical bug was not including the dot in {{ template "main" . }} in the base template. THIS MEANT THAT NO DATA PASSED TO ExecuteTemplate function rendered and took a long time to figure out.
2024-02-11wip: Cannot get the dynamic data to show up in templateMatthew Lemon2-6/+19
2024-02-11Adds an operations html templateMatthew Lemon1-4/+17
Does not contain any dynamic data at this point, i.e. does not actually list the operations from the database - just dummy data at this point.
2024-02-11Have added a listAll handler for new operation modelMatthew Lemon3-0/+16
This is the first attempt at querying a table with a foreign key relation and returning the result to be used in Go code. Learned quite a bit! Including getting a null pointer error because I forgot to initialise the sql.DB in the application structure.
2024-02-10Implements Latest() organisation model methodMatthew Lemon1-11/+21
And puts the list in plain text on the home page.
2024-02-10Adds the Get handler for organisation model and fixesMatthew Lemon2-27/+46
Also fixes the NotAuthorised response I was mistakenly getting when it should have been a 404.
2024-02-10Adds the view handler for our organisation modelMatthew Lemon2-0/+6
We omitted to include this earlier and it is needed for the create handler, which creates the new entity in the database and then redirects to the view handler which will show the organisation page.
2024-02-10Adds a comment above code to handle "/" routeMatthew Lemon1-0/+4
We only want "/" to match the home route; this comment explains that.
2024-02-10Adds missing importMatthew Lemon1-1/+0
2024-02-10Have added Insert handler for Organisation modelMatthew Lemon2-13/+45
This is a straight forward wrapper around INSERT. Also added a clientError into a new helpers.go file.
2024-02-09Adds the Organisations modelMatthew Lemon1-2/+5
We have separation of concerns: the model is initalised and passed into the app struct, therefore our database logic will not be tied to our handlers. Our model, with its methods, is nicely encapsulated. We can initialise it and pass it to our handlers as a dependency. We can in future create an interface to mock the OrganisationModel object to be used in unit testing. We can also switch databases (theoretically) but providing a -dsn command-line flag.
2024-02-09Adds the database driver and opens database poolMatthew Lemon1-4/+36
Adds the new -dsn flag so that the user can pass any database into the program. Adds a new function that wraps sql.Open() to create the connection pool, and pings it to ensure it is alive.
2024-02-09Adds flagsMatthew Lemon1-2/+7
Accepts -addr for the port. Commented out flag for dsn (database string) - not yet implemented. See https://github.com/go-sql-driver/mysql#dsn-data-source-name for the correct format to be used for MySQL/MariaDB.
2024-02-08Added nav partialMatthew Lemon1-2/+2
Added a partial html for the navigation bar. So far it just has a link to "Home" on it.
2024-02-08Created a /organisations/list routeMatthew Lemon3-4/+35
There is also some basic CSS here. Also introduced a proper structured logger.
2024-02-08First proper use of templatesMatthew Lemon1-1/+1
2024-02-08First appearance of HTML on the home pageMatthew Lemon1-1/+33
2024-02-08Moved main to cmd/web and added routes() methodMatthew Lemon3-0/+45
Started to separate out funtionality: added an application struct and several methods (routes(), home() and a notFound() error). At the moment, the application struct does not carry any other configuration objects or a database pool connection - it is just there to get the routing going.