Changeset fda671c for src/main


Ignore:
Timestamp:
02/23/25 22:27:46 (3 months ago)
Author:
ste08 <sjovanoska@…>
Branches:
master
Children:
07fe0be
Parents:
62bba0c
Message:

Wishlist working, need to fix the Book on Wishlist

Location:
src/main
Files:
4 edited

Legend:

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

    r62bba0c rfda671c  
    33import com.example.skychasemk.dto.WishlistDTO;
    44import com.example.skychasemk.model.Wishlist;
     5import com.example.skychasemk.repository.WishlistRepository;
    56import com.example.skychasemk.services.WishlistService;
    67import org.springframework.beans.factory.annotation.Autowired;
     
    1819    private WishlistService wishlistService;
    1920
     21    @Autowired
     22    private WishlistRepository wishlistRepository;
     23
    2024    @GetMapping
    2125    public List<Wishlist> getAllWishlists() {
    22         return wishlistService.getAllWishlists();
     26        return wishlistRepository.findAll();
    2327    }
     28
    2429    @PostMapping("/add")
    2530    public Wishlist createWishlist(@RequestBody Wishlist wishlist) {
     
    3338
    3439    @GetMapping("/{userId}")
    35     public ResponseEntity<List<Wishlist>> getWishlist(@RequestParam("userId") Long userId) {
     40    public ResponseEntity<List<Wishlist>> getWishlist(@PathVariable Long userId) {
    3641        List<Wishlist> wishlist = wishlistService.getAllItems(userId);
    3742        return ResponseEntity.ok(wishlist);
  • src/main/java/com/example/skychasemk/model/WebConfig.java

    r62bba0c rfda671c  
    3434        registry.addViewController("/transaction").setViewName("forward:/TransactionPage.html");
    3535        registry.addViewController("/login").setViewName("forward:/UserLogin.html");
    36         registry.addViewController("/wishlist").setViewName("forward:/Wishlist.html");
     36        registry.addViewController("/wishlists").setViewName("forward:/Wishlist.html");
    3737        registry.addViewController("/signup").setViewName("forward:/UserSignup.html");
    3838        registry.addViewController("/views").setViewName("forward:/ViewReport.html");
  • src/main/resources/static/FlightSearch.html

    r62bba0c rfda671c  
    405405            },
    406406            async goToWishlistPage() {
    407                 window.location.href = `/api/wishlists?userId=${encodeURIComponent(this.userId)}`;
    408 
     407                window.location.href = `/wishlists?userId=${encodeURIComponent(this.userId)}`;
    409408            },
    410409            showReportPopup() {
  • src/main/resources/static/Wishlist.html

    r62bba0c rfda671c  
    44    <meta charset="UTF-8">
    55    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     6    <title>SkyChase - Wishlist</title>
    67    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    78    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    89    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
    910    <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/css/all.min.css'>
    10 
    11     <title>SkyChase - Wishlist</title>
     11    <link rel="stylesheet" href="/css/main.css">
    1212    <style>
    1313        body {
    14             background: url('images/homepage.jpg') no-repeat center center fixed;
     14            background: url('images/sky.jpg') no-repeat center center fixed;
    1515            background-size: cover;
    1616            display: flex;
     
    4646            padding-right: 50px;
    4747        }
    48 
    49         .buttons {
    50             text-align: center;
     48        .header button{
     49            background-color:rebeccapurple;
    5150        }
    52 
    53         .buttons button {
    54             padding: 15px 30px;
    55             margin: 10px;
    56             font-size: 18px;
    57             border: none;
    58             border-radius: 5px;
     51        select {
     52            -webkit-appearance: none;
     53            -moz-appearance: none;
     54            appearance: none;
     55            border: 0;
     56            outline: 0;
     57            font: inherit;
     58            width: 20em;
     59            height: 3em;
     60            padding: 0 4em 0 1em;
     61            background: url(https://upload.wikimedia.org/wikipedia/commons/9/9d/Caret_down_font_awesome_whitevariation.svg) no-repeat right 0.8em center/1.4em, linear-gradient(to left, rgba(255, 255, 255, 0.3) 3em, rgba(255, 255, 255, 0.2) 3em);
     62            color: white;
     63            border-radius: 0.25em;
     64            box-shadow: 0 0 1em 0 rgba(0, 0, 0, 0.2);
    5965            cursor: pointer;
    60             transition: 0.3s;
    6166        }
    62 
    63         .signup {
    64             background-color: rebeccapurple;
    65             color: white;
     67        select option {
     68            color: inherit;
     69            background-color: #320a28;
    6670        }
    67 
    68         .signup:hover {
    69             background-color: mediumpurple;
     71        select:focus {
     72            outline: none;
    7073        }
    71 
    72         .login {
    73             background-color: #007bff;
    74             color: white;
     74        select::-ms-expand {
     75            display: none;
    7576        }
    76 
    77         .login:hover {
    78             background-color: #0056b3;
    79         }
    80 
    81         .adminlogin {
    82             top: 0;
    83             right: 0;
    84             background-color: rebeccapurple;
    85             border: 0;
    86             color: white;
    87             padding: 0 1200px;
    88         }
    89 
    9077        .wishlist-content {
    9178            margin-top: 60px;
    9279            color: white;
    9380        }
     81        #app {
     82            text-align: center;
    9483
     84        }
    9585        ul {
    9686            list-style-type: none;
     87            border: 2px solid rebeccapurple;
     88            width: 80%; /* Adjust the width as needed */
     89            background-color: rebeccapurple;
     90            position: relative;
     91            display: flex;
     92            flex-direction: column; /* Stack items vertically */
     93            align-items: center; /* Center horizontally */
     94            justify-content: center; /* Center vertically */
     95            padding: 20px;
     96            border-radius: 15px;
     97            margin: 0 auto; /* Center the ul itself */
     98            text-align: center; /* Center text inside the ul */
    9799        }
    98100
    99101        li {
    100             margin: 10px 0;
    101             font-size: 18px;
     102            font-size: 14px;
     103            display: block; /* Make each item block-level */
     104            padding: 10px;
     105            width: 100%; /* Make li take full width inside ul */
    102106        }
     107
     108
     109        .book {
     110            background-color: white;
     111            color: rebeccapurple;
     112            width: 5em;
     113            height: 3em;
     114            align-content: center;
     115            font-size: 14px;
     116        }
     117
    103118    </style>
    104119</head>
     
    107122    <img src="/images/home.png" alt="Home Icon">
    108123    <h1>SkyChase</h1>
    109     <button class="adminlogin" onclick="location.href='/admin'">Admin?</button>
     124    <button @click="home">Log Out</button>
    110125</div>
    111126
    112 <div class="wishlist-content">
     127<div id="app" class="wishlist-content">
    113128    <h1>Your Wishlist</h1>
    114129    <ul>
    115130        <li v-if="wishlist.length === 0">Your wishlist is empty!</li>
    116         <li v-else v-for="item in wishlist" :key="item.wishlistID">{{ item.targetId }} || {{item.userId}}</li>
     131        <li v-else v-for="item in wishlist" :key="item.wishlistID">
     132            Wishlist ID: {{ item.wishlistID }} | Added on: {{ item.date_added }}
     133            <br>
     134            <br>
     135            <button @click="bookFlights"  class="book">
     136                Book
     137            </button>
     138        </li>
    117139    </ul>
    118140</div>
    119 
    120 <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    121141
    122142<script>
     
    124144        el: '#app',
    125145        data: {
    126             userId: ''
     146            userId: '',
     147            wishlist: [] // Array to hold the wishlist items
    127148        },
    128149        mounted() {
     
    131152            this.fetchWishlist();
    132153        },
    133         async fetchWishlist() {
    134             try {
    135                 const response = await fetch(`/api/wishlists/${this.userId}`);
    136                 const wishlist = await response.json();
     154        methods: {
     155            async fetchWishlist() {
     156                try {
     157                    const response = await fetch(`/api/wishlists/${this.userId}`);
     158                    this.wishlist = await response.json(); // Directly assign the result to the wishlist data
     159                } catch (error) {
     160                    console.error('Error fetching wishlist:', error);
     161                }
     162            },
     163            bookFlights() {
     164                if (!this.selectedFlights.length) {
     165                    alert("Please select at least one flight.");
     166                    return;
     167                }
    137168
    138                 const wishlistElement = document.getElementById('wishlist');
    139                 const emptyMessage = document.getElementById('empty-message');
     169                const flight = this.selectedFlights[0];
     170                console.log(flight);
     171                const totalCost = flight.price;
    140172
    141                 if (wishlist.length === 0) {
    142                     emptyMessage.style.display = 'block';
    143                 } else {
    144                     emptyMessage.style.display = 'none';
    145                     wishlistElement.innerHTML = wishlist.map(item => `<li>${item.name}</li>`).join('');
    146                 }
    147             } catch (error) {
    148                 console.error('Error fetching wishlist:', error);
     173                const bookingData = {
     174                    flightId: flight.flightID,
     175                    bookingDate: new Date().toISOString().split('T')[0],
     176                    status: 'PENDING',
     177                    totalCost: totalCost,
     178                    userId:this.userId
     179                };
     180                axios.post('/api/bookings', bookingData)
     181                    .then(response => {
     182                        const bookingID = response.data.bookingId;
     183                        alert("Booked successfully!");
     184                        window.location.href = `/transaction?amount=${encodeURIComponent(totalCost)}&bookingId=${encodeURIComponent(bookingID)}&flightId=${encodeURIComponent(flight.flightID)}&userId=${encodeURIComponent(this.userId)}`;
     185                    })
     186                    .catch(error => {
     187                        console.error("Error booking flight", error);
     188                        alert("There was an error creating your booking. Please try again.");
     189                    });
    149190            }
    150191        }
    151     })
    152     //window.onload = fetchWishlist;
     192    });
    153193</script>
    154194</body>
Note: See TracChangeset for help on using the changeset viewer.