Skip to content

Commit dc4b84d

Browse files
committed
feat: more models + migrations (wip)
1 parent dc25db1 commit dc4b84d

23 files changed

Lines changed: 5366 additions & 1124 deletions

.devcontainer/devcontainer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@
3333

3434
// Use 'forwardPorts' to make a list of ports inside the container available locally.
3535
// This can be used to network with other containers or with the host.
36-
"forwardPorts": [5432, 8000],
36+
"forwardPorts": [3000, 5432, 8000],
3737

3838
"portsAttributes": {
39+
"3000": {
40+
"label": "Application",
41+
"onAutoForward": "silent"
42+
},
3943
"5432": {
4044
"label": "PostgreSQL",
4145
"onAutoForward": "silent"

backend/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ audit = false
22
fund = false
33
save-exact = true
44
save-prefix = ""
5+
update-notifier = false

backend/api/sites.mjs

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,70 @@ async function routes (app, options) {
2020
return { hello: 'world' }
2121
})
2222

23+
/**
24+
* CREATE SITE
25+
*/
2326
app.post('/', {
27+
config: {
28+
// permissions: ['create:sites', 'manage:sites']
29+
},
2430
schema: {
2531
summary: 'Create a new site',
2632
tags: ['Sites'],
2733
body: {
2834
type: 'object',
29-
required: ['name', 'hostname'],
35+
required: ['hostname', 'title'],
3036
properties: {
31-
name: { type: 'string' },
32-
hostname: { type: 'string' }
37+
hostname: {
38+
type: 'string',
39+
minLength: 1,
40+
maxLength: 255,
41+
pattern: '^(\\*|[a-z0-9.-]+)$'
42+
},
43+
title: {
44+
type: 'string',
45+
minLength: 1,
46+
maxLength: 255
47+
}
48+
},
49+
examples: [
50+
{
51+
hostname: 'wiki.example.org',
52+
title: 'My Wiki Site'
53+
}
54+
]
55+
},
56+
response: {
57+
200: {
58+
description: 'Site created successfully',
59+
type: 'object',
60+
properties: {
61+
message: {
62+
type: 'string'
63+
},
64+
id: {
65+
type: 'string',
66+
format: 'uuid'
67+
}
68+
}
3369
}
3470
}
3571
}
3672
}, async (req, reply) => {
37-
return { hello: 'world' }
73+
const result = await WIKI.models.sites.createSite(req.body.hostname, { title: req.body.title })
74+
return {
75+
message: 'Site created successfully.',
76+
id: result.id
77+
}
3878
})
3979

80+
/**
81+
* UPDATE SITE
82+
*/
4083
app.put('/:siteId', {
84+
config: {
85+
permissions: ['manage:sites']
86+
},
4187
schema: {
4288
summary: 'Update a site',
4389
tags: ['Sites']
@@ -50,6 +96,9 @@ async function routes (app, options) {
5096
* DELETE SITE
5197
*/
5298
app.delete('/:siteId', {
99+
config: {
100+
permissions: ['manage:sites']
101+
},
53102
schema: {
54103
summary: 'Delete a site',
55104
tags: ['Sites'],
@@ -71,7 +120,9 @@ async function routes (app, options) {
71120
}
72121
}, async (req, reply) => {
73122
try {
74-
if (await WIKI.models.sites.deleteSite(req.params.siteId)) {
123+
if (await WIKI.models.sites.countSites() <= 1) {
124+
reply.conflict('Cannot delete the last site. At least 1 site must exist at all times.')
125+
} else if (await WIKI.models.sites.deleteSite(req.params.siteId)) {
75126
reply.code(204)
76127
} else {
77128
reply.badRequest('Site does not exist.')

backend/core/config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export default {
140140
await WIKI.models.sites.init(ids)
141141
await WIKI.models.groups.init(ids)
142142
await WIKI.models.authentication.init(ids)
143+
await WIKI.models.users.init(ids)
143144
},
144145
/**
145146
* Subscribe to HA propagation events

backend/db/migrations/0001_main.sql

Lines changed: 0 additions & 57 deletions
This file was deleted.
File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"id": "061e8c84-e05e-40b0-a074-7a56bd794fc7",
3+
"prevIds": [
4+
"00000000-0000-0000-0000-000000000000"
5+
],
6+
"version": "8",
7+
"dialect": "postgres",
8+
"ddl": [],
9+
"renames": []
10+
}

0 commit comments

Comments
 (0)