Skip to content

Commit

Permalink
fix frontend redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbjoralt committed Oct 19, 2023
1 parent 1c5af9f commit bb05fcf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
15 changes: 9 additions & 6 deletions backend/Api/Consultants/ConsultantController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Api.Consultants;

[Authorize]
[Route("/v0/consultants")]
[Route("/v0/{orgUrlKey}/consultants")]
[ApiController]
public class ConsultantController : ControllerBase
{
Expand All @@ -28,10 +28,11 @@ public ConsultantController(ApplicationContext context, IMemoryCache cache, Cons

[HttpGet]
public ActionResult<List<ConsultantReadModel>> Get(
[FromRoute] string orgUrlKey,
[FromQuery(Name = "weeks")] int numberOfWeeks = 8,
[FromQuery(Name = "includeOccupied")] bool includeOccupied = true)
{
var consultants = GetConsultantsWithAvailability(numberOfWeeks)
var consultants = GetConsultantsWithAvailability(orgUrlKey, numberOfWeeks)
.Where(c =>
includeOccupied
|| c.IsOccupied
Expand Down Expand Up @@ -69,24 +70,25 @@ public async Task<Results<Created<ConsultantWriteModel>, ProblemHttpResult, Vali
}
}

private List<ConsultantReadModel> GetConsultantsWithAvailability(int numberOfWeeks)
private List<ConsultantReadModel> GetConsultantsWithAvailability(string orgUrlKey, int numberOfWeeks)
{
if (numberOfWeeks == 8)
{
_cache.TryGetValue(CacheKeys.ConsultantAvailability8Weeks,
_cache.TryGetValue(
$"{orgUrlKey}/{CacheKeys.ConsultantAvailability8Weeks}",
out List<ConsultantReadModel>? cachedConsultants);
if (cachedConsultants != null) return cachedConsultants;
}

var consultants = LoadConsultantAvailability(numberOfWeeks)
var consultants = LoadConsultantAvailability(orgUrlKey, numberOfWeeks)
.Select(c => _consultantService.MapConsultantToReadModel(c, numberOfWeeks)).ToList();


_cache.Set(CacheKeys.ConsultantAvailability8Weeks, consultants);
return consultants;
}

private List<Consultant> LoadConsultantAvailability(int numberOfWeeks)
private List<Consultant> LoadConsultantAvailability(string orgUrlKey, int numberOfWeeks)
{
var applicableWeeks = DateService.GetNextWeeks(numberOfWeeks);
var firstDayOfCurrentWeek = DateService.GetFirstDayOfWeekContainingDate(DateTime.Now);
Expand Down Expand Up @@ -122,6 +124,7 @@ private List<Consultant> LoadConsultantAvailability(int numberOfWeeks)
|| (yearB <= pa.Year && minWeekB <= pa.WeekNumber && pa.WeekNumber <= maxWeekB)))
.Include(c => c.Department)
.ThenInclude(d => d.Organization)
.Where(c => c.Department.Organization.UrlKey == orgUrlKey)
.Include(c => c.Staffings.Where(s =>
(s.Year <= yearA && minWeekA <= s.Week && s.Week <= maxWeekA)
|| (yearB <= s.Year && minWeekB <= s.Week && s.Week <= maxWeekB)))
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/components/SearchBarComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
"use client";
import { useRouter, useSearchParams } from "next/navigation";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { useEffect, useRef, useState } from "react";
import { Search } from "react-feather";

export default function SearchBarComponent() {
const router = useRouter();
const searchParams = useSearchParams();
const pathname = usePathname();
const [searchText, setSearchText] = useState(
searchParams.get("search") || "",
);
const inputRef = useRef<HTMLInputElement>(null);

useEffect(() => {
const currentFilter = searchParams.get("filter") || "";
router.push(`/bemanning?search=${searchText}&filter=${currentFilter}`);
}, [searchText, searchParams, router]);
router.push(`${pathname}?search=${searchText}&filter=${currentFilter}`);
}, [searchText, searchParams, router, pathname]);

useEffect(() => {
function keyDownHandler(e: { code: string }) {
Expand Down
Empty file.

0 comments on commit bb05fcf

Please sign in to comment.