From ba1130b65abbbc8f880ac8d71296f7e861ad0e66 Mon Sep 17 00:00:00 2001 From: Marco Santos Date: Fri, 27 Sep 2024 18:40:30 +0100 Subject: [PATCH] JenkinsFile --- .dockerignore | 5 ++- GeradoresService/NIF.cs | 44 ++++++++++++++++--- GeradoresService/Utils.cs | 18 ++++++++ GeradoresWS/Controllers/GenerateController.cs | 7 +++ Jenkinsfile | 14 ++++++ docker-compose.yml | 6 +-- geradoresfe/.env | 1 + geradoresfe/src/App.tsx | 13 +++--- geradoresfe/src/components/GeradorNIF.tsx | 14 ++---- 9 files changed, 94 insertions(+), 28 deletions(-) create mode 100644 GeradoresService/Utils.cs create mode 100644 Jenkinsfile create mode 100644 geradoresfe/.env diff --git a/.dockerignore b/.dockerignore index b512c09..2bbfeda 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,4 @@ -node_modules \ No newline at end of file +node_modules +Dockerfile +.git +.gitignore diff --git a/GeradoresService/NIF.cs b/GeradoresService/NIF.cs index aa10072..c0a04d9 100644 --- a/GeradoresService/NIF.cs +++ b/GeradoresService/NIF.cs @@ -1,9 +1,38 @@ -using System.Net.NetworkInformation; +using System.ComponentModel; +using System.Net.NetworkInformation; namespace GeradoresService { 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) { return GenerateRandomNIF(type); @@ -11,7 +40,7 @@ namespace GeradoresService public static string GenerateRandomNIF(string? nifType) { - var firstDigitValidate = new char[] { '1', '2','3', '5', '6', '8', '9' }; + var firstDigitValidate = new char[] { '1', '2', '3', '5', '6', '8', '9' }; Random rnd = new Random(); char firstDigit; @@ -20,10 +49,14 @@ namespace GeradoresService // Gera o primeiro dígito aleatório dentro dos válidos int firstDigitIndex = rnd.Next(0, 6); // Escolhe um índice de 0 a 5 firstDigit = firstDigitValidate[firstDigitIndex]; - } else { - if (firstDigitValidate.Contains(nifType[0])){ + } + else + { + if (firstDigitValidate.Contains(nifType[0])) + { firstDigit = nifType[0]; - }else + } + else { int firstDigitIndex = rnd.Next(0, 6); // Escolhe um índice de 0 a 5 firstDigit = firstDigitValidate[firstDigitIndex]; @@ -53,7 +86,6 @@ namespace GeradoresService return randomNIF; } - public static bool Validate(string nif) { // Verificar se o NIF tem 9 dígitos diff --git a/GeradoresService/Utils.cs b/GeradoresService/Utils.cs new file mode 100644 index 0000000..f4891aa --- /dev/null +++ b/GeradoresService/Utils.cs @@ -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() where T : Enum + { + return typeof(T).GetFields() + .Select(field => ( + Value: (T)field.GetValue(null), + Description: field.GetCustomAttribute()?.Description ?? field.Name + )) + .ToList(); + } +} \ No newline at end of file diff --git a/GeradoresWS/Controllers/GenerateController.cs b/GeradoresWS/Controllers/GenerateController.cs index ead9f4c..068d462 100644 --- a/GeradoresWS/Controllers/GenerateController.cs +++ b/GeradoresWS/Controllers/GenerateController.cs @@ -8,6 +8,13 @@ namespace GeradoresWS.Controllers public class GenerateController : Controller { #region NIF + + [HttpGet("GetNIFTypes")] + public List GetNIFTypes() + { + return new List(); + } + [HttpGet("GenerateNIF")] public string GenerateNIF(string? type) { diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..6663c0c --- /dev/null +++ b/Jenkinsfile @@ -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...' + } + } + } +} diff --git a/docker-compose.yml b/docker-compose.yml index d4b49eb..751c394 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,9 @@ -version: "3" +version: "3.8" services: geradoresws: build: . ports: - - "5000:8080" + - "5050:8080" networks: - app-network @@ -14,7 +14,7 @@ services: depends_on: - geradoresws environment: - - REACT_APP_API_URL=http://localhost:5000/ + - REACT_APP_API_URL=http://localhost:5050/ networks: - app-network diff --git a/geradoresfe/.env b/geradoresfe/.env new file mode 100644 index 0000000..0fcaa18 --- /dev/null +++ b/geradoresfe/.env @@ -0,0 +1 @@ +REACT_APP_API_URL=http://localhost:5015/ \ No newline at end of file diff --git a/geradoresfe/src/App.tsx b/geradoresfe/src/App.tsx index a4a7b4f..7bded8c 100644 --- a/geradoresfe/src/App.tsx +++ b/geradoresfe/src/App.tsx @@ -66,7 +66,7 @@ function ToggleCustomTheme({ ); } function App() { - const [mode, setMode] = React.useState('light'); + /*const [mode, setMode] = React.useState('light'); const [showCustomTheme, setShowCustomTheme] = React.useState(true); const LPtheme = createTheme(getLPTheme(mode)); const defaultTheme = createTheme({ palette: { mode } }); @@ -77,7 +77,7 @@ function App() { const toggleCustomTheme = () => { setShowCustomTheme((prev) => !prev); - }; + };*/ return (
@@ -85,13 +85,12 @@ function App() { Geradores - + { /**/} +
- - - - +
+
); diff --git a/geradoresfe/src/components/GeradorNIF.tsx b/geradoresfe/src/components/GeradorNIF.tsx index 3c04710..6e5c7f9 100644 --- a/geradoresfe/src/components/GeradorNIF.tsx +++ b/geradoresfe/src/components/GeradorNIF.tsx @@ -30,14 +30,6 @@ export default function GeradorNIF() { return ( ({ - 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', - })} > - - NIFC + + NIF +
{nif} @@ -67,7 +60,6 @@ export default function GeradorNIF() {
-