Skip to content

Commit

Permalink
feat: fetching stages by city
Browse files Browse the repository at this point in the history
  • Loading branch information
1grzyb1 committed Sep 17, 2023
1 parent dca8f2a commit ba4045c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
7 changes: 7 additions & 0 deletions odyseja-ui/src/routes/panel/stage/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<script lang="ts">
import {put} from "$lib/apiService";
import type {Stages} from "$lib/types"
import {city} from "$lib/cityStore";
import {fetchStages} from "./stageService";
export let data;
let initialData = JSON.parse(JSON.stringify(data))
$: isChanged = JSON.stringify(data) !== JSON.stringify(initialData);
city.subscribe(async currentCity => {
data = await fetchStages();
initialData = JSON.parse(JSON.stringify(data))
});
function save() {
saveStages(data.stages);
initialData = JSON.parse(JSON.stringify(data))
Expand Down
10 changes: 2 additions & 8 deletions odyseja-ui/src/routes/panel/stage/+page.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import {get} from '$lib/apiService';
import type { PageLoad } from './$types';
import type {Stage, Stages} from "$lib/types";
import type {PageLoad} from './$types';
import {fetchStages} from "./stageService";

export const load = (({params}) => {
return fetchStages();
}) satisfies PageLoad;


async function fetchStages(): Promise<Stages> {
const data = await get('/stage')
const stages = data as Stage[]
return {stages: stages};
}
8 changes: 8 additions & 0 deletions odyseja-ui/src/routes/panel/stage/stageService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type {Stage, Stages} from "$lib/types";
import {get} from "$lib/apiService";

export async function fetchStages(): Promise<Stages> {
const data = await get('/stage')
const stages = data as Stage[]
return {stages: stages};
}
11 changes: 3 additions & 8 deletions src/main/kotlin/odyseja/odysejapka/rest/StageController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@ class StageController(
private val stageService: StageService
) {

@GetMapping("{cityId}")
fun getStages(@PathVariable cityId: Int): List<Stage> {
return stageService.getStages(cityId)
}

@GetMapping
fun getStages(): List<Stage> {
return stageService.getStages()
@GetMapping()
fun getStages(@RequestParam(required = false) cityId: Int?): List<Stage> {
return cityId?.let { stageService.getStages(cityId) } ?: stageService.getStages()
}

@Secured("ROLE_ADMIN")
Expand Down

0 comments on commit ba4045c

Please sign in to comment.