summaryrefslogtreecommitdiffstats
path: root/internal/models/organisations.go
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-02-09 16:38:46 +0000
committerMatthew Lemon <y@yulqen.org>2024-02-09 16:38:46 +0000
commit7c4a913645ba1e347ab94097de44eb04d7df4e47 (patch)
tree82fe2f9db6c549756f4f1e96ff1e781c0099603c /internal/models/organisations.go
parentb8ed10b800d24a94bb6a9339d5764c6dbe7d9f6e (diff)
Adds the Organisations model
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.
Diffstat (limited to 'internal/models/organisations.go')
-rw-r--r--internal/models/organisations.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/internal/models/organisations.go b/internal/models/organisations.go
new file mode 100644
index 0000000..7a8898c
--- /dev/null
+++ b/internal/models/organisations.go
@@ -0,0 +1,29 @@
+package models
+
+import (
+ "database/sql"
+ "time"
+)
+
+type Organisation struct {
+ ID int
+ Name string
+ Created time.Time
+}
+
+type OrganisationModel struct {
+ DB *sql.DB
+}
+
+func (m *OrganisationModel) Insert(name string) (int, error) {
+ return 0, nil
+}
+
+func (m *OrganisationModel) Get(id int) (Organisation, error) {
+ return Organisation{}, nil
+}
+
+// Ten most recent...
+func (m *OrganisationModel) Latest() ([]Organisation, error) {
+ return nil, nil
+}