/** * Creates a new area. Does NOT save the area to repository. * * @param name name of the area * @param person owner of the area * @param visibility is area visible for unauthenticated visitors * @return created Area */ public Area createArea(String name, Person person, Boolean visibility) { Area area = new Area(); area.setName(name); area.setOwner(person); area.setVisibility(visibility); area.setElements(new ArrayList<>()); return area; }
/** * Updates an Area's attributes if the currently logged in user is the owner of the Area. * * @param areaId which area will be updated * @param name areas new name * @param visibility areas new visibility * @param whoIsLogged to check who is logged in * @return true if update was successful, false if not */ public boolean updateArea(Long areaId, String name, boolean visibility, Person whoIsLogged) { Area area = findAreaById(areaId); if (whoIsLogged.getId() == area.getOwner().getId()) { area.setName(name); area.setVisibility(visibility); areaRepository.save(area); return true; } return false; }