💄 Fix missing days on trip creation
This commit is contained in:
parent
abbfdd9d21
commit
2670662c9f
@ -32,10 +32,10 @@ def read_trip(
|
|||||||
return TripRead.serialize(db_trip)
|
return TripRead.serialize(db_trip)
|
||||||
|
|
||||||
|
|
||||||
@router.post("", response_model=TripRead)
|
@router.post("", response_model=TripReadBase)
|
||||||
def create_trip(
|
def create_trip(
|
||||||
trip: TripCreate, session: SessionDep, current_user: Annotated[str, Depends(get_current_username)]
|
trip: TripCreate, session: SessionDep, current_user: Annotated[str, Depends(get_current_username)]
|
||||||
) -> TripRead:
|
) -> TripReadBase:
|
||||||
new_trip = Trip(
|
new_trip = Trip(
|
||||||
name=trip.name,
|
name=trip.name,
|
||||||
user=current_user,
|
user=current_user,
|
||||||
@ -63,7 +63,7 @@ def create_trip(
|
|||||||
session.add(new_trip)
|
session.add(new_trip)
|
||||||
session.commit()
|
session.commit()
|
||||||
session.refresh(new_trip)
|
session.refresh(new_trip)
|
||||||
return TripRead.serialize(new_trip)
|
return TripReadBase.serialize(new_trip)
|
||||||
|
|
||||||
|
|
||||||
@router.put("/{trip_id}", response_model=TripRead)
|
@router.put("/{trip_id}", response_model=TripRead)
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
import { Component } from "@angular/core";
|
import { Component, OnInit } from "@angular/core";
|
||||||
import { ApiService } from "../../services/api.service";
|
import { ApiService } from "../../services/api.service";
|
||||||
import { ButtonModule } from "primeng/button";
|
import { ButtonModule } from "primeng/button";
|
||||||
import { SkeletonModule } from "primeng/skeleton";
|
import { SkeletonModule } from "primeng/skeleton";
|
||||||
import { TripBase } from "../../types/trip";
|
import { TripBase } from "../../types/trip";
|
||||||
import { Category } from "../../types/poi";
|
|
||||||
import { DialogService, DynamicDialogRef } from "primeng/dynamicdialog";
|
import { DialogService, DynamicDialogRef } from "primeng/dynamicdialog";
|
||||||
import { TripCreateModalComponent } from "../../modals/trip-create-modal/trip-create-modal.component";
|
import { TripCreateModalComponent } from "../../modals/trip-create-modal/trip-create-modal.component";
|
||||||
import { Router } from "@angular/router";
|
import { Router } from "@angular/router";
|
||||||
|
import { take } from "rxjs";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "app-trips",
|
selector: "app-trips",
|
||||||
@ -15,50 +15,40 @@ import { Router } from "@angular/router";
|
|||||||
templateUrl: "./trips.component.html",
|
templateUrl: "./trips.component.html",
|
||||||
styleUrls: ["./trips.component.scss"],
|
styleUrls: ["./trips.component.scss"],
|
||||||
})
|
})
|
||||||
export class TripsComponent {
|
export class TripsComponent implements OnInit {
|
||||||
categories: Category[] = [];
|
|
||||||
map: any;
|
|
||||||
mapSettings: L.LatLng | undefined;
|
|
||||||
markerClusterGroup: any;
|
|
||||||
|
|
||||||
trips: TripBase[] = [];
|
trips: TripBase[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private apiService: ApiService,
|
private apiService: ApiService,
|
||||||
private dialogService: DialogService,
|
private dialogService: DialogService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
) {
|
) {}
|
||||||
this.apiService.getTrips().subscribe({
|
|
||||||
next: (trips) => {
|
|
||||||
this.trips = trips;
|
|
||||||
this.sortTrips();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
viewTrip(id: number) {
|
ngOnInit() {
|
||||||
this.router.navigateByUrl(`/trips/${id}`);
|
this.apiService
|
||||||
}
|
.getTrips()
|
||||||
|
.pipe(take(1))
|
||||||
sortTrips() {
|
.subscribe({
|
||||||
this.trips = this.trips.sort((a, b) => {
|
next: (trips) => {
|
||||||
if (!!a.archived !== !!b.archived) {
|
this.trips = trips;
|
||||||
return Number(!!a.archived) - Number(!!b.archived);
|
this.sortTrips();
|
||||||
}
|
},
|
||||||
|
});
|
||||||
return a.name.localeCompare(b.name);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gotoMap() {
|
gotoMap() {
|
||||||
this.router.navigateByUrl("/");
|
this.router.navigateByUrl("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewTrip(id: number) {
|
||||||
|
this.router.navigateByUrl(`/trips/${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
addTrip() {
|
addTrip() {
|
||||||
const modal: DynamicDialogRef = this.dialogService.open(
|
const modal: DynamicDialogRef = this.dialogService.open(
|
||||||
TripCreateModalComponent,
|
TripCreateModalComponent,
|
||||||
{
|
{
|
||||||
header: "Create Place",
|
header: "Create Trip",
|
||||||
modal: true,
|
modal: true,
|
||||||
appendTo: "body",
|
appendTo: "body",
|
||||||
closable: true,
|
closable: true,
|
||||||
@ -70,7 +60,7 @@ export class TripsComponent {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
modal.onClose.subscribe({
|
modal.onClose.pipe(take(1)).subscribe({
|
||||||
next: (trip: TripBase | null) => {
|
next: (trip: TripBase | null) => {
|
||||||
if (!trip) return;
|
if (!trip) return;
|
||||||
|
|
||||||
@ -83,4 +73,14 @@ export class TripsComponent {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortTrips() {
|
||||||
|
this.trips = this.trips.sort((a, b) => {
|
||||||
|
if (!!a.archived !== !!b.archived) {
|
||||||
|
return Number(!!a.archived) - Number(!!b.archived);
|
||||||
|
}
|
||||||
|
|
||||||
|
return a.name.localeCompare(b.name);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user