Fix endpoints, null checks
This commit is contained in:
parent
2338ecec39
commit
7e5ba88e8c
@ -71,8 +71,13 @@ public class Endpoints {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/family/{id}")
|
@GetMapping("/family/{id}")
|
||||||
public Optional<Family> _2(@PathVariable Long id) {
|
public FamilyContainer _2(@PathVariable Long id) {
|
||||||
return families.findById(id);
|
if (families.existsById(id)) {
|
||||||
|
Family f = families.findById(id).get();
|
||||||
|
return new FamilyContainer(f.getName(),families,relationships,members);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/family")
|
@PostMapping("/family")
|
||||||
@ -173,6 +178,7 @@ public class Endpoints {
|
|||||||
FamilyMember m = members.findById(fr.getMemberId()).get();
|
FamilyMember m = members.findById(fr.getMemberId()).get();
|
||||||
boolean isParent = relationships.findByMemberIdAndRelationshipIn(Long.parseLong(body.get("member")),Arrays.asList("Father","Mother","Parent")).size()>0;
|
boolean isParent = relationships.findByMemberIdAndRelationshipIn(Long.parseLong(body.get("member")),Arrays.asList("Father","Mother","Parent")).size()>0;
|
||||||
if (loc.size()>0) {
|
if (loc.size()>0) {
|
||||||
|
if (m.getLastLocationId()==null||m.getLastLocationId()!=loc.get(0).getId()) {
|
||||||
KnownLocation ll = loc.get(0);
|
KnownLocation ll = loc.get(0);
|
||||||
if (!ll.isSafe()) {
|
if (!ll.isSafe()) {
|
||||||
notifications.save(new Notification("You are arriving at "+ll.getName()+", which is considered an unsafe location! Be careful!",m.getId(),1,new Date()));
|
notifications.save(new Notification("You are arriving at "+ll.getName()+", which is considered an unsafe location! Be careful!",m.getId(),1,new Date()));
|
||||||
@ -188,6 +194,9 @@ public class Endpoints {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m.setLastLocationId(loc.get(0).getId());
|
||||||
|
members.save(m);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//notifications.save(new Notification());
|
//notifications.save(new Notification());
|
||||||
|
@ -21,17 +21,18 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
public class FamilyContainer extends Family{
|
public class FamilyContainer extends Family{
|
||||||
|
|
||||||
List<FamilyMember> members = new ArrayList<>();
|
List<FamilyMember> members = new ArrayList<>();
|
||||||
|
Long id = -1l;
|
||||||
|
|
||||||
FamilyContainer(String name
|
FamilyContainer(String name
|
||||||
,FamilyRepository families
|
,FamilyRepository families
|
||||||
,FamilyRelationshipRepository relationships
|
,FamilyRelationshipRepository relationships
|
||||||
,FamilyMemberRepository members) {
|
,FamilyMemberRepository members) {
|
||||||
super(name);
|
super(name);
|
||||||
List<FamilyRelationship> relations = relationships.findByFamilyId(families.findByName(name).get(0).getId());
|
id = families.findByName(name).get(0).getId();
|
||||||
|
List<FamilyRelationship> relations = relationships.findByFamilyId(id);
|
||||||
for (FamilyRelationship r : relations) {
|
for (FamilyRelationship r : relations) {
|
||||||
this.members.add(members.findById(r.getMemberId()).get());
|
this.members.add(members.findById(r.getMemberId()).get());
|
||||||
}
|
}
|
||||||
System.out.println("Called: "+this.members);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FamilyMember> getMembers() {
|
public List<FamilyMember> getMembers() {
|
||||||
@ -41,4 +42,12 @@ public class FamilyContainer extends Family{
|
|||||||
public void setMembers(List<FamilyMember> members) {
|
public void setMembers(List<FamilyMember> members) {
|
||||||
this.members = members;
|
this.members = members;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ public class FamilyMember {
|
|||||||
|
|
||||||
Long mobileDeviceId;
|
Long mobileDeviceId;
|
||||||
|
|
||||||
|
Long lastLocationId;
|
||||||
|
|
||||||
FamilyMember(){}
|
FamilyMember(){}
|
||||||
|
|
||||||
public FamilyMember(String firstName, String lastName, Long mobileDeviceId) {
|
public FamilyMember(String firstName, String lastName, Long mobileDeviceId) {
|
||||||
@ -55,4 +57,12 @@ public class FamilyMember {
|
|||||||
public void setMobileDeviceId(Long mobileDeviceId) {
|
public void setMobileDeviceId(Long mobileDeviceId) {
|
||||||
this.mobileDeviceId = mobileDeviceId;
|
this.mobileDeviceId = mobileDeviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getLastLocationId() {
|
||||||
|
return lastLocationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastLocationId(Long lastLocationId) {
|
||||||
|
this.lastLocationId = lastLocationId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user