- Timestamp:
- 02/23/25 20:37:56 (3 months ago)
- Branches:
- master
- Children:
- fda671c
- Parents:
- de83113
- git-author:
- ste08 <sjovanoska@…> (02/23/25 20:37:23)
- git-committer:
- ste08 <sjovanoska@…> (02/23/25 20:37:56)
- Location:
- src/main
- Files:
-
- 2 added
- 2 deleted
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/com/example/skychasemk/controller/TopMonthlyReportController.java
rde83113 r62bba0c 2 2 3 3 import com.example.skychasemk.model.TopMonthlyReport; 4 import com.example.skychasemk. services.TopMonthlyReportService;4 import com.example.skychasemk.repository.TopMonthlyReportRepository; 5 5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.ui.Model; 6 7 import org.springframework.web.bind.annotation.*; 7 8 8 import java.time.LocalDate;9 9 import java.util.List; 10 10 11 11 @RestController 12 @RequestMapping("/api/reports") 13 @CrossOrigin("*") 12 @RequestMapping("/api/views") 14 13 public class TopMonthlyReportController { 15 14 @Autowired 16 private TopMonthlyReportService service; 15 private TopMonthlyReportRepository repository; 16 17 17 18 @GetMapping 18 public String getReportsPage() {19 return "TopMonthlyReport";19 public List<TopMonthlyReport> getAllReports() { 20 return repository.findAll(); 20 21 } 21 22 22 @GetMapping("/top-monthly")23 public List<TopMonthlyReport> getAllReports() {24 return service.getAllReports();25 }26 27 @GetMapping("/top-monthly/{month}")28 public List<TopMonthlyReport> getReportsByMonth(@PathVariable String month) {29 return service.getReportsByMonth(LocalDate.parse(month));30 }31 23 } -
src/main/java/com/example/skychasemk/controller/WishlistController.java
rde83113 r62bba0c 18 18 private WishlistService wishlistService; 19 19 20 @GetMapping ("/wishlists-all")20 @GetMapping 21 21 public List<Wishlist> getAllWishlists() { 22 22 return wishlistService.getAllWishlists(); … … 27 27 } 28 28 29 @DeleteMapping("/wishlist/{id}") 30 public void deleteWishlist(@PathVariable("id") Integer wishlistID) { 31 wishlistService.deleteWishlist(wishlistID); 29 @DeleteMapping 30 public void deleteWishlist(@RequestParam("userId") Integer userId, @RequestParam("targetId") Integer targetId) { 31 wishlistService.deleteRecordFromWishlist(userId, targetId); 32 } 33 34 @GetMapping("/{userId}") 35 public ResponseEntity<List<Wishlist>> getWishlist(@RequestParam("userId") Long userId) { 36 List<Wishlist> wishlist = wishlistService.getAllItems(userId); 37 return ResponseEntity.ok(wishlist); 32 38 } 33 39 -
src/main/java/com/example/skychasemk/dto/SupportTicketDTO.java
rde83113 r62bba0c 1 1 package com.example.skychasemk.dto; 2 3 import lombok.Getter; 4 import lombok.Setter; 2 5 3 6 import java.time.LocalDate; … … 5 8 public class SupportTicketDTO { 6 9 10 // Getters and Setters 11 @Setter 12 @Getter 7 13 private Integer ticketID; 8 private Integer userI D;14 private Integer userId; 9 15 private String subject; 10 16 private String description; … … 20 26 } 21 27 22 // Getters and Setters 23 public Integer getTicketID() { 24 return ticketID; 28 public Integer getUserId() { 29 return userId; 25 30 } 26 31 27 public void setTicketID(Integer ticketID) { 28 this.ticketID = ticketID; 29 } 30 31 public Integer getUserID() { 32 return userID; 33 } 34 35 public void setUserID(Integer userID) { 36 this.userID = userID; 32 public void setUserId(Integer userId) { 33 this.userId = userId; 37 34 } 38 35 -
src/main/java/com/example/skychasemk/dto/WishlistDTO.java
rde83113 r62bba0c 1 1 package com.example.skychasemk.dto; 2 3 import lombok.Getter; 4 import lombok.Setter; 2 5 3 6 public class WishlistDTO { 4 7 5 private Integer userID; 6 private Integer targetID; 8 private Integer userId; 9 private Integer targetId; 10 @Setter 11 @Getter 7 12 private boolean wishlisted; 8 13 9 14 public Integer getUserID() { 10 return userI D;15 return userId; 11 16 } 12 17 13 18 public void setUserID(Integer userID) { 14 this.userI D= userID;19 this.userId = userID; 15 20 } 16 21 17 22 public Integer getTargetID() { 18 return targetI D;23 return targetId; 19 24 } 20 25 21 26 public void setTargetID(Integer targetID) { 22 this.targetI D= targetID;27 this.targetId = targetID; 23 28 } 24 29 25 public boolean isWishlisted() {26 return wishlisted;27 }28 29 public void setWishlisted(boolean wishlisted) {30 this.wishlisted = wishlisted;31 }32 30 } -
src/main/java/com/example/skychasemk/model/SupportTicket.java
rde83113 r62bba0c 3 3 import jakarta.persistence.*; 4 4 import lombok.Getter; 5 import lombok.Setter; 5 6 6 7 import java.time.LocalDate; … … 10 11 public class SupportTicket { 11 12 13 @Setter 12 14 @Id 13 15 @GeneratedValue(strategy = GenerationType.IDENTITY) … … 15 17 16 18 private Integer ticketID; 19 @Setter 17 20 @Getter 18 @Column(name = " UserID")21 @Column(name = "userid") 19 22 20 private Integer userI D;23 private Integer userId; 21 24 25 @Setter 22 26 @Getter 23 27 @Column(name = "Description") 24 28 25 29 private String description; 30 @Setter 31 26 32 @Getter 27 33 @Column(name = "status") 28 34 @Enumerated(EnumType.STRING) 29 35 private TicketStatus status; 36 @Setter 30 37 @Column(name = "date_created") 31 38 32 39 private LocalDate dateCreated; 40 @Setter 33 41 @Getter 34 42 @Column(name = "date_resolved") 35 43 36 44 private LocalDate dateResolved; 45 @Setter 37 46 @Column(name = "assigned_to") 38 47 … … 44 53 } 45 54 46 public TicketStatus getStatus() {47 return status;48 }49 50 public Integer getTicketID() {51 return ticketID;52 }53 54 public void setTicketID(Integer ticketID) {55 this.ticketID = ticketID;56 }57 58 public void setUserID(Integer userID) {59 this.userID = userID;60 }61 62 63 public void setDescription(String description) {64 this.description = description;65 }66 67 public void setStatus(TicketStatus status) {68 this.status = status;69 }70 55 71 56 public LocalDate getDateCreated(LocalDate now) { … … 73 58 } 74 59 75 public void setDateCreated(LocalDate dateCreated) {76 this.dateCreated = dateCreated;77 }78 79 public void setDateResolved(LocalDate dateResolved) {80 this.dateResolved = dateResolved;81 }82 83 public void setAssignedTo(Integer assignedTo) {84 this.assignedTo = assignedTo;85 }86 60 } -
src/main/java/com/example/skychasemk/model/TopMonthlyReport.java
rde83113 r62bba0c 1 1 package com.example.skychasemk.model; 2 2 3 import jakarta.persistence. Column;4 import jakarta.persistence.Entity;5 import jakarta.persistence.Id;6 import jakarta.persistence.Table;3 import jakarta.persistence.*; 4 import lombok.Getter; 5 import lombok.Setter; 6 import org.hibernate.annotations.Immutable; 7 7 8 8 import java.time.LocalDate; 9 9 @Setter 10 @Getter 10 11 @Entity 11 12 @Table(name="topmonhtlyreport") 13 @IdClass(TopMonthlyReportId.class) // Define composite key 14 12 15 public class TopMonthlyReport { 16 // Getters and Setters 13 17 @Id 14 18 @Column(name = "month") 15 19 private LocalDate month; 16 20 @Id 17 21 @Column(name = "category") 18 22 private String category; 19 23 @Id 20 24 @Column(name = "name") 21 25 private String name; 22 23 26 @Column(name = "count") 24 27 private int count; 25 28 26 // Getters and Setters27 public LocalDate getMonth() {28 return month;29 }30 31 public void setMonth(LocalDate month) {32 this.month = month;33 }34 35 public String getCategory() {36 return category;37 }38 39 public void setCategory(String category) {40 this.category = category;41 }42 43 public String getName() {44 return name;45 }46 47 public void setName(String name) {48 this.name = name;49 }50 51 public int getCount() {52 return count;53 }54 55 public void setCount(int count) {56 this.count = count;57 }58 29 } -
src/main/java/com/example/skychasemk/model/WebConfig.java
rde83113 r62bba0c 34 34 registry.addViewController("/transaction").setViewName("forward:/TransactionPage.html"); 35 35 registry.addViewController("/login").setViewName("forward:/UserLogin.html"); 36 registry.addViewController("/wishlist").setViewName("forward:/Wishlist Page.html");36 registry.addViewController("/wishlist").setViewName("forward:/Wishlist.html"); 37 37 registry.addViewController("/signup").setViewName("forward:/UserSignup.html"); 38 registry.addViewController("/views").setViewName("forward:/ViewReport.html"); 38 39 } 39 40 -
src/main/java/com/example/skychasemk/model/Wishlist.java
rde83113 r62bba0c 3 3 import jakarta.persistence.*; 4 4 import lombok.Getter; 5 import lombok.Setter; 5 6 6 7 import java.time.LocalDate; … … 16 17 17 18 private Integer wishlistID; 18 @Column(name = "userId") 19 @Setter 20 @Column(name = "userid") 19 21 20 private Integer userID; 21 @Column(name = "targetId") 22 private Integer userId; 23 @Setter 24 @Column(name = "targetid") 22 25 23 private Integer targetID; 26 private Integer targetId; 27 @Setter 28 @Getter 24 29 @Column(name = "date_added") 30 private LocalDate date_added; 25 31 26 private LocalDate dateAdded;27 32 28 public Integer getWishlistID() {29 return wishlistID;30 }31 32 public void setWishlistID(Integer wishlistID) {33 this.wishlistID = wishlistID;34 }35 36 public Integer getUserID() {37 return userID;38 }39 40 public void setUserID(Integer userID) {41 this.userID = userID;42 }43 44 public Integer getTargetID() {45 return targetID;46 }47 48 public void setTargetID(Integer targetID) {49 this.targetID = targetID;50 }51 52 public LocalDate getDateAdded() {53 return dateAdded;54 }55 56 public void setDateAdded(LocalDate dateAdded) {57 this.dateAdded = dateAdded;58 }59 33 } 60 34 -
src/main/java/com/example/skychasemk/repository/TopMonthlyReportRepository.java
rde83113 r62bba0c 3 3 import com.example.skychasemk.model.TopMonthlyReport; 4 4 import org.springframework.data.jpa.repository.JpaRepository; 5 import org.springframework.data.jpa.repository.Query; 5 6 import org.springframework.stereotype.Repository; 6 7 … … 10 11 @Repository 11 12 public interface TopMonthlyReportRepository extends JpaRepository<TopMonthlyReport, LocalDate> { 12 List<TopMonthlyReport> findByMonth(LocalDate month); 13 @Query("SELECT v FROM TopMonthlyReport v") 14 List<TopMonthlyReport> findAllRecords(); 15 13 16 } -
src/main/java/com/example/skychasemk/repository/WishlistRepository.java
rde83113 r62bba0c 4 4 import com.example.skychasemk.model.Flight; 5 5 import com.example.skychasemk.model.Wishlist; 6 import jakarta.transaction.Transactional; 6 7 import org.springframework.beans.factory.annotation.Autowired; 7 8 import org.springframework.data.jpa.repository.JpaRepository; 9 import org.springframework.data.jpa.repository.Modifying; 8 10 import org.springframework.data.jpa.repository.Query; 11 import org.springframework.data.repository.query.Param; 9 12 import org.springframework.jdbc.core.JdbcTemplate; 10 13 import org.springframework.stereotype.Repository; 14 15 import java.util.List; 11 16 12 17 @Repository 13 18 public interface WishlistRepository extends JpaRepository<Wishlist, Integer> { 14 19 15 @Query("SELECT w FROM Wishlist w WHERE w.targetI D = :targetId AND w.userID= :userId")20 @Query("SELECT w FROM Wishlist w WHERE w.targetId = :targetId AND w.userId = :userId") 16 21 Wishlist findByTargetIdAndUserId(Integer targetId, Integer userId); 22 23 @Query("SELECT w FROM Wishlist w WHERE w.userId = :userId") 24 List<Wishlist> findWishlistByUserId(@Param("userId") Long userId); 25 26 @Modifying 27 @Transactional 28 @Query("DELETE FROM Wishlist w WHERE w.userId = :userId AND w.targetId = :targetId") 29 void deleteByUserIdAndTargetId(@Param("userId") Integer userId, @Param("targetId") Integer targetId); 30 17 31 } -
src/main/java/com/example/skychasemk/services/SupportTicketService.java
rde83113 r62bba0c 39 39 public SupportTicket createTicket(@RequestBody SupportTicketDTO dto) { 40 40 SupportTicket ticket = new SupportTicket(); 41 ticket.setUserId(dto.getUserId()); 41 42 ticket.setDateCreated(LocalDate.now()); 42 43 ticket.setStatus(OPEN); 43 44 ticket.setDescription(dto.getDescription()); 44 45 45 return supportTicketRepository.save(ticket); 46 46 } -
src/main/java/com/example/skychasemk/services/TopMonthlyReportService.java
rde83113 r62bba0c 15 15 16 16 public List<TopMonthlyReport> getAllReports() { 17 return repository.findAll(); 18 } 19 20 public List<TopMonthlyReport> getReportsByMonth(LocalDate month) { 21 return repository.findByMonth(month); 17 return repository.findAllRecords(); 22 18 } 23 19 } -
src/main/java/com/example/skychasemk/services/WishlistService.java
rde83113 r62bba0c 2 2 3 3 import com.example.skychasemk.dto.WishlistDTO; 4 import com.example.skychasemk.model.Booking; 4 5 import com.example.skychasemk.model.Flight; 5 6 import com.example.skychasemk.model.Wishlist; … … 7 8 import com.example.skychasemk.repository.WishlistRepository; 8 9 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.http.HttpStatus; 11 import org.springframework.http.ResponseEntity; 9 12 import org.springframework.stereotype.Service; 13 import org.springframework.web.bind.annotation.PostMapping; 14 import org.springframework.web.bind.annotation.RequestBody; 10 15 11 16 import java.time.LocalDate; … … 26 31 } 27 32 33 28 34 public Wishlist saveWishlist(Wishlist wishlist) { 35 if (wishlist == null) { 36 throw new IllegalArgumentException("Wishlist cannot be null"); 37 } 38 wishlist.setDate_added(LocalDate.now()); 29 39 return wishlistRepository.save(wishlist); 30 40 } 31 41 32 public void deleteWishlist(Integer wishlistID) {33 wishlistRepository.deleteById(wishlistID);34 }35 42 36 43 public void updateWishlist(WishlistDTO wishlistRequest) { … … 43 50 if (existingItem == null) { 44 51 Wishlist newWishlistItem = new Wishlist(); 45 newWishlistItem.setTargetI D(Math.toIntExact(wishlistRequest.getTargetID()));46 newWishlistItem.setUserI D(wishlistRequest.getUserID());47 newWishlistItem.setDate Added(LocalDate.now());52 newWishlistItem.setTargetId(Math.toIntExact(wishlistRequest.getTargetID())); 53 newWishlistItem.setUserId(wishlistRequest.getUserID()); 54 newWishlistItem.setDate_added(LocalDate.now()); 48 55 wishlistRepository.save(newWishlistItem); 49 56 } … … 57 64 } 58 65 66 public List<Wishlist> getAllItems(Long userId) { 67 return wishlistRepository.findWishlistByUserId(userId); 68 } 69 70 public void deleteRecordFromWishlist(Integer userId, Integer targetId) { 71 wishlistRepository.deleteByUserIdAndTargetId(userId, targetId); 72 } 59 73 } 60 74 -
src/main/resources/static/FlightSearch.html
rde83113 r62bba0c 113 113 padding: 10px; 114 114 color:white; 115 font-family: Cambria ;115 font-family: Cambria,sans-serif; 116 116 } 117 117 .search { … … 170 170 align-items: center; 171 171 justify-content: center; 172 z-index: 1000; 173 overflow:hidden; 174 } 175 176 .popup textarea{ 177 width: 100%; 178 padding: 10px; 179 margin-top: 10px; 180 border: 1px solid #ccc; 181 border-radius: 4px; 182 resize: vertical; 183 box-sizing: border-box; 172 184 } 173 185 … … 209 221 <button @click="showReportPopup">Report Issue</button> 210 222 <button @click="goToWishlistPage">🤍</button> 223 <button @click="goToReports">Monthly Report</button> 211 224 <button @click="home">Log Out</button> 212 225 </header> … … 296 309 showPopup: false, 297 310 issueDescription: '', 298 userId:'' 311 userId:'', 312 wishlisted:false 299 313 }, 300 314 computed: { … … 363 377 window.location.href = '/'; 364 378 }, 379 goToReports(){ 380 window.location.href = '/views' 381 }, 365 382 async toggleWishlist(flight) { 366 383 flight.wishlisted = !flight.wishlisted; 384 this.$set(this.flights, this.flights.indexOf(flight), flight); 367 385 const wishlistData = { 368 targetId: flight.flightId,369 wishlisted: flight.wishlisted386 userId: parseInt(this.userId), 387 targetId: flight.flightID 370 388 }; 371 try { 372 await axios.post('/api/wishlists', wishlistData); 373 } catch (error) { 374 console.error("Error updating wishlist:", error); 389 console.log(wishlistData); 390 if (!flight.wishlisted) { 391 try { 392 await axios.delete('/api/wishlists', { params: wishlistData }); 393 console.log("Removed from wishlist"); 394 } catch (error) { 395 console.error("Error removing from wishlist:", error); 396 } 397 } else { 398 try { 399 await axios.post('/api/wishlists/add', wishlistData); 400 console.log("Added to wishlist"); 401 } catch (error) { 402 console.error("Error adding to wishlist:", error); 403 } 375 404 } 376 405 }, 377 goToWishlistPage() { 378 window.location.href = '/api/wishlists'; 406 async goToWishlistPage() { 407 window.location.href = `/api/wishlists?userId=${encodeURIComponent(this.userId)}`; 408 379 409 }, 380 410 showReportPopup() { … … 387 417 if (this.issueDescription.trim()) { 388 418 const reviewData = { 389 userI D: this.userId,419 userId: this.userId, 390 420 subject: "Issue Report", 391 421 description: this.issueDescription -
src/main/resources/static/Wishlist.html
rde83113 r62bba0c 4 4 <meta charset="UTF-8"> 5 5 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 6 <title>SkyChase-mk</title> 6 <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script> 7 <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> 8 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> 9 <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> 7 12 <style> 8 13 body { … … 24 29 display: flex; 25 30 align-items: center; 26 background-color: rebeccapurple;31 background-color: rebeccapurple; 27 32 padding: 10px; 28 33 width: 100%; … … 73 78 background-color: #0056b3; 74 79 } 80 75 81 .adminlogin { 76 top: 0;82 top: 0; 77 83 right: 0; 78 84 background-color: rebeccapurple; 79 border: 0;80 color: white;85 border: 0; 86 color: white; 81 87 padding: 0 1200px; 88 } 89 90 .wishlist-content { 91 margin-top: 60px; 92 color: white; 93 } 94 95 ul { 96 list-style-type: none; 97 } 98 99 li { 100 margin: 10px 0; 101 font-size: 18px; 82 102 } 83 103 </style> … … 90 110 </div> 91 111 92 <div class="buttons"> 93 <h1>Test</h1> 112 <div class="wishlist-content"> 113 <h1>Your Wishlist</h1> 114 <ul> 115 <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> 117 </ul> 94 118 </div> 119 120 <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script> 121 122 <script> 123 new Vue({ 124 el: '#app', 125 data: { 126 userId: '' 127 }, 128 mounted() { 129 const params = new URLSearchParams(window.location.search); 130 this.userId = params.get("userId"); 131 this.fetchWishlist(); 132 }, 133 async fetchWishlist() { 134 try { 135 const response = await fetch(`/api/wishlists/${this.userId}`); 136 const wishlist = await response.json(); 137 138 const wishlistElement = document.getElementById('wishlist'); 139 const emptyMessage = document.getElementById('empty-message'); 140 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); 149 } 150 } 151 }) 152 //window.onload = fetchWishlist; 153 </script> 95 154 </body> 96 155 </html>
Note:
See TracChangeset
for help on using the changeset viewer.