Skip to content

Conversation

@1eonID
Copy link
Owner

@1eonID 1eonID commented Nov 30, 2017

HW from Lesson 5, CRUD for DoctorController class


if (doctor.getId() == null) {
synchronized (DoctorController.class) {
Integer index = doctorMap.size();
Copy link

@mfarsikov mfarsikov Nov 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution works but:

  • Use class as monitor is not good idea.
  • Better to usage: with this as monitor (it is default monitor for synchronized { ... })
  • Even more better: avoid synchronization using non-blocking data types (Atomic....)
  • And the best solution: avoid any state and any counters

… and PetController classes. Avoid synchronization using non-blocking data type AtomicInteger.
…orController class into Doctor, Controller, Service and Repository classes.
…YAML config file and create methods getSpecializations and getSpecieList(in DoctorController class) for returning list of available specializations from application.yml file.

private List<String> specializations = new ArrayList<>();

public List<String> getSpecializations() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use lombok

public class DoctorRepository {

@Autowired
private DoctorConfig doctorConfig = new DoctorConfig();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use constructor injection


private final UUID uuid1 = UUID.randomUUID();
private final UUID uuid2 = UUID.randomUUID();
private final UUID uuid3 = UUID.randomUUID();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline these fields

}};

Integer counter = 2;
private Map<Integer, Pet> synPets = Collections.synchronizedMap(pets);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this collection is thread-safe, but it is blocking. better choice: ConcurrentHashMap

…ig class. Add annotation @requiredargsconstructor for using constructor injection in DoctorRepository class. Instead synchronizedMap added ConcurrentHashMap in PetController class. Don't inline UUID fields in DoctorRepository class, because we use Map.
… PostgreSQL DB. Remove class DoctorRepository and implement JpaRepository for working with DB. Change some methods in DoctorController and DoctorService classes for correct working with JPA.
…again - Remove class DoctorRepository and implement JpaRepository for working with DB. Change some methods in DoctorController and DoctorService classes for correct working with JPA.
…ization, for searching name of doctor ignoring case.
…octor schedule. Add date converter. Some changes in config files.
… for find method in JpaDoctorRepository interface. Change SpreengeeConfig.
…tor' in DoctorController class and update query in JpaDoctorRepository.
…tory, Service and Controller classes for Schedule. Refactor all classes in package 'doctor', for separating Doctor and Schedule entities.
… classes and methods with operations of validating from entities classes. Create 'dto' package and PetIdInputDto class for correct working with 'pet id' in Request Body.
SortedMap<Integer, Integer> sortedSchedule = new TreeMap<>();
for (Schedule schedule: set) {
if(schedule.getDate().equals(date)) {
sortedSchedule.put(schedule.getTime(), schedule.getPetId());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all schedule manipulation (especially modifications) must be done in ScheduleService

SortedMap<Integer, Integer> sortedSchedule = new TreeMap<>();
for (Schedule schedule: set) {
if(schedule.getDate().equals(date)) {
sortedSchedule.put(schedule.getTime(), schedule.getPetId());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to rework it using Stream API

…ntroller class, removed logic for getting schedule in concrete day to ScheduleService class and rework it using Stream API.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants