Skip to content
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
124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 22 additions & 6 deletions src/ParkingLot/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@

import ParkingLot.controllers.TicketController;
import ParkingLot.dtos.IssueTicketRequestDTO;
import ParkingLot.dtos.IssueTicketResponseDTO;
import ParkingLot.models.Bill;
import ParkingLot.models.Gate;
import ParkingLot.models.GateType;
import ParkingLot.models.VehicleType;
import ParkingLot.repositories.GateRepository;
import ParkingLot.repositories.ParkingLotRepository;
import ParkingLot.repositories.TicketRepository;
import ParkingLot.repositories.VehicleRepository;
import ParkingLot.repositories.*;
import ParkingLot.service.BillService;
import ParkingLot.service.TicketService;

import java.util.Scanner;

public class Client {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
VehicleRepository vehicleRepository = new VehicleRepository();
TicketRepository ticketRepository = new TicketRepository();
ParkingLotRepository parkingLotRepository = new ParkingLotRepository();
GateRepository gateRepository = new GateRepository();
BillRepository billRepository = new BillRepository();

TicketService ticketService = new TicketService(
gateRepository,
Expand All @@ -29,11 +34,22 @@ public static void main(String[] args) {
IssueTicketRequestDTO request = new IssueTicketRequestDTO();
request.setGateId(1);
request.setOwnerName("Mohit");
request.setVehicleType(VehicleType.AUTO);
request.setVehicleType(VehicleType.CAR);
request.setVehicleNumber("DL 1VC 0001");
request.setParkingLotId(1);

ticketController.issueTicket(request);
IssueTicketResponseDTO responseDTO = ticketController.issueTicket(request);
System.out.println("Ticket Issued : "+responseDTO);


BillService billService = new BillService(ticketRepository,billRepository,gateRepository);
int durationInHours = sc.nextInt();
int exitGateId = 2;
Gate gate = new Gate(2,"Ex-G1", GateType.EXIT);
gateRepository.save(gate);
Gate gte = gateRepository.findGateById(exitGateId).get();
Bill bill = billService.generateBill(responseDTO,durationInHours,exitGateId);
System.out.println(bill);
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/ParkingLot/dtos/IssueTicketResponseDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ public void setTicketId(int ticketId) {
this.ticketId = ticketId;
}

@Override
public String toString() {
return "IssueTicketResponseDTO{" +
"ticketId=" + ticketId +
", parkingSlotNumber='" + parkingSlotNumber + '\'' +
", responseStatus=" + responseStatus +
'}';
}
}
18 changes: 18 additions & 0 deletions src/ParkingLot/models/Bill.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ public class Bill extends BaseModel{
// there can be partial payments
// Cash : 20 , UPI : 30
// AmazonPay : 20 , CC : 50
public Bill(Ticket ticket, int amount, Gate gate, Operator operator) {
this.ticket = ticket;
this.amount = amount;
this.gate = gate;
this.operator = operator;
}


public Date getExitTime() {
Expand Down Expand Up @@ -62,6 +68,18 @@ public List<Payment> getPayment() {
public void setPayment(List<Payment> payment) {
this.payment = payment;
}

@Override
public String toString() {
return "Bill{" +
"exitTime=" + exitTime +
", ticket=" + ticket +
", amount=" + amount +
", gate=" + gate +
", operator=" + operator +
", payment=" + payment +
'}';
}
}

// double amount
Expand Down
20 changes: 20 additions & 0 deletions src/ParkingLot/models/Gate.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ public class Gate extends BaseModel{
private Operator currentOperator;
private GateStatus gateStatus;

public Gate() {
}
public Gate(int id,String gateNumber, GateType gateType) {
this.setId(id);
this.gateNumber = gateNumber;
this.gateType = gateType;
this.currentOperator = new Operator("Operator-1");
this.gateStatus = GateStatus.OPEN;
}

public String getGateNumber() {
return gateNumber;
}
Expand Down Expand Up @@ -37,4 +47,14 @@ public GateStatus getGateStatus() {
public void setGateStatus(GateStatus gateStatus) {
this.gateStatus = gateStatus;
}

@Override
public String toString() {
return "Gate{" +
"gateNumber='" + gateNumber + '\'' +
", gateType=" + gateType +
", currentOperator=" + currentOperator +
", gateStatus=" + gateStatus +
'}';
}
}
12 changes: 12 additions & 0 deletions src/ParkingLot/models/Operator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,16 @@
public class Operator extends BaseModel{
private String Name;
private Gate gate;

public Operator(String name) {
super();
this.Name = name;
}

@Override
public String toString() {
return "Operator{" +
"Name='" + Name + '\'' +
'}';
}
}
6 changes: 6 additions & 0 deletions src/ParkingLot/models/ParkingFloor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ParkingLot.models;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand All @@ -9,6 +10,11 @@ public class ParkingFloor extends BaseModel {
private ParkingFloorStatus parkingFloorStatus;
private List<VehicleTypeCapacity> vehicleCapacities;

public ParkingFloor() {
this.parkingSlots = new ArrayList<ParkingSlot>();
parkingSlots.add(new ParkingSlot());
}

public String getFloorName() {
return floorName;
}
Expand Down
6 changes: 6 additions & 0 deletions src/ParkingLot/models/ParkingSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ public class ParkingSlot extends BaseModel {
private VehicleType vehicleType;
private ParkingFloor parkingFloor;

public ParkingSlot() {
this.parkingSlotStatus = ParkingSlotStatus.EMPTY;
this.vehicleType = VehicleType.CAR;
this.slotNumber = "SLOT-0";
}

public ParkingFloor getParkingFloor() {
return parkingFloor;
}
Expand Down
24 changes: 24 additions & 0 deletions src/ParkingLot/repositories/BillRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ParkingLot.repositories;

import ParkingLot.models.Bill;
import ParkingLot.models.Ticket;

import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;

public class BillRepository {
private static Map<Integer, Bill> bills = new TreeMap<>();
private static int id =1;
public BillRepository() {
// bills.put(id, new Bill(id++));
}

public void saveBill(Bill bill){
bills.put(id++, bill);
}

public Optional<Bill> getBill(int id){
return Optional.ofNullable(bills.get(id));
}
}
19 changes: 18 additions & 1 deletion src/ParkingLot/repositories/GateRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,28 @@

import ParkingLot.models.Gate;

import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;

public class GateRepository {
private static final Map<Integer,Gate> gateMap = new TreeMap<>();
private static int idCounter =1;
public GateRepository() {
Gate gate = new Gate();
gate.setId(idCounter);
gateMap.put(idCounter, gate);
idCounter++;
}

public Optional<Gate> findGateById(int gateId){
return Optional.empty();
if(!gateMap.containsKey(gateId))
return Optional.empty();
return Optional.of(gateMap.get(gateId));
}

public void save(Gate gate) {
gateMap.put(gate.getId(), gate);
}
}
// ORM
Expand Down
8 changes: 4 additions & 4 deletions src/ParkingLot/repositories/ParkingLotRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import java.util.TreeMap;

public class ParkingLotRepository {
private Map<Integer, ParkingLot> parkingLots = new TreeMap<>();

private static final Map<Integer, ParkingLot> parkingLots = new TreeMap<>();
private static int idCounter = 1;
public ParkingLotRepository() {
ParkingLot parkingLot = new ParkingLot();
parkingLot.setId(1);
parkingLot.setId(idCounter++);
parkingLots.put(parkingLot.getId(), parkingLot);
}

ParkingLot findParkingLotByGate(Gate gate){
public ParkingLot findParkingLotByGate(Gate gate){
for(ParkingLot parkingLot : parkingLots.values()){
for(Gate gate1 : parkingLot.getEntryGates()){
if(gate1.getId() == gate.getId()){
Expand Down
5 changes: 5 additions & 0 deletions src/ParkingLot/repositories/TicketRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ParkingLot.models.Ticket;

import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;

public class TicketRepository {
Expand All @@ -16,5 +17,9 @@ public Ticket save(Ticket ticket){
return ticket;
}

public Optional<Ticket> findById(int id){
return Optional.ofNullable(tickets.get(id));
}


}
Loading