Skip to content

Commit

Permalink
feat: add leave_at to slot
Browse files Browse the repository at this point in the history
  • Loading branch information
xfoxfu committed Jul 15, 2024
1 parent e9d802b commit 1555877
Show file tree
Hide file tree
Showing 7 changed files with 709 additions and 6 deletions.
111 changes: 111 additions & 0 deletions Net.Vatprc.Uniapi.UI.Event/src/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,38 @@ export interface paths {
patch?: never;
trace?: never;
};
"/api/notams": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get: operations["Notam_List"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/notams/{id}": {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
get: operations["Notam_Get"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/api/session": {
parameters: {
query?: never;
Expand Down Expand Up @@ -261,6 +293,8 @@ export interface components {
airspace_id: string;
/** Format: date-time */
enter_at: string;
/** Format: date-time */
leave_at?: string | null;
};
ErrorProdResponse: {
error_code: string;
Expand Down Expand Up @@ -310,6 +344,8 @@ export interface components {
/** Format: date-time */
enter_at: string;
/** Format: date-time */
leave_at?: string | null;
/** Format: date-time */
created_at: string;
/** Format: date-time */
updated_at: string;
Expand All @@ -324,6 +360,19 @@ export interface components {
token_type: string;
issued_token_type: string;
};
NotamDto: {
id: string;
title: string;
description: string;
/** Format: date-time */
effective_from: string;
/** Format: date-time */
expire_after: string;
/** Format: date-time */
created_at: string;
/** Format: date-time */
updated_at: string;
};
TokenDto: {
user: components["schemas"]["UserDto"];
/** Format: date-time */
Expand All @@ -350,6 +399,8 @@ export interface components {
UpdateEventSlotDto: {
/** Format: date-time */
enter_at: string;
/** Format: date-time */
leave_at?: string | null;
};
UserDto: {
id: string;
Expand Down Expand Up @@ -1180,6 +1231,66 @@ export interface operations {
};
};
};
Notam_List: {
parameters: {
query?: never;
header?: never;
path?: never;
cookie?: never;
};
requestBody?: never;
responses: {
/** @description Success */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["NotamDto"][];
};
};
/** @description INTERNAL_SERVER_ERROR */
500: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["ErrorProdResponse"];
};
};
};
};
Notam_Get: {
parameters: {
query?: never;
header?: never;
path: {
id: string;
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description Success */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["NotamDto"];
};
};
/** @description INTERNAL_SERVER_ERROR */
500: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["ErrorProdResponse"];
};
};
};
};
Session_Get: {
parameters: {
query?: never;
Expand Down
36 changes: 30 additions & 6 deletions Net.Vatprc.Uniapi.UI.Event/src/routes/events/$event_id.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,21 @@ import { SlotReleaseButton } from "@/components/slot-button-release";
import { CreateSlot } from "@/components/slot-create";
import { DeleteSlot } from "@/components/slot-delete";
import { SlotDetail } from "@/components/slot-detail";
import { ActionIcon, Alert, Card, Group, Image, LoadingOverlay, Pill, Stack, Table, Text, Title } from "@mantine/core";
import { useUser } from "@/services/auth";
import {
ActionIcon,
Alert,
Card,
Group,
Image,
LoadingOverlay,
Pill,
Stack,
Table,
Text,
Title,
useMantineTheme,
} from "@mantine/core";
import { createFileRoute } from "@tanstack/react-router";

const EventComponent = () => {
Expand All @@ -21,15 +35,25 @@ const EventComponent = () => {
const { data: airspaces, isLoading: isLoadingAirspaces } = useApi("/api/events/{eid}/airspaces", {
path: { eid: event_id },
});
const theme = useMantineTheme();
const user = useUser();

const rows = slots?.map((slot) => (
<Table.Tr key={slot.id}>
<Table.Tr key={slot.id} bg={slot?.booking?.user_id === user?.id ? theme.colors.green[0] : undefined}>
<Table.Td>{slot.airspace.name}</Table.Td>
<Table.Td>
<Text>
<Pill mr="xs">CTOT</Pill>
<DateTime>{slot.enter_at}</DateTime>
</Text>
<Stack gap="xs">
<Text>
<Pill mr="xs">CTOT</Pill>
<DateTime>{slot.enter_at}</DateTime>
</Text>
{slot.leave_at && (
<Text>
<Pill mr="xs">TTA</Pill>
<DateTime>{slot.enter_at}</DateTime>
</Text>
)}
</Stack>
</Table.Td>
<Table.Td>
<Group>
Expand Down
5 changes: 5 additions & 0 deletions Net.Vatprc.Uniapi/Controllers/EventSlotController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public record EventSlotDto
public Ulid AirspaceId { get; set; }
public EventAirspaceController.EventAirspaceDto Airspace { get; set; }
public DateTimeOffset EnterAt { get; set; }
public DateTimeOffset? LeaveAt { get; set; }
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
public EventSlotBookingController.EventBookingDto? Booking { get; set; }
Expand Down Expand Up @@ -72,6 +73,7 @@ public record CreateEventSlotDto
{
public required Ulid AirspaceId { get; set; }
public required DateTimeOffset EnterAt { get; set; }
public DateTimeOffset? LeaveAt { get; set; }
}

[HttpPost]
Expand All @@ -84,6 +86,7 @@ public async Task<EventSlotDto> Create(Ulid eid, CreateEventSlotDto dto)
{
EventAirspace = airspace,
EnterAt = dto.EnterAt.ToUniversalTime(),
LeaveAt = dto.LeaveAt?.ToUniversalTime(),
};
DbContext.EventSlot.Add(slot);
await DbContext.SaveChangesAsync();
Expand All @@ -93,6 +96,7 @@ public async Task<EventSlotDto> Create(Ulid eid, CreateEventSlotDto dto)
public record UpdateEventSlotDto
{
public required DateTimeOffset EnterAt { get; set; }
public DateTimeOffset? LeaveAt { get; set; }
}

[HttpPut("{sid}")]
Expand All @@ -101,6 +105,7 @@ public async Task<EventSlotDto> Update(Ulid eid, Ulid sid, UpdateEventSlotDto dt
{
var slot = await LoadAsync(eid, sid);
slot.EnterAt = dto.EnterAt;
slot.LeaveAt = dto.LeaveAt;
await DbContext.SaveChangesAsync();
return new(slot);
}
Expand Down
Loading

0 comments on commit 1555877

Please sign in to comment.