feat: entire application
No files matched your search
@@ -0,0 +1,25 @@
|
||||
module.exports = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
project: 'tsconfig.json',
|
||||
tsconfigRootDir: __dirname,
|
||||
sourceType: 'module',
|
||||
},
|
||||
plugins: ['@typescript-eslint/eslint-plugin'],
|
||||
extends: [
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:prettier/recommended',
|
||||
],
|
||||
root: true,
|
||||
env: {
|
||||
node: true,
|
||||
jest: true,
|
||||
},
|
||||
ignorePatterns: ['.eslintrc.js'],
|
||||
rules: {
|
||||
'@typescript-eslint/interface-name-prefix': 'off',
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all",
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.hbs"],
|
||||
"options": {
|
||||
"parser": "html",
|
||||
"htmlWhitespaceSensitivity": "css",
|
||||
"singleQuote": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<!DOCTYPE html><html><head>
|
||||
<title>README</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<link rel="stylesheet" href="file:////home/biggy/.vscode/extensions/shd101wyy.markdown-preview-enhanced-0.8.15/crossnote/dependencies/katex/katex.min.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
code[class*=language-],pre[class*=language-]{color:#333;background:0 0;font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.4;-moz-tab-size:8;-o-tab-size:8;tab-size:8;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]{padding:.8em;overflow:auto;border-radius:3px;background:#f5f5f5}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal;background:#f5f5f5}.token.blockquote,.token.comment{color:#969896}.token.cdata{color:#183691}.token.doctype,.token.macro.property,.token.punctuation,.token.variable{color:#333}.token.builtin,.token.important,.token.keyword,.token.operator,.token.rule{color:#a71d5d}.token.attr-value,.token.regex,.token.string,.token.url{color:#183691}.token.atrule,.token.boolean,.token.code,.token.command,.token.constant,.token.entity,.token.number,.token.property,.token.symbol{color:#0086b3}.token.prolog,.token.selector,.token.tag{color:#63a35c}.token.attr-name,.token.class,.token.class-name,.token.function,.token.id,.token.namespace,.token.pseudo-class,.token.pseudo-element,.token.url-reference .token.variable{color:#795da3}.token.entity{cursor:help}.token.title,.token.title .token.punctuation{font-weight:700;color:#1d3e81}.token.list{color:#ed6a43}.token.inserted{background-color:#eaffea;color:#55a532}.token.deleted{background-color:#ffecec;color:#bd2c00}.token.bold{font-weight:700}.token.italic{font-style:italic}.language-json .token.property{color:#183691}.language-markup .token.tag .token.punctuation{color:#333}.language-css .token.function,code.language-css{color:#0086b3}.language-yaml .token.atrule{color:#63a35c}code.language-yaml{color:#183691}.language-ruby .token.function{color:#333}.language-markdown .token.url{color:#795da3}.language-makefile .token.symbol{color:#795da3}.language-makefile .token.variable{color:#183691}.language-makefile .token.builtin{color:#0086b3}.language-bash .token.keyword{color:#0086b3}pre[data-line]{position:relative;padding:1em 0 1em 3em}pre[data-line] .line-highlight-wrapper{position:absolute;top:0;left:0;background-color:transparent;display:block;width:100%}pre[data-line] .line-highlight{position:absolute;left:0;right:0;padding:inherit 0;margin-top:1em;background:hsla(24,20%,50%,.08);background:linear-gradient(to right,hsla(24,20%,50%,.1) 70%,hsla(24,20%,50%,0));pointer-events:none;line-height:inherit;white-space:pre}pre[data-line] .line-highlight:before,pre[data-line] .line-highlight[data-end]:after{content:attr(data-start);position:absolute;top:.4em;left:.6em;min-width:1em;padding:0 .5em;background-color:hsla(24,20%,50%,.4);color:#f4f1ef;font:bold 65%/1.5 sans-serif;text-align:center;vertical-align:.3em;border-radius:999px;text-shadow:none;box-shadow:0 1px #fff}pre[data-line] .line-highlight[data-end]:after{content:attr(data-end);top:auto;bottom:.4em}html body{font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif;font-size:16px;line-height:1.6;color:#333;background-color:#fff;overflow:initial;box-sizing:border-box;word-wrap:break-word}html body>:first-child{margin-top:0}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{line-height:1.2;margin-top:1em;margin-bottom:16px;color:#000}html body h1{font-size:2.25em;font-weight:300;padding-bottom:.3em}html body h2{font-size:1.75em;font-weight:400;padding-bottom:.3em}html body h3{font-size:1.5em;font-weight:500}html body h4{font-size:1.25em;font-weight:600}html body h5{font-size:1.1em;font-weight:600}html body h6{font-size:1em;font-weight:600}html body h1,html body h2,html body h3,html body h4,html body h5{font-weight:600}html body h5{font-size:1em}html body h6{color:#5c5c5c}html body strong{color:#000}html body del{color:#5c5c5c}html body a:not([href]){color:inherit;text-decoration:none}html body a{color:#08c;text-decoration:none}html body a:hover{color:#00a3f5;text-decoration:none}html body img{max-width:100%}html body>p{margin-top:0;margin-bottom:16px;word-wrap:break-word}html body>ol,html body>ul{margin-bottom:16px}html body ol,html body ul{padding-left:2em}html body ol.no-list,html body ul.no-list{padding:0;list-style-type:none}html body ol ol,html body ol ul,html body ul ol,html body ul ul{margin-top:0;margin-bottom:0}html body li{margin-bottom:0}html body li.task-list-item{list-style:none}html body li>p{margin-top:0;margin-bottom:0}html body .task-list-item-checkbox{margin:0 .2em .25em -1.8em;vertical-align:middle}html body .task-list-item-checkbox:hover{cursor:pointer}html body blockquote{margin:16px 0;font-size:inherit;padding:0 15px;color:#5c5c5c;background-color:#f0f0f0;border-left:4px solid #d6d6d6}html body blockquote>:first-child{margin-top:0}html body blockquote>:last-child{margin-bottom:0}html body hr{height:4px;margin:32px 0;background-color:#d6d6d6;border:0 none}html body table{margin:10px 0 15px 0;border-collapse:collapse;border-spacing:0;display:block;width:10Line truncated
|
||||
/* Please visit the URL below for more information: */
|
||||
/* https://shd101wyy.github.io/markdown-preview-enhanced/#/customize-css */
|
||||
|
||||
</style>
|
||||
<!-- The content below will be included at the end of the <head> element. --><script type="text/javascript">
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
// your code here
|
||||
});
|
||||
</script></head><body for="html-export">
|
||||
|
||||
|
||||
<div class="crossnote markdown-preview ">
|
||||
|
||||
<h1 id="galeria-kotów---aplikacja-mvc-w-nestjs">Galeria kotów - Aplikacja MVC w NestJS </h1>
|
||||
<h2 id="autor">Autor </h2>
|
||||
<p>Igor Barcik</p>
|
||||
<h2 id="opis-aplikacji">Opis Aplikacji </h2>
|
||||
<p>Galeria kotów to aplikacja webowa zbudowana w NestJS, wykorzystująca wzorzec projektowy MVC (Model-View-Controller). Aplikacja służy do przeglądania kolekcją zdjęć kotów.</p>
|
||||
<h3 id="dla-kogo">Dla kogo? </h3>
|
||||
<ul>
|
||||
<li>Miłośników kotów</li>
|
||||
<li>Osób chcących przeglądać zdjęcia kotów</li>
|
||||
</ul>
|
||||
<h2 id="implementacja-mvc-w-aplikacji">Implementacja MVC w Aplikacji </h2>
|
||||
<h3 id="model">Model </h3>
|
||||
<p>Reprezentacja danych i logiki biznesowej w <code>cats.service.ts</code>:</p>
|
||||
<pre data-role="codeBlock" data-info="ts" class="language-ts ts"><code><span class="token decorator"><span class="token at operator">@</span><span class="token function">Injectable</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
||||
<span class="token keyword keyword-export">export</span> <span class="token keyword keyword-class">class</span> <span class="token class-name">CatsService</span> <span class="token punctuation">{</span>
|
||||
<span class="token comment">// Logika biznesowa związana z kotami</span>
|
||||
<span class="token comment">// Operacje na danych</span>
|
||||
<span class="token punctuation">}</span>
|
||||
</code></pre><h3 id="view">View </h3>
|
||||
<p>Widoki są renderowane przy użyciu silnika Handlebars (hbs):</p>
|
||||
<pre data-role="codeBlock" data-info="ts" class="language-ts ts"><code><span class="token keyword keyword-const">const</span> app <span class="token operator">=</span> <span class="token keyword keyword-await">await</span> NestFactory<span class="token punctuation">.</span><span class="token generic-function"><span class="token function">create</span><span class="token generic class-name"><span class="token operator"><</span>NestExpressApplication<span class="token operator">></span></span></span><span class="token punctuation">(</span>AppModule<span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
app<span class="token punctuation">.</span><span class="token function">setViewEngine</span><span class="token punctuation">(</span><span class="token string">'hbs'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
|
||||
</code></pre><h3 id="controller">Controller </h3>
|
||||
<p>Kontrolery obsługujące żądania HTTP w <code>cats.controller.ts</code>:</p>
|
||||
<pre data-role="codeBlock" data-info="ts" class="language-ts ts"><code><span class="token decorator"><span class="token at operator">@</span><span class="token function">Controller</span></span><span class="token punctuation">(</span><span class="token string">'cats'</span><span class="token punctuation">)</span>
|
||||
<span class="token keyword keyword-export">export</span> <span class="token keyword keyword-class">class</span> <span class="token class-name">CatsController</span> <span class="token punctuation">{</span>
|
||||
<span class="token function">constructor</span><span class="token punctuation">(</span>
|
||||
<span class="token keyword keyword-private">private</span> <span class="token keyword keyword-readonly">readonly</span> catsService<span class="token operator">:</span> CatsService<span class="token punctuation">,</span>
|
||||
<span class="token keyword keyword-private">private</span> <span class="token keyword keyword-readonly">readonly</span> navigationService<span class="token operator">:</span> NavigationService<span class="token punctuation">,</span>
|
||||
<span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>
|
||||
|
||||
<span class="token decorator"><span class="token at operator">@</span><span class="token function">Get</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span>
|
||||
<span class="token decorator"><span class="token at operator">@</span><span class="token function">Render</span></span><span class="token punctuation">(</span><span class="token string">'cats'</span><span class="token punctuation">)</span>
|
||||
<span class="token keyword keyword-async">async</span> <span class="token function">getCats</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
||||
<span class="token comment">// Logika kontrolera</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">}</span>
|
||||
</code></pre><h2 id="struktura-projektu">Struktura Projektu </h2>
|
||||
<pre data-role="codeBlock" data-info="" class="language-text"><code>src/
|
||||
├── cats/
|
||||
│ ├── cats.controller.ts # Kontroler obsługujący endpointy
|
||||
│ ├── cats.service.ts # Serwis zawierający logikę biznesową
|
||||
│ └── cats.module.ts # Moduł kotów
|
||||
├── views/ # Szablony widoków
|
||||
└── app.module.ts # Główny moduł aplikacji
|
||||
</code></pre><h2 id="uruchomienie-aplikacji">Uruchomienie Aplikacji </h2>
|
||||
<p>Instalacja zależności:<br>
|
||||
<code>pnpm install</code></p>
|
||||
<p>Uruchomienie w trybie developerskim:<br>
|
||||
<code>pnpm run start:dev</code></p>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</body></html>
|
||||
@@ -0,0 +1,69 @@
|
||||
# Galeria kotów - Aplikacja MVC w NestJS
|
||||
|
||||
## Autor
|
||||
Igor Barcik
|
||||
|
||||
## Opis Aplikacji
|
||||
Galeria kotów to aplikacja webowa zbudowana w NestJS, wykorzystująca wzorzec projektowy MVC (Model-View-Controller). Aplikacja służy do przeglądania kolekcją zdjęć kotów.
|
||||
|
||||
### Dla kogo?
|
||||
- Miłośników kotów
|
||||
- Osób chcących przeglądać zdjęcia kotów
|
||||
|
||||
## Implementacja MVC w Aplikacji
|
||||
|
||||
### Model
|
||||
Reprezentacja danych i logiki biznesowej w `cats.service.ts`:
|
||||
|
||||
```ts
|
||||
@Injectable()
|
||||
export class CatsService {
|
||||
// Logika biznesowa związana z kotami
|
||||
// Operacje na danych
|
||||
}
|
||||
```
|
||||
|
||||
### View
|
||||
Widoki są renderowane przy użyciu silnika Handlebars (hbs):
|
||||
```ts
|
||||
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
||||
app.setViewEngine('hbs');
|
||||
```
|
||||
|
||||
### Controller
|
||||
Kontrolery obsługujące żądania HTTP w `cats.controller.ts`:
|
||||
|
||||
```ts
|
||||
@Controller('cats')
|
||||
export class CatsController {
|
||||
constructor(
|
||||
private readonly catsService: CatsService,
|
||||
private readonly navigationService: NavigationService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@Render('cats')
|
||||
async getCats() {
|
||||
// Logika kontrolera
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Struktura Projektu
|
||||
```
|
||||
src/
|
||||
├── cats/
|
||||
│ ├── cats.controller.ts # Kontroler obsługujący endpointy
|
||||
│ ├── cats.service.ts # Serwis zawierający logikę biznesową
|
||||
│ └── cats.module.ts # Moduł kotów
|
||||
├── views/ # Szablony widoków
|
||||
└── app.module.ts # Główny moduł aplikacji
|
||||
```
|
||||
|
||||
## Uruchomienie Aplikacji
|
||||
|
||||
Instalacja zależności:
|
||||
`pnpm install`
|
||||
|
||||
Uruchomienie w trybie developerskim:
|
||||
`pnpm run start:dev`
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/nest-cli",
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src",
|
||||
"compilerOptions": {
|
||||
"deleteOutDir": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"name": "mvc-app-nestjs",
|
||||
"version": "1.0",
|
||||
"description": "Simple cats gallery app built with NestJS",
|
||||
"author": "Igor Barcik",
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"build": "nest build",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/core": "^10.0.0",
|
||||
"@nestjs/platform-express": "^10.0.0",
|
||||
"@types/hbs": "^4.0.4",
|
||||
"hbs": "^4.2.0",
|
||||
"reflect-metadata": "^0.2.0",
|
||||
"rxjs": "^7.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^10.0.0",
|
||||
"@nestjs/schematics": "^10.0.0",
|
||||
"@nestjs/testing": "^10.0.0",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/jest": "^29.5.2",
|
||||
"@types/node": "^20.3.1",
|
||||
"@types/supertest": "^6.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
||||
"@typescript-eslint/parser": "^8.0.0",
|
||||
"eslint": "^8.0.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-prettier": "^5.0.0",
|
||||
"jest": "^29.5.0",
|
||||
"prettier": "^3.3.3",
|
||||
"source-map-support": "^0.5.21",
|
||||
"supertest": "^7.0.0",
|
||||
"ts-jest": "^29.1.0",
|
||||
"ts-loader": "^9.4.3",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsconfig-paths": "^4.2.0",
|
||||
"typescript": "^5.1.3"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"testRegex": ".*\\.spec\\.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"collectCoverageFrom": [
|
||||
"**/*.(t|j)s"
|
||||
],
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
},
|
||||
"packageManager": "pnpm@9.12.3+sha512.cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee"
|
||||
}
|
||||
|
After Width: | Height: | Size: 761 KiB |
|
After Width: | Height: | Size: 8.4 MiB |
|
After Width: | Height: | Size: 3.8 MiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 2.2 MiB |
|
After Width: | Height: | Size: 1.9 MiB |
|
After Width: | Height: | Size: 2.6 MiB |
|
After Width: | Height: | Size: 3.6 MiB |
|
After Width: | Height: | Size: 6.1 MiB |
|
After Width: | Height: | Size: 1.6 MiB |
|
After Width: | Height: | Size: 2.9 MiB |
|
After Width: | Height: | Size: 1.6 MiB |
|
After Width: | Height: | Size: 3.6 MiB |
|
After Width: | Height: | Size: 6.4 MiB |
|
After Width: | Height: | Size: 4.1 MiB |
@@ -0,0 +1,22 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile();
|
||||
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Controller, Get, Render, Req } from '@nestjs/common';
|
||||
import { Request } from 'express';
|
||||
import { AppService } from './app.service';
|
||||
import { NavigationService } from './navigation/navigation.service';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(
|
||||
private readonly appService: AppService,
|
||||
private readonly navigationService: NavigationService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@Render('index')
|
||||
root(@Req() request: Request) {
|
||||
return {
|
||||
navItems: this.navigationService.getNavigationItems(request.path),
|
||||
message: this.appService.getHello(),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { DiscoveryModule } from '@nestjs/core';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { CatsController } from './cats/cats.controller';
|
||||
import { CatsService } from './cats/cats.service';
|
||||
import { NavigationService } from './navigation/navigation.service';
|
||||
|
||||
@Module({
|
||||
imports: [DiscoveryModule],
|
||||
controllers: [AppController, CatsController],
|
||||
providers: [AppService, CatsService, NavigationService],
|
||||
})
|
||||
export class AppModule {}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { CatsController } from './cats.controller';
|
||||
|
||||
describe('CatsController', () => {
|
||||
let controller: CatsController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [CatsController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<CatsController>(CatsController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Controller, Get, Render, Req } from '@nestjs/common';
|
||||
import { Request } from 'express';
|
||||
import { NavigationService } from 'src/navigation/navigation.service';
|
||||
import { CatsService } from './cats.service';
|
||||
|
||||
@Controller('cats')
|
||||
export class CatsController {
|
||||
constructor(
|
||||
private readonly catsService: CatsService,
|
||||
private readonly navigationService: NavigationService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
@Render('cats')
|
||||
getGallery(@Req() request: Request) {
|
||||
const images = this.catsService.findAll();
|
||||
return {
|
||||
navItems: this.navigationService.getNavigationItems(request.path),
|
||||
images,
|
||||
message: 'Cats Gallery',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { CatsService } from './cats.service';
|
||||
|
||||
describe('CatsService', () => {
|
||||
let service: CatsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [CatsService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<CatsService>(CatsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
@Injectable()
|
||||
export class CatsService {
|
||||
private readonly imagesPath = path.join(
|
||||
process.cwd(),
|
||||
'public',
|
||||
'assets',
|
||||
'images',
|
||||
'cats',
|
||||
);
|
||||
|
||||
findAll(): string[] {
|
||||
const files = fs.readdirSync(this.imagesPath);
|
||||
const shuffled = [...files].sort(() => 0.5 - Math.random());
|
||||
return shuffled.map((file) => `/assets/images/cats/${file}`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { NestExpressApplication } from '@nestjs/platform-express';
|
||||
import { join } from 'path';
|
||||
import { AppModule } from './app.module';
|
||||
import * as hbs from 'hbs';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
||||
|
||||
app.useStaticAssets(join(__dirname, '..', 'public'));
|
||||
app.setBaseViewsDir(join(__dirname, '..', 'views'));
|
||||
app.setViewEngine('hbs');
|
||||
|
||||
hbs.registerPartials(join(__dirname, '..', 'views', 'partials'));
|
||||
|
||||
await app.listen(3000);
|
||||
}
|
||||
bootstrap();
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { NavigationService } from './navigation.service';
|
||||
|
||||
describe('NavigationService', () => {
|
||||
let service: NavigationService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [NavigationService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<NavigationService>(NavigationService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DiscoveryService, MetadataScanner, Reflector } from '@nestjs/core';
|
||||
|
||||
export interface NavItem {
|
||||
path: string;
|
||||
label: string;
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class NavigationService {
|
||||
constructor(
|
||||
private readonly discovery: DiscoveryService,
|
||||
private readonly metadataScanner: MetadataScanner,
|
||||
private readonly reflector: Reflector,
|
||||
) {}
|
||||
|
||||
private isGetMethod(handler: (...args: any[]) => any): boolean {
|
||||
return Reflect.getMetadata('method', handler) === 'GET';
|
||||
}
|
||||
|
||||
getNavigationItems(currentPath: string = '/'): NavItem[] {
|
||||
const navItems: NavItem[] = [
|
||||
{
|
||||
path: '/',
|
||||
label: 'Home',
|
||||
active: currentPath === '/',
|
||||
},
|
||||
{
|
||||
path: '/cats',
|
||||
label: 'Cats',
|
||||
active: currentPath === '/cats',
|
||||
},
|
||||
];
|
||||
|
||||
return navItems;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import * as request from 'supertest';
|
||||
import { AppModule } from './../src/app.module';
|
||||
|
||||
describe('AppController (e2e)', () => {
|
||||
let app: INestApplication;
|
||||
|
||||
beforeEach(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
}).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
await app.init();
|
||||
});
|
||||
|
||||
it('/ (GET)', () => {
|
||||
return request(app.getHttpServer())
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect('Hello World!');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"moduleFileExtensions": ["js", "json", "ts"],
|
||||
"rootDir": ".",
|
||||
"testEnvironment": "node",
|
||||
"testRegex": ".e2e-spec.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
"strictNullChecks": false,
|
||||
"noImplicitAny": false,
|
||||
"strictBindCallApply": false,
|
||||
"forceConsistentCasingInFileNames": false,
|
||||
"noFallthroughCasesInSwitch": false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<h1>{{message}}</h1>
|
||||
<div class="container">
|
||||
<div class="gallery">
|
||||
{{#each images}}
|
||||
<div class="gallery-item">
|
||||
<img src="{{this}}" alt="Cat Image" />
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.gallery {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
width: 100%;
|
||||
gap: 10px;
|
||||
}
|
||||
.gallery-item {
|
||||
height: 300px;
|
||||
flex-grow: 1;
|
||||
min-width: 200px;
|
||||
}
|
||||
img:hover {
|
||||
transform: scale(1.1);
|
||||
filter: drop-shadow(0 0 10px rgba(0, 0, 0, 0.5));
|
||||
transition: 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
|
||||
}
|
||||
.gallery-item img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 10pt;
|
||||
vertical-align: bottom;
|
||||
transition: 0.2s cubic-bezier(0.68, -0.55, 0.265, 1.55);
|
||||
user-select: none;
|
||||
}
|
||||
img:active {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: auto;
|
||||
height: auto;
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
object-fit: cover;
|
||||
background: rgba(0, 0, 0, 0.8);
|
||||
translate: translate(-50%, -50%);
|
||||
transform: scale(1);
|
||||
z-index: 1000;
|
||||
inset: 0;
|
||||
margin: auto;
|
||||
filter: drop-shadow(0 0 40px rgba(0, 0, 0, 1));
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1 @@
|
||||
<h1>{{message}}</h1>
|
||||
@@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>NestJS MVC</title>
|
||||
<link rel="stylesheet" href="https://matcha.mizu.sh/matcha.css">
|
||||
<link rel="stylesheet" href="https://matcha.mizu.sh/matcha.istanbul.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{{> navbar}}
|
||||
<div class="container mt-4">
|
||||
{{{body}}}
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,9 @@
|
||||
<nav>
|
||||
<menu>
|
||||
{{#each navItems}}
|
||||
<li class="{{#if active}}selected{{/if}}">
|
||||
<a href="{{this.path}}">{{this.label}}</a>
|
||||
</li>
|
||||
{{/each}}
|
||||
</menu>
|
||||
</nav>
|
||||