Changeset 3a74959


Ignore:
Timestamp:
03/26/25 00:25:45 (2 months ago)
Author:
ste08 <sjovanoska@…>
Branches:
master
Children:
ff72ad2
Parents:
8a947b9
Message:

Review page added

Location:
src/main
Files:
5 edited

Legend:

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

    r8a947b9 r3a74959  
    22
    33import com.example.skychasemk.dto.ReviewDTO;
     4import com.example.skychasemk.model.Notification;
    45import com.example.skychasemk.model.Review;
    56import com.example.skychasemk.repository.ReviewRepository;
     
    2728    }
    2829
    29 
    30     @GetMapping("/{flightId}")
    31     public List<Review> getReviewsByFlightId(@PathVariable("flightId") Integer flightId) {
    32         return reviewRepository.findReviews(flightId);
    33     }
    34 
    35     // Get review by ID
    36     @GetMapping("/{id}")
    37     public Optional<Review> getReviewById(@PathVariable("id") Integer reviewID) {
    38         return reviewService.getReviewById(reviewID);
     30    @GetMapping("/{userId}")
     31    public ResponseEntity<List<Review>> getReviewsByFlightId(@PathVariable Integer userId) {
     32        List<Review> reviews = reviewRepository.findByUserId(userId);
     33        return ResponseEntity.ok(reviews);
    3934    }
    4035
  • src/main/java/com/example/skychasemk/model/Review.java

    r8a947b9 r3a74959  
    55
    66@Entity
    7 @Table(name="Review")
     7@Table(name="review")
    88public class Review {
    99
    1010    @Id
    1111    @GeneratedValue(strategy = GenerationType.IDENTITY)
    12     @Column(name = "reviewId")
     12    @Column(name = "reviewid")
    1313
    1414    private Integer reviewID;
    15     @Column(name = "userId")
     15    @Column(name = "userid")
    1616
    1717    private Integer userID;
    18     @Column(name = "targetId")
     18    @Column(name = "targetid")
    1919
    2020    private Integer targetID;
  • src/main/java/com/example/skychasemk/repository/ReviewRepository.java

    r8a947b9 r3a74959  
    11package com.example.skychasemk.repository;
    22
     3import com.example.skychasemk.model.Notification;
    34import com.example.skychasemk.model.Review;
    45import org.springframework.data.jpa.repository.JpaRepository;
     
    1112    @Query("SELECT r from Review r where r.targetID = :flightId")
    1213    List<Review> findReviews(@Param("flightId") Integer flightId);
     14
     15    @Query("SELECT r FROM Review r WHERE r.userID = :userId")
     16    List<Review> findByUserId(@Param("userId") Integer userId);
    1317}
    1418
  • src/main/resources/static/FlightSearch.html

    r8a947b9 r3a74959  
    277277        <button @click="goToWishlistPage">🤍</button>
    278278        <button @click="goToReports">Monthly Report</button>
     279        <button @click="goToReviews">Reviews</button>
    279280        <button @click="home">Log Out</button>
    280281
     
    375376            places: [],
    376377            bookings: [],
     378            pastBookings: [],
    377379            showReturnDate: false,
    378380            showPopup: false,
     
    528530                    console.error("Error fetching Destinations", error);
    529531                }
     532            },
     533            goToReviews(){
     534                window.location.href = `/reviews?userId=${encodeURIComponent(this.userId)}`;
    530535            }
    531536        },
  • src/main/resources/static/ReviewPage.html

    r8a947b9 r3a74959  
    77    <link rel="stylesheet" href="/css/main.css">
    88    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
     9    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
     10    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
     11    <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/css/all.min.css'>
     12    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet">
    913</head>
     14<style>
     15    .popup-overlay {
     16        position: fixed;
     17        top: 0;
     18        left: 0;
     19        width: 100%;
     20        height: 100%;
     21        background: rgba(0, 0, 0, 0.7);
     22        display: flex;
     23        align-items: center;
     24        justify-content: center;
     25        z-index: 1000;
     26        overflow:hidden;
     27    }
     28
     29    .popup textarea{
     30        width: 100%;
     31        padding: 10px;
     32        margin-top: 10px;
     33        border: 1px solid #ccc;
     34        border-radius: 4px;
     35        resize: vertical;
     36        box-sizing: border-box;
     37    }
     38
     39    .popup {
     40        background-color: white;
     41        padding: 20px;
     42        width: 300px;
     43        border-radius: 10px;
     44    }
     45
     46    .popup button {
     47        margin-top: 10px;
     48        background-color: rebeccapurple;
     49        color: white;
     50        border: none;
     51        padding: 5px;
     52        cursor: pointer;
     53    }
     54
     55    .popup button:hover {
     56        background-color: mediumpurple;
     57    }
     58
     59    .popup select {
     60        width: 100%;
     61        padding: 8px;
     62        margin: 10px 0;
     63        border-radius: 4px;
     64        border: 1px solid #ccc;
     65    }
     66
     67    .popup select:focus {
     68        outline: none;
     69        border-color: #007bff;
     70    }
     71
     72</style>
    1073<body>
    1174
     
    1376    <header class="app-header">
    1477        <button class="logout-btn" @click="logout">Log Out</button>
     78        <button class="logout-btn" @click="leaveReview">Leave a review</button>
    1579    </header>
    1680
     
    2084
    2185            <div class="review-list">
    22                 <div v-for="review in reviews" :key="review.id" class="review-item">
    23                     <h3>{{ review.subject }}</h3>
    24                     <p>{{ review.description }}</p>
    25                     <span>{{ review.date }}</span>
     86                <div v-for="review in reviews" :key="review.reviewid" class="review-item">
     87                    <h3>{{ review.date }}</h3>
     88                    <p>{{ review.reviewComment }}</p>
     89                    <span>{{ review.rating }}</span>
    2690                </div>
    2791            </div>
     92        </div>
     93    </div>
     94</div>
     95
     96<div v-if="showPopup" class="popup-overlay">
     97    <div class="popup">
     98        <h3>Leave a review</h3>
     99
     100        <select v-model="selectedFlightNumber" id="flights">
     101            <option value="" disabled selected>Select a flight</option>
     102            <option v-for="flight in flights" :key="flight.flightNumber" :value="flight.flightNumber">
     103                {{ flight.flightNumber }}
     104            </option>
     105        </select>
     106
     107        <textarea v-model="reviewComment" placeholder="Leave a comment here..." rows="5"></textarea>
     108
     109        <textarea v-model="rating" placeholder="Rate 1-5" rows="1"></textarea>
     110
     111        <div class="popup-actions">
     112            <button @click="submitReview" class="submit-btn">Submit</button>
     113            <button @click="closePopup" class="cancel-btn">Cancel</button>
    28114        </div>
    29115    </div>
     
    34120        el: '#app',
    35121        data: {
    36             reviews: [
    37                 {
    38                     id: 1,
    39                     subject: 'Great experience!',
    40                     description: 'The flight was amazing, the service was excellent, and the views were breathtaking.',
    41                     date: '2025-02-01',
    42                 },
    43                 {
    44                     id: 2,
    45                     subject: 'Good but delayed',
    46                     description: 'The flight was comfortable, but it was delayed by two hours, which caused some inconvenience.',
    47                     date: '2025-02-02',
    48                 },
    49                 {
    50                     id: 3,
    51                     subject: 'Okay, but not perfect',
    52                     description: 'Everything was fine, but the food options could have been better.',
    53                     date: '2025-02-03',
    54                 },
    55             ]
     122            userId: '',
     123            reviews: [],
     124            showPopup: false,
     125            reviewComment: '',
     126            rating: '',
     127            flights: [],
     128            selectedFlightNumber: ''
    56129        },
    57130        methods: {
    58131            logout() {
    59132                window.location.href = '/';
     133            },
     134            async fetchReviews() {
     135                try {
     136                    const response = await axios.get("api/reviews");
     137                    this.reviews = response.data;
     138                } catch (error) {
     139                    console.error(error);
     140                }
     141            },
     142            leaveReview() {
     143                this.showPopup = true;
     144            },
     145            closePopup() {
     146                this.showPopup = false;
     147            },
     148            submitReview() {
     149                if (this.reviewComment.trim() && this.selectedFlightNumber) {
     150                    const reviewData = {
     151                        userId: this.userId,
     152                        flightNumber: this.selectedFlightNumber,
     153                        reviewComment: this.reviewComment,
     154                        rating: this.rating
     155                    };
     156
     157                    axios.post('/api/reviews', reviewData)
     158                        .then(response => {
     159                            alert("Review added successfully!");
     160                            this.closePopup();
     161                        })
     162                        .catch(error => {
     163                            console.error("Error submitting review:", error);
     164                            alert("There was an error submitting your review. Please try again.");
     165                        });
     166                }
     167            },
     168            async fetchFlights() {
     169                try {
     170                    const response = await axios.get('/api/flights');
     171                    this.flights = response.data;
     172                    console.log(this.flights);
     173                } catch (error) {
     174                    console.error('Error fetching flights:', error);
     175                }
    60176            }
    61177        },
    62178        mounted() {
    63             axios.get('api/reviews')
    64                 .then(response => {
    65                     this.review = response.data;
    66                 })
    67                 .catch(error => {
    68                     console.error("Error fetching reviews", error);
    69                 });
     179            const params = new URLSearchParams(window.location.search);
     180            this.userId = params.get("userId");
     181            this.fetchReviews();
     182            this.fetchFlights();
    70183        }
    71184    });
Note: See TracChangeset for help on using the changeset viewer.