-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72160f6
commit ef3cc48
Showing
23 changed files
with
1,642 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
namespace Application.Common.DTOs.Highlights; | ||
|
||
public class HighlightInDto | ||
{ | ||
[Required] | ||
public Guid Guid { get; set; } | ||
|
||
[Required] | ||
public string Color { get; set; } | ||
|
||
[Required] | ||
public int PageNumber { get; set; } | ||
|
||
[Required] | ||
public ICollection<RectFInDto> Rects { get; set; } = new List<RectFInDto>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Application.Common.DTOs.Highlights; | ||
|
||
public class HighlightOutDto | ||
{ | ||
public string Guid { get; set; } | ||
|
||
public string Color { get; set; } | ||
|
||
public int PageNumber { get; set; } | ||
|
||
public ICollection<RectFOutDto> Rects { get; set; } = new List<RectFOutDto>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
namespace Application.Common.DTOs.Highlights; | ||
|
||
public class RectFInDto | ||
{ | ||
[Required] | ||
public float X { get; set; } | ||
|
||
[Required] | ||
public float Y { get; set; } | ||
|
||
[Required] | ||
public float Width { get; set; } | ||
|
||
[Required] | ||
public float Height { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Application.Common.DTOs.Highlights; | ||
|
||
public class RectFOutDto | ||
{ | ||
public float X { get; set; } | ||
|
||
public float Y { get; set; } | ||
|
||
public float Width { get; set; } | ||
|
||
public float Height { get; set; } | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Application/Common/Mappings/HighlightAutoMapperProfile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using Application.Common.DTOs.Highlights; | ||
using Application.Common.DTOs.Tags; | ||
using AutoMapper; | ||
using Domain.Entities; | ||
|
||
namespace Application.Common.Mappings; | ||
|
||
public class HighlightAutoMapperProfile : Profile | ||
{ | ||
public HighlightAutoMapperProfile() | ||
{ | ||
CreateMap<HighlightInDto, Highlight>() | ||
.ForMember(dest => dest.HighlightId, temp => temp.MapFrom(src => src.Guid)); | ||
CreateMap<Highlight, HighlightOutDto>() | ||
.ForMember(dest => dest.Guid, temp => temp.MapFrom(src => src.HighlightId.ToString())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Application.Common.DTOs.Highlights; | ||
using AutoMapper; | ||
using Domain.Entities; | ||
|
||
namespace Application.Common.Mappings; | ||
|
||
public class RectFAutoMapperProfile : Profile | ||
{ | ||
public RectFAutoMapperProfile() | ||
{ | ||
CreateMap<RectFInDto, RectF>(); | ||
CreateMap<RectF, RectFOutDto>(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Application/Interfaces/Repositories/IHighlightRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Domain.Entities; | ||
|
||
namespace Application.Interfaces.Repositories; | ||
|
||
public interface IHighlightRepository | ||
{ | ||
public Task<int> SaveChangesAsync(); | ||
void Add(Highlight highlight); | ||
void Delete(Highlight highlight); | ||
Task<Highlight> GetAsync(Guid bookId, Guid highlightGuid); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Application.Common.DTOs.Highlights; | ||
|
||
namespace Application.Interfaces.Services; | ||
|
||
public interface IHighlightService | ||
{ | ||
Task CreateHighlightAsync(string email, Guid bookGuid, HighlightInDto highlightIn); | ||
Task DeleteHighlightAsync(string email, Guid bookGuid, Guid highlightGuid); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using Application.Common.DTOs.Highlights; | ||
using Application.Common.Exceptions; | ||
using Application.Interfaces.Repositories; | ||
using Application.Interfaces.Services; | ||
using AutoMapper; | ||
using Domain.Entities; | ||
|
||
namespace Application.Services; | ||
|
||
public class HighlightService : IHighlightService | ||
{ | ||
private readonly IUserRepository _userRepository; | ||
private readonly IMapper _mapper; | ||
private readonly IHighlightRepository _highlightRepository; | ||
private readonly IBookRepository _bookRepository; | ||
|
||
|
||
public HighlightService(IMapper mapper, | ||
IHighlightRepository highlightRepository, | ||
IBookRepository bookRepository, | ||
IUserRepository userRepository) | ||
{ | ||
_mapper = mapper; | ||
_highlightRepository = highlightRepository; | ||
_bookRepository = bookRepository; | ||
_userRepository = userRepository; | ||
} | ||
|
||
|
||
public async Task CreateHighlightAsync(string email, Guid bookGuid, HighlightInDto highlightIn) | ||
{ | ||
var user = await _userRepository.GetAsync(email, trackChanges: true); | ||
var book = user.Books.SingleOrDefault(book => book.BookId == bookGuid); | ||
if (book == default) | ||
{ | ||
const string message = "No book with this id exists"; | ||
throw new CommonErrorException(404, message, 4); | ||
} | ||
|
||
var highlightExists = book.Highlights.Any(h => h.HighlightId == highlightIn.Guid); | ||
if(highlightExists) | ||
{ | ||
const string message = "A highlight with this id already exists"; | ||
throw new CommonErrorException(409, message, 0); | ||
} | ||
|
||
var newHighlight = _mapper.Map<Highlight>(highlightIn); | ||
newHighlight.Book = book; | ||
book.Highlights.Add(newHighlight); | ||
|
||
await _highlightRepository.SaveChangesAsync(); | ||
} | ||
|
||
public async Task DeleteHighlightAsync(string email, Guid bookGuid, Guid highlightGuid) | ||
{ | ||
var user = await _userRepository.GetAsync(email, trackChanges: true); | ||
var bookExists = await _bookRepository.ExistsAsync(user.Id, bookGuid); | ||
if (!bookExists) | ||
return; | ||
|
||
var highlight = await _highlightRepository.GetAsync(bookGuid, | ||
highlightGuid); | ||
if (highlight == default) | ||
{ | ||
const string message = "No highlight with this id exists"; | ||
throw new CommonErrorException(404, message, 0); | ||
} | ||
|
||
_highlightRepository.Delete(highlight); | ||
await _highlightRepository.SaveChangesAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
namespace Domain.Entities; | ||
|
||
public class Highlight | ||
{ | ||
[DatabaseGenerated(DatabaseGeneratedOption.None)] | ||
[Key] | ||
public Guid HighlightId { get; set; } | ||
|
||
[Required] | ||
public string Color { get; set; } | ||
|
||
[Required] | ||
public int PageNumber { get; set; } | ||
|
||
[Required] | ||
public ICollection<RectF> Rects { get; set; } = new List<RectF>(); | ||
|
||
public Guid BookId { get; set; } | ||
public Book Book { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Domain.Entities; | ||
|
||
public class RectF | ||
{ | ||
[Key] | ||
public Guid RectFId { get; set; } | ||
|
||
[Required] | ||
public float X { get; set; } | ||
|
||
[Required] | ||
public float Y { get; set; } | ||
|
||
[Required] | ||
public float Width { get; set; } | ||
|
||
[Required] | ||
public float Height { get; set; } | ||
|
||
public Guid HighlightId { get; set; } | ||
public Highlight Highlight { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.