Changeset de83113 for src/main


Ignore:
Timestamp:
02/17/25 21:52:11 (4 months ago)
Author:
ste08 <sjovanoska@…>
Branches:
master
Children:
62bba0c
Parents:
9868304
Message:

Signup,Login,FlightSearch,Booking and Payment working!

Location:
src/main
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/example/skychasemk/controller/BookingController.java

    r9868304 rde83113  
    2727    }
    2828
    29     @PutMapping("/flights/{id}")
    30     public Booking updateBooking(@PathVariable("id") Integer bookingID, @RequestBody Booking booking) {
     29    @PutMapping("/flights/{bookingId}")
     30    public Booking updateBooking(@PathVariable("bookingId") Integer bookingID, @RequestBody Booking booking) {
    3131        return bookingService.updateBooking(bookingID, booking);
    3232    }
     
    4040    public Booking createBooking(@RequestBody BookingDTO bookingRequest) {
    4141        Booking newBooking = new Booking();
    42         newBooking.setUserID(bookingRequest.getUserID());
     42        newBooking.setUserId(bookingRequest.getUserId());
    4343        newBooking.setFlightId(bookingRequest.getFlightId());
    4444        newBooking.setBookingDate(LocalDate.now());
    4545        newBooking.setStatus(Booking.payment_status.PENDING);
    46         newBooking.setTotalCost(bookingRequest.getTotalCost());
     46        newBooking.setTotal_cost(bookingRequest.getTotalCost());
    4747        newBooking.setSeatNumber(bookingRequest.getSeatNumber());
    4848        System.out.println("Saving Booking: " + newBooking);
  • src/main/java/com/example/skychasemk/dto/BookingDTO.java

    r9868304 rde83113  
    11package com.example.skychasemk.dto;
    22
    3 import com.example.skychasemk.model.Flight;
     3import lombok.Getter;
     4import lombok.Setter;
    45
    56import java.math.BigDecimal;
     
    89public class BookingDTO {
    910
    10     private Integer bookingID;
    11     private Integer userID;
     11    @Setter
     12    private Integer bookingId;
     13
     14    @Getter
     15    private Integer userId;
     16    @Setter
     17    @Getter
    1218    private Integer flightId;
     19    @Setter
     20    @Getter
    1321    private LocalDate bookingDate;
     22    @Setter
     23    @Getter
    1424    private PaymentStatus status;
     25    @Setter
     26    @Getter
    1527    private BigDecimal totalCost;
     28    @Setter
     29    @Getter
    1630    private Integer seatNumber;
    17 
    18     public Integer getFlightId() {
    19         return flightId;
    20     }
    21 
    22     public void setFlightId(Integer flightId) {
    23         this.flightId = flightId;
    24     }
    2531
    2632    public enum PaymentStatus {
     
    3036    }
    3137
    32     // Getters and Setters
    33     public Integer getBookingID() {
    34         return bookingID;
     38    public void setUserID(Integer userId) {
     39        this.userId = userId;
    3540    }
    3641
    37     public void setBookingID(Integer bookingID) {
    38         this.bookingID = bookingID;
    39     }
    40 
    41     public Integer getUserID() {
    42         return userID;
    43     }
    44 
    45     public void setUserID(Integer userID) {
    46         this.userID = userID;
    47     }
    48 
    49     public Integer getFlightID() {
    50         return flightId;
    51     }
    52 
    53     public void setFlightID(Integer flightId) {
    54         this.flightId = flightId;
    55     }
    56 
    57     public LocalDate getBookingDate() {
    58         return bookingDate;
    59     }
    60 
    61     public void setBookingDate(LocalDate bookingDate) {
    62         this.bookingDate = bookingDate;
    63     }
    64 
    65     public PaymentStatus getStatus() {
    66         return status;
    67     }
    68 
    69     public void setStatus(PaymentStatus status) {
    70         this.status = status;
    71     }
    72 
    73     public BigDecimal getTotalCost() {
    74         return totalCost;
    75     }
    76 
    77     public void setTotalCost(BigDecimal totalCost) {
    78         this.totalCost = totalCost;
    79     }
    80 
    81     public Integer getSeatNumber() {
    82         return seatNumber;
    83     }
    84 
    85     public void setSeatNumber(Integer seatNumber) {
    86         this.seatNumber = seatNumber;
    87     }
    8842}
  • src/main/java/com/example/skychasemk/dto/PaymentDTO.java

    r9868304 rde83113  
    11package com.example.skychasemk.dto;
    22
     3import com.example.skychasemk.model.Booking;
    34import lombok.Getter;
    45import lombok.Setter;
     
    1011
    1112    // Getters and Setters
     13    @Setter
    1214    @Getter
    1315    private Long paymentID;
    1416    @Getter
    1517    private Integer bookingId;
    16     private Integer userID;
     18    @Setter
     19    private Integer userId;
     20    @Setter
    1721    @Getter
    1822    private PaymentMethod method;
     23    @Setter
    1924    @Getter
    2025    private BigDecimal amount;
    2126    @Getter
    2227    private LocalDate transactionDate;
     28    @Setter
    2329    @Getter
    2430    private PaymentStatus status;
     
    3844        CREDIT
    3945    }
    40     public Integer getBookingID() {
    41         return bookingId;
    42     }
    43     public void setPaymentID(Long paymentID) {
    44         this.paymentID = paymentID;
     46
     47
     48    public Long getUserId() {
     49        return Long.valueOf(userId);
    4550    }
    4651
    47 
    48     public Long getUserID() {
    49         return Long.valueOf(userID);
    50     }
    51 
    52     public void setUserID(Integer userID) {
    53         this.userID = userID;
    54     }
    55 
    56     public void setMethod(PaymentMethod method) {
    57         this.method = method;
    58     }
    59 
    60     public void setAmount(BigDecimal amount) {
    61         this.amount = amount;
    62     }
    63 
    64     public void setTransactionDate(LocalDate transactionDate) {
    65         this.transactionDate = transactionDate;
    66     }
    67 
    68     public void setStatus(PaymentStatus status) {
    69         this.status = status;
    70     }
    7152}
    7253
  • src/main/java/com/example/skychasemk/model/Booking.java

    r9868304 rde83113  
    1212public class Booking {
    1313
    14     @Setter
    15     @Getter
    1614    @Id
    1715    @GeneratedValue(strategy = GenerationType.IDENTITY)
    1816    @Column(name = "bookingid")
    1917
    20     private Integer bookingID;
    21     @Setter
    22     @Getter
     18    private Integer bookingId;
    2319    @Column(name = "userid")
    2420
    25     private Integer userID;
     21    private Integer userId;
    2622
    2723    @Column(name = "booking_date")
    2824
    2925    private LocalDate booking_date;
    30     @Setter
    31     @Getter
     26
    3227    @Column(name = "payment_status")
    3328
     
    6257    }
    6358
    64     public Integer getBookingID() {
    65         return bookingID;
     59    public Integer getBookingId() {
     60        return bookingId;
    6661    }
    6762
    68     public void setBookingID(Integer bookingID) {
    69         this.bookingID = bookingID;
     63    public void setBookingId(Integer bookingID) {
     64        this.bookingId = bookingID;
    7065    }
    7166
    72     public Integer getUserID() {
    73         return userID;
     67    public Integer getUserId() {
     68        return userId;
    7469    }
    7570
    76     public void setUserID(Integer userID) {
    77         this.userID = userID;
     71    public void setUserId(Integer userId) {
     72        this.userId = userId;
    7873    }
    7974
     
    114109    }
    115110
    116     public BigDecimal getTotalCost() {
    117         return total_cost;
    118     }
    119 
    120     public void setTotalCost(BigDecimal totalCost) {
    121         this.total_cost = totalCost;
    122     }
    123 
    124111    public Integer getSeatNumber() {
    125112        return seat_number;
  • src/main/java/com/example/skychasemk/model/Payment.java

    r9868304 rde83113  
    1313public class Payment {
    1414
     15    @Setter
    1516    @Id
    1617    @GeneratedValue(strategy = GenerationType.IDENTITY)
     
    1920    private Integer paymentID;
    2021
    21     @Column(name = "bookingid")
     22    //@Column(name = "bookingId")
     23    @Setter
     24    @Column(name="bookingid")
     25    private Integer bookingId;
     26    @Getter
     27    @Column(name = "userid")
    2228
    23     private Integer bookingID;
    24     @Column(name = "UserID")
    25 
    26     private Integer userID;
     29    private Integer userId;
    2730    @Setter
    2831    @Column(name = "payment_method")
     
    3942
    4043    private LocalDate transactionDate;
     44    @Setter
     45    @Getter
    4146    @Column(name = "payment_status")
    4247
    4348    @Enumerated(EnumType.STRING)
    4449    private PaymentStatus status;
     50
    4551
    4652    public enum PaymentStatus {
     
    5662    }
    5763
    58     public Integer getPaymentID() {
    59         return paymentID;
     64    public Integer getBookingID() {
     65        return bookingId;
    6066    }
    6167
    62     public Integer getBookingID() {
    63         return bookingID;
     68    public void setUserID(Integer userId) {
     69        this.userId = userId;
    6470    }
    6571
    66     public Integer getUserID() {
    67         return userID;
    68     }
    69 
    70     public void setUserID(Integer userID) {
    71         this.userID = userID;
    72     }
    73 
    74     public PaymentMethod getMethod() {
    75         return method;
    76     }
    77 
    78     public void setMethod(PaymentMethod method) {
    79         this.method = method;
    80     }
    81 
    82     public BigDecimal getAmount() {
    83         return amount;
    84     }
    85 
    86     public void setPaymentID(Integer paymentID) {
    87         this.paymentID = paymentID;
    88     }
    89 
    90     public void setBookingID(Integer bookingID) {
    91         this.bookingID = bookingID;
    92     }
    93 
    94     public void setAmount(BigDecimal amount) {
    95         this.amount = amount;
    96     }
    97 
    98     public LocalDate getTransactionDate() {
    99         return transactionDate;
    100     }
    101 
    102     public void setTransactionDate(LocalDate transactionDate) {
    103         this.transactionDate = transactionDate;
    104     }
    105 
    106     public PaymentStatus getStatus() {
    107         return status;
    108     }
    109 
    110     public void setStatus(PaymentStatus status) {
    111         this.status = status;
    112     }
    113 
    114     public void setUserID(Long userID) {
    115         this.userID = Math.toIntExact(userID);
     72    public void setUserId(Long userId) {
     73        this.userId = Math.toIntExact(userId);
    11674    }
    11775
  • src/main/java/com/example/skychasemk/repository/PaymentRepository.java

    r9868304 rde83113  
    99
    1010public interface PaymentRepository extends JpaRepository<Payment, Integer> {
    11     @Query("SELECT p FROM Payment p WHERE p.userID = :userID")
    12     List<Payment> findByUserId(@Param("userID") Long userID);
     11    @Query("SELECT p FROM Payment p WHERE p.userId = :userId")
     12    List<Payment> findByUserId(@Param("userID") Long userId);
    1313}
    1414
     15
     16
  • src/main/java/com/example/skychasemk/services/BookingService.java

    r9868304 rde83113  
    88import java.util.List;
    99import java.util.Optional;
     10
     11import static com.example.skychasemk.model.Booking.payment_status.COMPLETED;
     12
    1013
    1114@Service
     
    2932    public Booking updateBooking(Integer bookingID, Booking booking) {
    3033        if (bookingRepository.existsById(bookingID)) {
    31             booking.setBookingID(bookingID);
     34            booking.setStatus(COMPLETED);
     35            booking.setUserId(booking.getUserId());
     36            booking.setTotal_cost(booking.getTotal_cost());
     37            booking.setFlightId(booking.getFlightId());
     38            booking.setBooking_date(booking.getBooking_date());
    3239            return bookingRepository.save(booking);
    3340        } else {
  • src/main/java/com/example/skychasemk/services/PaymentService.java

    r9868304 rde83113  
    5555
    5656    public Payment createTransaction(PaymentDTO dto){
    57         //ApplicationUser user = userRepository.findById(dto.getUserID())
    58         //        .orElseThrow(() -> new RuntimeException("User not found"));
    59 
     57        System.out.println( dto);
    6058        Payment payment = new Payment();
    6159        payment.setAmount(dto.getAmount());
    62         payment.setBookingID(dto.getBookingID());
    63         //payment.setUserID(dto.getUserID());
     60        payment.setBookingId(dto.getBookingId());
     61        payment.setUserId(dto.getUserId());
    6462        payment.setStatus(COMPLETED);
    6563        payment.setMethod(CREDIT);
  • src/main/resources/static/FlightSearch.html

    r9868304 rde83113  
    252252            <h2>Available Flights</h2>
    253253            <div class="flights-list">
    254                 <div class="flight-item" v-for="flight in flights" :key="flight.flightId">
     254                <div class="flight-item" v-for="flight in flights" :key="flight.flightID">
    255255                    <input type="checkbox" v-model="flight.selected" />
    256256                    <span>{{ flight.departureTime }} | {{ flight.arrivalTime }} | ${{ flight.price }} | {{ flight.availableSeats }}</span>
     
    295295            showReturnDate: false,
    296296            showPopup: false,
    297             issueDescription: ""
     297            issueDescription: '',
     298            userId:''
    298299        },
    299300        computed: {
     
    302303            }
    303304        },
     305
    304306        methods: {
    305307            async searchFlights() {
     
    337339
    338340                const flight = this.selectedFlights[0];
     341                console.log(flight);
    339342                const totalCost = flight.price;
     343
    340344                const bookingData = {
    341                     flightId: flight.flightId,
     345                    flightId: flight.flightID,
    342346                    bookingDate: new Date().toISOString().split('T')[0],
    343347                    status: 'PENDING',
    344                     totalCost: totalCost
     348                    totalCost: totalCost,
     349                    userId:this.userId
    345350                };
    346 
    347351                axios.post('/api/bookings', bookingData)
    348352                    .then(response => {
    349                         const bookingID = response.data.bookingID;
     353                        const bookingID = response.data.bookingId;
    350354                        alert("Booked successfully!");
    351                         window.location.href = `/transaction?amount=${encodeURIComponent(totalCost)}&bookingId=${encodeURIComponent(bookingID)}&flightId=${encodeURIComponent(flight.flightId)}`;
     355                        window.location.href = `/transaction?amount=${encodeURIComponent(totalCost)}&bookingId=${encodeURIComponent(bookingID)}&flightId=${encodeURIComponent(flight.flightID)}&userId=${encodeURIComponent(this.userId)}`;
    352356                    })
    353357                    .catch(error => {
     
    383387                if (this.issueDescription.trim()) {
    384388                    const reviewData = {
    385                         userID: 1,
     389                        userID: this.userId,
    386390                        subject: "Issue Report",
    387391                        description: this.issueDescription
     
    413417        mounted() {
    414418            this.fetchFlights();
     419            const params = new URLSearchParams(window.location.search);
     420            this.userId = params.get("userId");
    415421            axios.get('api/flights')
    416422                .then(response => {
     
    420426                    console.error("Error fetching flights", error);
    421427                });
     428
    422429        }
    423430    });
  • src/main/resources/static/TransactionPage.html

    r9868304 rde83113  
    263263            expiration: '',
    264264            amount: '',
    265             paymentSuccess: false
    266         },
    267         created(){
    268             const urlParams = new URLSearchParams(window.location.search);
    269             this.flightId = urlParams.get('flightId');
    270             this.amount = urlParams.get('amount');
    271             this.bookingId = urlParams.get('bookingId')
    272 
    273             const user = JSON.parse(localStorage.getItem("user"));
    274             if(user){
    275                 this.userId = user.id;
    276             }
     265            paymentSuccess: false,
     266            flightId:'',
     267            userId:''
    277268        },
    278269        methods: {
     
    282273                    transaction_date:paymentDate,
    283274                    payment_status:'SUCCESS',
    284                     amount:this.amount,
    285                     userId:this.userId,
    286                     bookingId:this.bookingId
     275                    amount:Number(this.amount) || null,
     276                    userId:Number(this.userId) || null,
     277                    bookingId:Number(this.bookingId) || null
    287278                };
    288279                console.log(transaction);
     
    291282                        console.log(response.data);
    292283                        this.paymentSuccess = true;
     284                        this.updateBooking();
    293285                        setTimeout(() => window.location.href = '/flights',2000);
    294286                })
    295287                    .catch(error => console.error("Payment failed", error));
    296288            },
     289            updateBooking() {
     290                const booking = {
     291                    bookingDate: new Date().toISOString().split('T')[0],
     292                    flightId:this.flightId,
     293                    payment_status:'SUCCESS',
     294                    total_cost:Number(this.amount) || null,
     295                    userId:Number(this.userId) || null,
     296                    bookingId:Number(this.bookingId) || null
     297                };
     298                console.log(booking);
     299                axios.put(`api/flights/${this.bookingId}`, booking)
     300                    .then(response => {
     301                        console.log(response.data);
     302                    })
     303                    .catch(error => console.error("Booking update failed", error));
     304            },
    297305            cancelPayment() {
    298                 window.location.href = '/flights'; // Redirecting to flight search on cancel
     306                window.location.href = '/flights';
    299307            },
    300308            validateForm() {
     
    305313                );
    306314            }
     315        },
     316        mounted(){
     317            const params = new URLSearchParams(window.location.search);
     318            this.userId = params.get("userId");
     319            this.bookingId = params.get("bookingId");
     320            this.flightId = params.get("flightId");
     321            this.amount=params.get("amount");
    307322        }
    308323    });
Note: See TracChangeset for help on using the changeset viewer.