Skip to content

Commit b4350bd

Browse files
authored
Merge pull request #124 from aquariophilie/feature/validation_and_lookup
Feature/validation and lookup
2 parents 94bfe26 + 2a1960a commit b4350bd

File tree

20 files changed

+267
-129
lines changed

20 files changed

+267
-129
lines changed

.github/linters/.eslintrc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"plugins": ["@typescript-eslint"],
4+
"extends": [
5+
"plugin:@typescript-eslint/recommended"
6+
],
7+
"rules": {
8+
"@typescript-eslint/no-var-requires": 0,
9+
"@typescript-eslint/no-empty-interface": 0
10+
}
11+
}

.github/linters/.htmlhintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"spec-char-escape": true,
1111
"id-unique": false,
1212
"src-not-empty": true,
13-
"title-require": false,
13+
"title-require": true,
1414
"alt-require": true,
1515
"doctype-html5": true,
1616
"id-class-value": false,
@@ -21,5 +21,5 @@
2121
"id-class-ad-disabled": false,
2222
"href-abs-or-rel": false,
2323
"attr-unsafe-chars": true,
24-
"head-script-disabled": false
24+
"head-script-disabled": true
2525
}

.github/workflows/linter.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,8 @@ jobs:
5353
VALIDATE_ALL_CODEBASE: false
5454
DEFAULT_BRANCH: main
5555
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
FILTER_REGEX_EXCLUDE: .*vscode/.*.json
57+
VALIDATE_JAVASCRIPT_STANDARD: false
58+
TYPESCRIPT_ES_CONFIG_FILE: .eslintrc.json
59+
VALIDATE_TYPESCRIPT_STANDARD: false
60+
VALIDATE_MARKDOWN: false

client/src/app.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4+
<title>Blobfishes app</title>
45
<meta charset="utf-8" />
56
<link rel="icon" href="/favicon.png" />
67
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">

client/src/lib/api.author.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import axios from 'axios'
2+
import {
3+
API_PATH
4+
} from './api';
5+
6+
const apiAuthorPath = `${API_PATH}/author`;
7+
8+
function findAuthors() {
9+
return axios.get(apiAuthorPath);
10+
}
11+
12+
function insertAuthor(payload) {
13+
return axios.post(apiAuthorPath, payload);
14+
}
15+
16+
function updateAuthor(id, payload) {
17+
const path = `${apiAuthorPath}/${id}`;
18+
return axios.put(path, payload);
19+
}
20+
21+
function removeAuthor(id) {
22+
const path = `${apiAuthorPath}/${id}`;
23+
return axios.delete(path);
24+
}
25+
26+
export const apiAuthor = {
27+
findAuthors,
28+
insertAuthor,
29+
updateAuthor,
30+
removeAuthor
31+
}

client/src/lib/api.book.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import axios from 'axios'
2+
import {
3+
API_PATH
4+
} from './api';
5+
6+
const apiBookPath = `${API_PATH}/book`;
7+
8+
function findBooks() {
9+
return axios.get(apiBookPath);
10+
}
11+
12+
function insertBook(payload) {
13+
return axios.post(apiBookPath, payload);
14+
}
15+
16+
function updateBook(id, payload) {
17+
const path = `${apiBookPath}/${id}`;
18+
return axios.put(path, payload);
19+
}
20+
21+
function removeBook(id) {
22+
const path = `${apiBookPath}/${id}`;
23+
return axios.delete(path);
24+
}
25+
26+
export const apiBook = {
27+
findBooks,
28+
insertBook,
29+
updateBook,
30+
removeBook
31+
}

client/src/lib/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const API_PATH = '/api';

client/src/lib/requests.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

client/src/routes/authors.svelte

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script>
2-
import axios from "axios";
32
import { onMount } from "svelte";
43
import {
54
Button,
@@ -14,8 +13,7 @@
1413
Label,
1514
Table,
1615
} from "sveltestrap";
17-
18-
const apiPath = "/api/author";
16+
import { apiAuthor } from "../lib/api.author";
1917
2018
var authors = [];
2119
var addAuthorForm = {
@@ -28,15 +26,13 @@
2826
let updateopen = false;
2927
3028
function getAuthors() {
31-
axios.get(`${apiPath}`).then((res) => {
29+
apiAuthor.findAuthors().then((res) => {
3230
authors = res.data;
3331
});
3432
}
3533
3634
function deleteAuthor(author) {
37-
const path = `${apiPath}/${author._id}`;
38-
axios
39-
.delete(path)
35+
apiAuthor.removeAuthor(author._id)
4036
.then(() => {
4137
getAuthors();
4238
})
@@ -55,13 +51,11 @@
5551
}
5652
5753
function addAuthor() {
58-
const path = `${apiPath}`;
5954
const payload = {
6055
name: addAuthorForm.name,
6156
bio: addAuthorForm.bio,
6257
};
63-
axios
64-
.post(path, payload)
58+
apiAuthor.insertAuthor(payload)
6559
.then(() => {
6660
getAuthors();
6761
})
@@ -74,13 +68,11 @@
7468
}
7569
7670
function updateAuthor() {
77-
const path = `${apiPath}/${addAuthorForm._id}`;
7871
const payload = {
7972
name: addAuthorForm.name,
8073
bio: addAuthorForm.bio,
8174
};
82-
axios
83-
.put(path, payload)
75+
apiAuthor.updateAuthor(addAuthorForm._id, payload)
8476
.then(() => {
8577
getAuthors();
8678
})

0 commit comments

Comments
 (0)