Anul 3 Semestrul 1
This commit is contained in:
+160
@@ -0,0 +1,160 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WebApi.Context;
|
||||
using WebApi.Models;
|
||||
using WebApi.Repositories;
|
||||
using WebApi.RepositoryInterfaces;
|
||||
|
||||
namespace WebApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class BacklogController : ControllerBase
|
||||
{
|
||||
private readonly User user = Globals.curretUser;
|
||||
private readonly IStoryRepository _storyRepository;
|
||||
private readonly ISprintRepository _sprintRepository;
|
||||
private readonly IAdjustmentRepository _adjustmentRepository;
|
||||
private readonly ITeamMemberAvailabilityRepository _teamMemberAvailabilityRepository;
|
||||
|
||||
public BacklogController(IStoryRepository storyRepository,
|
||||
ISprintRepository sprintRepository,
|
||||
IAdjustmentRepository adjustmentRepository,
|
||||
ITeamMemberAvailabilityRepository teamMemberAvailabilityRepository)
|
||||
{
|
||||
_storyRepository = storyRepository;
|
||||
_sprintRepository = sprintRepository;
|
||||
user = new User
|
||||
{
|
||||
UserId = 1,
|
||||
Username = "alice_smith"
|
||||
};
|
||||
_adjustmentRepository = adjustmentRepository;
|
||||
_teamMemberAvailabilityRepository = teamMemberAvailabilityRepository;
|
||||
}
|
||||
|
||||
[HttpGet("{page}/{count}")]
|
||||
public async Task<IActionResult> GetAsync(int page, int count)
|
||||
{
|
||||
if (count <= 200)
|
||||
return Ok(await _storyRepository.GetPaginated(page, count));
|
||||
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
[HttpGet("details/{id}")]
|
||||
public async Task<IActionResult> Get(int id)
|
||||
{
|
||||
var story = await _storyRepository.GetById(id);
|
||||
|
||||
return story != null ? Ok(story) : NotFound();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> PostAsync([FromBody] Story story)
|
||||
{
|
||||
try
|
||||
{
|
||||
story.CreatedBy = user.UserId;
|
||||
story.StoryId = default;
|
||||
await _storyRepository.Add(story);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutAsync([FromBody] Story story)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _storyRepository.Update(story);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteAsync(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _storyRepository.Delete(id);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{searchKey}/{page}/{pageSize}")]
|
||||
public async Task<IActionResult> GetFilteredPaginated(string searchKey, int page, int pageSize)
|
||||
{
|
||||
if (pageSize <= 200)
|
||||
return Ok(await _storyRepository.GetFilteredPaginated(searchKey, page, pageSize));
|
||||
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
[HttpGet("shift/{page}/{count}")]
|
||||
public async Task<IActionResult> GetShiftAsync(int page, int count)
|
||||
{
|
||||
if (count <= 200)
|
||||
return Ok(await _sprintRepository.GetPaginated(page, count));
|
||||
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("shift/details/{id}")]
|
||||
public async Task<IActionResult> GetShift(int id)
|
||||
{
|
||||
var sprint = await _sprintRepository.GetById(id);
|
||||
|
||||
return sprint != null ? Ok(sprint) : NotFound();
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("shift")]
|
||||
public async Task<IActionResult> PostSprintAsync([FromBody] Sprint sprint)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _sprintRepository.Add(sprint);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("availability")]
|
||||
public async Task<IActionResult> GetNetAvailabilityOnShift()
|
||||
{
|
||||
var availabilities = (await _sprintRepository.GetAll())
|
||||
.Select(async s => new
|
||||
{
|
||||
sprintId = s.SprintId,
|
||||
availability = await _teamMemberAvailabilityRepository.GetTotalAvailabilityPerSprint(s.SprintId) -
|
||||
await _adjustmentRepository.GetAdjustmentsPerSprint(s.SprintId)
|
||||
})
|
||||
.Select(s => s.Result);
|
||||
|
||||
return Ok(availabilities);
|
||||
|
||||
/*int adjustmentsPerSprintTask =
|
||||
await _adjustmentRepository.GetAdjustmentsPerSprint(sprint_id);
|
||||
int devAvailabilityPerSprintTask =
|
||||
await _teamMemberAvailabilityRepository.GetTotalAvailabilityPerSprint(sprint_id);
|
||||
|
||||
return Ok(devAvailabilityPerSprintTask - adjustmentsPerSprintTask);*/
|
||||
}
|
||||
}
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WebApi.Context;
|
||||
using WebApi.Models;
|
||||
|
||||
namespace WebApi.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class TestController : ControllerBase
|
||||
{
|
||||
private readonly JyrosContext _context;
|
||||
|
||||
public TestController(JyrosContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult> Index()
|
||||
{
|
||||
try
|
||||
{
|
||||
var teams = await _context.Teams.Include(t => t.TeamLead).ToListAsync();
|
||||
return Ok(teams);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return BadRequest(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("AddRandomTeam")]
|
||||
public async Task<ActionResult> AddRandomTeam()
|
||||
{
|
||||
try
|
||||
{
|
||||
var random = new Random();
|
||||
var team = new Team
|
||||
{
|
||||
TeamName = "Team " + random.Next(1, 1000),
|
||||
TeamDescription = "Description for team " + random.Next(1, 1000),
|
||||
TeamLeadId = 1
|
||||
};
|
||||
|
||||
_context.Teams.Add(team);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Ok(team);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return BadRequest(e.Message);
|
||||
}
|
||||
}
|
||||
//add a method that gets a team id and returns the teamlead of that team
|
||||
[HttpGet("GetTeamLead/{teamId}")]
|
||||
public async Task<ActionResult> GetTeamLead(int teamId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var team = await _context.Teams.FirstOrDefaultAsync(t => t.TeamId == teamId);
|
||||
return Ok(team?.TeamLead);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return BadRequest(e.Message);
|
||||
}
|
||||
}
|
||||
//add a methode that adds a team
|
||||
[HttpPost("AddTeam")]
|
||||
public async Task<ActionResult> AddTeam(Team team)
|
||||
{
|
||||
try
|
||||
{
|
||||
_context.Teams.Add(team);
|
||||
await _context.SaveChangesAsync();
|
||||
return Ok(team);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return BadRequest(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
//get all users
|
||||
[HttpGet("GetAllUsers")]
|
||||
public async Task<ActionResult> GetAllUsers()
|
||||
{
|
||||
try
|
||||
{
|
||||
var users = await _context.Users.ToListAsync();
|
||||
return Ok(users);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return BadRequest(e.Message);
|
||||
}
|
||||
}
|
||||
//get users in a team
|
||||
[HttpGet("GetUsersInTeam/{teamId}")]
|
||||
public async Task<ActionResult> GetUsersInTeam(int teamId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var team = await _context.Teams.Include(t => t.Users).FirstOrDefaultAsync(t => t.TeamId == teamId);
|
||||
return Ok(team?.Users);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return BadRequest(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WebApi.Models;
|
||||
using WebApi.RepositoryInterfaces;
|
||||
|
||||
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||
|
||||
namespace WebApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
|
||||
public class ShiftAvailabilityController : Controller
|
||||
{
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly ITeamMemberAvailabilityRepository _teamMemberAvailabilityRepository;
|
||||
private readonly ISprintRepository _sprintRepository;
|
||||
private readonly IAdjustmentRepository _adjustmentRepository;
|
||||
|
||||
public ShiftAvailabilityController(IUserRepository userRepository, ITeamMemberAvailabilityRepository teamMemberAvailabilityRepository, ISprintRepository sprintRepository, IAdjustmentRepository adjustmentRepository)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
_teamMemberAvailabilityRepository = teamMemberAvailabilityRepository;
|
||||
_sprintRepository = sprintRepository;
|
||||
_adjustmentRepository = adjustmentRepository;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get()
|
||||
{
|
||||
return Ok(await _teamMemberAvailabilityRepository.GetAll());
|
||||
}
|
||||
|
||||
[HttpGet("{sprintId}/{userId}")]
|
||||
public async Task<IActionResult> GetAvailability(int sprintId, int userId)
|
||||
{
|
||||
var teamMemberAvailability = await _teamMemberAvailabilityRepository.GetBySprintIdAndUserId(sprintId, userId);
|
||||
return teamMemberAvailability != null ? Ok(teamMemberAvailability) : NotFound();
|
||||
}
|
||||
|
||||
[HttpGet("{sprintId}/adjustment")]
|
||||
public async Task<IActionResult> GetAdjustmentLength(int sprintId)
|
||||
{
|
||||
var adjustments = await _adjustmentRepository.GetAll();
|
||||
var filteredAdjustments = adjustments.Where(a => a.SprintId == sprintId).ToList();
|
||||
|
||||
var totalAdjustment = filteredAdjustments.Sum(a => a.AdjustmentPoints);
|
||||
|
||||
return Ok(totalAdjustment);
|
||||
}
|
||||
|
||||
[HttpGet("{sprintId}/adjustment/all")]
|
||||
public async Task<IActionResult> GetAllAdjustments(int sprintId)
|
||||
{
|
||||
var adjustments = await _adjustmentRepository.GetAll();
|
||||
var filteredAdjustments = adjustments.Where(a => a.SprintId == sprintId).ToList();
|
||||
return Ok(filteredAdjustments);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("sprints")]
|
||||
public async Task<IActionResult> GetSprints()
|
||||
{
|
||||
return Ok(await _sprintRepository.GetAll());
|
||||
}
|
||||
|
||||
[HttpGet("sprints/{sprintId}/users")]
|
||||
public async Task<IActionResult> GetUsers(int sprintId)
|
||||
{
|
||||
return Ok(await _userRepository.GetUsersBySprintId(sprintId));
|
||||
}
|
||||
|
||||
[HttpPost("{sprintId}/adjustment")]
|
||||
public async Task<IActionResult> PostAdjustment(int sprintId, [FromBody] Adjustment adjustment)
|
||||
{
|
||||
try
|
||||
{
|
||||
adjustment.SprintId = sprintId;
|
||||
adjustment.Id = default;
|
||||
await _adjustmentRepository.Add(adjustment);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("{sprintId}/{userId}")]
|
||||
public async Task<IActionResult> PutAvailability(int sprintId, int userId, [FromBody] TeamMemberAvailability teamMemberAvailability)
|
||||
{
|
||||
try
|
||||
{
|
||||
TeamMemberAvailability existingAvailability = await _teamMemberAvailabilityRepository.GetBySprintIdAndUserId(sprintId, userId);
|
||||
existingAvailability.AvailabilityPoints = teamMemberAvailability.AvailabilityPoints;
|
||||
await _teamMemberAvailabilityRepository.Update(existingAvailability);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WebApi.Context;
|
||||
using WebApi.Models;
|
||||
using WebApi.RepositoryInterfaces;
|
||||
using WebApi.Services;
|
||||
|
||||
namespace WebApi.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class TicketController : ControllerBase
|
||||
{
|
||||
private readonly User user = Globals.curretUser;
|
||||
private readonly IStoryRepository _storyRepository;
|
||||
private readonly StoryPointEstimator _storyPointEstimator;
|
||||
public TicketController(IStoryRepository storyRepository)
|
||||
{
|
||||
_storyRepository = storyRepository;
|
||||
user = new User
|
||||
{
|
||||
UserId = 1,
|
||||
Username = "alice_smith"
|
||||
};
|
||||
_storyPointEstimator = new StoryPointEstimator();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAsync()
|
||||
{
|
||||
return Ok(await _storyRepository.GetAll());
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<IActionResult> Get(int id)
|
||||
{
|
||||
var story = await _storyRepository.GetById(id);
|
||||
|
||||
return story != null ? Ok(story) : NotFound();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> PostAsync([FromBody] Story story)
|
||||
{
|
||||
try
|
||||
{
|
||||
story.CreatedBy = user.UserId;
|
||||
story.StoryId = default;
|
||||
story.ParentId = default;
|
||||
await _storyRepository.Add(story);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public struct StatusUpdate
|
||||
{
|
||||
public string Status { get; set; }
|
||||
}
|
||||
|
||||
[HttpPut("{id}/status")]
|
||||
public async Task<IActionResult> PutAsync([FromBody] StatusUpdate status, int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var story = await _storyRepository.GetById(id);
|
||||
story.Status = status.Status;
|
||||
await _storyRepository.Update(story);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> PutAsync([FromBody] Story story, int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
story.StoryId = id;
|
||||
await _storyRepository.Update(story);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteAsync(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var story = await _storyRepository.GetById(id);
|
||||
if (story == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
await _storyRepository.Delete(id);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("EstimateStoryPoints")]
|
||||
public async Task<IActionResult> EstimateStoryPointsAsync(string title, string? description)
|
||||
{
|
||||
var stories = await _storyRepository.GetAll();
|
||||
var storyPoints = await _storyPointEstimator.EstimateStoryPoints(title, description ?? string.Empty);
|
||||
return Ok(storyPoints);
|
||||
}
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WebApi.Models;
|
||||
using WebApi.RepositoryInterfaces;
|
||||
|
||||
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||
|
||||
namespace WebApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
public UserController(IUserRepository userRepository)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get()
|
||||
{
|
||||
return Ok(await _userRepository.GetAll());
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<IActionResult> Get(int id)
|
||||
{
|
||||
var user = await _userRepository.GetById(id);
|
||||
return user != null ? Ok(user) : NotFound();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Post([FromBody] User user)
|
||||
{
|
||||
try
|
||||
{
|
||||
user.UserId = default;
|
||||
await _userRepository.Add(user);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("/login")]
|
||||
public async Task<IActionResult> LogIn([FromBody]User user)
|
||||
{
|
||||
var userDb = await _userRepository.GetUserByName(user.Username);
|
||||
Console.WriteLine(user.Username);
|
||||
if (user == null)
|
||||
{
|
||||
return BadRequest(new { Message = "Invalid username" });
|
||||
}
|
||||
else if (user.Password != userDb.Password)
|
||||
{
|
||||
return BadRequest(new { Message = "Password is incorect" });
|
||||
}
|
||||
Globals.curretUser = user;
|
||||
return Ok(new {Message = "Login succes", User = userDb});
|
||||
}
|
||||
|
||||
[HttpGet("currentUser")]
|
||||
public async Task<IActionResult> GetGlobalUser()
|
||||
{
|
||||
return Ok(Globals.curretUser);
|
||||
}
|
||||
|
||||
[HttpGet("isLoggedIn")]
|
||||
public async Task<IActionResult> IsLoggedIn()
|
||||
{
|
||||
return Ok(Globals.curretUser.Username == null ? false : true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user