Skip to content

Commit

Permalink
Changed exceptions directory location
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoper02 committed Jun 9, 2024
1 parent 5d5a0d0 commit d4457e8
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Moq;
using Moq.EntityFrameworkCore;
using ReasnAPI.Models.Enums;
using ReasnAPI.Services.Exceptions;
using ReasnAPI.Exceptions;


namespace ReasnAPI.Tests.Services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System.Linq.Expressions;
using Moq;
using Moq.EntityFrameworkCore;
using ReasnAPI.Services.Exceptions;
using ReasnAPI.Exceptions;


namespace ReasnAPI.Tests.Services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System.Linq.Expressions;
using Moq;
using Moq.EntityFrameworkCore;
using ReasnAPI.Services.Exceptions;
using ReasnAPI.Exceptions;

namespace ReasnAPI.Tests.Services
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System.Linq.Expressions;
using Moq;
using Moq.EntityFrameworkCore;
using ReasnAPI.Services.Exceptions;
using ReasnAPI.Exceptions;

namespace ReasnAPI.Tests.Services
{
Expand Down
2 changes: 1 addition & 1 deletion Server/ReasnAPI/ReasnAPI.Tests/Services/TagServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System.Linq.Expressions;
using Moq;
using Moq.EntityFrameworkCore;
using ReasnAPI.Services.Exceptions;
using ReasnAPI.Exceptions;

namespace ReasnAPI.Tests.Services
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ReasnAPI.Services.Exceptions;
namespace ReasnAPI.Exceptions;

public class NotFoundException : Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ReasnAPI.Services.Exceptions;
namespace ReasnAPI.Exceptions;
public class ObjectExistsException : Exception
{
public ObjectExistsException() : base() { }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ReasnAPI.Services.Exceptions;
namespace ReasnAPI.Exceptions;

public class ObjectInUseException : Exception
{
Expand Down
12 changes: 5 additions & 7 deletions Server/ReasnAPI/ReasnAPI/Services/EventService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Microsoft.EntityFrameworkCore;
using ReasnAPI.Exceptions;
using ReasnAPI.Models.Database;
using ReasnAPI.Models.DTOs;
using System.Linq.Expressions;
using System.Linq;
using System.Transactions;
using ReasnAPI.Models.Enums;
using ReasnAPI.Services.Exceptions;

namespace ReasnAPI.Services;
public class EventService(ReasnContext context)
Expand All @@ -18,9 +16,9 @@ public EventDto CreateEvent(EventDto eventDto)
var nowTime = DateTime.UtcNow;
var newEvent = MapEventFromDto(eventDto);
newEvent.CreatedAt = nowTime;
newEvent.UpdatedAt = nowTime;
newEvent.UpdatedAt = nowTime;
newEvent.Slug = eventDto.Slug;

context.Events.Add(newEvent);
context.SaveChanges();

Expand Down Expand Up @@ -61,7 +59,7 @@ public EventDto UpdateEvent(int eventId, EventDto eventDto)
using (var scope = new TransactionScope())
{
var eventToUpdate = context.Events.FirstOrDefault(r => r.Id == eventId);

if (eventToUpdate is null)
{
throw new NotFoundException("Event not found");
Expand Down Expand Up @@ -121,7 +119,7 @@ public EventDto UpdateEvent(int eventId, EventDto eventDto)
.Select(paramDto => new Parameter
{
Key = paramDto.Key,
Value = paramDto.Value
Value = paramDto.Value
}).ToList();

var paramsToRemove = eventToUpdate.Parameters
Expand Down
2 changes: 1 addition & 1 deletion Server/ReasnAPI/ReasnAPI/Services/ImageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using ReasnAPI.Models.Enums;
using static System.Net.Mime.MediaTypeNames;
using Image = ReasnAPI.Models.Database.Image;
using ReasnAPI.Services.Exceptions;
using ReasnAPI.Exceptions;

namespace ReasnAPI.Services;
public class ImageService(ReasnContext context)
Expand Down
6 changes: 3 additions & 3 deletions Server/ReasnAPI/ReasnAPI/Services/InterestService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using ReasnAPI.Models.Database;
using ReasnAPI.Exceptions;
using ReasnAPI.Models.Database;
using ReasnAPI.Models.DTOs;
using ReasnAPI.Services.Exceptions;
using System.Linq.Expressions;

namespace ReasnAPI.Services;
Expand Down Expand Up @@ -46,7 +46,7 @@ public void DeleteInterest(int id)
}

var eventInterest = context.UserInterests.FirstOrDefault(r => r.InterestId == id);
if (eventInterest is not null)
if (eventInterest is not null)
{
throw new ObjectInUseException("Interest is in use");
}
Expand Down
16 changes: 8 additions & 8 deletions Server/ReasnAPI/ReasnAPI/Services/ParameterService.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using ReasnAPI.Models.Database;
using Microsoft.EntityFrameworkCore;
using ReasnAPI.Exceptions;
using ReasnAPI.Models.Database;
using ReasnAPI.Models.DTOs;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;
using ReasnAPI.Services.Exceptions;

namespace ReasnAPI.Services;
public class ParameterService(ReasnContext context)
Expand Down Expand Up @@ -32,13 +32,13 @@ public ParameterDto UpdateParameter(int parameterId, ParameterDto parameterDto)

var parameters = context.Events.Include(p => p.Parameters);

var parameterCheck = parameters.FirstOrDefault(r => r.Parameters.Any(p => p.Id == parameterId));
var parameterCheck = parameters.FirstOrDefault(r => r.Parameters.Any(p => p.Id == parameterId));

if (parameterCheck is not null) // if parameter is associated with an event, it cannot be updated
{
throw new ObjectInUseException("Parameter is associated with an event");
}
}

parameter.Key = parameterDto.Key;
parameter.Value = parameterDto.Value;
context.Parameters.Update(parameter);
Expand All @@ -62,7 +62,7 @@ public void DeleteParameter(int parameterId)
var parameterCheck = eventsWithParameters
.Any(e => e.Parameters.Any(p => p.Id == parameterId));

if (parameterCheck)
if (parameterCheck)
{
throw new ObjectInUseException("Parameter is associated with an event");
}
Expand Down
2 changes: 1 addition & 1 deletion Server/ReasnAPI/ReasnAPI/Services/TagService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Linq.Expressions;
using System.Transactions;
using Microsoft.EntityFrameworkCore;
using ReasnAPI.Services.Exceptions;
using ReasnAPI.Exceptions;

namespace ReasnAPI.Services;
public class TagService (ReasnContext context)
Expand Down

0 comments on commit d4457e8

Please sign in to comment.