Skip to content

Commit

Permalink
Merge pull request #115 from FlorianPix/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
FlorianPix authored Jun 30, 2023
2 parents 2b464f0 + 4e88de1 commit d7c298d
Show file tree
Hide file tree
Showing 61 changed files with 2,245 additions and 1,303 deletions.
2 changes: 1 addition & 1 deletion src/climbingAPI/app/routers/spot.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@ async def delete_spot(spot_id: str, user: Auth0User = Security(auth.get_user, sc
trips = await db["trip"].find({"user_id": user.id}).to_list(None)
if trips:
for trip in trips:
update_result = await db["trip"].update_one({"_id": ObjectId(trip['_id'])}, {"$pull": {"spot_ids": ObjectId(spot_id)}})
update_result = await db["trip"].update_one({"_id": ObjectId(trip['_id']), "user_id": user.id}, {"$pull": {"spot_ids": spot_id}})
# spot_id was removed from trips
return Response(status_code=status.HTTP_204_NO_CONTENT)
2 changes: 1 addition & 1 deletion src/climbingAPI/app/routers/trip.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def retrieve_trips(user: Auth0User = Security(auth.get_user, scopes=["read
@router.get('/{trip_id}', description="Get a trip", response_model=TripModel, dependencies=[Depends(auth.implicit_scheme)])
async def retrieve_trip(trip_id: str, user: Auth0User = Security(auth.get_user, scopes=["read:diary"])):
db = await get_db()
if (trip := await db["trips"].find_one({"_id": ObjectId(trip_id), "user_id": user.id})) is not None:
if (trip := await db["trip"].find_one({"_id": ObjectId(trip_id), "user_id": user.id})) is not None:
return trip
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Trip {trip_id} not found")

Expand Down
31 changes: 9 additions & 22 deletions src/flutter_app/lib/components/add/add_ascent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import '../../interfaces/pitch/pitch.dart';
import '../../services/ascent_service.dart';
import 'package:internet_connection_checker/internet_connection_checker.dart';

import '../MyTextStyles.dart';

class AddAscent extends StatefulWidget {
const AddAscent({super.key, required this.pitches, this.onAdd});
const AddAscent({super.key, required this.pitch, this.onAdd});

final ValueSetter<Ascent>? onAdd;
final List<Pitch> pitches;
final Pitch pitch;

@override
State<StatefulWidget> createState() => _AddAscentState();
Expand All @@ -26,13 +28,11 @@ class _AddAscentState extends State<AddAscent>{
final TextEditingController controllerComment = TextEditingController();
final TextEditingController controllerDate = TextEditingController();

Pitch? pitchValue;
AscentStyle? ascentStyleValue;
AscentType? ascentTypeValue;

@override
void initState(){
pitchValue = widget.pitches[0];
ascentStyleValue = AscentStyle.lead;
ascentTypeValue = AscentType.redPoint;
controllerDate.text = DateFormat('yyyy-MM-dd').format(DateTime.now());
Expand All @@ -52,19 +52,9 @@ class _AddAscentState extends State<AddAscent>{
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
DropdownButton<Pitch>(
value: pitchValue,
items: widget.pitches.map<DropdownMenuItem<Pitch>>((Pitch pitch) {
return DropdownMenuItem<Pitch>(
value: pitch,
child: Text(pitch.name),
);
}).toList(),
onChanged: (Pitch? pitch) {
setState(() {
pitchValue = pitch!;
});
}
Text(
widget.pitch.name,
style: MyTextStyles.title,
),
TextFormField(
controller: controllerComment,
Expand Down Expand Up @@ -141,11 +131,8 @@ class _AddAscentState extends State<AddAscent>{
type: ascentTypeIndex,
);
Navigator.popUntil(context, ModalRoute.withName('/'));
final pitchValue = this.pitchValue;
if (pitchValue != null) {
Ascent? createdAscent = await ascentService.createAscent(pitchValue.id, ascent, result);
widget.onAdd?.call(createdAscent!);
}
Ascent? createdAscent = await ascentService.createAscent(widget.pitch.id, ascent, result);
widget.onAdd?.call(createdAscent!);
}
}
},
Expand Down
28 changes: 8 additions & 20 deletions src/flutter_app/lib/components/add/add_pitch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import '../../interfaces/route/route.dart';
import '../../services/pitch_service.dart';
import 'package:internet_connection_checker/internet_connection_checker.dart';

import '../MyTextStyles.dart';

class AddPitch extends StatefulWidget {
const AddPitch({super.key, required this.routes});
const AddPitch({super.key, required this.route});

final List<ClimbingRoute> routes;
final ClimbingRoute route;

@override
State<StatefulWidget> createState() => _AddPitchState();
Expand All @@ -28,7 +30,6 @@ class _AddPitchState extends State<AddPitch>{
final TextEditingController controllerRating = TextEditingController();

double currentSliderValue = 0;
ClimbingRoute? dropdownValue;
GradingSystem? gradingSystem;

@override
Expand All @@ -49,19 +50,9 @@ class _AddPitchState extends State<AddPitch>{
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
DropdownButton<ClimbingRoute>(
value: dropdownValue,
items: widget.routes.map<DropdownMenuItem<ClimbingRoute>>((ClimbingRoute route) {
return DropdownMenuItem<ClimbingRoute>(
value: route,
child: Text(route.name),
);
}).toList(),
onChanged: (ClimbingRoute? route) {
setState(() {
dropdownValue = route!;
});
}
Text(
widget.route.name,
style: MyTextStyles.title,
),
TextFormField(
validator: (value) {
Expand Down Expand Up @@ -148,10 +139,7 @@ class _AddPitchState extends State<AddPitch>{
num: int.parse(controllerNum.text),
rating: currentSliderValue.toInt(),
);
final dropdownValue = this.dropdownValue;
if (dropdownValue != null) {
Pitch? createdPitch = await pitchService.createPitch(pitch, dropdownValue.id, result);
}
Pitch? createdPitch = await pitchService.createPitch(pitch, widget.route.id, result);
Navigator.popUntil(context, ModalRoute.withName('/'));
}
},
Expand Down
98 changes: 44 additions & 54 deletions src/flutter_app/lib/components/add/add_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ import 'package:flutter/services.dart';
import '../../interfaces/grade.dart';
import '../../interfaces/grading_system.dart';
import '../../interfaces/multi_pitch_route/create_multi_pitch_route.dart';
import '../../interfaces/multi_pitch_route/multi_pitch_route.dart';
import '../../interfaces/route/route.dart';
import '../../interfaces/single_pitch_route/create_single_pitch_route.dart';
import '../../interfaces/single_pitch_route/single_pitch_route.dart';
import '../../interfaces/spot/spot.dart';
import '../../services/route_service.dart';
import 'package:internet_connection_checker/internet_connection_checker.dart';

import '../MyTextStyles.dart';

class AddRoute extends StatefulWidget {
const AddRoute({super.key, required this.spots, this.onAdd});
const AddRoute({super.key, required this.spot, this.onAddMultiPitchRoute, this.onAddSinglePitchRoute});

final List<Spot> spots;
final ValueSetter<ClimbingRoute>? onAdd;
final Spot spot;
final ValueSetter<MultiPitchRoute>? onAddMultiPitchRoute;
final ValueSetter<SinglePitchRoute>? onAddSinglePitchRoute;

@override
State<StatefulWidget> createState() => _AddRouteState();
Expand All @@ -23,7 +28,6 @@ class AddRoute extends StatefulWidget {
class _AddRouteState extends State<AddRoute>{
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final RouteService routeService = RouteService();
final TextEditingController controllerSpotId = TextEditingController();
final TextEditingController controllerComment = TextEditingController();
final TextEditingController controllerLocation = TextEditingController();
final TextEditingController controllerName = TextEditingController();
Expand All @@ -32,18 +36,17 @@ class _AddRouteState extends State<AddRoute>{
final TextEditingController controllerLength = TextEditingController();

double currentSliderValue = 0;
Spot? dropdownValue;
GradingSystem? gradingSystem;
bool isMultiPitch = false;

@override
void initState(){
dropdownValue = widget.spots[0];
super.initState();
}

@override
Widget build(BuildContext context) {
Spot spot = widget.spot;
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
Expand All @@ -55,6 +58,20 @@ class _AddRouteState extends State<AddRoute>{
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
spot.name,
style: MyTextStyles.title,
),
TextFormField(
validator: (value) {
return value!.isNotEmpty
? null
: "please add a name";
},
controller: controllerName,
decoration: const InputDecoration(
hintText: "name of the route", labelText: "name"),
),
Row(children: [
const Text("Multi-pitch"),
Switch(
Expand Down Expand Up @@ -103,30 +120,6 @@ class _AddRouteState extends State<AddRoute>{
hintText: "length of the route", labelText: "length"),
),
),
DropdownButton<Spot>(
value: dropdownValue,
items: widget.spots.map<DropdownMenuItem<Spot>>((Spot spot) {
return DropdownMenuItem<Spot>(
value: spot,
child: Text(spot.name),
);
}).toList(),
onChanged: (Spot? spot) {
setState(() {
dropdownValue = spot!;
});
}
),
TextFormField(
validator: (value) {
return value!.isNotEmpty
? null
: "please add a name";
},
controller: controllerName,
decoration: const InputDecoration(
hintText: "name of the route", labelText: "name"),
),
TextFormField(
controller: controllerLocation,
decoration: const InputDecoration(
Expand Down Expand Up @@ -171,31 +164,28 @@ class _AddRouteState extends State<AddRoute>{
bool result = await InternetConnectionChecker().hasConnection;
if (_formKey.currentState!.validate()) {
Navigator.popUntil(context, ModalRoute.withName('/'));
final dropdownValue = this.dropdownValue;
if (dropdownValue != null){
ClimbingRoute? createdRoute;
if (isMultiPitch){
CreateMultiPitchRoute route = CreateMultiPitchRoute(
name: controllerName.text,
location: controllerLocation.text,
rating: currentSliderValue.toInt(),
comment: controllerComment.text,
);
createdRoute = await routeService.createMultiPitchRoute(route, dropdownValue.id, result);
} else {
CreateSinglePitchRoute route = CreateSinglePitchRoute(
name: controllerName.text,
location: controllerLocation.text,
rating: currentSliderValue.toInt(),
comment: controllerComment.text,
grade: Grade(grade: controllerGrade.text, system: gradingSystem!),
length: int.parse(controllerLength.text)
);
createdRoute = await routeService.createSinglePitchRoute(route, dropdownValue.id, result);
}
widget.onAdd?.call(createdRoute!);
setState(() {});
if (isMultiPitch){
CreateMultiPitchRoute route = CreateMultiPitchRoute(
name: controllerName.text,
location: controllerLocation.text,
rating: currentSliderValue.toInt(),
comment: controllerComment.text,
);
MultiPitchRoute? createdRoute = await routeService.createMultiPitchRoute(route, spot.id, result);
widget.onAddMultiPitchRoute?.call(createdRoute!);
} else {
CreateSinglePitchRoute route = CreateSinglePitchRoute(
name: controllerName.text,
location: controllerLocation.text,
rating: currentSliderValue.toInt(),
comment: controllerComment.text,
grade: Grade(grade: controllerGrade.text, system: gradingSystem!),
length: int.parse(controllerLength.text)
);
SinglePitchRoute? createdRoute = await routeService.createSinglePitchRoute(route, spot.id, result);
widget.onAddSinglePitchRoute?.call(createdRoute!);
}
setState(() {});
}
},
child: const Text("Save"))
Expand Down
Loading

0 comments on commit d7c298d

Please sign in to comment.