JenkinsFile

This commit is contained in:
Marco Santos
2024-09-27 18:40:30 +01:00
parent f88eb65384
commit ba1130b65a
9 changed files with 94 additions and 28 deletions

View File

@@ -1 +1,4 @@
node_modules node_modules
Dockerfile
.git
.gitignore

View File

@@ -1,9 +1,38 @@
using System.Net.NetworkInformation; using System.ComponentModel;
using System.Net.NetworkInformation;
namespace GeradoresService namespace GeradoresService
{ {
public class NIF public class NIF
{ {
public enum NIFType
{
[Description("Pessoa singular (1)")]
PessoaSingular1 = 1,
[Description("Pessoa singular (2)")]
PessoaSingular2 = 2,
[Description("Pessoa singular (3; novo em 2019)")]
PessoaSingular3 = 3,
[Description("Pessoa colectiva (5)")]
PessoaColectiva = 5,
[Description("Pessoa colectiva pública (6)")]
PessoaColectivaPublica = 6,
[Description("Empresário em nome individual (8)")]
EmpresarioIndividual = 8,
[Description("Pessoa colectiva irregular ou número provisório (9)")]
PessoaColectivaIrregular = 9
}
/*public static GetNIFTypes(){
EnumHelper.GetEnumValuesAndDescriptions(NIFType);
}*/
public static string Generate(string? type) public static string Generate(string? type)
{ {
return GenerateRandomNIF(type); return GenerateRandomNIF(type);
@@ -20,10 +49,14 @@ namespace GeradoresService
// Gera o primeiro dígito aleatório dentro dos válidos // Gera o primeiro dígito aleatório dentro dos válidos
int firstDigitIndex = rnd.Next(0, 6); // Escolhe um índice de 0 a 5 int firstDigitIndex = rnd.Next(0, 6); // Escolhe um índice de 0 a 5
firstDigit = firstDigitValidate[firstDigitIndex]; firstDigit = firstDigitValidate[firstDigitIndex];
} else { }
if (firstDigitValidate.Contains(nifType[0])){ else
{
if (firstDigitValidate.Contains(nifType[0]))
{
firstDigit = nifType[0]; firstDigit = nifType[0];
}else }
else
{ {
int firstDigitIndex = rnd.Next(0, 6); // Escolhe um índice de 0 a 5 int firstDigitIndex = rnd.Next(0, 6); // Escolhe um índice de 0 a 5
firstDigit = firstDigitValidate[firstDigitIndex]; firstDigit = firstDigitValidate[firstDigitIndex];
@@ -53,7 +86,6 @@ namespace GeradoresService
return randomNIF; return randomNIF;
} }
public static bool Validate(string nif) public static bool Validate(string nif)
{ {
// Verificar se o NIF tem 9 dígitos // Verificar se o NIF tem 9 dígitos

18
GeradoresService/Utils.cs Normal file
View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
public static class EnumHelper
{
public static List<(T Value, string Description)> GetEnumValuesAndDescriptions<T>() where T : Enum
{
return typeof(T).GetFields()
.Select(field => (
Value: (T)field.GetValue(null),
Description: field.GetCustomAttribute<DescriptionAttribute>()?.Description ?? field.Name
))
.ToList();
}
}

View File

@@ -8,6 +8,13 @@ namespace GeradoresWS.Controllers
public class GenerateController : Controller public class GenerateController : Controller
{ {
#region NIF #region NIF
[HttpGet("GetNIFTypes")]
public List<NIF.NIFType> GetNIFTypes()
{
return new List<NIF.NIFType>();
}
[HttpGet("GenerateNIF")] [HttpGet("GenerateNIF")]
public string GenerateNIF(string? type) public string GenerateNIF(string? type)
{ {

14
Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,14 @@
pipeline {
agent {
dockerfile {
filename 'Dockerfile' // Nome do Dockerfile (se for diferente, modifique aqui)
}
}
stages {
stage('Build') {
steps {
echo 'Construindo o projeto...'
}
}
}
}

View File

@@ -1,9 +1,9 @@
version: "3" version: "3.8"
services: services:
geradoresws: geradoresws:
build: . build: .
ports: ports:
- "5000:8080" - "5050:8080"
networks: networks:
- app-network - app-network
@@ -14,7 +14,7 @@ services:
depends_on: depends_on:
- geradoresws - geradoresws
environment: environment:
- REACT_APP_API_URL=http://localhost:5000/ - REACT_APP_API_URL=http://localhost:5050/
networks: networks:
- app-network - app-network

1
geradoresfe/.env Normal file
View File

@@ -0,0 +1 @@
REACT_APP_API_URL=http://localhost:5015/

View File

@@ -66,7 +66,7 @@ function ToggleCustomTheme({
); );
} }
function App() { function App() {
const [mode, setMode] = React.useState<PaletteMode>('light'); /*const [mode, setMode] = React.useState<PaletteMode>('light');
const [showCustomTheme, setShowCustomTheme] = React.useState(true); const [showCustomTheme, setShowCustomTheme] = React.useState(true);
const LPtheme = createTheme(getLPTheme(mode)); const LPtheme = createTheme(getLPTheme(mode));
const defaultTheme = createTheme({ palette: { mode } }); const defaultTheme = createTheme({ palette: { mode } });
@@ -77,7 +77,7 @@ function App() {
const toggleCustomTheme = () => { const toggleCustomTheme = () => {
setShowCustomTheme((prev) => !prev); setShowCustomTheme((prev) => !prev);
}; };*/
return ( return (
<div className="App"> <div className="App">
@@ -85,13 +85,12 @@ function App() {
<meta charSet="utf-8" /> <meta charSet="utf-8" />
<title>Geradores</title> <title>Geradores</title>
</Helmet> </Helmet>
<ThemeProvider theme={showCustomTheme ? LPtheme : defaultTheme}> { /*<ThemeProvider theme={showCustomTheme ? LPtheme : defaultTheme}></ThemeProvider>*/}
<div>
<CssBaseline /> <CssBaseline />
<GeradorCC /> <GeradorCC />
<Box sx={{ bgcolor: 'background.default' }}> </div>
</Box>
</ThemeProvider>
</div> </div>
); );

View File

@@ -30,14 +30,6 @@ export default function GeradorNIF() {
return ( return (
<Box <Box
id="GeradorNIF" id="GeradorNIF"
sx={(theme) => ({
width: '100%',
backgroundImage:
theme.palette.mode === 'light'
? 'radial-gradient(ellipse 80% 50% at 50% -20%, hsl(210, 100%, 90%), transparent)'
: 'radial-gradient(ellipse 80% 50% at 50% -20%, hsl(210, 100%, 16%), transparent)',
backgroundRepeat: 'no-repeat',
})}
> >
<Container <Container
sx={{ sx={{
@@ -56,9 +48,10 @@ export default function GeradorNIF() {
> >
<Card sx={{ minWidth: 275 }}> <Card sx={{ minWidth: 275 }}>
<CardContent> <CardContent>
<Typography sx={{ fontSize: 14 }} color="text.secondary" gutterBottom> <Typography variant='h4'>
NIFC NIF<Button size="small">copiar</Button>
</Typography> </Typography>
<br />
<Typography sx={{ mb: 1.5 }} color="text.secondary"> <Typography sx={{ mb: 1.5 }} color="text.secondary">
{nif} {nif}
</Typography> </Typography>
@@ -67,7 +60,6 @@ export default function GeradorNIF() {
<Button size="small" onClick={fetchNif}>Gerar</Button> <Button size="small" onClick={fetchNif}>Gerar</Button>
</CardActions> </CardActions>
</Card> </Card>
</Stack> </Stack>
</Container> </Container>
</Box> </Box>