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

Commit 31e1246

Browse files
authored
Merge pull request #1 from Invoices-Manager/dev_01
Dev 01 - Version 1.0.0.0
2 parents 91bad76 + 0fb4c20 commit 31e1246

56 files changed

Lines changed: 4153 additions & 58 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*.user
1010
*.userosscache
1111
*.sln.docstates
12+
Migrations/
1213

1314
# User-specific files (MonoDevelop/Xamarin Studio)
1415
*.userprefs
@@ -360,4 +361,9 @@ MigrationBackup/
360361
.ionide/
361362

362363
# Fody - auto-generated XML schema
363-
FodyWeavers.xsd
364+
FodyWeavers.xsd
365+
366+
367+
# Ignore the data directory
368+
/Data
369+
/.config

Classes/ResponseMgr.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace Invoices_Manager_API.Classes
2+
{
3+
public class ResponseMgr
4+
{
5+
public static Object CreateResponse(int statusCode, Guid traceId, string message, Dictionary<string, object>? args = null)
6+
{
7+
DateTime dateTime = DateTime.Now;
8+
9+
if (args is null)
10+
args = new Dictionary<string, object>();
11+
12+
return new
13+
{
14+
statusCode,
15+
traceId,
16+
dateTime,
17+
message,
18+
args
19+
};
20+
}
21+
}
22+
}

Controllers/WeatherForecastController.cs

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
namespace Invoices_Manager_API.Controllers.v01
2+
{
3+
[ApiController]
4+
[TypeFilter(typeof(AuthFilter))]
5+
[Route("api/v01/[controller]")]
6+
public class BackUpController : ControllerBase
7+
{
8+
private readonly ILogger<BackUpController> _logger;
9+
private readonly DataBaseContext _db;
10+
11+
public BackUpController(ILogger<BackUpController> logger, DataBaseContext db)
12+
{
13+
_logger = logger;
14+
_db = db;
15+
}
16+
17+
private async Task<UserModel?> GetCurrentUser()
18+
{
19+
// Get the bearer token from the header
20+
var bearerToken = HttpContext.Request.Headers["bearerToken"].ToString();
21+
var user = await UserCore.GetCurrentUser(_db, bearerToken);
22+
return user;
23+
}
24+
25+
[HttpGet]
26+
[Route("GetAll")]
27+
public async Task<IActionResult> GetAll()
28+
{
29+
// not implemented yet
30+
return await Task.FromResult(new StatusCodeResult(501));
31+
32+
//get the user
33+
var user = await GetCurrentUser();
34+
if (user == null)
35+
return BadRequest("The user is null");
36+
37+
//get all back ups
38+
var backUps = user.BackUpInfos.ToList();
39+
40+
//return all back ups
41+
return Ok(backUps);
42+
}
43+
44+
[HttpGet]
45+
public async Task<IActionResult> Get(int id)
46+
{
47+
// not implemented yet
48+
return await Task.FromResult(new StatusCodeResult(501));
49+
50+
//get the user
51+
var user = await GetCurrentUser();
52+
if (user == null)
53+
return BadRequest("The user is null");
54+
55+
//check if there is an id
56+
if (id == 0 || id < 0)
57+
return BadRequest("The id is not valid");
58+
59+
//get the back up
60+
var backUp = user.BackUpInfos.Find(x => x.Id == id);
61+
62+
//check if the back up exist
63+
if (backUp is null)
64+
return NotFound($"The back up with the id '{id}' does not exist");
65+
66+
//return the back up
67+
return Ok(backUp);
68+
}
69+
70+
[HttpGet]
71+
[Route("Download")]
72+
public async Task<IActionResult> Download(int id)
73+
{
74+
// not implemented yet
75+
return await Task.FromResult(new StatusCodeResult(501));
76+
77+
//get the user
78+
var user = await GetCurrentUser();
79+
if (user == null)
80+
return BadRequest("The user is null");
81+
82+
//check if there is an id
83+
if (id == 0 || id < 0)
84+
return BadRequest("The id is not valid");
85+
86+
//get the back up
87+
var backUp = user.BackUpInfos.Find(x => x.Id == id);
88+
89+
//check if the back up exist
90+
if (backUp is null)
91+
return NotFound($"The back up with the id '{id}' does not exist");
92+
93+
//get the file
94+
string filePath = FileCore.GetBackUpFilePath(backUp.FileID, user);
95+
96+
//check if the file exist
97+
if (filePath is null)
98+
return NotFound($"The file with the id '{id}' does not exist");
99+
100+
//open a filestream for the chunking
101+
var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
102+
return new FileStreamResult(fileStream, "application/octet-stream")
103+
{
104+
FileDownloadName = Path.GetFileName(filePath),
105+
EnableRangeProcessing = true
106+
};
107+
}
108+
109+
[HttpPost]
110+
[Route("Upload")]
111+
public async Task<IActionResult> Upload()
112+
{
113+
// not implemented yet
114+
return await Task.FromResult(new StatusCodeResult(501));
115+
}
116+
117+
[HttpPost]
118+
[Route("GenerateBackUp")]
119+
public async Task<IActionResult> GenerateBackUp()
120+
{
121+
// not implemented yet
122+
return await Task.FromResult(new StatusCodeResult(501));
123+
124+
//get the user
125+
var user = await GetCurrentUser();
126+
if (user == null)
127+
return BadRequest("The user is null");
128+
129+
//check if the user is already in the queue
130+
if (BackUpCore.IsUserInQueue(user))
131+
return Conflict("You are already in the queue");
132+
133+
int place = BackUpCore.AddUserToQueue(user);
134+
135+
//return the back up
136+
return Ok($"You place in the Queue '{place}'");
137+
}
138+
139+
[HttpGet]
140+
[Route("QueuePlace")]
141+
public async Task<IActionResult> QueuePlace()
142+
{
143+
// not implemented yet
144+
return await Task.FromResult(new StatusCodeResult(501));
145+
146+
//get the user
147+
var user = await GetCurrentUser();
148+
if (user == null)
149+
return BadRequest("The user is null");
150+
151+
//check if the user is already in the queue
152+
if (!BackUpCore.IsUserInQueue(user))
153+
return Conflict("You are not in the queue");
154+
155+
int place = BackUpCore.GetQueuePlace(user);
156+
157+
//return the back up
158+
return Ok($"You place in the Queue '{place}'");
159+
}
160+
161+
[HttpDelete]
162+
public async Task<IActionResult> Delete(int id)
163+
{
164+
// not implemented yet
165+
return await Task.FromResult(new StatusCodeResult(501));
166+
167+
//get the user
168+
var user = await GetCurrentUser();
169+
if (user == null)
170+
return BadRequest("The user is null");
171+
172+
//check if there is an id
173+
if (id == 0 || id < 0)
174+
return BadRequest("The id is not valid");
175+
176+
//get the back up
177+
var backUp = user.BackUpInfos.Find(x => x.Id == id);
178+
179+
//check if the back up exist
180+
if (backUp is null)
181+
return NotFound($"The back up with the id '{id}' does not exist");
182+
183+
//remove the back up from the db
184+
_db.BackUpInfo.Remove(backUp);
185+
186+
//remove the back up from the user
187+
user.BackUpInfos.Remove(backUp);
188+
189+
//save the changes
190+
await _db.SaveChangesAsync();
191+
192+
//return the back up
193+
return Ok(backUp);
194+
}
195+
}
196+
}

0 commit comments

Comments
 (0)