Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLID refactor #68

Open
wants to merge 2 commits into
base: solid-refactor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ namespace HealthCareCenter.Core.Equipment.Services
public class EquipmentRearrangementService : IEquipmentRearrangementService
{
private readonly IRoomService _roomService;
private readonly IHospitalRoomUnderConstructionService _hospitalRoomUnderConstructionService;

public EquipmentRearrangementService(IRoomService roomService)
public EquipmentRearrangementService(IRoomService roomService, IHospitalRoomUnderConstructionService hospitalRoomUnderConstructionService)
{
_roomService = roomService;
_hospitalRoomUnderConstructionService = hospitalRoomUnderConstructionService;
}

public EquipmentRearrangementService()
Expand Down Expand Up @@ -211,7 +213,7 @@ public void DoPossibleRearrangement(Models.Equipment equipment)

public bool IsIrrevocable(EquipmentRearrangement rearrangement)
{
List<HospitalRoom> rooms = HospitalRoomUnderConstructionService.GetRooms();
List<HospitalRoom> rooms = _hospitalRoomUnderConstructionService.GetRooms();
foreach (HospitalRoom room in rooms)
{
if (room.ID == rearrangement.OldRoomID || room.ID == rearrangement.NewRoomID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ namespace HealthCareCenter.Core.Medicine.Controllers
{
public class ChangedMedicineCreationRequestController : BaseMedicineCreationRequestController
{
private IMedicineCreationRequestService _medicineCreationRequestService;
private AMedicineCreationRequestRepository _medicineCreationRequestRepository;

public ChangedMedicineCreationRequestController(IMedicineCreationRequestService medicineCreationRequestService, AMedicineCreationRequestRepository medicineCreationRequestRepository)
{
_medicineCreationRequestService = medicineCreationRequestService;
_medicineCreationRequestRepository = medicineCreationRequestRepository;
}

public MedicineCreationRequest DisplayedRequest { get; set; }

public override void Send(string medicineName, string manufacturer)
Expand All @@ -29,14 +38,14 @@ public void DisplayRequest(string requestId)
{
IsRequestValide(requestId);
int parsedChangeRequestId = Convert.ToInt32(requestId);
DisplayedRequest = MedicineCreationRequestService.Get(parsedChangeRequestId);
DisplayedRequest = _medicineCreationRequestService.Get(parsedChangeRequestId);
AddedIngrediens = DisplayedRequest.Ingredients;
}

public List<List<string>> GetRequestsForDisplay()
{
List<List<string>> requestsAttributesForDisplay = new List<List<string>>();
foreach (MedicineCreationRequest request in MedicineCreationRequestRepository.Requests)
foreach (MedicineCreationRequest request in _medicineCreationRequestRepository.Requests)
{
if (request.State == RequestState.Denied)
{
Expand All @@ -52,8 +61,8 @@ public List<List<string>> GetRequestsForDisplay()

private void SendRequest(MedicineCreationRequest request)
{
MedicineCreationRequestService.Delete(request);
MedicineCreationRequestService.Add(request);
_medicineCreationRequestService.Delete(request);
_medicineCreationRequestService.Add(request);
}

private bool IsRequestIdValide(string id)
Expand All @@ -64,7 +73,7 @@ private bool IsRequestIdValide(string id)
private bool IsRequestFound(string id)
{
int parsedId = Convert.ToInt32(id);
MedicineCreationRequest request = MedicineCreationRequestService.Get(parsedId);
MedicineCreationRequest request = _medicineCreationRequestService.Get(parsedId);

if (request == null) { return false; }
else if (request.State != RequestState.Denied) { return false; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ namespace HealthCareCenter.Core.Medicine.Controllers
{
public class MedicineCreationRequestController : BaseMedicineCreationRequestController
{
public MedicineCreationRequestController()
private IMedicineCreationRequestService _medicineCreationRequestService;

public MedicineCreationRequestController(IMedicineCreationRequestService medicineCreationRequestService)
{
_medicineCreationRequestService = medicineCreationRequestService;
AddedIngrediens = new List<string>();
}

Expand All @@ -18,7 +21,7 @@ public override void Send(string medicineName, string medicineManufacturer)
IsPossibleToCreateMedicineCreationRequest(medicineName, medicineManufacturer);
MedicineCreationRequest medicineCreationRequest = new MedicineCreationRequest(
medicineName, AddedIngrediens, medicineManufacturer, RequestState.Waiting);
MedicineCreationRequestService.Add(medicineCreationRequest);
_medicineCreationRequestService.Add(medicineCreationRequest);
AddedIngrediens.Clear();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public MedicineCreationRequest(int id, string name, List<string> ingredients, st

public MedicineCreationRequest(string name, List<string> ingredients, string manufacturer, RequestState state, string denyComment = "")
{
ID = MedicineCreationRequestRepository.GetLargestId() + 1;
MedicineCreationRequestRepository medicineCreationRequestRepository = new MedicineCreationRequestRepository();
ID = medicineCreationRequestRepository.GetLargestId() + 1;
Name = name;
Ingredients = ingredients;
Manufacturer = manufacturer;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using HealthCareCenter.Core.Medicine.Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace HealthCareCenter.Core.Medicine.Repositories
{
public abstract class AMedicineCreationRequestRepository
{
public List<MedicineCreationRequest> Requests;
private int LargestID { get; set; }

public abstract int GetLargestId();

public abstract List<MedicineCreationRequest> Load();

public abstract void Save();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@

namespace HealthCareCenter.Core.Medicine.Repositories
{
public class MedicineCreationRequestRepository
public class MedicineCreationRequestRepository : AMedicineCreationRequestRepository
{
public static List<MedicineCreationRequest> Requests = Load();
public static int LargestID { get; set; }
public int LargestID { get; set; }

public static int GetLargestId()
public MedicineCreationRequestRepository()
{
Requests = Load();
}

public override int GetLargestId()
{
try
{
Expand All @@ -31,7 +35,7 @@ public static int GetLargestId()
}
}

public static List<MedicineCreationRequest> Load()
public override List<MedicineCreationRequest> Load()
{
var settings = new JsonSerializerSettings
{
Expand All @@ -44,7 +48,7 @@ public static List<MedicineCreationRequest> Load()
return Requests;
}

public static void Save()
public override void Save()
{
try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using HealthCareCenter.Core.Medicine.Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace HealthCareCenter.Core.Medicine.Services
{
public interface IMedicineCreationRequestService
{
MedicineCreationRequest GetMedicineCreationRequest(int id);

string GetIngredients(MedicineCreationRequest request);

MedicineCreationRequest Get(int id);

List<MedicineCreationRequest> GetMedicines();

void Add(MedicineCreationRequest newMedicineCreationRequest);

bool Delete(int id);

bool Delete(MedicineCreationRequest medicineCreationRequest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@

namespace HealthCareCenter.Core.Medicine.Services
{
public class MedicineCreationRequestService
public class MedicineCreationRequestService : IMedicineCreationRequestService
{
public static MedicineCreationRequest GetMedicineCreationRequest(int id)
private readonly AMedicineCreationRequestRepository _medicineCreationRequestRepository;

public MedicineCreationRequestService(AMedicineCreationRequestRepository medicineCreationRequestRepository)
{
_medicineCreationRequestRepository = medicineCreationRequestRepository;
}

public MedicineCreationRequest GetMedicineCreationRequest(int id)
{
foreach (MedicineCreationRequest request in MedicineCreationRequestRepository.Requests)
foreach (MedicineCreationRequest request in _medicineCreationRequestRepository.Requests)
{
if (id == request.ID)
return request;
}
return null;
}
public static string GetIngredients(MedicineCreationRequest request)

public string GetIngredients(MedicineCreationRequest request)
{
string ingredients = "";
foreach (string ingredient in request.Ingredients)
Expand All @@ -29,11 +37,12 @@ public static string GetIngredients(MedicineCreationRequest request)
return ingredients.Substring(0, ingredients.Length - 1);
return ingredients;
}
public static MedicineCreationRequest Get(int id)

public MedicineCreationRequest Get(int id)
{
try
{
foreach (MedicineCreationRequest request in MedicineCreationRequestRepository.Requests)
foreach (MedicineCreationRequest request in _medicineCreationRequestRepository.Requests)
{
if (request.ID == id)
{
Expand All @@ -54,27 +63,27 @@ public static MedicineCreationRequest Get(int id)
}
}

public static List<MedicineCreationRequest> GetMedicines()
public List<MedicineCreationRequest> GetMedicines()
{
return MedicineCreationRequestRepository.Requests;
return _medicineCreationRequestRepository.Requests;
}

public static void Add(MedicineCreationRequest newMedicineCreationRequest)
public void Add(MedicineCreationRequest newMedicineCreationRequest)
{
MedicineCreationRequestRepository.Requests.Add(newMedicineCreationRequest);
MedicineCreationRequestRepository.Save();
_medicineCreationRequestRepository.Requests.Add(newMedicineCreationRequest);
_medicineCreationRequestRepository.Save();
}

public static bool Delete(int id)
public bool Delete(int id)
{
try
{
for (int i = 0; i < MedicineCreationRequestRepository.Requests.Count; i++)
for (int i = 0; i < _medicineCreationRequestRepository.Requests.Count; i++)
{
if (id == MedicineCreationRequestRepository.Requests[i].ID)
if (id == _medicineCreationRequestRepository.Requests[i].ID)
{
MedicineCreationRequestRepository.Requests.RemoveAt(i);
MedicineCreationRequestRepository.Save();
_medicineCreationRequestRepository.Requests.RemoveAt(i);
_medicineCreationRequestRepository.Save();
return true;
}
}
Expand All @@ -91,16 +100,16 @@ public static bool Delete(int id)
}
}

public static bool Delete(MedicineCreationRequest medicineCreationRequest)
public bool Delete(MedicineCreationRequest medicineCreationRequest)
{
try
{
for (int i = 0; i < MedicineCreationRequestRepository.Requests.Count; i++)
for (int i = 0; i < _medicineCreationRequestRepository.Requests.Count; i++)
{
if (medicineCreationRequest.ID == MedicineCreationRequestRepository.Requests[i].ID)
if (medicineCreationRequest.ID == _medicineCreationRequestRepository.Requests[i].ID)
{
MedicineCreationRequestRepository.Requests.RemoveAt(i);
MedicineCreationRequestRepository.Save();
_medicineCreationRequestRepository.Requests.RemoveAt(i);
_medicineCreationRequestRepository.Save();
return true;
}
}
Expand All @@ -117,5 +126,4 @@ public static bool Delete(MedicineCreationRequest medicineCreationRequest)
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ namespace HealthCareCenter.Core.Rooms.Controllers
public class CRUDHospitalRoomController
{
private IRoomService _roomService;
private IHospitalRoomForRenovationService _hospitalRoomForRenovationService;

public CRUDHospitalRoomController(IRoomService roomService)
public CRUDHospitalRoomController(IRoomService roomService, IHospitalRoomForRenovationService hospitalRoomForRenovationService)
{
_roomService = roomService;
_hospitalRoomForRenovationService = hospitalRoomForRenovationService;
}

public void Create(RoomType roomType, string roomName)
Expand Down Expand Up @@ -44,7 +46,7 @@ public void Update(string newRoomName, RoomType newRoomType, string roomId)
public List<HospitalRoom> GetRoomsToDisplay()
{
List<HospitalRoom> availableRooms = HospitalRoomService.GetRooms();
List<HospitalRoom> roomsUnderRenovationProcess = HospitalRoomForRenovationService.GetRooms();
List<HospitalRoom> roomsUnderRenovationProcess = _hospitalRoomForRenovationService.GetRooms();
List<HospitalRoom> roomsForDisplay = new List<HospitalRoom>();
roomsForDisplay.AddRange(availableRooms);
roomsForDisplay.AddRange(roomsUnderRenovationProcess);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@ namespace HealthCareCenter.Core.Rooms.Controllers
internal class ComplexHospitalRoomRenovationMergeController
{
private readonly IRoomService _roomSerivece;
private readonly IHospitalRoomUnderConstructionService _hospitalRoomUnderConstructionService;
private readonly IRenovationScheduleService _renovationScheduleService;
private readonly IHospitalRoomForRenovationService _hospitalRoomForRenovationService;

public ComplexHospitalRoomRenovationMergeController(IRoomService roomService)
public ComplexHospitalRoomRenovationMergeController(IRoomService roomService,
IHospitalRoomUnderConstructionService hospitalRoomUnderConstructionService,
IRenovationScheduleService renovationScheduleService, IHospitalRoomForRenovationService hospitalRoomForRenovationService)
{
_roomSerivece = roomService;
_hospitalRoomUnderConstructionService = hospitalRoomUnderConstructionService;
_renovationScheduleService = renovationScheduleService;
_hospitalRoomForRenovationService = hospitalRoomForRenovationService;
}

public List<HospitalRoom> GetRoomsForDisplay()
Expand Down Expand Up @@ -41,22 +49,22 @@ public void Merge(string room1Id, string room2Id, string renovationStartDate, st
parsedRenovationStartDate, parsedRenovationFinishDate,
room1, room2, newRoom, RenovationType.Merge
);
RenovationScheduleService.ScheduleMergeRenovation(mergeRenovation, room1, room2, newRoom);
_renovationScheduleService.ScheduleMergeRenovation(mergeRenovation, room1, room2, newRoom);
// -----------------------------------------
}

public List<List<string>> GetAllMergeRenovations()
{
List<List<string>> renovationsForDisplay = new List<List<string>>();

List<RenovationSchedule> renovations = RenovationScheduleService.GetRenovations();
List<RenovationSchedule> renovations = _renovationScheduleService.GetRenovations();
foreach (RenovationSchedule renovation in renovations)
{
if (renovation.RenovationType == RenovationType.Merge)
{
HospitalRoom room1 = HospitalRoomForRenovationService.Get(renovation.Room1ID);
HospitalRoom room2 = HospitalRoomForRenovationService.Get(renovation.Room2ID);
HospitalRoom newRoom = HospitalRoomUnderConstructionService.Get(renovation.MainRoomID);
HospitalRoom room1 = _hospitalRoomForRenovationService.Get(renovation.Room1ID);
HospitalRoom room2 = _hospitalRoomForRenovationService.Get(renovation.Room2ID);
HospitalRoom newRoom = _hospitalRoomUnderConstructionService.Get(renovation.MainRoomID);

List<string> renovationAttribute = new List<string> {
room1.ID.ToString(),room1.Name,room1.Type.ToString(),
Expand Down
Loading