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
78 changes: 52 additions & 26 deletions src/ParkingLot/Client.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,66 @@
package ParkingLot;

import ParkingLot.controllers.BillController;
import ParkingLot.controllers.PaymentController;
import ParkingLot.controllers.TicketController;
import ParkingLot.dtos.BillRequestDTO;
import ParkingLot.dtos.BillResponseDTO;
import ParkingLot.dtos.IssueTicketRequestDTO;
import ParkingLot.models.Gate;
import ParkingLot.dtos.IssueTicketResponseDTO;
import ParkingLot.dtos.PaymentDTO;
import ParkingLot.models.PaymentMode;
import ParkingLot.models.PaymentStatus;
import ParkingLot.models.VehicleType;
import ParkingLot.repositories.BillRepository;
import ParkingLot.repositories.GateRepository;
import ParkingLot.repositories.ParkingLotRepository;
import ParkingLot.repositories.PaymentRepository;
import ParkingLot.repositories.TicketRepository;
import ParkingLot.repositories.VehicleRepository;
import ParkingLot.service.BillService;
import ParkingLot.service.PaymentService;
import ParkingLot.service.TicketService;

public class Client {
public static void main(String[] args) {
VehicleRepository vehicleRepository = new VehicleRepository();
TicketRepository ticketRepository = new TicketRepository();
ParkingLotRepository parkingLotRepository = new ParkingLotRepository();
GateRepository gateRepository = new GateRepository();

TicketService ticketService = new TicketService(
gateRepository,
vehicleRepository,
parkingLotRepository,
ticketRepository
);

TicketController ticketController = new TicketController(ticketService);

IssueTicketRequestDTO request = new IssueTicketRequestDTO();
request.setGateId(1);
request.setOwnerName("Mohit");
request.setVehicleType(VehicleType.AUTO);
request.setVehicleNumber("DL 1VC 0001");
request.setParkingLotId(1);

ticketController.issueTicket(request);
}
public static void main(String[] args) {
VehicleRepository vehicleRepository = new VehicleRepository();
TicketRepository ticketRepository = new TicketRepository();
ParkingLotRepository parkingLotRepository = new ParkingLotRepository();
GateRepository gateRepository = new GateRepository();

TicketService ticketService = new TicketService(gateRepository, vehicleRepository, parkingLotRepository,
ticketRepository);

TicketController ticketController = new TicketController(ticketService);

IssueTicketRequestDTO request1 = new IssueTicketRequestDTO(1, "DL 1VC 0001", "Mohit", VehicleType.BIKE, 1);
IssueTicketRequestDTO request2 = new IssueTicketRequestDTO(1, "OD 33M 0243", "Surajit", VehicleType.BIKE, 1);
IssueTicketResponseDTO ticket1 = ticketController.issueTicket(request1);
IssueTicketResponseDTO ticket2 = ticketController.issueTicket(request2);
System.out.println(ticket1);
System.out.println(ticket2);
BillRepository billRepository = new BillRepository();
BillService billService = new BillService(billRepository, ticketRepository, gateRepository,
parkingLotRepository);
BillController billController = new BillController(billRepository, ticketRepository, gateRepository,
parkingLotRepository);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
BillResponseDTO bill = billController.generateBill(new BillRequestDTO(ticket1.getTicketId(), 2, 1));
System.out.println(bill);
PaymentRepository paymentRepository = new PaymentRepository();
PaymentService paymentService = new PaymentService(paymentRepository);
PaymentController paymentController = new PaymentController(paymentService);
PaymentStatus status = paymentController
.PaymentProcessing(new PaymentDTO(bill.getAmount() / 2, PaymentMode.CASH));
System.out.println("Payment " + bill.getAmount() / 2 + " " + status + " via " + PaymentMode.CASH);
status = paymentController.PaymentProcessing(new PaymentDTO(bill.getAmount() / 2, PaymentMode.UPI));
System.out.println("Payment " + bill.getAmount() / 2 + " " + status + " via " + PaymentMode.UPI);

}
}

// Controllers
Expand All @@ -50,7 +76,7 @@ public static void main(String[] args) {
// schema design
// code models
// code controller
// DTO
// DTO
// Issue ticket completion

// HW : Generating the bill , check-out
8 changes: 8 additions & 0 deletions src/ParkingLot/adapter/PaymentAdaptor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ParkingLot.adapter;

import ParkingLot.models.Bill;
import ParkingLot.models.PaymentStatus;

public interface PaymentAdaptor {
PaymentStatus processPayment(Bill bill);
}
13 changes: 13 additions & 0 deletions src/ParkingLot/adapter/RazorPayPaymentAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ParkingLot.adapter;

import ParkingLot.models.Bill;
import ParkingLot.models.PaymentStatus;

public class RazorPayPaymentAdapter implements PaymentAdaptor {

@Override
public PaymentStatus processPayment(Bill bill) {
System.out.println("Payment SUCCESSFUL for bill ID : "+ bill.getId());
return PaymentStatus.SUCCESS;
}
}
30 changes: 30 additions & 0 deletions src/ParkingLot/controllers/BillController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ParkingLot.controllers;

import java.util.List;

import ParkingLot.dtos.BillRequestDTO;
import ParkingLot.dtos.BillResponseDTO;
import ParkingLot.dtos.ResponseStatus;
import ParkingLot.models.Bill;
import ParkingLot.repositories.BillRepository;
import ParkingLot.repositories.GateRepository;
import ParkingLot.repositories.ParkingLotRepository;
import ParkingLot.repositories.TicketRepository;
import ParkingLot.service.BillService;
import ParkingLot.service.PaymentService;

public class BillController {

BillService billService;

public BillController(BillRepository billRepository, TicketRepository ticketRepository,
GateRepository gateRepository, ParkingLotRepository parkingLotRepository) {
billService = new BillService(billRepository, ticketRepository, gateRepository, parkingLotRepository);
}

public BillResponseDTO generateBill(BillRequestDTO billRequest) {
Bill bill = billService.generateBill(billRequest);
return new BillResponseDTO(bill.getId(),billRequest.getTicketId(), ResponseStatus.SUCCESS, bill.getAmount(),bill.getTicket().getEntryTime(), bill.getExitTime());
}

}
20 changes: 20 additions & 0 deletions src/ParkingLot/controllers/PaymentController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ParkingLot.controllers;

import ParkingLot.dtos.PaymentDTO;
import ParkingLot.models.Payment;
import ParkingLot.models.PaymentStatus;
import ParkingLot.service.PaymentService;

public class PaymentController {

PaymentService paymentService;

public PaymentController(PaymentService paymentService) {
this.paymentService = paymentService;
}

public PaymentStatus PaymentProcessing(PaymentDTO paymentDto) {
Payment p = paymentService.processPayment(paymentDto);
return p.getPaymentStatus();
}
}
1 change: 1 addition & 0 deletions src/ParkingLot/controllers/TicketController.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public IssueTicketResponseDTO issueTicket(IssueTicketRequestDTO request){
response.setParkingSlotNumber(ticket.getParkingSlot().getSlotNumber());
response.setResponseStatus(ResponseStatus.SUCCESS);
} catch (Exception e){
e.printStackTrace();
response.setResponseStatus(ResponseStatus.FAILURE);
}
return response;
Expand Down
33 changes: 33 additions & 0 deletions src/ParkingLot/dtos/BillRequestDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ParkingLot.dtos;

import java.util.List;

public class BillRequestDTO {
int ticketId;
int gateId;
int parkingLotId;
public BillRequestDTO(int ticketId, int gateId, int parkingLotId) {
super();
this.ticketId = ticketId;
this.gateId = gateId;
this.parkingLotId = parkingLotId;
}
public int getTicketId() {
return ticketId;
}
public void setTicketId(int ticketId) {
this.ticketId = ticketId;
}
public int getGateId() {
return gateId;
}
public void setGateId(int gateId) {
this.gateId = gateId;
}
public int getParkingLotId() {
return parkingLotId;
}
public void setParkingLotId(int parkingLotId) {
this.parkingLotId = parkingLotId;
}
}
72 changes: 72 additions & 0 deletions src/ParkingLot/dtos/BillResponseDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package ParkingLot.dtos;

import java.util.Date;

public class BillResponseDTO {
int billId;
int ticketId;
ResponseStatus billStatus;
int amount;
Date entryTime;
Date exitTime;
public BillResponseDTO() {
// TODO Auto-generated constructor stub
}
public BillResponseDTO(int billId,int ticketId, ResponseStatus billStatus, int amount, Date entryTime,Date exitTime) {
super();
this.billId = billId;
this.ticketId=ticketId;
this.billStatus = billStatus;
this.amount = amount;
this.entryTime=entryTime;
this.exitTime = exitTime;
}
@Override
public String toString() {
return "Bill: [billId=" + billId + ", ticketId=" + ticketId + ", billStatus=" + billStatus
+ ", amount=" + amount + ", entryTime=" + entryTime + ", exitTime=" + exitTime + "]";
}
public int getBillId() {
return billId;
}
public void setBillId(int billId) {
this.billId = billId;
}
public int getTicketId() {
return ticketId;
}
public void setTicketId(int ticketId) {
this.ticketId = ticketId;
}
public ResponseStatus getBillStatus() {
return billStatus;
}
public void setBillStatus(ResponseStatus billStatus) {
this.billStatus = billStatus;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public Date getEntryTime() {
return entryTime;
}
public void setEntryTime(Date entryTime) {
this.entryTime = entryTime;
}
public Date getExitTime() {
return exitTime;
}
public void setExitTime(Date exitTime) {
this.exitTime = exitTime;
}







}
15 changes: 14 additions & 1 deletion src/ParkingLot/dtos/IssueTicketRequestDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,21 @@ public class IssueTicketRequestDTO {
private String ownerName;
private VehicleType vehicleType;
private int parkingLotId;

public IssueTicketRequestDTO() {
}

public int getParkingLotId() {
public IssueTicketRequestDTO(int gateId, String vehicleNumber, String ownerName, VehicleType vehicleType,
int parkingLotId) {
super();
this.gateId = gateId;
this.vehicleNumber = vehicleNumber;
this.ownerName = ownerName;
this.vehicleType = vehicleType;
this.parkingLotId = parkingLotId;
}

public int getParkingLotId() {
return parkingLotId;
}

Expand Down
14 changes: 11 additions & 3 deletions src/ParkingLot/dtos/IssueTicketResponseDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

public class IssueTicketResponseDTO {
private int ticketId;
private String parkingSlotNumber;
private int parkingSlotNumber;
private ResponseStatus responseStatus;

public String getParkingSlotNumber() {
public int getParkingSlotNumber() {
return parkingSlotNumber;
}

public void setParkingSlotNumber(String parkingSlotNumber) {
public void setParkingSlotNumber(int parkingSlotNumber) {
this.parkingSlotNumber = parkingSlotNumber;
}

Expand All @@ -29,4 +29,12 @@ public void setTicketId(int ticketId) {
this.ticketId = ticketId;
}

@Override
public String toString() {
return "Ticket: [ticketId=" + ticketId + ", parkingSlotNumber=" + parkingSlotNumber
+ ", responseStatus=" + responseStatus + "]";
}



}
32 changes: 32 additions & 0 deletions src/ParkingLot/dtos/PaymentDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ParkingLot.dtos;

import ParkingLot.models.PaymentMode;

public class PaymentDTO {
private int amount;
private PaymentMode mode;

public PaymentDTO() {
}

public PaymentDTO(int amount, PaymentMode mode) {
super();
this.amount = amount;
this.mode = mode;
}


public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public PaymentMode getMode() {
return mode;
}
public void setMode(PaymentMode mode) {
this.mode = mode;
}

}
Loading