feat: add diagnostics route and broken link method
All checks were successful
Deploy eolas-api / deploy (push) Successful in 46s

This commit is contained in:
Thomas Bishop 2025-12-22 17:16:42 +00:00
parent 2dadba0cbe
commit db1f92cb66
6 changed files with 95 additions and 3 deletions

View file

@ -34,6 +34,47 @@ On the VPS, `eolas-api` runs as a `systemd` service. See the
## API
### Search
```
GET /search/<search_term>
```
```json
{
"count": 2,
"data": [
{
"entry": "Test_values_in_Bash",
"excerpt": "# <mark>Test</mark> values in Bash\n\n`<mark>test</mark>` is a built-in command that is used to compare values or determine whether\nsomething is the case.\n\nWe..."
},
{
"entry": "Testing_Python_code",
"excerpt": "...for a module called `lorem`, it will detzect the unit <mark>test</mark>\n files `lorem_<mark>test</mark>.py` and `<mark>test</mark>_lorem.py`.\n- In order to detect tests..."
},
```
### Diagnostics
#### Get broken links
```
GET /diagnostics/broken-links
```
```json
{
"count": 1,
"data": [
{
"source_entry_title": "Reducing_fractions",
"broken_link_title": "Equivalent%20fractions"
}
]
}
```
### Entries
#### Get all entries

View file

@ -0,0 +1,18 @@
export default class DiagnosticsController {
diagnosticsService
constructor(diagnosticsService) {
this.diagnosticsService = diagnosticsService
}
getBrokenLinks = (req, res) => {
const brokenLinks = this.diagnosticsService.getBrokenLinks()
if (!brokenLinks) {
return res.status(404).json({
message: `Broken link list could not be retrieved`,
})
}
return res.json(brokenLinks)
}
}

View file

@ -2,6 +2,7 @@ import express from "express"
import entries from "./routes/entries.js"
import tags from "./routes/tags.js"
import search from "./routes/search.js"
import diagnostics from "./routes/diagnostics.js"
import cors from "cors"
import { validateApiKey } from "./middlewear/auth.js"
import morgan from "morgan"
@ -17,6 +18,7 @@ app.use("/", validateApiKey)
app.use("/entries", entries)
app.use("/tags", tags)
app.use("/search", search)
app.use("/diagnostics", diagnostics)
app.listen(port, () => {
console.info(`TB-INFO eolas-api running on NodeJS ${process.version}`)

11
src/routes/diagnostics.js Normal file
View file

@ -0,0 +1,11 @@
import express from "express"
import DiagnosticsService from "../services/DiagnosticsService.js"
import DiagnosticsController from "../controllers/DiagnosticsController.js"
import database from "../db/connection.js"
const router = express.Router()
const diagnosticsService = new DiagnosticsService(database)
const diagnosticsContoller = new DiagnosticsController(diagnosticsService)
router.get("/broken-links", diagnosticsContoller.getBrokenLinks)
export default router

View file

@ -0,0 +1,17 @@
import { GET_BROKEN_LINKS } from "../sql/diagnostics.js"
export default class DiagnosticsService {
database
constructor(database) {
this.database = database
}
getBrokenLinks = () => {
const brokenLinks = this.database.prepare(GET_BROKEN_LINKS).all()
return {
count: brokenLinks.length,
data: brokenLinks,
}
}
}

3
src/sql/diagnostics.js Normal file
View file

@ -0,0 +1,3 @@
const GET_BROKEN_LINKS = `SELECT * from broken_links`
export { GET_BROKEN_LINKS }