Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optional title search parameter added to Recipes endpoint #194

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/client/CookingAppFE/http/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ export async function getChat({ token, chatId }) {
}

export async function getUserChats({ token, userId, pageIndex }) {
const response = await fetch(`${ip}/user-chats/${userId}/${pageIndex}/20`, {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
});
const response = await fetch(
`${ip}/user-chats/${userId}/?pageIndex=${pageIndex}&pageSize=20`,
{
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
}
);

if (!response.ok) {
throw new Error(response.statusText);
Expand Down
16 changes: 9 additions & 7 deletions src/client/CookingAppFE/http/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ export async function createRecipe({ token, request }) {
}

export async function getRecipes({ token, userId, page }) {
const response = await fetch(`${ip}/recipes/${userId}/${page}/5`, {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
});
const response = await fetch(
`${ip}/recipes/${userId}?pageIndex=${page}&pageSize=5`,
{
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
}
);
if (!response.ok) {
throw new Error("Resource not found");
}
Expand Down
16 changes: 9 additions & 7 deletions src/client/CookingAppReact/src/http/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ export async function getChat({ token, chatId }) {
}

export async function getUserChats({ token, userId, pageIndex }) {
const response = await fetch(`${ip}/user-chats/${userId}/${pageIndex}/20`, {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
});
const response = await fetch(
`${ip}/user-chats/${userId}/?pageIndex=${pageIndex}&pageSize=20`,
{
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
}
);

if (!response.ok) {
throw new Error(response.statusText);
Expand Down
16 changes: 9 additions & 7 deletions src/client/CookingAppReact/src/http/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ export async function createRecipe({ token, request }) {
}

export async function getRecipes({ token, userId, page }) {
const response = await fetch(`${ip}/recipes/${userId}/${page}/5`, {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
});
const response = await fetch(
`${ip}/recipes/${userId}?pageIndex=${page}&pageSize=5`,
{
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
}
);
if (!response.ok) {
throw new Error("Resource not found");
}
Expand Down
4 changes: 3 additions & 1 deletion src/server/CookingApp/Controllers/ChatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ public async Task<IActionResult> Delete(string chatId)
};
}

[HttpPost("user-chats/{userId}/{pageIndex}/{pageSize}")]
[HttpGet("user-chats/{userId}")]
public async Task<IActionResult> ChatsByUser(string userId,
[Range(1, int.MaxValue, ErrorMessage = "Value must be greater than 0")]
[FromQuery]
int pageIndex = 1,
[Range(1, int.MaxValue, ErrorMessage = "Value must be greater than 0")]
[FromQuery]
int pageSize = 50)
{
var result = await chatService.GetActiveUserChats(userId, pageIndex, pageSize);
Expand Down
11 changes: 8 additions & 3 deletions src/server/CookingApp/Controllers/RecipeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@ public async Task<IActionResult> RecipeById(string recipeId)
};
}

[HttpPost("recipes/{userId}/{pageIndex}/{pageSize}")]
public async Task<IActionResult> Recipes(string userId,
[HttpGet("recipes/{userId}")]
public async Task<IActionResult> Recipes(
string userId,
[FromQuery]
string? title = null,
[Range(1, int.MaxValue, ErrorMessage = "Value must be greater than 0")]
[FromQuery]
int pageIndex = 1,
[Range(1, int.MaxValue, ErrorMessage = "Value must be greater than 0")]
[FromQuery]
int pageSize = 10)
{
var result = await recipeService.GetMine(userId, pageIndex, pageSize);
var result = await recipeService.GetMine(userId, pageIndex, pageSize, title);
return new ApiResponse<RecipePage>()
{
Status = 200,
Expand Down
3 changes: 2 additions & 1 deletion src/server/CookingApp/Services/Recipe/IRecipeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public interface IRecipeService
/// <exception cref="NotFoundException">Thrown when no recipe is found with the given ID.</exception>
Task<Recipe> GetById(string recipeId);

Task<IPagedList<Recipe>> GetMine(string userId, int pageIndex, int pageSize = 10, bool includeDeleted = false);
Task<IPagedList<Recipe>> GetMine(string userId, int pageIndex, int pageSize = 10, string? title = null,
bool includeDeleted = false);
Task<IEnumerable<Recipe>> GetArchived(string userId);
}
}
10 changes: 8 additions & 2 deletions src/server/CookingApp/Services/Recipe/RecipeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ public async Task<string> CreateRecipe(string request, string userId)
return recipe.Id;
}

public async Task<IPagedList<Recipe>> GetMine(string userId, int pageIndex, int pageSize = 10, bool includeDeleted = false)
public async Task<IPagedList<Recipe>> GetMine(string userId, int pageIndex, int pageSize = 10, string? title = null, bool includeDeleted = false)
{
return await repo.GetPagedListAsync(pageIndex, pageSize, r => r.UserId == userId, null, SortDirection.Descending, includeDeleted);
return await repo.GetPagedListAsync(
pageIndex,
pageSize,
r => r.UserId == userId && (title == null || r.Title.ToLower().Contains(title.ToLower())),
null,
SortDirection.Descending,
includeDeleted);
}

public async Task ArchiveRecipe(string recipeId)
Expand Down
Loading