diff --git a/CoviDok/Controllers/DoctorsController.cs b/CoviDok/Controllers/DoctorsController.cs new file mode 100644 index 0000000..57f6da1 --- /dev/null +++ b/CoviDok/Controllers/DoctorsController.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using CoviDok.data; + +namespace CoviDok.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class DoctorsController : ControllerBase + { + private readonly MySQLContext _context; + + public DoctorsController(MySQLContext context) + { + _context = context; + } + + // GET: api/Doctors + [HttpGet] + public async Task<ActionResult<IEnumerable<Doctor>>> GetDoctors() + { + return await _context.Doctors.ToListAsync(); + } + + // GET: api/Doctors/5 + [HttpGet("{id}")] + public async Task<ActionResult<Doctor>> GetDoctor(string id) + { + var doctor = await _context.Doctors.FindAsync(id); + + if (doctor == null) + { + return NotFound(); + } + + return doctor; + } + + // PUT: api/Doctors/5 + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. + [HttpPut("{id}")] + public async Task<IActionResult> PutDoctor(string id, Doctor doctor) + { + if (id != doctor.Id) + { + return BadRequest(); + } + + _context.Entry(doctor).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!DoctorExists(id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return NoContent(); + } + + // POST: api/Doctors + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. + [HttpPost] + public async Task<ActionResult<Doctor>> PostDoctor(Doctor doctor) + { + _context.Doctors.Add(doctor); + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateException) + { + if (DoctorExists(doctor.Id)) + { + return Conflict(); + } + else + { + throw; + } + } + + return CreatedAtAction("GetDoctor", new { id = doctor.Id }, doctor); + } + + // DELETE: api/Doctors/5 + [HttpDelete("{id}")] + public async Task<ActionResult<Doctor>> DeleteDoctor(string id) + { + var doctor = await _context.Doctors.FindAsync(id); + if (doctor == null) + { + return NotFound(); + } + + _context.Doctors.Remove(doctor); + await _context.SaveChangesAsync(); + + return doctor; + } + + private bool DoctorExists(string id) + { + return _context.Doctors.Any(e => e.Id == id); + } + } +} diff --git a/CoviDok/CoviDok.csproj b/CoviDok/CoviDok.csproj index 43df7ad..ddedeaa 100644 --- a/CoviDok/CoviDok.csproj +++ b/CoviDok/CoviDok.csproj @@ -7,7 +7,14 @@ </PropertyGroup> <ItemGroup> + <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.8" /> + <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.8" /> + <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.8"> + <PrivateAssets>all</PrivateAssets> + <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> + </PackageReference> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" /> + <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" /> <PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.21" /> </ItemGroup> diff --git a/CoviDok/Startup.cs b/CoviDok/Startup.cs index 8c89764..61f37d6 100644 --- a/CoviDok/Startup.cs +++ b/CoviDok/Startup.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -16,6 +17,7 @@ namespace CoviDok // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { + services.AddMvc(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -28,13 +30,15 @@ namespace CoviDok app.UseRouting(); - app.UseEndpoints(endpoints => - { - endpoints.MapGet("/", async context => - { - await context.Response.WriteAsync("Hello World!"); - }); - }); + app.UseMvc(); + + //app.UseEndpoints(endpoints => + //{ + // endpoints.MapGet("/", async context => + // { + // await context.Response.WriteAsync("Hello World!"); + // }); + //}); } } } diff --git a/CoviDok/data/Case.cs b/CoviDok/data/Case.cs index d9d403c..4043962 100644 --- a/CoviDok/data/Case.cs +++ b/CoviDok/data/Case.cs @@ -7,6 +7,7 @@ namespace CoviDok.data { public class Case { + public string Id { get; set; } public string DoctorID { get; set; } public string ParentID { get; set; } public string ChildID { get; set; } diff --git a/CoviDok/data/Image.cs b/CoviDok/data/Image.cs index 6453057..0c27561 100644 --- a/CoviDok/data/Image.cs +++ b/CoviDok/data/Image.cs @@ -8,7 +8,7 @@ namespace CoviDok.data //Store Image ID, get actual content from MinIO backend. public class Image { - public string ImageID { get; set; } - + public string Id { get; set; } + } } diff --git a/CoviDok/data/MySQLContext.cs b/CoviDok/data/MySQLContext.cs new file mode 100644 index 0000000..33acf82 --- /dev/null +++ b/CoviDok/data/MySQLContext.cs @@ -0,0 +1,23 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Threading.Tasks; + +namespace CoviDok.data +{ + public class MySQLContext : DbContext + { + public DbSet<Case> Cases { get; set; } + public DbSet<Child> Children { get; set; } + public DbSet<Doctor> Doctors { get; set; } + public DbSet<Image> Images { get; set; } + public DbSet<Parent> Parents { get; set; } + public DbSet<Update> Updates { get; set; } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseMySQL("server=localhost;database=library;user=user;password=password"); + } + } +} diff --git a/CoviDok/data/Update.cs b/CoviDok/data/Update.cs index fe499d0..c73cc27 100644 --- a/CoviDok/data/Update.cs +++ b/CoviDok/data/Update.cs @@ -7,6 +7,7 @@ namespace CoviDok.data { public class Update { + public string Id { get; set; } public string Sender { get; set; } public string Content { get; set; }