Skip to content

Commit

Permalink
feat: can edit description and site in CompanyScreen and edit bio and…
Browse files Browse the repository at this point in the history
… notes in SpeakerScreen #298
  • Loading branch information
bvlourenco committed Dec 27, 2022
1 parent f4f58aa commit fac7336
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 61 deletions.
6 changes: 0 additions & 6 deletions backend/src/mongodb/flightInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ func (cfid *CreateFlightInfoData) ParseBody(body io.Reader) error {
return errors.New("inbound must be after outbound")
}

var now = time.Now()

if now.After(*cfid.Outbound) || now.After(*cfid.Inbound) {
return errors.New("invalid outbound or inbound dates: must be in the future")
}

if cfid.From == nil {
return errors.New("invalid from")
}
Expand Down
38 changes: 16 additions & 22 deletions backend/src/mongodb/speaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,22 +423,6 @@ func (usd *UpdateSpeakerData) ParseBody(body io.Reader) error {
return err
}

if usd.Name == nil || len(*usd.Name) == 0 {
return errors.New("Invalid name")
}

if usd.Bio == nil {
return errors.New("Invalid bio")
}

if usd.Title == nil {
return errors.New("Invalid title")
}

if usd.Notes == nil {
return errors.New("Invalid notes")
}

return nil
}

Expand All @@ -448,13 +432,23 @@ func (s *SpeakersType) UpdateSpeaker(speakerID primitive.ObjectID, data UpdateSp

var updatedSpeaker models.Speaker

updateFields := bson.M{}

if data.Name != nil {
updateFields["name"] = *data.Name
}
if data.Bio != nil {
updateFields["bio"] = *data.Bio
}
if data.Title != nil {
updateFields["title"] = *data.Title
}
if data.Notes != nil {
updateFields["notes"] = *data.Notes
}

var updateQuery = bson.M{
"$set": bson.M{
"name": data.Name,
"bio": data.Bio,
"title": data.Title,
"notes": data.Notes,
},
"$set": updateFields,
}

var filterQuery = bson.M{"_id": speakerID}
Expand Down
58 changes: 44 additions & 14 deletions frontend/lib/routes/company/DetailsScreen.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
import 'package:flutter/material.dart';
import 'package:frontend/components/EditableCard.dart';
import 'package:frontend/models/company.dart';
import 'package:frontend/services/companyService.dart';

class DetailsScreen extends StatelessWidget {
final Company company;
const DetailsScreen({Key? key, required this.company}) : super(key: key);
final _companyService = CompanyService();

DetailsScreen({Key? key, required this.company}) : super(key: key);

Future<void> _editCompany(
BuildContext context, String updatedValue, bool isDescription) async {
Company? c;
if (isDescription) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Updating Description...')),
);
c = await _companyService.updateCompany(
id: company.id, description: updatedValue);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Updating Site...')),
);
c = await _companyService.updateCompany(
id: company.id, site: updatedValue);
}

if (c != null) {
ScaffoldMessenger.of(context).hideCurrentSnackBar();

ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Done'),
duration: Duration(seconds: 2),
),
);
} else {
ScaffoldMessenger.of(context).hideCurrentSnackBar();

ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('An error occured.')),
);
}
}

@override
Widget build(BuildContext context) {
Expand All @@ -18,12 +56,8 @@ class DetailsScreen extends StatelessWidget {
child: EditableCard(
title: 'Description',
body: company.description ?? "",
bodyEditedCallback: (newBio) {
//speaker.bio = newBio;
//TODO replace bio with service call to change bio
print('replaced bio');
return Future.delayed(Duration.zero);
},
bodyEditedCallback: (newDescription) =>
_editCompany(context, newDescription, true),
isSingleline: false,
textInputType: TextInputType.multiline,
),
Expand All @@ -33,12 +67,8 @@ class DetailsScreen extends StatelessWidget {
child: EditableCard(
title: 'Site',
body: company.site ?? "",
bodyEditedCallback: (newNotes) {
//speaker.bio = newBio;
//TODO replace bio with service call to change bio
print('replaced notes');
return Future.delayed(Duration.zero);
},
bodyEditedCallback: (newSite) =>
_editCompany(context, newSite, false),
isSingleline: false,
textInputType: TextInputType.multiline,
),
Expand All @@ -47,4 +77,4 @@ class DetailsScreen extends StatelessWidget {
)),
);
}
}
}
51 changes: 39 additions & 12 deletions frontend/lib/routes/speaker/DetailsScreen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:frontend/components/EditableCard.dart';
import 'package:frontend/models/speaker.dart';
import 'package:frontend/services/speakerService.dart';

class DetailsScreen extends StatefulWidget {
final Speaker speaker;
Expand All @@ -12,10 +13,46 @@ class DetailsScreen extends StatefulWidget {

class _DetailsScreenState extends State<DetailsScreen>
with AutomaticKeepAliveClientMixin {
final _speakerService = SpeakerService();

@override
bool get wantKeepAlive => true;

Future<void> _editSpeaker(
BuildContext context, String updatedValue, bool isBio) async {
Speaker? s;
if (isBio) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Updating Bio...')),
);
s = await _speakerService.updateSpeaker(
id: widget.speaker.id, bio: updatedValue);
} else {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Updating Notes...')),
);
s = await _speakerService.updateSpeaker(
id: widget.speaker.id, notes: updatedValue);
}

if (s != null) {
ScaffoldMessenger.of(context).hideCurrentSnackBar();

ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Done'),
duration: Duration(seconds: 2),
),
);
} else {
ScaffoldMessenger.of(context).hideCurrentSnackBar();

ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('An error occured.')),
);
}
}

@override
Widget build(BuildContext context) {
super.build(context);
Expand All @@ -29,12 +66,7 @@ class _DetailsScreenState extends State<DetailsScreen>
child: EditableCard(
title: 'Bio',
body: widget.speaker.bio ?? "",
bodyEditedCallback: (newBio) {
//speaker.bio = newBio;
//TODO replace bio with service call to change bio
print('replaced bio');
return Future.delayed(Duration.zero);
},
bodyEditedCallback: (newBio) => _editSpeaker(context, newBio, true),
isSingleline: false,
textInputType: TextInputType.multiline,
),
Expand All @@ -44,12 +76,7 @@ class _DetailsScreenState extends State<DetailsScreen>
child: EditableCard(
title: 'Notes',
body: widget.speaker.notes ?? "",
bodyEditedCallback: (newNotes) {
//speaker.bio = newBio;
//TODO replace bio with service call to change bio
print('replaced notes');
return Future.delayed(Duration.zero);
},
bodyEditedCallback: (newNotes) => _editSpeaker(context, newNotes, false),
isSingleline: false,
textInputType: TextInputType.multiline,
),
Expand Down
11 changes: 5 additions & 6 deletions frontend/lib/services/companyService.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,11 @@ class CompanyService extends Service {
String? description,
String? name,
String? site}) async {
var body = {
'billingInfo': billingInfo!.toJson(),
'description': description,
'name': name,
'site': site
};
final Map<String, dynamic> body = {'description': description, 'name': name, 'site': site};

if (billingInfo != null) {
body['billingInfo'] = billingInfo.toJson();
}

Response<String> response = await dio.put('/companies/' + id, data: body);
try {
Expand Down
2 changes: 1 addition & 1 deletion frontend/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies:
dotted_border: ^2.0.0+1
provider: ^6.0.0
flutter_dropzone: ^3.0.5
google_fonts: ^2.1.0
google_fonts: ^3.0.1
intl: ^0.17.0
collection: ^1.15.0
image: ^3.0.5
Expand Down

0 comments on commit fac7336

Please sign in to comment.