Skip to content

Commit 5f354ed

Browse files
committed
Minor bug fixes
1 parent 39c6d86 commit 5f354ed

File tree

12 files changed

+39
-26
lines changed

12 files changed

+39
-26
lines changed

src/Adapters/Database/MySql/Repositories/AccountRepository.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,10 @@ public async Task<IEnumerable<AccountModel>> FindWriters(int libraryId, string q
160160
var sql = @"Select a.* from Accounts as a
161161
INNER JOIN AccountLibrary as al on a.Id = al.AccountId
162162
WHERE al.LibraryId = @LibraryId AND al.Role IN (0, 1, 2) AND a.Name LIKE @Query";
163-
var command = new CommandDefinition(sql, new { LibraryId = libraryId, Query = query }, cancellationToken: cancellationToken);
163+
var command = new CommandDefinition(sql, new { LibraryId = libraryId, Query = $"%{query}%" }, cancellationToken: cancellationToken);
164164

165-
return await connection.QueryAsync<AccountModel>(command);
165+
var result = await connection.QueryAsync<AccountModel>(command);
166+
return result;
166167
}
167168
}
168169

src/Adapters/Database/MySql/Repositories/CorrectionRepository.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ FROM Corrections
4343
AND (IncorrectText LIKE @Query OR CorrectText LIKE @Query)
4444
AND `Profile` = @Profile
4545
ORDER BY `Language`, `Profile`, IncorrectText
46-
LIMIT @PageSize
47-
OFFSET @PageSize * (@PageNumber - 1)";
48-
var command = new CommandDefinition(sql,
49-
new { Language = language, Query = $"%{query}%", Profile = profile, PageSize = pageSize, PageNumber = pageNumber },
46+
LIMIT @PageSize OFFSET @Offset";
47+
var command = new CommandDefinition(sql, new {
48+
Language = language,
49+
Query = $"%{query}%",
50+
Profile = profile,
51+
PageSize = pageSize,
52+
Offset = pageSize * (pageNumber - 1) },
5053
cancellationToken: cancellationToken);
5154

5255
var authors = await connection.QueryAsync<CorrectionModel>(command);

src/Adapters/Database/MySql/Repositories/Library/BookPageRepository.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ public async Task<BookPageModel> UpdatePage(int libraryId, int bookId, int seque
9494
{
9595
var sql = @"UPDATE BookPage p
9696
INNER JOIN Book b ON b.Id = p.BookId
97-
SET p.ImageId = @ImageId,
98-
p.`Status` = @Status,
97+
SET p.`Status` = @Status,
9998
ChapterId = @ChapterId,
10099
ContentId = @ContentId
101100
WHERE b.LibraryId = @LibraryId
@@ -162,11 +161,14 @@ FROM BookPage p
162161
}
163162
}
164163

165-
public async Task<Page<BookPageModel>> GetPagesByBook(int libraryId, int bookId, int pageNumber, int pageSize, EditingStatus status, AssignmentFilter assignmentFilter, AssignmentFilter reviewerAssignmentFilter, int? assignedTo, CancellationToken cancellationToken)
164+
public async Task<Page<BookPageModel>> GetPagesByBook(int libraryId, int bookId, int pageNumber, int pageSize,
165+
EditingStatus status, AssignmentFilter assignmentFilter, AssignmentFilter reviewerAssignmentFilter,
166+
SortDirection sortDirection, int? assignedTo, CancellationToken cancellationToken)
166167
{
167168
using (var connection = _connectionProvider.GetLibraryConnection())
168169
{
169-
var sql = @"SELECT p.BookId, p.SequenceNumber, p.Status,
170+
var sortDirectionValue = sortDirection == SortDirection.Descending ? "DESC" : "ASC";
171+
var sql = @$"SELECT p.BookId, p.SequenceNumber, p.Status,
170172
p.WriterAccountId, a.Name As WriterAccountName, p.WriterAssignTimeStamp,
171173
p.ReviewerAccountId, ar.Name As ReviewerAccountName, p.ReviewerAssignTimeStamp,
172174
f.Id As ImageId, f.FilePath AS ImageUrl, p.ContentId, p.ChapterId, c.ChapterNumber, c.Title As ChapterTitle
@@ -190,7 +192,7 @@ FROM BookPage AS p
190192
( @ReviewerAssignmentFilter = 2 AND p.ReviewerAccountId IS NULL) OR
191193
( (@ReviewerAssignmentFilter = 3 OR @ReviewerAssignmentFilter = 4) AND p.ReviewerAccountId = @AccountId )
192194
)
193-
ORDER BY p.SequenceNumber
195+
ORDER BY p.SequenceNumber {sortDirectionValue}
194196
LIMIT @PageSize
195197
OFFSET @Offset";
196198
var command = new CommandDefinition(sql,

src/Adapters/Database/MySql/Repositories/Library/IssueArticleRepository.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ public async Task<IssueArticleModel> AddIssueArticle(int libraryId, int periodic
2525
using (var connection = _connectionProvider.GetLibraryConnection())
2626
{
2727
var sql = @"INSERT INTO IssueArticle (`Title`, IssueId, `Status`, SequenceNumber, SeriesName, SeriesIndex, WriterAccountId, WriterAssignTimeStamp, ReviewerAccountId, ReviewerAssignTimeStamp)
28-
VALUES (@Title, (SELECT Id FROM Issue WHERE VolumeNumber = @VolumeNumber AND IssueNumber = @IssueNumber), @Status, @SequenceNumber, @SeriesName, @SeriesIndex, @WriterAccountId, @WriterAssignTimeStamp, @ReviewerAccountId, @ReviewerAssignTimeStamp);
28+
VALUES (@Title, (SELECT Id FROM Issue WHERE PeriodicalId = @PeriodicalId AND VolumeNumber = @VolumeNumber AND IssueNumber = @IssueNumber), @Status, @SequenceNumber, @SeriesName, @SeriesIndex, @WriterAccountId, @WriterAssignTimeStamp, @ReviewerAccountId, @ReviewerAssignTimeStamp);
2929
SELECT LAST_INSERT_ID();";
3030
var command = new CommandDefinition(sql, new
3131
{
3232
Title = issueArticle.Title,
33+
PeriodicalId = periodicalId,
3334
VolumeNumber = volumeNumber,
3435
IssueNumber = issueNumber,
3536
SequenceNumber = int.MaxValue,

src/Adapters/Database/SqlServer/Repositories/Library/BookPageRepository.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,14 @@ FROM BookPage p
149149
}
150150
}
151151

152-
public async Task<Page<BookPageModel>> GetPagesByBook(int libraryId, int bookId, int pageNumber, int pageSize, EditingStatus status, AssignmentFilter assignmentFilter, AssignmentFilter reviewerAssignmentFilter, int? assignedTo, CancellationToken cancellationToken)
152+
public async Task<Page<BookPageModel>> GetPagesByBook(int libraryId, int bookId, int pageNumber, int pageSize,
153+
EditingStatus status, AssignmentFilter assignmentFilter, AssignmentFilter reviewerAssignmentFilter,
154+
SortDirection sortDirection, int? assignedTo, CancellationToken cancellationToken)
153155
{
154156
using (var connection = _connectionProvider.GetLibraryConnection())
155157
{
156-
var sql = @"SELECT p.BookId, p.SequenceNumber, p.Status,
158+
var sortDirectionValue = sortDirection == SortDirection.Descending ? "DESC" : "ASC";
159+
var sql = @$"SELECT p.BookId, p.SequenceNumber, p.Status,
157160
p.WriterAccountId, a.Name As WriterAccountName, p.WriterAssignTimeStamp,
158161
p.ReviewerAccountId, ar.Name As ReviewerAccountName, p.ReviewerAssignTimeStamp,
159162
f.Id As ImageId, f.FilePath AS ImageUrl, p.Text, p.ChapterId, c.Title As ChapterTitle
@@ -177,7 +180,7 @@ FROM BookPage AS p
177180
( @ReviewerAssignmentFilter = 2 AND p.ReviewerAccountId IS NULL) OR
178181
( (@ReviewerAssignmentFilter = 3 OR @ReviewerAssignmentFilter = 4) AND p.ReviewerAccountId = @AccountId )
179182
)
180-
ORDER BY p.SequenceNumber
183+
ORDER BY p.SequenceNumber {sortDirectionValue}
181184
OFFSET @PageSize * (@PageNumber - 1) ROWS
182185
FETCH NEXT @PageSize ROWS ONLY";
183186
var command = new CommandDefinition(sql,

src/Adapters/Database/SqlServer/Repositories/Library/IssueArticleRepository.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ public async Task<IssueArticleModel> AddIssueArticle(int libraryId, int periodic
2525
using (var connection = _connectionProvider.GetLibraryConnection())
2626
{
2727
var sql = @"INSERT INTO IssueArticle (Title, IssueId, Status, SequenceNumber, SeriesName, SeriesIndex, WriterAccountId, WriterAssignTimeStamp, ReviewerAccountId, ReviewerAssignTimeStamp)
28-
OUTPUT Inserted.Id VALUES (@Title, (SELECT Id FROM Issue WHERE VolumeNumber = @VolumeNumber AND IssueNumber = @IssueNumber), @Status, @SequenceNumber, @SeriesName, @SeriesIndex, @WriterAccountId, @WriterAssignTimeStamp, @ReviewerAccountId, @ReviewerAssignTimeStamp)";
28+
OUTPUT Inserted.Id VALUES (@Title, (SELECT Id FROM Issue WHERE PeriodicalId = @PeriodicalId AND VolumeNumber = @VolumeNumber AND IssueNumber = @IssueNumber), @Status, @SequenceNumber, @SeriesName, @SeriesIndex, @WriterAccountId, @WriterAssignTimeStamp, @ReviewerAccountId, @ReviewerAssignTimeStamp)";
2929
var command = new CommandDefinition(sql, new
3030
{
3131
Title = issueArticle.Title,
32+
PeriodicalId = periodicalId,
3233
VolumeNumber = volumeNumber,
3334
IssueNumber = issueNumber,
3435
SequenceNumber = issueArticle.SequenceNumber,

src/Inshapardaz.Api/Controllers/AccountsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public async Task<IActionResult> GetUser(CancellationToken cancellationToken)
243243
}
244244

245245
[HttpGet("/libraries/{libraryId}/writers", Name = nameof(AccountsController.GetWriters))]
246-
public async Task<IActionResult> GetWriters(int libraryId, string query, CancellationToken token = default(CancellationToken))
246+
public async Task<IActionResult> GetWriters(int libraryId, [FromQuery] string query, CancellationToken token = default(CancellationToken))
247247
{
248248
var writersQuery = new GetWritersQuery(libraryId, query);
249249
var writers = await _queryProcessor.ExecuteAsync(writersQuery, cancellationToken: token);

src/Inshapardaz.Api/Controllers/BookPageController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public async Task<IActionResult> GetPagesByBook(int libraryId,
4444
[FromQuery] EditingStatus status = EditingStatus.All,
4545
[FromQuery] AssignmentFilter assignmentFilter = AssignmentFilter.All,
4646
[FromQuery] AssignmentFilter reviewerAssignmentFilter = AssignmentFilter.All,
47+
[FromQuery] SortDirection sortDirection = SortDirection.Ascending,
4748
[FromQuery] int? assignmentTo = null,
4849
CancellationToken token = default(CancellationToken))
4950
{
@@ -52,6 +53,7 @@ public async Task<IActionResult> GetPagesByBook(int libraryId,
5253
StatusFilter = status,
5354
AssignmentFilter = assignmentFilter,
5455
ReviewerAssignmentFilter = reviewerAssignmentFilter,
56+
SortDirection = sortDirection,
5557
AccountId = assignmentFilter == AssignmentFilter.AssignedToMe || reviewerAssignmentFilter == AssignmentFilter.AssignedToMe ? _userHelper.AccountId : assignmentTo
5658
};
5759
var result = await _queryProcessor.ExecuteAsync(getBookPagesQuery, token);

src/Inshapardaz.Domain/Adapters/Repositories/Library/IBookPageRepository.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public interface IBookPageRepository
2525
Task DeletePageImage(int libraryId, int bookId, int sequenceNumber, CancellationToken cancellationToken);
2626
Task<IEnumerable<UserPageSummaryItem>> GetUserPageSummary(int libraryId, int accountId, CancellationToken cancellationToken);
2727
Task<int> GetPageCount(int libraryId, int bookId, int oldSequenceNumber, CancellationToken cancellationToken);
28-
Task<Page<BookPageModel>> GetPagesByBook(int libraryId, int bookId, int pageNumber, int pageSize, EditingStatus status, AssignmentFilter assignmentFilter, AssignmentFilter reviewerAssignmentFilter, int? assignedTo, CancellationToken cancellationToken);
28+
Task<Page<BookPageModel>> GetPagesByBook(int libraryId, int bookId, int pageNumber, int pageSize,
29+
EditingStatus status, AssignmentFilter assignmentFilter, AssignmentFilter reviewerAssignmentFilter,
30+
SortDirection sortDirection, int? assignedTo, CancellationToken cancellationToken);
2931
Task<Page<BookPageModel>> GetPagesByUser(int libraryId, int assignedTo, EditingStatus statusFilter, int pageNumber, int pageSize, CancellationToken cancellationToken);
3032
Task<IEnumerable<BookPageModel>> GetPagesByBookChapter(int libraryId, int bookId, long chapterId, CancellationToken cancellationToken);
3133

src/Inshapardaz.Domain/Ports/Command/Library/Book/Chapter/AssignChapterToUserRequest.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ public AssignChapterToUserRequestHandler(IAccountRepository accountRepository,
4444
[LibraryAuthorize(1, Role.LibraryAdmin, Role.Writer)]
4545
public override async Task<AssignChapterToUserRequest> HandleAsync(AssignChapterToUserRequest command, CancellationToken cancellationToken = new CancellationToken())
4646
{
47-
var accountToAssign = command.AccountId ?? _userHelper.Account.Id;
48-
if (!_userHelper.IsAdmin)
47+
if (!_userHelper.IsAdmin && command.AccountId.HasValue)
4948
{
50-
var account = await _accountRepository.GetLibraryAccountById(command.LibraryId, accountToAssign, cancellationToken);
49+
var account = await _accountRepository.GetLibraryAccountById(command.LibraryId, command.AccountId.Value, cancellationToken);
5150
if (account.Role != Role.LibraryAdmin && account.Role != Role.Writer)
5251
{
5352
throw new BadRequestException("user cannot be assigned chapter");
@@ -62,11 +61,11 @@ public AssignChapterToUserRequestHandler(IAccountRepository accountRepository,
6261

6362
if (chapter.Status == EditingStatus.Available || chapter.Status == EditingStatus.Typing)
6463
{
65-
command.Result = await _chapterRepository.UpdateWriterAssignment(command.LibraryId, command.BookId, command.ChapterNumber, accountToAssign, cancellationToken);
64+
command.Result = await _chapterRepository.UpdateWriterAssignment(command.LibraryId, command.BookId, command.ChapterNumber, command.AccountId, cancellationToken);
6665
}
6766
else if (chapter.Status == EditingStatus.Typed || chapter.Status == EditingStatus.InReview)
6867
{
69-
command.Result = await _chapterRepository.UpdateReviewerAssignment(command.LibraryId, command.BookId, command.ChapterNumber, accountToAssign, cancellationToken);
68+
command.Result = await _chapterRepository.UpdateReviewerAssignment(command.LibraryId, command.BookId, command.ChapterNumber, command.AccountId, cancellationToken);
7069
}
7170
else
7271
{

0 commit comments

Comments
 (0)