Skip to content

Commit

Permalink
Merge pull request #2 from TeamBuilderApp/Feature/NewFeatures
Browse files Browse the repository at this point in the history
Feature/new features
  • Loading branch information
TeamBuilder authored May 9, 2024
2 parents c6edbaf + 2755fc1 commit 8834388
Show file tree
Hide file tree
Showing 12 changed files with 384 additions and 224 deletions.
169 changes: 169 additions & 0 deletions TeamBuilder/Controllers/TeamBuilderController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using TeamBuilder.Models;

namespace TeamBuilder.Controllers
{
[ApiController]
[Route("[controller]")]
public class TeamBuilderController : ControllerBase
{
private readonly TeamBuilderContext _context;

private readonly ILogger<TeamBuilderController> _logger;

//Example: Converts a value by ID match, when creating a new object.
/*private static readonly string[] SetNameIdMapping = new[]
{
"a", "b", "c", "d"
};*/

//Example of how to use logging.
//public TeamBuilderController(ILogger<TeamBuilderController> logger)
public TeamBuilderController(TeamBuilderContext context, ILogger<TeamBuilderController> logger)
{
_context = context;
_logger = logger;
}

// <snippet_Get>
//The most basic HTTP Get example.
/*
[HttpGet(Name = "GetTeamBuilder")]
public IEnumerable<TeamBuilderEventDto> Get()
{
return _context.TeamBuilder
.Select(x => TeamBuilder.TeamBuilderEventToDto(x))
.ToList();
}*/

//GETTER
// GET: TeamBuilder
//HTTP GET(s) all Team Builder Event(s).
[HttpGet]
public async Task<ActionResult<IEnumerable<TeamBuilderEventDto>>> GetTeamBuilder()
{
return await _context.TeamBuilder
.Select(x => TeamBuilder.Models.TeamBuilder.ObjectToDto(x))
.ToListAsync();
}

//GETTER
//GET: TeamBuilder/id
//Example: TeamBuilder/5
//Getter by id.
// Exact match. HTTP GETs a Team Builder Event via lookup by its ID.
[HttpGet("{id}")]
public async Task<ActionResult<TeamBuilderEventDto>> GetTeamBuilderEvent(long id)
{
TeamBuilder.Models.TeamBuilder? teamBuilderEvent = await _context.TeamBuilder.FindAsync(id);

if (teamBuilderEvent == null)
{
return NotFound(); //404
}

return TeamBuilder.Models.TeamBuilder.ObjectToDto(teamBuilderEvent);
}
// </snippet_Get>

// <snippet_Update>
//SETTER
//The PUT method is used to update a single resource by its ID.
// Exact match. Updates a Team Builder Event via lookup by its ID.
// PUT: TeamBuilder/id
// Example: TeamBuilder/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")]
public async Task<IActionResult> PutTeamBuilderEvent(long id, TeamBuilderEventDto TeamBuilderEventDto)
{
if (id != TeamBuilderEventDto.Id)
{
return BadRequest(); //400
}

TeamBuilder.Models.TeamBuilder? teamBuilderEvent = await _context.TeamBuilder.FindAsync(id);
if (teamBuilderEvent == null)
{
return NotFound(); //404
}

try
{
_ = await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException) when (!TeamBuilderEventExists(id))
{
return NotFound(); //404
}

return NoContent();
}
// </snippet_Update>

// <snippet_Create>
// CREATE
// The POST method is used to create a new resource.
// POST: TeamBuilder
// Example: TeamBuilder
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<TeamBuilderEventDto>> PostTeamBuilderEvent(TeamBuilderEventDto teamBuilderEventDto)
{
Models.TeamBuilder teamBuilderEvent = new(teamBuilderEventDto);

try
{
_ = _context.TeamBuilder.Add(teamBuilderEvent);
_ = await _context.SaveChangesAsync();
}
catch (Exception)
{
return NotFound(); //404
}

return CreatedAtAction(
nameof(GetTeamBuilderEvent),
new { id = teamBuilderEvent.Id },
teamBuilderEventDto);
}
// </snippet_Create>


// <snippet_Delete>
// DELETE
// The DELETE method is used to delete an existing resource by its ID.
// Exact match. Deletes a Team Builder Event via lookup by its ID.
// DELETE: TeamBuilder/id
// Example: TeamBuilder/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteTeamBuilderEvent(long id)
{
TeamBuilder.Models.TeamBuilder? teamBuilderEvent = await _context.TeamBuilder.FindAsync(id);
if (teamBuilderEvent == null)
{
return NotFound(); //404
}

try
{
_ = _context.TeamBuilder.Remove(teamBuilderEvent);
_ = await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException) when (!TeamBuilderEventExists(id))
{
return NotFound(); //404
}

return NoContent();
}
// </snippet_Delete>

// Exact match. Finds a Team Builder Event via lookup by its ID.
private bool TeamBuilderEventExists(long id)
{
return _context.TeamBuilder.Any(e => e.Id == id);
}
}
}
119 changes: 0 additions & 119 deletions TeamBuilder/Controllers/TodoItemsController.cs

This file was deleted.

33 changes: 0 additions & 33 deletions TeamBuilder/Controllers/WeatherForecastController.cs

This file was deleted.

16 changes: 13 additions & 3 deletions TeamBuilder/Dal/DataAccessLayer.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
namespace TeamBuilder.Dal
{
public static class DataAccessLayer

public abstract class TeamBuilderAPI
{
static DataAccessLayer()
/*
//Example properties.
public abstract string Name { get; }
public abstract string Description { get; }
*/

}
public static class DAL
{
static DAL()
{
//If there's a need for a Dal!
//If there's a need for a Data Access Layer!
}
}
}
Loading

0 comments on commit 8834388

Please sign in to comment.