Skip to content

Commit

Permalink
Merge pull request #11 from dotClique/i1/database-models
Browse files Browse the repository at this point in the history
Add additional database models and RequirementController
  • Loading branch information
LarsSelbekk authored Jan 13, 2022
2 parents 8df61f8 + c5f392f commit 190a0f9
Show file tree
Hide file tree
Showing 11 changed files with 583 additions and 52 deletions.
6 changes: 3 additions & 3 deletions SpeiderappAPI/Controllers/BadgeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task<ActionResult<IEnumerable<Badge>>> GetBadges()
return await _context.Badges/* .Include(badge => badge.Resources) */.ToListAsync();
}

// GET: api/Badge/5
// GET: api/Badge/<id>
[HttpGet("{id:long}")]
public async Task<ActionResult<Badge>> GetBadge(long id)
{
Expand All @@ -41,7 +41,7 @@ public async Task<ActionResult<Badge>> GetBadge(long id)
return badge;
}

// PUT: api/Badge/5
// PUT: api/Badge/<id>
// To protect from over-posting attacks, enable the specific properties you want to bind to, for
// more details, see https://go.microsoft.com/fwlink/?linkid=2123754.
[HttpPut("{id:long}")]
Expand Down Expand Up @@ -85,7 +85,7 @@ public async Task<ActionResult<Badge>> PostBadge(Badge badge)
return CreatedAtAction("GetBadge", new { id = badge.RequirementID }, badge);
}

// DELETE: api/Badge/5
// DELETE: api/Badge/<id>
[HttpDelete("{id:long}")]
public async Task<ActionResult<Badge>> DeleteBadge(long id)
{
Expand Down
52 changes: 52 additions & 0 deletions SpeiderappAPI/Controllers/RequirementController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using SpeiderappAPI.Database;
using SpeiderappAPI.Models;

namespace SpeiderappAPI.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class RequirementController : ControllerBase
{
private readonly ApiContext _context;

public RequirementController(ApiContext context)
{
_context = context;
}

// GET: api/Requirement
[HttpGet]
public async Task<ActionResult<IEnumerable<Requirement>>> GetRequirements()
{
return await _context.Requirements
.Where(requirement => requirement.Discriminator == "Requirement")
.ToListAsync();
}

// GET: api/Requirement/all
[HttpGet("all")]
public async Task<ActionResult<IEnumerable<Requirement>>> GetRequirementsAll()
{
return await _context.Requirements.ToListAsync();
}

// Get: api/Requirement/<id>
[HttpGet("{id:long}")]
public async Task<ActionResult<Requirement>> GetRequirement(long id)
{
var requirement = await _context.Requirements.FindAsync(id);

if (requirement == null)
{
return NotFound();
}

return requirement;
}
}
}
20 changes: 3 additions & 17 deletions SpeiderappAPI/Controllers/ResourceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task<ActionResult<IEnumerable<Resource>>> GetResource()
return await _context.Resources.ToListAsync();
}

// GET: api/Resource/5
// GET: api/Resource/<id>
[HttpGet("{id:long}")]
public async Task<ActionResult<Resource>> GetResource(long id)
{
Expand All @@ -40,21 +40,7 @@ public async Task<ActionResult<Resource>> GetResource(long id)
return resource;
}

// GET: api/Resource/badge/5
[HttpGet("badge/{id:long}")]
public async Task<ActionResult<Requirement?>> GetBadgeFor(long id)
{
var resource = await _context.Resources.FindAsync(id);

if (resource == null)
{
return NotFound();
}

return resource.Requirement;
}

// PUT: api/Resource/5
// PUT: api/Resource/<id>
// To protect from over-posting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id:long}")]
public async Task<IActionResult> PutResource(long id, Resource resource)
Expand Down Expand Up @@ -96,7 +82,7 @@ public async Task<ActionResult<Resource>> PostResource(Resource resource)
return CreatedAtAction("GetResource", new { id = resource.ResourceID }, resource);
}

// DELETE: api/Resource/5
// DELETE: api/Resource/<id>
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteResource(long id)
{
Expand Down
6 changes: 3 additions & 3 deletions SpeiderappAPI/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task<ActionResult<IEnumerable<User>>> GetUsers()
return await _context.Users.ToListAsync();
}

// GET: api/User/5
// GET: api/User/<id>
[HttpGet("{id:long}")]
public async Task<ActionResult<User>> GetUser(long id)
{
Expand All @@ -40,7 +40,7 @@ public async Task<ActionResult<User>> GetUser(long id)
return user;
}

// PUT: api/User/5
// PUT: api/User/<id>
// To protect from over-posting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id:long}")]
public async Task<IActionResult> PutUser(long id, User user)
Expand Down Expand Up @@ -82,7 +82,7 @@ public async Task<ActionResult<User>> PostUser(User user)
return CreatedAtAction("GetUser", new { id = user.UserID }, user);
}

// DELETE: api/User/5
// DELETE: api/User/<id>
[HttpDelete("{id:long}")]
public async Task<IActionResult> DeleteUser(long id)
{
Expand Down
2 changes: 2 additions & 0 deletions SpeiderappAPI/Database/ApiContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace SpeiderappAPI.Database
public class ApiContext : DbContext
{
public DbSet<Badge> Badges { get; set; } = null!;
public DbSet<MultipleChoice> MultipleChoices { get; set; } = null!;
public DbSet<UserDefined> UserDefineds { get; set; } = null!;
public DbSet<Requirement> Requirements { get; set; } = null!;
public DbSet<RequirementPrerequisite> RequirementPrerequisites { get; set; } = null!;
public DbSet<User> Users { get; set; } = null!;
Expand Down
Loading

0 comments on commit 190a0f9

Please sign in to comment.