Skip to content

Commit

Permalink
Fixing api refs (#354)
Browse files Browse the repository at this point in the history
* fixing namespaces and packages in API

* removes sharedMethods from service, by creating weekService, and dependency injecting it into a controller.

---------

Co-authored-by: Desktop <[email protected]>
Co-authored-by: Andreas Würtz <[email protected]>
  • Loading branch information
3 people authored Nov 22, 2023
1 parent b866c06 commit 148408a
Show file tree
Hide file tree
Showing 57 changed files with 177 additions and 522 deletions.
1 change: 0 additions & 1 deletion Giraf.IntegrationTest/CustomWebApplicationFactory.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using System;
using GirafAPI.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Authentication.JwtBearer;
Expand Down
16 changes: 8 additions & 8 deletions GirafAPI/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using GirafEntities.User;
using GirafEntities.Authentication;
using GirafEntities.Authentication.DTOs;
using GirafEntities.Responses;
using GirafEntities.Settings.DTOs;
using GirafEntities.User;
using GirafEntities.User.DTOs;
using GirafRepositories.Interfaces;
using GirafAPI.Models;
using GirafAPI.Models.DTOs;
using GirafAPI.Models.DTOs.AccountDTOs;
using GirafAPI.Models.Responses;
using GirafAPI.Services;
using GirafAPI.Interfaces;
using GirafServices.Authentication;
using GirafServices.User;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
Expand Down
9 changes: 3 additions & 6 deletions GirafAPI/Controllers/ActivityController.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using GirafEntities.User;
using GirafEntities.Responses;
using GirafEntities.User;
using GirafEntities.WeekPlanner;
using GirafEntities.WeekPlanner.DTOs;
using GirafRepositories.Interfaces;
using System.Collections.Generic;
using GirafAPI.Models;
using GirafAPI.Models.DTOs;
using GirafAPI.Models.Responses;
using GirafAPI.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System.Linq;
using System.Threading.Tasks;
Expand Down
7 changes: 4 additions & 3 deletions GirafAPI/Controllers/AlternateNameController.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using GirafEntities.User;
using GirafEntities.WeekPlanner;
using GirafEntities.WeekPlanner.DTOs;
using GirafRepositories.Interfaces;
using GirafAPI.Models;
using GirafAPI.Interfaces;
using GirafServices.Authentication;
using GirafServices.User;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
using GirafAPI.Models.DTOs;
using Microsoft.AspNetCore.Http;

namespace GirafAPI.Controllers
Expand Down
3 changes: 1 addition & 2 deletions GirafAPI/Controllers/BaseControllerExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

using GirafAPI.Models.Responses;
using GirafEntities.Responses;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
Expand Down
7 changes: 3 additions & 4 deletions GirafAPI/Controllers/DepartmentController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using GirafEntities.Responses;
using GirafEntities.User;
using GirafEntities.User.DTOs;
using GirafRepositories.Interfaces;
using GirafAPI.Interfaces;
using GirafAPI.Models;
using GirafAPI.Models.DTOs;
using GirafAPI.Models.Responses;
using GirafServices.User;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
Expand Down
3 changes: 1 addition & 2 deletions GirafAPI/Controllers/ErrorController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using GirafAPI.Models.Responses;
using GirafEntities.Responses;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Net;

namespace GirafAPI.Controllers
{
Expand Down
8 changes: 4 additions & 4 deletions GirafAPI/Controllers/PictogramController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using GirafEntities.Responses;
using GirafEntities.User;
using GirafEntities.WeekPlanner;
using GirafEntities.WeekPlanner.DTOs;
using GirafRepositories.Interfaces;
using GirafAPI.Interfaces;
using GirafAPI.Models;
using GirafAPI.Models.DTOs;
using GirafAPI.Models.Responses;
using GirafServices.User;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand Down
7 changes: 3 additions & 4 deletions GirafAPI/Controllers/StatusController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using GirafRepositories.Persistence;
using GirafEntities.Responses;
using GirafRepositories.Persistence;
using GirafServices.User;
using System;
using System.IO;
using System.Linq;
using GirafAPI.Models.Responses;
using GirafAPI.Interfaces;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using GirafAPI.Data;

namespace GirafAPI.Controllers
{
Expand Down
13 changes: 8 additions & 5 deletions GirafAPI/Controllers/UserController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using GirafEntities.Responses;
using GirafEntities.Settings.DTOs;
using GirafEntities.User;
using GirafEntities.User.DTOs;
using GirafEntities.WeekPlanner;
using GirafEntities.WeekPlanner.DTOs;
using GirafRepositories;
using GirafRepositories.Interfaces;
using GirafAPI.Extensions;
using GirafAPI.Models;
using GirafAPI.Models.DTOs;
using GirafAPI.Models.Responses;
using GirafAPI.Interfaces;
using GirafServices.Authentication;
using GirafServices.User;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
Expand Down
55 changes: 27 additions & 28 deletions GirafAPI/Controllers/WeekController.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
using GirafEntities.Responses;
using GirafEntities.User;
using GirafEntities.WeekPlanner;
using GirafEntities.WeekPlanner.DTOs;
using GirafRepositories.Interfaces;
using GirafAPI.Models;
using GirafAPI.Models.DTOs;
using GirafAPI.Models.Responses;
using GirafAPI.Interfaces;
using GirafServices.User;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using static GirafAPI.Shared.SharedMethods;


namespace GirafAPI.Controllers
Expand Down Expand Up @@ -157,34 +155,35 @@ public async Task<ActionResult> ReadUsersWeekSchedule(string userId, int weekYea

//Create default thumbnail
var emptyThumbnail = await _pictogramRepository.GetPictogramWithName("default");
if (emptyThumbnail == null)
{
//Create default thumbnail
await _pictogramRepository.AddPictogramWith_NO_ImageHash("default", AccessLevel.PUBLIC);

emptyThumbnail = await _pictogramRepository.GetPictogramWithName("default");

return Ok(new SuccessResponse<WeekDTO>(new WeekDTO()
{
WeekYear = weekYear,
Name = $"{weekYear} - {weekNumber}",
WeekNumber = weekNumber,
Thumbnail = new Models.DTOs.WeekPictogramDTO(emptyThumbnail),
Days = new int[] { 1, 2, 3, 4, 5, 6, 7 }
.Select(d => new WeekdayDTO()
{
Activities = new List<ActivityDTO>(),
Day = (Days)d
}).ToArray()
}));
}
// IDE SAYS THIS IS ALWAYS FALSE
// if (emptyThumbnail == null)
// {
// //Create default thumbnail
// await _pictogramRepository.AddPictogramWith_NO_ImageHash("default", AccessLevel.PUBLIC);
//
// emptyThumbnail = await _pictogramRepository.GetPictogramWithName("default");
//
// return Ok(new SuccessResponse<WeekDTO>(new WeekDTO()
// {
// WeekYear = weekYear,
// Name = $"{weekYear} - {weekNumber}",
// WeekNumber = weekNumber,
// Thumbnail = new Models.DTOs.WeekPictogramDTO(emptyThumbnail),
// Days = new int[] { 1, 2, 3, 4, 5, 6, 7 }
// .Select(d => new WeekdayDTO()
// {
// Activities = new List<ActivityDTO>(),
// Day = (Days)d
// }).ToArray()
// }));
// }

return Ok(new SuccessResponse<WeekDTO>(new WeekDTO()
{
WeekYear = weekYear,
Name = $"{weekYear} - {weekNumber}",
WeekNumber = weekNumber,
Thumbnail = new Models.DTOs.WeekPictogramDTO(emptyThumbnail),
Thumbnail = new WeekPictogramDTO(emptyThumbnail),
Days = new[] { 1, 2, 3, 4, 5, 6, 7 }
.Select(d => new WeekdayDTO()
{
Expand Down
23 changes: 13 additions & 10 deletions GirafAPI/Controllers/WeekTemplateController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using GirafEntities.User;
using GirafEntities.Responses;
using GirafEntities.User;
using GirafEntities.WeekPlanner;
using GirafEntities.WeekPlanner.DTOs;
using GirafRepositories.Persistence;
using GirafAPI.Models;
using GirafAPI.Models.DTOs;
using GirafAPI.Models.Responses;
using GirafAPI.Interfaces;
using GirafServices.Authentication;
using GirafServices.User;
using GirafServices.WeekPlanner;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -12,8 +14,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using static GirafAPI.Shared.SharedMethods;
using GirafAPI.Data;

namespace GirafAPI.Controllers
{
Expand All @@ -24,6 +24,7 @@ namespace GirafAPI.Controllers
[Route("v1/[controller]")]
public class WeekTemplateController : Controller
{
private readonly IWeekService _weekService;
/// <summary>
/// A reference to GirafService, that contains common functionality for all controllers.
/// </summary>
Expand All @@ -47,12 +48,14 @@ public class WeekTemplateController : Controller
public WeekTemplateController(IGirafService giraf,
ILoggerFactory loggerFactory,
IAuthenticationService authentication,
GirafDbContext context)
GirafDbContext context,
IWeekService weekService)
{
_giraf = giraf;
_giraf._logger = loggerFactory.CreateLogger("WeekTemplate");
_authentication = authentication;
_context = context;
_weekService = weekService;
}

/// <summary>
Expand Down Expand Up @@ -152,7 +155,7 @@ public async Task<ActionResult> CreateWeekTemplate([FromBody] WeekTemplateDTO te

var newTemplate = new WeekTemplate(department);

var errorCode = await SetWeekFromDTO(templateDto, newTemplate, _giraf);
var errorCode = await _weekService.SetWeekFromDTO(templateDto, newTemplate, _giraf);
if (errorCode != null)
return BadRequest(errorCode);

Expand Down Expand Up @@ -205,7 +208,7 @@ public async Task<ActionResult> UpdateWeekTemplate(long id, [FromBody] WeekTempl
if (!await _authentication.HasTemplateAccess(user, template?.DepartmentKey))
return StatusCode(StatusCodes.Status403Forbidden, new ErrorResponse(ErrorCode.NotAuthorized, "User does not have permission"));

var errorCode = await SetWeekFromDTO(newValuesDto, template, _giraf);
var errorCode = await _weekService.SetWeekFromDTO(newValuesDto, template, _giraf);
if (errorCode != null)
return BadRequest(errorCode);

Expand Down
4 changes: 0 additions & 4 deletions GirafAPI/GirafAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MySql.Data" Version="8.0.30" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.0-beta.1" />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="2.0.0" />
<PackageReference Include="SkiaSharp" Version="2.88.6" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.2" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.6.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
Expand Down
14 changes: 1 addition & 13 deletions GirafAPI/Setup/GirafExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
using GirafEntities.User;
using GirafAPI.Data;
using GirafAPI.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using System;
using System.IO;
using System.Threading.Tasks;

namespace GirafAPI.Extensions
namespace GirafAPI.Setup
{
/// <summary>
/// The class for extension-methods for Giraf REST-api.
Expand Down
9 changes: 3 additions & 6 deletions GirafAPI/Setup/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using AspNetCoreRateLimit;
using GirafEntities.Authentication;
using GirafEntities.User;
using GirafRepositories;
using GirafRepositories.Interfaces;
using GirafRepositories.Persistence;
using GirafRepositories.User;
using GirafRepositories.WeekPlanner;
using GirafAPI.Data;
using GirafAPI.Extensions;
using GirafAPI.Interfaces;
using GirafAPI.Models;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
Expand All @@ -28,9 +25,9 @@
using System.IO;
using System.Text;
using System.Threading.Tasks;
using GirafAPI.Repositories;
using GirafAPI.Services;
using GirafServices;
using GirafServices.Authentication;
using GirafServices.User;

namespace GirafAPI.Setup
{
Expand Down
13 changes: 0 additions & 13 deletions GirafEntities/DTOs/ResourceIdDTO.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;

namespace GirafEntities.Settings
namespace GirafEntities.Settings.DTOs
{
/// <summary>
/// DTO Used for changing password
Expand Down
Loading

0 comments on commit 148408a

Please sign in to comment.