Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
H
Homework83_M11
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ли Джен Сеп
Homework83_M11
Commits
3f46dd44
Commit
3f46dd44
authored
Dec 19, 2024
by
Ли Джен Сеп
💬
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'validation' into 'master'
Validation See merge request
!14
parents
7b9451a2
38b0cdb6
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
155 additions
and
308 deletions
+155
-308
README.md
README.md
+3
-0
InputField.tsx
frontend/src/app/components/InputField.tsx
+48
-51
page.tsx
frontend/src/app/page.tsx
+95
-113
package-lock.json
package-lock.json
+0
-6
app.controller.spec.ts
service/src/app.controller.spec.ts
+0
-22
app.controller.ts
service/src/app.controller.ts
+0
-12
app.module.ts
service/src/app.module.ts
+0
-11
app.service.ts
service/src/app.service.ts
+0
-8
main.ts
service/src/main.ts
+5
-5
update-message.dto.ts
service/src/message/dto/update-message.dto.ts
+0
-4
message.entity.ts
service/src/message/entities/message.entity.ts
+0
-1
message.controller.spec.ts
service/src/message/message.controller.spec.ts
+0
-20
message.controller.ts
service/src/message/message.controller.ts
+2
-2
message.service.spec.ts
service/src/message/message.service.spec.ts
+0
-18
message.service.ts
service/src/message/message.service.ts
+2
-2
app.e2e-spec.ts
service/test/app.e2e-spec.ts
+0
-24
jest-e2e.json
service/test/jest-e2e.json
+0
-9
No files found.
README.md
View file @
3f46dd44
POST http://localhost:8000/encode
POST http://localhost:8000/decode
frontend/src/app/components/InputField.tsx
View file @
3f46dd44
...
@@ -2,60 +2,57 @@ import { Grid2, TextField, Typography } from "@mui/material";
...
@@ -2,60 +2,57 @@ import { Grid2, TextField, Typography } from "@mui/material";
import
{
ChangeEvent
}
from
"react"
;
import
{
ChangeEvent
}
from
"react"
;
interface
Props
{
interface
Props
{
name
:
"Decoded"
|
"Encoded"
|
"Password"
;
name
:
"Decoded"
|
"Encoded"
|
"Password"
;
value
:
string
;
value
:
string
;
onChange
:
(
e
:
ChangeEvent
<
HTMLInputElement
>
)
=>
void
;
onChange
:
(
e
:
ChangeEvent
<
HTMLInputElement
>
)
=>
void
;
}
}
export
default
function
InputField
({
name
,
value
,
onChange
}:
Props
)
{
export
default
function
InputField
({
name
,
value
,
onChange
}:
Props
)
{
let
labelText
:
string
=
""
;
let
labelText
:
string
=
""
;
switch
(
name
)
{
switch
(
name
)
{
case
"Decoded"
:
case
"Decoded"
:
labelText
=
`Decoded message`
;
labelText
=
`Decoded message`
;
break
;
break
;
case
"Encoded"
:
case
"Encoded"
:
labelText
=
`Encoded message`
;
labelText
=
`Encoded message`
;
break
;
break
;
case
"Password"
:
case
"Password"
:
labelText
=
""
;
labelText
=
""
;
break
;
break
;
default
:
default
:
break
;
break
;
}
}
return
(
return
(
<
Grid2
container
alignItems=
"center"
paddingY=
{
2
}
spacing=
{
2
}
>
<
Grid2
container
alignItems=
"center"
paddingY=
{
2
}
spacing=
{
2
}
>
<
Grid2
flexGrow=
{
1
}
>
<
Grid2
flexGrow=
{
1
}
>
<
Typography
<
Typography
component=
"label"
component=
"label"
htmlFor=
{
`${name}-input`
}
htmlFor=
{
`${name}-input`
}
sx=
{
{
sx=
{
{
fontSize
:
{
fontSize
:
{
xs
:
"16px"
,
xs
:
"16px"
,
sm
:
"20px"
,
sm
:
"20px"
,
},
},
}
}
}
}
>
>
{
labelText
}
{
labelText
}
</
Typography
>
</
Typography
>
</
Grid2
>
</
Grid2
>
<
Grid2
<
Grid2
size=
{
name
===
"Password"
?
6
:
8
}
sx=
{
{
"@media (max-width: 900px)"
:
{
width
:
"100%"
}
}
}
>
size=
{
name
===
"Password"
?
6
:
8
}
<
TextField
sx=
{
{
"@media (max-width: 900px)"
:
{
width
:
"100%"
}
}
}
fullWidth
>
multiline=
{
name
!==
"Password"
}
<
TextField
rows=
{
name
===
"Password"
?
1
:
6
}
fullWidth
variant=
"outlined"
multiline=
{
name
!==
"Password"
}
id=
{
`${name}-input`
}
rows=
{
name
===
"Password"
?
1
:
6
}
name=
{
name
}
variant=
"outlined"
label=
{
name
}
id=
{
`${name}-input`
}
value=
{
value
}
name=
{
name
}
onChange=
{
onChange
}
label=
{
name
}
/>
value=
{
value
}
</
Grid2
>
onChange=
{
onChange
}
</
Grid2
>
/>
);
</
Grid2
>
</
Grid2
>
);
}
}
frontend/src/app/page.tsx
View file @
3f46dd44
...
@@ -5,125 +5,107 @@ import { ChangeEvent, FormEvent, useState } from "react";
...
@@ -5,125 +5,107 @@ import { ChangeEvent, FormEvent, useState } from "react";
import
InputField
from
"./components/InputField"
;
import
InputField
from
"./components/InputField"
;
interface
IFormData
{
interface
IFormData
{
decoded
:
string
;
decoded
:
string
;
encoded
:
string
;
encoded
:
string
;
password
:
string
;
password
:
string
;
}
}
export
default
function
Home
()
{
export
default
function
Home
()
{
const
[
formData
,
setFormData
]
=
useState
<
IFormData
>
({
const
[
formData
,
setFormData
]
=
useState
<
IFormData
>
({
encoded
:
""
,
encoded
:
""
,
decoded
:
""
,
decoded
:
""
,
password
:
""
,
password
:
""
,
});
});
const
submitFormHandler
=
(
e
:
FormEvent
<
HTMLFormElement
>
)
=>
{
const
submitFormHandler
=
(
e
:
FormEvent
<
HTMLFormElement
>
)
=>
{
e
.
preventDefault
();
e
.
preventDefault
();
};
};
const
onInputChangeHandler
=
(
e
:
ChangeEvent
<
HTMLInputElement
>
)
=>
{
const
onInputChangeHandler
=
(
e
:
ChangeEvent
<
HTMLInputElement
>
)
=>
{
const
{
name
,
value
}
=
e
.
target
;
const
{
name
,
value
}
=
e
.
target
;
setFormData
((
prevData
)
=>
({
setFormData
((
prevData
)
=>
({
...
prevData
,
...
prevData
,
[
name
.
toLowerCase
()]:
value
,
[
name
.
toLowerCase
()]:
value
,
}));
}));
};
};
return
(
return
(
<
div
className=
"App"
>
<
div
className=
"App"
>
<
Container
sx=
{
{
marginTop
:
2
}
}
maxWidth=
"lg"
>
<
Container
sx=
{
{
marginTop
:
2
}
}
maxWidth=
"lg"
>
<
Typography
<
Typography
variant=
"h3"
variant=
"h3"
sx=
{
{
sx=
{
{
fontSize
:
{
fontSize
:
{
xs
:
"24px"
,
xs
:
"24px"
,
sm
:
"36px"
,
sm
:
"36px"
,
},
},
}
}
}
}
>
>
Cypher Coder/Decoder
Cypher Coder/Decoder
</
Typography
>
</
Typography
>
<
Box
<
Box
sx=
{
{
sx=
{
{
maxWidth
:
{
maxWidth
:
{
xs
:
"90%"
,
xs
:
"90%"
,
sm
:
"80%"
,
sm
:
"80%"
,
lg
:
"70%"
,
lg
:
"70%"
,
},
},
}
}
}
}
component=
"form"
component=
"form"
autoComplete=
"off"
autoComplete=
"off"
onSubmit=
{
submitFormHandler
}
onSubmit=
{
submitFormHandler
}
paddingY=
{
2
}
paddingY=
{
2
}
>
>
<
Grid2
container
direction=
"column"
spacing=
{
2
}
>
<
Grid2
container
direction=
"column"
spacing=
{
2
}
>
<
InputField
<
InputField
name=
"Decoded"
value=
{
formData
.
decoded
}
onChange=
{
onInputChangeHandler
}
/>
name=
"Decoded"
<
Grid2
value=
{
formData
.
decoded
}
container
onChange=
{
onInputChangeHandler
}
alignItems=
"center"
/>
sx=
{
{
<
Grid2
flexDirection
:
{
container
xs
:
"column"
,
alignItems=
"center"
md
:
"row"
,
sx=
{
{
},
flexDirection
:
{
}
}
xs
:
"column"
,
>
md
:
"row"
,
<
Grid2
size=
{
7
}
>
},
<
InputField
name=
"Password"
value=
{
formData
.
password
}
onChange=
{
onInputChangeHandler
}
/>
}
}
</
Grid2
>
>
<
Grid2
container
justifyContent=
{
{}
}
>
<
Grid2
size=
{
7
}
>
<
Grid2
>
<
InputField
<
Button
size=
"small"
variant=
"contained"
startIcon=
{
<
ArrowDownwardIcon
/>
}
>
name=
"Password"
<
Typography
value=
{
formData
.
password
}
sx=
{
{
onChange=
{
onInputChangeHandler
}
display
:
{
xs
:
"none"
,
md
:
"inline"
},
/>
}
}
</
Grid2
>
>
<
Grid2
container
justifyContent=
{
{}
}
>
Encode
<
Grid2
>
</
Typography
>
<
Button
</
Button
>
size=
"small"
</
Grid2
>
variant=
"contained"
startIcon=
{
<
ArrowDownwardIcon
/>
}
>
<
Typography
sx=
{
{
display
:
{
xs
:
"none"
,
md
:
"inline"
},
}
}
>
Encode
</
Typography
>
</
Button
>
</
Grid2
>
<
Grid2
>
<
Grid2
>
<
Button
<
Button
size=
"small"
size=
"small"
variant=
"contained"
variant=
"contained"
startIcon=
{
startIcon=
{
<
ArrowDownwardIcon
sx=
{
{
transform
:
"rotate(180deg)"
}
}
/>
}
<
ArrowDownwardIcon
sx=
{
{
transform
:
"rotate(180deg)"
}
}
/>
>
}
<
Typography
>
sx=
{
{
<
Typography
display
:
{
xs
:
"none"
,
md
:
"inline"
},
sx=
{
{
}
}
display
:
{
xs
:
"none"
,
md
:
"inline"
},
>
}
}
Decode
>
</
Typography
>
Decode
</
Button
>
</
Typography
>
</
Grid2
>
</
Button
>
</
Grid2
>
</
Grid2
>
</
Grid2
>
</
Grid2
>
</
Grid2
>
<
InputField
<
InputField
name=
"Encoded"
value=
{
formData
.
encoded
}
onChange=
{
onInputChangeHandler
}
/>
name=
"Encoded"
</
Grid2
>
value=
{
formData
.
encoded
}
</
Box
>
onChange=
{
onInputChangeHandler
}
</
Container
>
/>
</
div
>
</
Grid2
>
);
</
Box
>
</
Container
>
</
div
>
);
}
}
package-lock.json
deleted
100644 → 0
View file @
7b9451a2
{
"name"
:
"homework83_m11"
,
"lockfileVersion"
:
3
,
"requires"
:
true
,
"packages"
:
{}
}
service/src/app.controller.spec.ts
deleted
100644 → 0
View file @
7b9451a2
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!'
);
});
});
});
service/src/app.controller.ts
deleted
100644 → 0
View file @
7b9451a2
import
{
Controller
,
Get
}
from
'@nestjs/common'
;
import
{
AppService
}
from
'./app.service'
;
@
Controller
()
export
class
AppController
{
constructor
(
private
readonly
appService
:
AppService
)
{}
@
Get
()
getHello
():
string
{
return
this
.
appService
.
getHello
();
}
}
service/src/app.module.ts
deleted
100644 → 0
View file @
7b9451a2
import
{
Module
}
from
'@nestjs/common'
;
import
{
AppController
}
from
'./app.controller'
;
import
{
AppService
}
from
'./app.service'
;
import
{
MessageModule
}
from
'./message/message.module'
;
@
Module
({
imports
:
[
MessageModule
],
controllers
:
[
AppController
],
providers
:
[
AppService
],
})
export
class
AppModule
{}
service/src/app.service.ts
deleted
100644 → 0
View file @
7b9451a2
import
{
Injectable
}
from
'@nestjs/common'
;
@
Injectable
()
export
class
AppService
{
getHello
():
string
{
return
'Hello World!'
;
}
}
service/src/main.ts
View file @
3f46dd44
import
{
NestFactory
}
from
'@nestjs/core'
;
import
{
NestFactory
}
from
'@nestjs/core'
;
import
{
AppModule
}
from
'./app.module'
;
import
{
ConfigModule
}
from
'@nestjs/config'
;
import
{
ConfigModule
}
from
'@nestjs/config'
;
import
{
MessageModule
}
from
'./message/message.module'
;
ConfigModule
.
forRoot
();
ConfigModule
.
forRoot
();
async
function
bootstrap
()
{
async
function
startServer
()
{
const
app
=
await
NestFactory
.
create
(
App
Module
);
const
app
=
await
NestFactory
.
create
(
Message
Module
);
await
app
.
listen
(
process
.
env
.
PORT
??
3
000
);
await
app
.
listen
(
8
000
);
}
}
bootstrap
();
startServer
();
service/src/message/dto/update-message.dto.ts
deleted
100644 → 0
View file @
7b9451a2
import
{
PartialType
}
from
'@nestjs/mapped-types'
;
import
{
CreateMessageDto
}
from
'./create-message.dto'
;
export
class
UpdateMessageDto
extends
PartialType
(
CreateMessageDto
)
{}
service/src/message/entities/message.entity.ts
deleted
100644 → 0
View file @
7b9451a2
export
class
Message
{}
service/src/message/message.controller.spec.ts
deleted
100644 → 0
View file @
7b9451a2
import
{
Test
,
TestingModule
}
from
'@nestjs/testing'
;
import
{
MessageController
}
from
'./message.controller'
;
import
{
MessageService
}
from
'./message.service'
;
describe
(
'MessageController'
,
()
=>
{
let
controller
:
MessageController
;
beforeEach
(
async
()
=>
{
const
module
:
TestingModule
=
await
Test
.
createTestingModule
({
controllers
:
[
MessageController
],
providers
:
[
MessageService
],
}).
compile
();
controller
=
module
.
get
<
MessageController
>
(
MessageController
);
});
it
(
'should be defined'
,
()
=>
{
expect
(
controller
).
toBeDefined
();
});
});
service/src/message/message.controller.ts
View file @
3f46dd44
...
@@ -6,7 +6,7 @@ import { CreateMessageDto } from './dto/create-message.dto';
...
@@ -6,7 +6,7 @@ import { CreateMessageDto } from './dto/create-message.dto';
export
class
MessageController
{
export
class
MessageController
{
constructor
(
private
readonly
messageService
:
MessageService
)
{}
constructor
(
private
readonly
messageService
:
MessageService
)
{}
@
Post
(
'encode'
)
@
Post
(
'
/
encode'
)
encodeMessage
(@
Body
()
createMessageDto
:
CreateMessageDto
):
{
encodeMessage
(@
Body
()
createMessageDto
:
CreateMessageDto
):
{
encoded
:
string
;
encoded
:
string
;
}
{
}
{
...
@@ -15,7 +15,7 @@ export class MessageController {
...
@@ -15,7 +15,7 @@ export class MessageController {
return
{
encoded
};
return
{
encoded
};
}
}
@
Post
(
'decode'
)
@
Post
(
'
/
decode'
)
decodeMessage
(@
Body
()
createMessageDto
:
CreateMessageDto
):
{
decodeMessage
(@
Body
()
createMessageDto
:
CreateMessageDto
):
{
decoded
:
string
;
decoded
:
string
;
}
{
}
{
...
...
service/src/message/message.service.spec.ts
deleted
100644 → 0
View file @
7b9451a2
import
{
Test
,
TestingModule
}
from
'@nestjs/testing'
;
import
{
MessageService
}
from
'./message.service'
;
describe
(
'MessageService'
,
()
=>
{
let
service
:
MessageService
;
beforeEach
(
async
()
=>
{
const
module
:
TestingModule
=
await
Test
.
createTestingModule
({
providers
:
[
MessageService
],
}).
compile
();
service
=
module
.
get
<
MessageService
>
(
MessageService
);
});
it
(
'should be defined'
,
()
=>
{
expect
(
service
).
toBeDefined
();
});
});
service/src/message/message.service.ts
View file @
3f46dd44
...
@@ -4,10 +4,10 @@ import { Vigenere } from 'caesar-salad';
...
@@ -4,10 +4,10 @@ import { Vigenere } from 'caesar-salad';
@
Injectable
()
@
Injectable
()
export
class
MessageService
{
export
class
MessageService
{
encodeMessage
(
password
:
string
,
message
:
string
):
string
{
encodeMessage
(
password
:
string
,
message
:
string
):
string
{
return
Vigenere
.
Cipher
(
password
).
crypt
(
message
);
return
Vigenere
.
Cipher
(
password
.
trim
()
).
crypt
(
message
);
}
}
decodeMessage
(
password
:
string
,
message
:
string
):
string
{
decodeMessage
(
password
:
string
,
message
:
string
):
string
{
return
Vigenere
.
Decipher
(
password
).
crypt
(
message
);
return
Vigenere
.
Decipher
(
password
.
trim
()
).
crypt
(
message
);
}
}
}
}
service/test/app.e2e-spec.ts
deleted
100644 → 0
View file @
7b9451a2
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!'
);
});
});
service/test/jest-e2e.json
deleted
100644 → 0
View file @
7b9451a2
{
"moduleFileExtensions"
:
[
"js"
,
"json"
,
"ts"
],
"rootDir"
:
"."
,
"testEnvironment"
:
"node"
,
"testRegex"
:
".e2e-spec.ts$"
,
"transform"
:
{
"^.+
\\
.(t|j)s$"
:
"ts-jest"
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment