-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from GeneriekPublicatiePlatformWoo/8-odpc-over…
…zicht-van-eigen-publicaties 8 odpc overzicht van eigen publicaties
- Loading branch information
Showing
15 changed files
with
565 additions
and
53 deletions.
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
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
89 changes: 87 additions & 2 deletions
89
ODPC.Server/Features/Publicaties/PublicatiesOverzicht/PublicatiesOverzichtController.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 |
---|---|---|
@@ -1,14 +1,99 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace ODPC.Features.Publicaties.PublicatiesOverzicht | ||
{ | ||
[ApiController] | ||
public class PublicatiesOverzichtController : ControllerBase | ||
{ | ||
[HttpGet("api/v1/publicaties")] | ||
public IActionResult Get() | ||
public IActionResult Get(int page = 1, string sorteer = "registratiedatum", string search = "", string registratiedatum__gte = "", string registratiedatum__lte = "", int pageSize = 5) | ||
{ | ||
return Ok(PublicatiesMock.Publicaties.Values.OrderByDescending(x => x.Creatiedatum)); | ||
var items = PublicatiesMock.Publicaties.Values.AsQueryable(); | ||
|
||
if (!string.IsNullOrEmpty(search)) | ||
{ | ||
items = items.Where(x => | ||
(x.OfficieleTitel != null && x.OfficieleTitel.Contains(search, StringComparison.OrdinalIgnoreCase)) || | ||
(x.VerkorteTitel != null && x.VerkorteTitel.Contains(search, StringComparison.OrdinalIgnoreCase))); | ||
} | ||
|
||
DateTime? fromDate = null; | ||
DateTime? untilDate = null; | ||
|
||
if (!string.IsNullOrEmpty(registratiedatum__gte)) | ||
{ | ||
if (DateTime.TryParseExact(registratiedatum__gte, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out DateTime parsedFromDate)) | ||
{ | ||
fromDate = parsedFromDate; | ||
} | ||
} | ||
|
||
if (!string.IsNullOrEmpty(registratiedatum__lte)) | ||
{ | ||
if (DateTime.TryParseExact(registratiedatum__lte, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out DateTime parsedUntilDate)) | ||
{ | ||
untilDate = parsedUntilDate.AddDays(1).AddTicks(-1); | ||
} | ||
} | ||
|
||
// Apply date range filtering if 'from' and/or 'until' dates are provided | ||
if (fromDate.HasValue) | ||
{ | ||
items = items.Where(x => x.Registratiedatum >= fromDate.Value); | ||
} | ||
|
||
if (untilDate.HasValue) | ||
{ | ||
items = items.Where(x => x.Registratiedatum <= untilDate.Value); | ||
} | ||
|
||
switch (sorteer.ToLower()) | ||
{ | ||
case "officiele_titel": | ||
items = items.OrderBy(x => x.OfficieleTitel ?? string.Empty); | ||
break; | ||
case "-officiele_titel": | ||
items = items.OrderByDescending(x => x.OfficieleTitel ?? string.Empty); | ||
break; | ||
case "verkorte_titel": | ||
items = items.OrderBy(x => x.VerkorteTitel); | ||
break; | ||
case "-verkorte_titel": | ||
items = items.OrderByDescending(x => x.VerkorteTitel); | ||
break; | ||
case "registratiedatum": | ||
items = items.OrderBy(x => x.Registratiedatum); | ||
break; | ||
default: | ||
items = items.OrderByDescending(x => x.Registratiedatum); // Default sorting | ||
break; | ||
} | ||
|
||
// Calculate total count | ||
var totalCount = items.Count(); | ||
|
||
// Paginate the items | ||
var pagedItems = items | ||
.Skip((page - 1) * pageSize) | ||
.Take(pageSize) | ||
.ToList(); | ||
|
||
// Build next and previous page URLs | ||
var nextPage = page * pageSize < totalCount ? $"api/v1/publicaties/?page={page + 1}" : null; | ||
var previousPage = page > 1 ? $"api/v1/publicaties/?page={page - 1}" : null; | ||
|
||
// Build the result | ||
var result = new | ||
{ | ||
count = totalCount, | ||
next = nextPage, | ||
previous = previousPage, | ||
results = pagedItems | ||
}; | ||
|
||
// Return the paged result | ||
return Ok(result); | ||
} | ||
} | ||
} |
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,86 @@ | ||
<template> | ||
<div class="form-group"> | ||
<label for="fromDate">Datum van</label> | ||
|
||
<input type="date" id="fromDate" ref="fromDateRef" v-model="fromDate" :max="today" /> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label for="untilDate">Datum tot</label> | ||
|
||
<input type="date" id="untilDate" ref="untilDateRef" v-model="untilDate" :max="today" /> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed, ref, watch } from "vue"; | ||
const props = defineProps<{ fromDate: string; untilDate: string }>(); | ||
const emit = defineEmits<{ | ||
(e: "update:fromDate", payload: string): void; | ||
(e: "update:untilDate", payload: string): void; | ||
}>(); | ||
const fromDate = computed<string>({ | ||
get: () => props.fromDate, | ||
set: (value) => emit("update:fromDate", value) | ||
}); | ||
const untilDate = computed<string>({ | ||
get: () => props.untilDate, | ||
set: (value) => emit("update:untilDate", value) | ||
}); | ||
const today = ref(new Date().toISOString().split("T")[0]); | ||
const fromDateRef = ref<HTMLInputElement>(); | ||
const untilDateRef = ref<HTMLInputElement>(); | ||
watch(fromDate, (value) => { | ||
if (!fromDateRef.value || !untilDateRef.value) return; | ||
if (value) { | ||
if (value > today.value) { | ||
fromDateRef.value.value = ""; | ||
fromDateRef.value.dispatchEvent(new Event("input")); | ||
return; | ||
} | ||
untilDateRef.value.min = value; | ||
if (untilDate.value && untilDate.value < value) { | ||
untilDateRef.value.value = value; | ||
untilDateRef.value.dispatchEvent(new Event("input")); | ||
} | ||
} else { | ||
untilDateRef.value.removeAttribute("min"); | ||
} | ||
}); | ||
watch(untilDate, (value) => { | ||
if (!fromDateRef.value || !untilDateRef.value) return; | ||
if (value) { | ||
if (value > today.value) { | ||
untilDateRef.value.value = ""; | ||
untilDateRef.value.dispatchEvent(new Event("input")); | ||
return; | ||
} | ||
fromDateRef.value.max = value; | ||
if (fromDate.value && value < fromDate.value) { | ||
fromDateRef.value.value = value; | ||
fromDateRef.value.dispatchEvent(new Event("input")); | ||
} | ||
} else { | ||
fromDateRef.value.max = today.value; | ||
} | ||
}); | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.form-group { | ||
margin-block-end: 0; | ||
} | ||
</style> |
Oops, something went wrong.