-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
52 lines (44 loc) · 1.62 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import express from "express";
import { RemoteDBRepository } from "./apps/remote-DB/adapters/RemoteDBRepository";
import { RedisCacheRepository } from "./apps/remote-DB/adapters/RedisCacheRepository";
import { CacheMemoryUser } from "./apps/remote-DB/CacheMemoryUser";
import { LogNotification } from "./apps/users/adapters/LogNotification";
import { MemoryUser } from "./apps/users/adapters/MemoryUser";
import { UserDomain } from "./apps/users/UserDomain";
const app = express();
const port = 3000;
app.get("/", (_req, res) => {
res.send("Hello World!");
});
const memoryRepo = new MemoryUser();
const logService = new LogNotification();
const cacheRepo = new RedisCacheRepository();
const dbRepo = new RemoteDBRepository();
const cacheUser = new CacheMemoryUser(cacheRepo, dbRepo);
// If we want to switch the store of user from memory to cache, we only need to change this.
// const userDomain = new UserDomain(memoryRepo, logService);
const userDomain = new UserDomain(cacheUser, logService);
app.get("/user", (req, res) => {
// Create User
// Domain
// create-user in database
// send notification
if (
typeof req.query.name === "string" &&
typeof req.query.email === "string" &&
req.query.name &&
req.query.email
) {
userDomain.create(req.query.name, req.query.email);
res.send("We are going to create a user for you, please wait !");
} else {
res.send({ message: "Please provide name and email" });
}
});
app.get("/users", async (req, res) => {
const users = await userDomain.list();
res.send(users);
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});