Skip to content

Commit

Permalink
Ispravka konkurentnog pristupa za studenta 4
Browse files Browse the repository at this point in the history
  • Loading branch information
draganaF committed Jun 15, 2021
1 parent 3ca2711 commit 6a2098f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ public interface PharmacyAdminRepositoryDB extends JpaRepository<AdminPharmacy,
@Query("select a from AdminPharmacy a join fetch a.address where a.deleted = false")
List<AdminPharmacy> getAllWithAddress();

@Lock(LockModeType.PESSIMISTIC_READ)

@Query("select a from AdminPharmacy a join fetch a.roles where a.email=?1 and a.deleted = false")
@QueryHints({@QueryHint(name = "javax.persistence.lock.timeout", value ="0")})
AdminPharmacy getOneLogin(String id);

@Lock(LockModeType.PESSIMISTIC_READ)
@Query("select a from AdminPharmacy a where a.email=?1 and a.deleted = false")
@QueryHints({@QueryHint(name = "javax.persistence.lock.timeout", value ="0")})
AdminPharmacy getOneForConcurrent(String id);

@Query("select a from AdminPharmacy a join fetch a.address join fetch a.pharmacy where a.email=?1 and a.deleted = false")
AdminPharmacy getOnePharmacyAdmin(String id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public List<AdminPharmacy> getAllUnemployedAdmins() {
@Override
@Transactional
public AdminPharmacy updatePharmacy(AdminPharmacyDTO adminDTO) {
AdminPharmacy admin = adminRepository.getOneLogin(adminDTO.getEmail());
AdminPharmacy admin = adminRepository.getOneForConcurrent(adminDTO.getEmail());

if(admin == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,25 +223,60 @@ public Set<Pharmacy> findAllWithAdmin() {

@Override
public void deletePharmacy(Long id) throws Exception {
Pharmacy pharmacy = this.findOneWithAppointments(id);
pharmacy.setDeleted(true);
pharmacyRepository.save(pharmacy);

Collection<MedicamentItem> medicaments = this.getAllMedicaments(pharmacy.getId());
for(MedicamentItem mi : medicaments) {
medicamentService.deleteMedicament(mi);
Pharmacy pharmacy = null;
boolean err = false;
try{
pharmacy = this.findOneWithAppointments(id);

}catch(NullPointerException e) {
err = true;

}

Collection<Appointment> appointments = pharmacy.getAppointments();
for(Appointment a : appointments) {
appointmentService.delete(a);
if(pharmacy == null) {
pharmacy = this.findOne(id);

pharmacy.setDeleted(true);
pharmacyRepository.save(pharmacy);
return;
}
pharmacy.setDeleted(true);

Set<AdminPharmacy> admins = pharmacyAdminService.getAllAdminsInPharmacy(pharmacy.getId());
for(AdminPharmacy ap : admins) {
ap.setPharmacy(null);
pharmacyAdminService.update(ap);
try {
Collection<MedicamentItem> medicaments = this.getAllMedicaments(pharmacy.getId());
if(medicaments != null) {
for(MedicamentItem mi : medicaments) {
medicamentService.deleteMedicament(mi);
}
}
}
catch(Exception e) {

}
try {
Collection<Appointment> appointments = pharmacy.getAppointments();
if(appointments != null) {
for(Appointment a : appointments) {
appointmentService.delete(a);
}
}
}
catch(Exception e) {

}
try {
Set<AdminPharmacy> admins = pharmacyAdminService.getAllAdminsInPharmacy(pharmacy.getId());
if(admins != null) {
for(AdminPharmacy ap : admins) {
ap.setPharmacy(null);
pharmacyAdminService.update(ap);
}
}
}
catch(Exception e) {

}
pharmacyRepository.save(pharmacy);

}

Expand Down
1 change: 0 additions & 1 deletion src/main/resources/data-postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ insert into medicament_ratings (medicament_id, ratings_id) values (2, 5)
insert into medicament_ratings (medicament_id, ratings_id) values (3, 6)
insert into medicament_ratings (medicament_id, ratings_id) values (4, 7)
insert into medicament_ratings (medicament_id, ratings_id) values (4, 8)
insert into medicament_ratings (medicament_id, ratings_id) values (1, 15)


insert into employee_ratings (employee_email, ratings_id ) values ('[email protected]', 9)
Expand Down
4 changes: 2 additions & 2 deletions src/main/ui/vue/src/components/PharmacyRegistration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ export default {
}
var locationFound = await this.guessCoordinatesFromLocation();
if(errorFound==false && locationFound==true){
console.log(locationFound);
if(errorFound==false){
this.axios
.post(`/api/pharmacy`, {
name: this.name,
Expand Down

0 comments on commit 6a2098f

Please sign in to comment.