Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Commit 2662915

Browse files
authored
Merge pull request #10 from Invoices-Manager/dev_01
Dev 01
2 parents ce01434 + 51f44e0 commit 2662915

11 files changed

Lines changed: 39 additions & 35 deletions

Controllers/v01/InvoiceController.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ public async Task<IActionResult> Add([FromBody] InvoiceWrapperModel wrapper)
136136
if (newInvoice.Id != 0)
137137
return new BadRequestObjectResult(ResponseMgr.CreateResponse(400, traceId, "You are not allowed to set the Id!", new Dictionary<string, object> { { "id", newInvoice.Id } }));
138138

139-
//check if the user already set an file id
140-
if (!string.IsNullOrEmpty(newInvoice.FileID))
141-
return new BadRequestObjectResult(ResponseMgr.CreateResponse(400, traceId, "You are not allowed to set the FileID!", new Dictionary<string, object> { { "fileId", newInvoice.FileID } }));
139+
//check if the user has set a file id
140+
if (String.IsNullOrWhiteSpace(newInvoice.FileID))
141+
return new BadRequestObjectResult(ResponseMgr.CreateResponse(400, traceId, "You have to set an File Id!", new Dictionary<string, object> { { "fileId", newInvoice.FileID } }));
142142

143143
//check if the enums are valid
144144
if (!Enum.IsDefined(typeof(ImportanceStateEnum), newInvoice.ImportanceState))
@@ -166,33 +166,22 @@ public async Task<IActionResult> Add([FromBody] InvoiceWrapperModel wrapper)
166166
if (invoiceFileInfo.Length > 32 * 1024 * 1024)
167167
return new BadRequestObjectResult(ResponseMgr.CreateResponse(400, traceId, "The file is too big (32 mb)"));
168168

169-
//get the file id
170-
var fileId = Security.FileHasher.GetMd5Hash(invoiceFileInfo.FullName);
171-
172169
//check if the file id already exist
173-
if (user.Invoices.Any(x => x.FileID == fileId))
170+
if (user.Invoices.Any(x => x.FileID == newInvoice.FileID))
174171
return new BadRequestObjectResult(ResponseMgr.CreateResponse(400, traceId, "The file already exist"));
175172

176-
//check if the file id is valid
177-
if (string.IsNullOrEmpty(fileId))
178-
return new BadRequestObjectResult(ResponseMgr.CreateResponse(400, traceId, "The file id is not valid"));
179-
180173
//move the file to the new path
181-
FileCore.MoveInvoiceFile_IntoUserFolder(invoiceFileInfo.FullName, fileId, user);
174+
FileCore.MoveInvoiceFile_IntoUserFolder(invoiceFileInfo.FullName, newInvoice.FileID, user);
182175

183176
//set the creation date
184177
newInvoice.CaptureDate = DateTime.Now;
185178

186-
//set the file id
187-
newInvoice.FileID = fileId;
188-
189179
//add the invoices to the db
190180
user.Invoices.Add(newInvoice);
191181
await _db.SaveChangesAsync();
192182

193183
//return the invoices
194184
return new CreatedAtActionResult("Get", "Invoice", new { id = newInvoice.Id }, ResponseMgr.CreateResponse(201, traceId, "Invoice created successfully", new Dictionary<string, object> { { "invoice", newInvoice } }));
195-
196185
}
197186
}
198187

@@ -240,6 +229,10 @@ public async Task<IActionResult> Edit([FromBody] InvoiceModel editInvoice)
240229
//get the invoice id
241230
int index = user.Invoices.FindIndex(x => x.Id == editInvoice.Id);
242231

232+
//check if the file id was manipulated
233+
if (user.Invoices[index].FileID != editInvoice.FileID)
234+
return new BadRequestObjectResult(ResponseMgr.CreateResponse(400, traceId, "The file id was manipulated", new Dictionary<string, object> { { "fileId", editInvoice.FileID } }));
235+
243236
//create a new invoice and delete the old one
244237
editInvoice.Id = user.Invoices[index].Id;
245238
editInvoice.FileID = user.Invoices[index].FileID;

Invoices-Manager-API.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<RootNamespace>Invoices_Manager_API</RootNamespace>
8-
<FileVersion>1.0.3.2</FileVersion>
9-
<AssemblyVersion>1.0.3.2</AssemblyVersion>
8+
<FileVersion>1.0.3.3</FileVersion>
9+
<AssemblyVersion>1.0.3.3</AssemblyVersion>
1010
<UserSecretsId>8e8f9154-9968-4e4a-81e6-a05431d2d71a</UserSecretsId>
1111
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
1212
<DockerfileContext>.</DockerfileContext>

Models/InvoiceModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public string TagsAsString
3434

3535
[Required(ErrorMessage = "PaidState is missing!")]
3636
public PaidStateEnum PaidState { get; set; } = default!; // { Paid , Unpaid, NoInvoice }
37-
public double MoneyTotal { get; set; }
37+
38+
public string? MoneyTotal { get; set; }
3839
}
3940
}

Models/UserModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class UserModel
2222
public string LastName { get; set; } = default!;
2323

2424
[Required(ErrorMessage = "Email is missing!")]
25-
[EmailAddress(ErrorMessage = "Invalid Email Address")]
25+
[RegularExpression(@"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$", ErrorMessage = "Invalid email format")]
2626
public string Email { get; set; } = default!;
2727

2828
[NotMapped]

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,25 @@ Press [here](https://github.com/Invoices-Manager/Invoices-Manager-API/blob/maste
7777
### Z = Minor version (small updates)
7878
### W = Revision version (bug fixes)
7979

80+
## v1.0.4.0
81+
- The money total is now a string instant of a double (for the encryption)
82+
- The Postman is updated belong to the new changes
83+
- The API Doc is updated belong to the new changes
84+
85+
!!! THAT MEANS YOU HAVE TO DO STEP 13. and 14. FROM THE LIST ABOVE, IF YOU UPDATE UR API !!!
86+
!!! name the migrations something with "version1040" but not "firstInit", because this migration already exists. !!!
87+
8088
## v1.0.3.2 (HOTFIX)
8189
-Tokens are no longer hashed, because it broked the logic for "DeleteOldTokens"
8290
-Hasher class was deleted, is no longer needed
8391
-The table "logins" has changed (CreationDate is useless, is already in the token)
84-
92+
8593
!!! THAT MEANS YOU HAVE TO DO STEP 13. and 14. FROM THE LIST ABOVE, IF YOU UPDATE UR API !!!
8694
!!! name the migrations something with "version1032" but not "firstInit", because this migration already exists. !!!
8795

96+
## v1.0.3.3
97+
- FIX: The API needs a FileID from the client and should not create it by itself
98+
8899
## v1.0.3.1
89100
- The Salt will be send at the who am i query
90101

Resources/ApiDoc_V01/Invoice/DEL__Invoice.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Content-Type: application/json*
5656
"importanceState": 1,
5757
"moneyState": 1,
5858
"paidState": 1,
59-
"moneyTotal": 10000
59+
"moneyTotal": "10000"
6060
}
6161
}
6262
}

Resources/ApiDoc_V01/Invoice/GET__Invoice.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Content-Type: application/json*
5757
"importanceState": 1,
5858
"moneyState": 1,
5959
"paidState": 1,
60-
"moneyTotal": 100
60+
"moneyTotal": "100"
6161
},
6262
"base64": "SGFsbG8="
6363
}

Resources/ApiDoc_V01/Invoice/GET__Invoice_GetAll.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Content-Type: application/json*
5757
"importanceState": 1,
5858
"moneyState": 1,
5959
"paidState": 1,
60-
"moneyTotal": 100
60+
"moneyTotal": "100"
6161
}
6262
]
6363
}

Resources/ApiDoc_V01/Invoice/POST__Invoice.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
```json
2323
{
2424
"NewInvoice": {
25+
//no matter what, best a hash from the file, and no special characters
26+
"fileId": "asd435fgddxf34456456fgdh",
2527
"CaptureDate": "2022-01-01T00:00:00Z",
2628
"ExhibitionDate": "2022-01-01T00:00:00Z",
2729
"Reference": "Ref-123",
@@ -35,7 +37,7 @@
3537
"ImportanceState": 1,
3638
"MoneyState": 1,
3739
"PaidState": 1,
38-
"MoneyTotal": 100.00
40+
"MoneyTotal": "100.00"
3941
},
4042
"InvoiceFileBase64": "SGFsbG8="
4143
}
@@ -72,7 +74,7 @@ Content-Type: application/json*
7274
"importanceState": 1,
7375
"moneyState": 1,
7476
"paidState": 1,
75-
"moneyTotal": 100
77+
"moneyTotal": "100"
7678
}
7779
}
7880
}

Resources/ApiDoc_V01/Invoice/PUT__Invoice.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"importanceState": 1,
3737
"moneyState": 1,
3838
"paidState": 1,
39-
"moneyTotal": 10000
39+
"moneyTotal": "10000"
4040
}
4141
```
4242

@@ -71,7 +71,7 @@ Content-Type: application/json*
7171
"importanceState": 1,
7272
"moneyState": 1,
7373
"paidState": 1,
74-
"moneyTotal": 10000
74+
"moneyTotal": "10000"
7575
}
7676
}
7777
}

0 commit comments

Comments
 (0)