diff --git a/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/controllers/InteractiveController.java b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/controllers/InteractiveController.java new file mode 100644 index 0000000000000000000000000000000000000000..c9b013cb4319464ba3d28bbf7cb048b08130b49a --- /dev/null +++ b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/controllers/InteractiveController.java @@ -0,0 +1,176 @@ +package vt.CS5934.SwitchRoom.controllers; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.*; +import vt.CS5934.SwitchRoom.models.InteractionModel; +import vt.CS5934.SwitchRoom.models.MatchedWishlistRecordModel; +import vt.CS5934.SwitchRoom.models.ResponseModel; +import vt.CS5934.SwitchRoom.models.UserOfferModel; +import vt.CS5934.SwitchRoom.services.InteractionService; +import vt.CS5934.SwitchRoom.services.MatchedWishlistRecordService; +import vt.CS5934.SwitchRoom.utility.LookupTables; + +import java.util.Map; + +/** + * The "@RestController" made the class into rest handle class + * The "@RequestMapping("example")" on the class level make it only react to url ".../example/..." + */ +@CrossOrigin( + allowCredentials = "true", + origins = {"http://localhost:8080/"} +) +@RestController +@RequestMapping("interactive") +public class InteractiveController { + + /** + * You can use logger.[trace,debug,info,warn,error]("messages") to log into file + */ + private final Logger logger = LoggerFactory.getLogger(UserController.class); + @Autowired + InteractionService interactionService; + + @Autowired + MatchedWishlistRecordService matchedWishlistRecordService; + + /** + * This function will handle the post function and change the JSON body into data class + * @param newData the JSON input in the request body + */ + @PostMapping("/newData") + public ResponseModel handlePost(@RequestBody Map<String, Object> newData) { + logger.info("You reached the handlePost() functions."); + System.out.println(newData); + ResponseModel response = new ResponseModel(); + InteractionModel back = null; + try{ + InteractionModel result = interactionService.searchBothIdFromDB(newData.get("offerId").toString(), newData.get("wishlistId").toString()); + if(result == null) { + back = interactionService.addDataToDB(Integer.parseInt(newData.get("userId").toString()), null, newData.get("phone").toString(), null, false, newData.get("offerId").toString(), newData.get("wishlistId").toString()); + if(newData.get("see").toString() == "offer") { + MatchedWishlistRecordModel history = matchedWishlistRecordService.getHistoryFromDB(Long.parseLong(newData.get("offerId").toString()), Long.parseLong(newData.get("wishlistId").toString())); + history.setOfferResult(LookupTables.MATCHING_RECORD_USER_RESULT.Accepted); + matchedWishlistRecordService.updateToDB(history); + } else { + MatchedWishlistRecordModel history = matchedWishlistRecordService.getHistoryFromDB(Long.parseLong(newData.get("offerId").toString()), Long.parseLong(newData.get("wishlistId").toString())); + history.setWishlistResult(LookupTables.MATCHING_RECORD_USER_RESULT.Accepted); + matchedWishlistRecordService.updateToDB(history); + } + } else { + if(result.getPhone1() == null) { + result.setUserId2(Integer.parseInt(newData.get("userId").toString())); + result.setPhone2(newData.get("phone").toString()); + result.setJudgement(false); + InteractionModel resultAfterUpdate = interactionService.updateToDB(result); + back = resultAfterUpdate; + } else { + result.setPhone2(newData.get("phone").toString()); + result.setJudgement(true); + result.setUserId2(Integer.parseInt(newData.get("userId").toString())); + InteractionModel resultAfterUpdate = interactionService.updateToDB(result); + back = resultAfterUpdate; + System.out.println("what is that?"); + MatchedWishlistRecordModel history = matchedWishlistRecordService.getHistoryFromDB(Long.parseLong(newData.get("offerId").toString()), Long.parseLong(newData.get("wishlistId").toString())); + System.out.println("why this happened " + history.toString()); + } + if(newData.get("see").toString() == "offer") { + MatchedWishlistRecordModel history = matchedWishlistRecordService.getHistoryFromDB(Long.parseLong(newData.get("offerId").toString()), Long.parseLong(newData.get("wishlistId").toString())); + history.setOfferResult(LookupTables.MATCHING_RECORD_USER_RESULT.Accepted); + matchedWishlistRecordService.updateToDB(history); + } else { + MatchedWishlistRecordModel history = matchedWishlistRecordService.getHistoryFromDB(Long.parseLong(newData.get("offerId").toString()), Long.parseLong(newData.get("wishlistId").toString())); + history.setWishlistResult(LookupTables.MATCHING_RECORD_USER_RESULT.Accepted); + matchedWishlistRecordService.updateToDB(history); + } + } + response.setMessage("Saved successfully"); + response.setStatus(HttpStatus.OK); + response.setData(back); + return response; + }catch (Exception e){ + return new ResponseModel( + "Error happen", + HttpStatus.OK, + null); + } + } + + /** + * This function will handle the post function and change the JSON body into data class + */ + @GetMapping("/{userId}") + public ResponseModel getInteraction(@PathVariable Integer userId) { + logger.info("You reached the getInteraction() function."); + try{ + InteractionModel[] tranBack = interactionService.findAllInteractionsFromDB(userId); + return new ResponseModel( + "This is a Interaction array response", + HttpStatus.OK, + tranBack); + }catch (Exception e){ + return new ResponseModel( + "Error occur on get All ExampleModels, Error info is: " + e, + HttpStatus.OK, + null); + } + } + + /** + * This function will handle the post function and change the JSON body into data class + * @param newData the JSON input in the request body + */ + @PostMapping("/disagree") + public ResponseModel disagreePost(@RequestBody Map<String, Object> newData) { + logger.info("You reached the disagreePost() functions."); + ResponseModel response = new ResponseModel(); + InteractionModel back; + try{ + InteractionModel result = interactionService.searchBothIdFromDB(newData.get("offerId").toString(), newData.get("wishlistId").toString()); + System.out.println(result); + if(result == null) { + back = interactionService.addDataToDB(Integer.parseInt(newData.get("userId").toString()), null, null, null, false, newData.get("offerId").toString(), newData.get("wishlistId").toString()); + if(newData.get("see").toString() == "offer") { + MatchedWishlistRecordModel history = matchedWishlistRecordService.getHistoryFromDB(Long.parseLong(newData.get("offerId").toString()), Long.parseLong(newData.get("wishlistId").toString())); + history.setOfferResult(LookupTables.MATCHING_RECORD_USER_RESULT.Declined); + matchedWishlistRecordService.updateToDB(history); + } else { + MatchedWishlistRecordModel history = matchedWishlistRecordService.getHistoryFromDB(Long.parseLong(newData.get("offerId").toString()), Long.parseLong(newData.get("wishlistId").toString())); + history.setWishlistResult(LookupTables.MATCHING_RECORD_USER_RESULT.Declined); + matchedWishlistRecordService.updateToDB(history); + } + } else { + if(result.getPhone1() == null) { + result.setUserId2(Integer.parseInt(newData.get("userId").toString())); + InteractionModel resultAfterUpdate = interactionService.updateToDB(result); + back = resultAfterUpdate; + } else { + result.setUserId2(Integer.parseInt(newData.get("userId").toString())); + InteractionModel resultAfterUpdate = interactionService.updateToDB(result); + back = resultAfterUpdate; + } + if(newData.get("see").toString() == "offer") { + MatchedWishlistRecordModel history = matchedWishlistRecordService.getHistoryFromDB(Long.parseLong(newData.get("offerId").toString()), Long.parseLong(newData.get("wishlistId").toString())); + history.setOfferResult(LookupTables.MATCHING_RECORD_USER_RESULT.Declined); + matchedWishlistRecordService.updateToDB(history); + } else { + MatchedWishlistRecordModel history = matchedWishlistRecordService.getHistoryFromDB(Long.parseLong(newData.get("offerId").toString()), Long.parseLong(newData.get("wishlistId").toString())); + history.setWishlistResult(LookupTables.MATCHING_RECORD_USER_RESULT.Declined); + matchedWishlistRecordService.updateToDB(history); + } + } + response.setMessage("Saved successfully"); + response.setStatus(HttpStatus.OK); + response.setData(back); + return response; + }catch (Exception e){ + return new ResponseModel( + "Error happen", + HttpStatus.OK, + null); + } + } +} diff --git a/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/controllers/MatchedOfferController.java b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/controllers/MatchedOfferController.java index bede6a5b3582fe55bae9dc9970565ceda78f2872..e42a76c050d34d29ec4f267b7bc719796a92cdcf 100644 --- a/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/controllers/MatchedOfferController.java +++ b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/controllers/MatchedOfferController.java @@ -40,7 +40,6 @@ public class MatchedOfferController { @GetMapping("/{offerId}") public ResponseModel getOffer(@PathVariable long offerId) { logger.info("You reached the getOffer() function."); - System.out.println(offerId); try{ UserOfferModel offer = offerPageService.getUserOfferInfo(offerId); // List<MatchedWishlistRecordModel> offerNotifications = matchedWishlistRecordService.getOfferListWithIDFromDB(userId); diff --git a/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/controllers/MatchedWishListController.java b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/controllers/MatchedWishListController.java index ed7cdec427db88bddd53d6e26e252d540f32546c..d38fb63316ce1dc512a9fa93673a8059c79baa8c 100644 --- a/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/controllers/MatchedWishListController.java +++ b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/controllers/MatchedWishListController.java @@ -40,7 +40,6 @@ public class MatchedWishListController { @GetMapping("/{wishlistId}") public ResponseModel getWishList(@PathVariable long wishlistId) { logger.info("You reached the getWishList() function."); - System.out.println(wishlistId); try{ WishlistItemModel wishlist = wishlistPageService.getWishlistItemInfo(wishlistId); return new ResponseModel( diff --git a/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/controllers/NotificationController.java b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/controllers/NotificationController.java index 7080bc3e0e6f6aee73a805d845c6ddc34fbc3de8..f166e2290f8750fa7819edba9ca2690f4e31a52d 100644 --- a/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/controllers/NotificationController.java +++ b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/controllers/NotificationController.java @@ -87,7 +87,6 @@ public class NotificationController { // System.out.println(userId); try{ List<UserOfferWishlistLookUpModel> lookup = offerWishlistLookUpService.getOfferWishlistLookUpWithIDFromDB(userId); - System.out.println(lookup); List<MatchedWishlistRecordModel> wishlists = dealWithWishlist.getMatchedWishlist(lookup); // List<MatchedWishlistRecordModel> offerNotifications = matchedWishlistRecordService.getOfferListWithIDFromDB(userId); // List<ExampleModel> exampleModels = exampleService.getAllExampleModelsFromDB(); diff --git a/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/models/InteractionModel.java b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/models/InteractionModel.java new file mode 100644 index 0000000000000000000000000000000000000000..f4685fd402e494c2c7c9491882043745ada160a9 --- /dev/null +++ b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/models/InteractionModel.java @@ -0,0 +1,66 @@ +package vt.CS5934.SwitchRoom.models; + +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.*; + +/** + * '@Data' tell spring this class can be map to JSON object if needed + * '@Entity' declare this class is a DB table + * '@Table(name=<table_name>)' declared which table stores its data + */ +@Data +@Entity +@Table(name = "Interaction") +@NoArgsConstructor +public class InteractionModel { + @Id + @Column(name="id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long userId; + @Column(name="user_id1") + private Integer userId1; + + @Column(name="user_id2") + private Integer userId2; + + @Column(name="phone1") + private String phone1; + + @Column(name="phone2") + private String phone2; + + @Column(name="judgement") + private Boolean judgement; + + @Column(name="offerId") + private String offerId; + + @Column(name="wishlistId") + private String wishlistId; + + + public InteractionModel(Integer userId1, Integer userId2, String phone1, String phone2, Boolean judgement, String offerId, String wishlistId) { + this.userId1 = userId1; + this.userId2 = userId2; + this.phone1 = phone1; + this.phone2 = phone2; + this.judgement = judgement; + this.offerId = offerId; + this.wishlistId = wishlistId; + } + + @Override + public String toString() { + return "InteractionModel{" + + "userId1=" + userId1 + + ", userId2=" + userId2 + + ", phone1='" + phone1 + '\'' + + ", phone2='" + phone2 + '\'' + + ", judgement=" + judgement + '\'' + + ", offerId=" + offerId + '\'' + + ", wishlistId=" + wishlistId + + '}'; + } +} diff --git a/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/repositories/InteractionRepository.java b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/repositories/InteractionRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..01f15af693fc70b3b81968c37058f49c5ea57ec7 --- /dev/null +++ b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/repositories/InteractionRepository.java @@ -0,0 +1,28 @@ +package vt.CS5934.SwitchRoom.repositories; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import vt.CS5934.SwitchRoom.models.InteractionModel; + + +public interface InteractionRepository extends JpaRepository<InteractionModel, Integer> { + + /** + * The function name is the SQL query: + * findByIdAndName(long inputId, String inputName) == "SELETE * FROM table WHERE Id==inputId" AND name == inputName; + * This is an example of how to declare a SQL command, those will be use in service class + * @param userId the id in table you are looking for + * @return ExampleModel object + */ + InteractionModel findByUserId(long userId); + + InteractionModel findInteractionModelByOfferIdAndWishlistId(String offerId, String wishlistId); + + InteractionModel[] findInteractionModelsByUserId1(Integer userId); + + InteractionModel[] findInteractionModelsByUserId2(Integer userId); + + + +} diff --git a/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/repositories/MatchedWishlistRecordRepository.java b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/repositories/MatchedWishlistRecordRepository.java index 06acd97c0c4c638787d26a50a40eb103f902a108..8e067f3c602b651c33e0dd12e1dc02115a4104c3 100644 --- a/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/repositories/MatchedWishlistRecordRepository.java +++ b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/repositories/MatchedWishlistRecordRepository.java @@ -3,6 +3,7 @@ package vt.CS5934.SwitchRoom.repositories; import org.springframework.data.jpa.repository.JpaRepository; import vt.CS5934.SwitchRoom.models.MatchedRecordIdModel; import vt.CS5934.SwitchRoom.models.MatchedWishlistRecordModel; +import vt.CS5934.SwitchRoom.utility.LookupTables; import java.util.Date; import java.util.List; @@ -12,23 +13,38 @@ public interface MatchedWishlistRecordRepository extends JpaRepository<MatchedWi * The function name is the SQL query: * findByIdAndName(long inputId, String inputName) == "SELETE * FROM table WHERE Id==inputId" AND name == inputName; * This is an example of how to declare a SQL command, those will be use in service class + * * @param offerId the id in table you are looking for * @return ExampleModel object */ List<MatchedWishlistRecordModel> findAllByOfferId(Long offerId); + /** * The function name is the SQL query: - * findByIdAndName(long inputId, String inputName) == "SELETE * FROM table WHERE Id==inputId" AND name == inputName; + * findByIdAndName(long inputId, String inputName) == "SELETE * FROM table WHERE Id==inputId" AND name == inputName; * This is an example of how to declare a SQL command, those will be use in service class + * * @param wishlistItemId the id in table you are looking for * @return ExampleModel object */ List<MatchedWishlistRecordModel> findAllByWishlistItemId(Long wishlistItemId); void deleteAllByOfferId(Long offerId); + void deleteAllByWishlistItemId(Long wishlistItemId); + Long countByWishlistItemId(Long wishlistItemId); MatchedWishlistRecordModel findByOfferIdAndWishlistItemId(Long offerId, Long wishlistId); List<MatchedWishlistRecordModel> findAllByOfferIdAndAgreedRecordIdIsNotNull(Long offerId); List<MatchedWishlistRecordModel> findAllByEndTimeBefore(Date todayDate); + + MatchedWishlistRecordModel findMatchedWishlistRecordModelByOfferIdAndWishlistItemId(Long offerId, Long wishlistItemId); + + void deleteByOfferIdAndWishlistItemId(Long offerId, Long wishlistItemId); + + void deleteMatchedWishlistRecordModelByOfferIdAndWishlistItemId(Long offerId, Long wishlistItemId); + + List<MatchedWishlistRecordModel> findAllByOfferIdAndOfferResultAndWishlistResult(Long offerId, LookupTables.MATCHING_RECORD_USER_RESULT offerResult, LookupTables.MATCHING_RECORD_USER_RESULT wishlistResult); + + List<MatchedWishlistRecordModel> findAllByWishlistItemIdAndWishlistResultAndOfferResult(Long wishlistItemId, LookupTables.MATCHING_RECORD_USER_RESULT offerResult, LookupTables.MATCHING_RECORD_USER_RESULT wishlistResult); } diff --git a/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/services/DealWithWishlist.java b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/services/DealWithWishlist.java index 247b50dfdce25a6f4e50ab124416eb22ade7813a..1b7b8e878775e2a97f1e4c6a379cd75a4bb39039 100644 --- a/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/services/DealWithWishlist.java +++ b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/services/DealWithWishlist.java @@ -8,6 +8,7 @@ import vt.CS5934.SwitchRoom.models.MatchedWishlistRecordModel; import vt.CS5934.SwitchRoom.models.UserOfferWishlistLookUpModel; import vt.CS5934.SwitchRoom.repositories.MatchedWishlistRecordRepository; import vt.CS5934.SwitchRoom.repositories.UserOfferWishlistLookUpRepository; +import vt.CS5934.SwitchRoom.utility.LookupTables; import java.util.ArrayList; import java.util.List; @@ -22,16 +23,27 @@ public class DealWithWishlist { @Autowired MatchedWishlistRecordRepository matchedWishlistRecordRepository; - public List<MatchedWishlistRecordModel> getMatchedWishlist(List<UserOfferWishlistLookUpModel> list) { logger.info("Reached get finalAns"); List<MatchedWishlistRecordModel> finalAns = new ArrayList<>(); for(int i = 0; i < list.size(); i++) { - System.out.println(list.get(i).getWishlistItemId()); - List<MatchedWishlistRecordModel> ans = matchedWishlistRecordRepository.findAllByWishlistItemId(list.get(i).getWishlistItemId()); - System.out.println(ans); +// System.out.println(list.get(i).getWishlistItemId() + " come on"); + List<MatchedWishlistRecordModel> ans = matchedWishlistRecordRepository.findAllByWishlistItemIdAndWishlistResultAndOfferResult(list.get(i).getWishlistItemId(), LookupTables.MATCHING_RECORD_USER_RESULT.Waiting, LookupTables.MATCHING_RECORD_USER_RESULT.Waiting); +// System.out.println(ans); finalAns.addAll(ans); } return finalAns; } +// public List<MatchedWishlistRecordModel> getMatchedWishlist(List<UserOfferWishlistLookUpModel> list) { +// logger.info("Reached get finalAns"); +// List<MatchedWishlistRecordModel> finalAns = new ArrayList<>(); +// for(int i = 0; i < list.size(); i++) { +// System.out.println(list.get(i).getWishlistItemId()+" come on"); +// List<MatchedWishlistRecordModel> ans = matchedWishlistRecordRepository.findAllByWishlistItemId(list.get(i).getWishlistItemId()); +// System.out.println(ans); +// finalAns.addAll(ans); +// } +// return finalAns; +// } + } diff --git a/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/services/InteractionService.java b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/services/InteractionService.java new file mode 100644 index 0000000000000000000000000000000000000000..2b8268d0d6b78f85f2e8ad53bbce15de519af435 --- /dev/null +++ b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/services/InteractionService.java @@ -0,0 +1,56 @@ +package vt.CS5934.SwitchRoom.services; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import vt.CS5934.SwitchRoom.models.InteractionModel; +import vt.CS5934.SwitchRoom.models.UserModel; +import vt.CS5934.SwitchRoom.repositories.InteractionRepository; +import vt.CS5934.SwitchRoom.repositories.UserRepository; + +@Service +public class InteractionService { + + /** + * You can use logger.[trace,debug,info,warn,error]("messages") to log into file + */ + private final Logger logger = LoggerFactory.getLogger(UserService.class); + + /** + * Autowired is a Spring feature that it will create or looking for the existing object in memory. + * It usually uses on Repository class, Service class, or some globe object in the class. + */ + @Autowired + InteractionRepository interactionRepository; + + + public InteractionModel addDataToDB(Integer userId1, Integer userId2, String phone1, String phone2, Boolean judgement, String offerId, String wishlistId){ + logger.info("Reached addNewExampleModelToDB()"); + InteractionModel data = new InteractionModel(userId1, userId2, phone1, phone2, judgement, offerId, wishlistId); + interactionRepository.save(data); + return data; + } + + public InteractionModel searchBothIdFromDB(String offerId, String wishlistId) { + logger.info("Reached searchBothIdFromDB()"); + InteractionModel result = interactionRepository.findInteractionModelByOfferIdAndWishlistId(offerId, wishlistId); + return result; + } + + public InteractionModel updateToDB(InteractionModel updateData) { + interactionRepository.save(updateData); + return updateData; + } + + public InteractionModel[] findAllInteractionsFromDB(Integer userId) { + InteractionModel[] res1 = interactionRepository.findInteractionModelsByUserId1(userId); + InteractionModel[] res2 = interactionRepository.findInteractionModelsByUserId2(userId); + int fal = res1.length; + int sal = res2.length; + InteractionModel[] res = new InteractionModel[fal + sal]; + System.arraycopy(res1, 0, res, 0, fal); + System.arraycopy(res2, 0, res, fal, sal); + return res; + } +} diff --git a/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/services/MatchedWishlistRecordService.java b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/services/MatchedWishlistRecordService.java index 89d6a43e60d66cfd54c5dc9a2f085ac8333ac764..583ad5195ecb7d47b5ebf6c43748e33f24c3cd1d 100644 --- a/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/services/MatchedWishlistRecordService.java +++ b/BackendFolder/SwitchRoom/src/main/java/vt/CS5934/SwitchRoom/services/MatchedWishlistRecordService.java @@ -7,6 +7,9 @@ import org.slf4j.LoggerFactory; import vt.CS5934.SwitchRoom.models.*; import vt.CS5934.SwitchRoom.repositories.*; import vt.CS5934.SwitchRoom.utility.LookupTables; +import vt.CS5934.SwitchRoom.models.MatchedWishlistRecordModel; +import vt.CS5934.SwitchRoom.repositories.MatchedWishlistRecordRepository; +import vt.CS5934.SwitchRoom.utility.LookupTables; import java.util.Date; import java.util.List; @@ -37,9 +40,26 @@ public class MatchedWishlistRecordService { @Autowired WishlistItemRepository wishlistItemRepository; + public List<MatchedWishlistRecordModel> getOfferListWithIDFromDB(long id){ logger.info("Reached getOfferListIDFromDB()"); - return matchedWishlistRecordRepository.findAllByOfferId(id); + return matchedWishlistRecordRepository.findAllByOfferIdAndOfferResultAndWishlistResult(id, LookupTables.MATCHING_RECORD_USER_RESULT.Waiting, LookupTables.MATCHING_RECORD_USER_RESULT.Waiting); + } + + public MatchedWishlistRecordModel getHistoryFromDB(Long offerId, Long wishlistItemId) { + logger.info("Reached getHistoryFromDB()"); + return matchedWishlistRecordRepository.findMatchedWishlistRecordModelByOfferIdAndWishlistItemId(offerId, wishlistItemId); + } + + public void deleteFromDB(Long offerId, Long wishlistItemId) { + logger.info("Reached deleteFromDB()"); + + matchedWishlistRecordRepository.deleteByOfferIdAndWishlistItemId(offerId, wishlistItemId); + } + + public MatchedWishlistRecordModel updateToDB(MatchedWishlistRecordModel updateData) { + matchedWishlistRecordRepository.save(updateData); + return updateData; } public void hostAcceptedOrUpdate(Long offerId, Long wishlistId, Date startTime, Date endTime){ diff --git a/FrontendFolder/switch-room/src/components/AppHeader.vue b/FrontendFolder/switch-room/src/components/AppHeader.vue index f53c160bdf92142032fb3f5899ab31bf4a78b635..88407039eb79f2bebeed102c1b242bb44351dd4e 100644 --- a/FrontendFolder/switch-room/src/components/AppHeader.vue +++ b/FrontendFolder/switch-room/src/components/AppHeader.vue @@ -27,6 +27,9 @@ <el-menu-item index="6" v-on:click="redirect('/profile')" >Profile</el-menu-item > + <el-menu-item index="6" v-on:click="redirect('/results')" + >Results</el-menu-item + > <notification class="position"></notification> <el-menu-item index="7" class="dock-right" @click="hanldeLogOut()" >Log Out</el-menu-item diff --git a/FrontendFolder/switch-room/src/components/Notification.vue b/FrontendFolder/switch-room/src/components/Notification.vue index f6d35a6340720b4772fa2416918ff17cd77eff67..a7cc89499c14b31360701124de45b72808976d4c 100644 --- a/FrontendFolder/switch-room/src/components/Notification.vue +++ b/FrontendFolder/switch-room/src/components/Notification.vue @@ -12,18 +12,23 @@ <el-dropdown-menu> <el-dropdown-item v-for="offer in offers" :key="offer.offerId"> <a> - <router-link - :to=" - '/matched-result/' + offer.offerId + '/' + offer.wishlistItemId + <!-- <router-link--> + <!-- :to="--> + <!-- '/matched-result/' + offer.offerId + '/' + offer.wishlistItemId--> + <!-- "--> + <!-- style="color: blue"--> + <!-- >--> + <div + @click=" + nextPageOffer('offer', offer.offerId, offer.wishlistItemId) " - style="color: blue" + class="offer-match" > - <div class="offer-match"> - <div class="offer-text"></div> - <font-awesome-icon icon="fa-solid fa-circle-info" /> - Offer Matched - </div> - </router-link> + <div class="offer-text"></div> + <font-awesome-icon icon="fa-solid fa-circle-info" /> + Offer Matched + </div> + <!-- </router-link>--> </a> </el-dropdown-item> <el-dropdown-item @@ -31,18 +36,23 @@ v-for="offer in offers2" :key="offer.offerId" > - <a - ><router-link - :to=" - '/matched-result/' + offer.offerId + '/' + offer.wishlistItemId + <a> + <!-- <router-link--> + <!-- :to="--> + <!-- '/matched-result/' + offer.offerId + '/' + offer.wishlistItemId--> + <!-- "--> + <!-- style="color: blue"--> + <!-- >--> + <div + @click=" + nextPageWish('wishlist', offer.offerId, offer.wishlistItemId) " - style="color: blue" + class="offer-match" > - <div class="offer-match"> - <font-awesome-icon icon="fa-solid fa-circle-info" /> - WishList Matched - </div> - </router-link> + <font-awesome-icon icon="fa-solid fa-circle-info" /> + WishList Matched + </div> + <!-- </router-link>--> </a> </el-dropdown-item> </el-dropdown-menu> @@ -55,10 +65,15 @@ import { ref, watch } from "vue"; import { OfferNotification } from "@/models/OfferNotification"; import * as NotificationService from "@/services/NotificationService"; import { useRoute } from "vue-router"; +import { useRouter } from "vue-router"; import { onMounted } from "vue"; import { Message } from "@element-plus/icons-vue"; +import { useJudgementStore } from "@/store/judgementStore"; + +const judgementStore = useJudgementStore(); const route = useRoute(); +const router = useRouter(); function getCookie(userId: string) { const value = `; ${document.cookie}`; @@ -66,6 +81,22 @@ function getCookie(userId: string) { if (parts.length === 2) return parts?.pop()?.split(";").shift(); } +function nextPageWish(input: string, oId: number, wId: number) { + judgementStore.markJudgement(input); + router.push({ + name: "MatchResultPage", + params: { offerId: oId, wishlistId: wId }, + }); +} + +function nextPageOffer(input: string, oId: number, wId: number) { + judgementStore.markJudgement(input); + router.push({ + name: "MatchResultPage", + params: { offerId: oId, wishlistId: wId }, + }); +} + const offers = ref([] as OfferNotification[]); const offers2 = ref([] as OfferNotification[]); diff --git a/FrontendFolder/switch-room/src/components/ResultCard.vue b/FrontendFolder/switch-room/src/components/ResultCard.vue new file mode 100644 index 0000000000000000000000000000000000000000..ad26c94cf3a440dd9d43e8d888933bbb158655d0 --- /dev/null +++ b/FrontendFolder/switch-room/src/components/ResultCard.vue @@ -0,0 +1,40 @@ +<template> + <div class="card"> + <div class="container"> + <h3>Please use the phone number here to contact with another resident</h3> + <div v-if="interaction.judgement"> + <p>Phone Number 1: {{ interaction.phone1 }}</p> + <p>Phone Number 2: {{ interaction.phone2 }}</p> + </div> + <div v-else> + <p>Another resident don't want to switch with you.</p> + </div> + </div> + </div> +</template> + +<script setup lang="ts"> +import { defineProps } from "vue"; +import { InteractionModel } from "@/models/InteractionModel"; +const props = defineProps<{ + interaction: InteractionModel; +}>(); +</script> + +<style scoped> +.card { + /* Add shadows to create the "card" effect */ + box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); + transition: 0.3s; +} + +/* On mouse-over, add a deeper shadow */ +.card:hover { + box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2); +} + +/* Add some padding inside the card container */ +.container { + padding: 2px 16px; +} +</style> diff --git a/FrontendFolder/switch-room/src/models/InteractionModel.ts b/FrontendFolder/switch-room/src/models/InteractionModel.ts new file mode 100644 index 0000000000000000000000000000000000000000..ca25ae0434d9ef8309b1ed80dba0e0c7ca7d7e3b --- /dev/null +++ b/FrontendFolder/switch-room/src/models/InteractionModel.ts @@ -0,0 +1,27 @@ +export class InteractionModel { + public userId1: number; + public userId2: number; + public phone1: string; + public phone2: string; + public judgement: boolean; + public offerId: string; + public wishlistId: string; + + constructor( + userId1 = -1, + userId2 = -1, + phone1 = "", + phone2 = "", + judgement = false, + offerId = "", + wishlistId = "" + ) { + this.userId1 = userId1; + this.userId2 = userId2; + this.phone1 = phone1; + this.phone2 = phone2; + this.judgement = judgement; + this.offerId = offerId; + this.wishlistId = wishlistId; + } +} diff --git a/FrontendFolder/switch-room/src/router/index.ts b/FrontendFolder/switch-room/src/router/index.ts index ef211696d7c1d8a028fba9dedd9fa9cbe99ba071..b5a73b7a4e4450860aac87496b8b76848adc3840 100644 --- a/FrontendFolder/switch-room/src/router/index.ts +++ b/FrontendFolder/switch-room/src/router/index.ts @@ -6,6 +6,11 @@ import ForgotPasswordFormView from "../views/ForgotPasswordFormView.vue"; import ResetPasswordView from "../views/ResetPasswordView.vue"; import ProfileView from "../views/ProfileView.vue"; import MatchedView from "../views/MatchedView.vue"; +import AgreementView from "../views/AgreementView.vue"; +import SendView from "../views/SendView.vue"; +import ConfirmationView from "../views/ConfirmationView.vue"; +import ResultsView from "../views/ResultsView.vue"; +import ConfirmationFailView from "../views/ConfirmationFailView.vue"; const routes: Array<RouteRecordRaw> = [ { @@ -121,7 +126,53 @@ const routes: Array<RouteRecordRaw> = [ path: "/flight-ticket", name: "TicketPage", component: () => - import(/* webpackChunkName: "about" */ "../views/FlightTicket.vue"), + import(/* webpackChunkName: "about" */ "../views/FlightTicket.vue"), + }, + { + path: "/agree/:offerId/:wishlistId", + name: "AgreementPage", + meta: { + requiresAuth: true, + hideHeader: false, + }, + component: AgreementView, + }, + { + path: "/agree/send/:offerId/:wishlistId", + name: "sendPage", + meta: { + requiresAuth: true, + hideHeader: false, + }, + component: SendView, + }, + { + path: "/confirmation", + name: "confirmationPage", + meta: { + requiresAuth: true, + hideHeader: false, + }, + component: ConfirmationView, + }, + { + path: "/confirmationFail", + name: "confirmationFailPage", + meta: { + requiresAuth: true, + hideHeader: false, + }, + component: ConfirmationFailView, + }, + + { + path: "/results", + name: "resultsPage", + meta: { + requiresAuth: true, + hideHeader: false, + }, + component: ResultsView, }, ]; diff --git a/FrontendFolder/switch-room/src/services/DisagreeService.ts b/FrontendFolder/switch-room/src/services/DisagreeService.ts new file mode 100644 index 0000000000000000000000000000000000000000..5ee7ffc5337b5926d7013ed0ee0cf0ffa1894ca8 --- /dev/null +++ b/FrontendFolder/switch-room/src/services/DisagreeService.ts @@ -0,0 +1,14 @@ +import * as serverHttpService from "./ServerHttpService"; + +const baseUrl = "interactive"; +function postDisagreeToServer(data: any) { + const urlPath = "/disagree"; + return serverHttpService.Post(baseUrl + urlPath, JSON.parse(data)); +} + +// function fetchFromServer(userId: any) { +// const urlPath = "/" + userId; +// return serverHttpService.Get(baseUrl + urlPath); +// } + +export { postDisagreeToServer }; diff --git a/FrontendFolder/switch-room/src/services/PhoneService.ts b/FrontendFolder/switch-room/src/services/PhoneService.ts new file mode 100644 index 0000000000000000000000000000000000000000..14555b25b8bea9d84fab9b36b563ad3a6b81db61 --- /dev/null +++ b/FrontendFolder/switch-room/src/services/PhoneService.ts @@ -0,0 +1,14 @@ +import * as serverHttpService from "./ServerHttpService"; + +const baseUrl = "interactive"; +function postPhoneToServer(phoneNumber: any) { + const urlPath = "/newData"; + return serverHttpService.Post(baseUrl + urlPath, JSON.parse(phoneNumber)); +} + +function fetchFromServer(userId: any) { + const urlPath = "/" + userId; + return serverHttpService.Get(baseUrl + urlPath); +} + +export { postPhoneToServer, fetchFromServer }; diff --git a/FrontendFolder/switch-room/src/store/flightdataStore.ts b/FrontendFolder/switch-room/src/store/flightdataStore.ts index 42b770f3ac34ec316bd5bf5e835f76f3a6eed54c..f9a2e425b005a58ba39862b6babb017550faf5fd 100644 --- a/FrontendFolder/switch-room/src/store/flightdataStore.ts +++ b/FrontendFolder/switch-room/src/store/flightdataStore.ts @@ -3,21 +3,21 @@ import { FlightResultModel } from "@/models/FlightResultModel"; import { FlightFormModel } from "@/models/FlightFormModel"; import * as FlightTicketService from "@/services/FlightTicketService"; - export const useTicketStore = defineStore("TicketStore", { - //state - //options - //getters - state: () => ({ - ticketList: [] as FlightResultModel[], - }), - actions: { - async fetchResultTicket(flightModel: FlightFormModel) { - await FlightTicketService.createNewFlight(flightModel).then((response) => { - - console.log("Save search flight data: ", response.data); - this.ticketList = response.data; - }); - }, + //state + //options + //getters + state: () => ({ + ticketList: [] as FlightResultModel[], + }), + actions: { + async fetchResultTicket(flightModel: FlightFormModel) { + await FlightTicketService.createNewFlight(flightModel).then( + (response) => { + console.log("Save search flight data: ", response.data); + this.ticketList = response.data; + } + ); }, -}); \ No newline at end of file + }, +}); diff --git a/FrontendFolder/switch-room/src/store/interactionStore.ts b/FrontendFolder/switch-room/src/store/interactionStore.ts new file mode 100644 index 0000000000000000000000000000000000000000..57c764a72561eb272c187f03f5f6822eb450a5f8 --- /dev/null +++ b/FrontendFolder/switch-room/src/store/interactionStore.ts @@ -0,0 +1,21 @@ +import { defineStore } from "pinia"; +import { InteractionModel } from "@/models/InteractionModel"; +import * as PhoneService from "@/services/PhoneService"; + +export const useInteractionStore = defineStore("InteractionStore", { + //state + //options + //getters + state: () => ({ + interactionList: [] as InteractionModel[], + }), + actions: { + async fetchInteractionData(data: any) { + await PhoneService.postPhoneToServer(data).then((response) => { + console.log("fetched interaction data", response.data); + this.interactionList = response.data; + console.log(this.interactionList); + }); + }, + }, +}); diff --git a/FrontendFolder/switch-room/src/store/judgementStore.ts b/FrontendFolder/switch-room/src/store/judgementStore.ts new file mode 100644 index 0000000000000000000000000000000000000000..a1e6b3c4b7b787ed1bef630ab1ae7b15cd19bb98 --- /dev/null +++ b/FrontendFolder/switch-room/src/store/judgementStore.ts @@ -0,0 +1,16 @@ +import { defineStore } from "pinia"; +import * as PhoneService from "@/services/PhoneService"; + +export const useJudgementStore = defineStore("JudgementStore", { + //state + //options + //getters + state: () => ({ + judgement: String, + }), + actions: { + markJudgement(data: any) { + this.judgement = data; + }, + }, +}); diff --git a/FrontendFolder/switch-room/src/views/AgreementView.vue b/FrontendFolder/switch-room/src/views/AgreementView.vue new file mode 100644 index 0000000000000000000000000000000000000000..547944924f956b5892d7e5f532b1d2a95f62bb12 --- /dev/null +++ b/FrontendFolder/switch-room/src/views/AgreementView.vue @@ -0,0 +1,306 @@ +<template> + <div><h1>The progress of signing the documentation</h1></div> + <div class="progress-bar"> + <div class="circle">1</div> + <progress class="file" value="0" max="100"></progress> + <div class="circle">2</div> + </div> + <div class="container"> + <ul class="cards"> + <li class="card"> + <div> + <h3 class="card-title">Term 1</h3> + <div class="card-content"> + <p> + Voluntarily agree to the terms of all home exchange if you agree + to the service + </p> + </div> + </div> + </li> + <li class="card"> + <div> + <h3 class="card-title">Term 2</h3> + <div class="card-content"> + <p> + No service and accommodation fees are required during the home + exchange process + </p> + </div> + </div> + </li> + <li class="card"> + <div> + <h3 class="card-title">Term 3</h3> + <div class="card-content"> + <p> + During the home exchange period, the house should be kept clean + and tidy, and furniture should not be damaged at will. + </p> + </div> + </div> + </li> + <li class="card"> + <div> + <h3 class="card-title">Term 4</h3> + <div class="card-content"> + <p> + During the house exchange period, the property of others shall not + be stolen. If the property is found to be lost, the occupant will + have legal benefits and bear legal responsibility. + </p> + </div> + </div> + </li> + <li class="card"> + <div> + <h3 class="card-title">Term 5</h3> + <div class="card-content"> + <p> + This site assumes no responsibility for security and all home + exchanges are voluntary. This site has no obligation to review + housing. + </p> + </div> + </div> + </li> + <li class="card"> + <div> + <h3 class="card-title">Term 6</h3> + <div class="card-content"> + <p> + If you agree to sign the agreement, you will wait for the other + party's reply. If the other party also agrees to the terms, the + home exchange will continue. If the other party does not agree to + the terms, the home exchange will be cancelled. + </p> + </div> + </div> + </li> + <li class="card"> + <div> + <h3 class="card-title">Term 7</h3> + <div class="card-content"> + <p>This website does not charge any fees.</p> + </div> + </div> + </li> + </ul> + </div> + + <div class="terms"> + <input v-model="checkBoolean" type="checkbox" id="agree" name="agree" /> + <label for="agree">I agree with the above terms</label> + </div> + + <div class="button-part"> + <button @click="nextStep()" class="next-button">Next</button> + </div> +</template> + +<script setup lang="ts"> +import { ref } from "vue"; +import { useRouter } from "vue-router"; +import { useRoute } from "vue-router"; + +const router = useRouter(); +const route = useRoute(); + +const checkBoolean = ref(false); + +function nextStep() { + if (checkBoolean.value) { + router.push({ + name: "sendPage", + params: { + offerId: route.params.offerId, + wishlistId: route.params.wishlistId, + }, + }); + } else { + alert("You need to agree the terms!"); + } +} +</script> + +<style scoped> +.progress-bar { + display: flex; + justify-content: center; + margin-top: 1%; + width: 100%; +} + +.progress-bar > * { + width: 33%; +} +.circle { + width: 30px; + height: 30px; + -webkit-border-radius: 25px; + -moz-border-radius: 25px; + border-radius: 25px; + background: black; + border-color: #1a66ff; + font-size: larger; + color: white; +} + +.file { + margin-left: 2px; + margin-right: 2px; +} + +.container { + margin-top: 2%; +} + +:root { + --red: #ef233c; + --darkred: #c00424; + --platinum: #e5e5e5; + --black: #2b2d42; + --white: #fff; + --thumb: #edf2f4; +} + +* { + box-sizing: border-box; + padding: 0; + margin: 0; +} + +body { + font: 16px / 24px "Rubik", sans-serif; + color: var(--black); + background: var(--platinum); + margin: 50px 0; +} + +.container { + max-width: 1400px; + padding: 0 15px; + margin: 0 auto; +} + +h2 { + font-size: 32px; + margin-bottom: 1em; +} + +.cards { + display: flex; + padding: 25px 0px; + list-style: none; + overflow-x: scroll; + scroll-snap-type: x mandatory; +} + +.card { + display: flex; + flex-direction: column; + flex: 0 0 100%; + padding: 20px; + background: var(--white); + border-radius: 12px; + box-shadow: 0 5px 15px rgba(0, 0, 0, 15%); + scroll-snap-align: start; + transition: all 0.2s; +} + +.card:not(:last-child) { + margin-right: 10px; +} + +.card:hover { + color: var(--white); + background: var(--red); +} + +.card .card-title { + font-size: 20px; +} + +.card .card-content { + margin: 20px 0; + max-width: 85%; +} + +.card .card-link-wrapper { + margin-top: auto; +} + +.card .card-link { + display: inline-block; + text-decoration: none; + color: white; + background: var(--red); + padding: 6px 12px; + border-radius: 8px; + transition: background 0.2s; +} + +.card:hover .card-link { + background: var(--darkred); +} + +.cards::-webkit-scrollbar { + height: 12px; +} + +.cards::-webkit-scrollbar-thumb, +.cards::-webkit-scrollbar-track { + border-radius: 92px; +} + +.cards::-webkit-scrollbar-thumb { + background: var(--darkred); +} + +.cards::-webkit-scrollbar-track { + background: var(--thumb); +} + +@media (min-width: 500px) { + .card { + flex-basis: calc(50% - 10px); + } + + .card:not(:last-child) { + margin-right: 20px; + } +} + +@media (min-width: 700px) { + .card { + flex-basis: calc(calc(100% / 3) - 20px); + } + + .card:not(:last-child) { + margin-right: 30px; + } +} + +@media (min-width: 1100px) { + .card { + flex-basis: calc(25% - 30px); + } + + .card:not(:last-child) { + margin-right: 40px; + } +} + +.terms { + margin-top: 2%; +} + +.button-part { + justify-content: right; + margin-top: 2%; +} + +.next-button { + width: 20%; +} +</style> diff --git a/FrontendFolder/switch-room/src/views/ConfirmationFailView.vue b/FrontendFolder/switch-room/src/views/ConfirmationFailView.vue new file mode 100644 index 0000000000000000000000000000000000000000..c303a140ea0b35c161abebca4a0e9240912fd53e --- /dev/null +++ b/FrontendFolder/switch-room/src/views/ConfirmationFailView.vue @@ -0,0 +1,36 @@ +<template> + <div class="card"> + <div class="container"> + <h4><b>You have successfully refuse the match</b></h4> + <p>System has already received your response</p> + <button @click="go()">Go to the result page</button> + </div> + </div> +</template> + +<script setup lang="ts"> +import { useRouter } from "vue-router"; +const router = useRouter(); +function go() { + router.push("/results"); +} +</script> + +<style scoped> +.card { + /* Add shadows to create the "card" effect */ + box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); + transition: 0.3s; + justify-content: center; +} + +/* On mouse-over, add a deeper shadow */ +.card:hover { + box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2); +} + +/* Add some padding inside the card container */ +.container { + padding: 2px 16px; +} +</style> diff --git a/FrontendFolder/switch-room/src/views/ConfirmationView.vue b/FrontendFolder/switch-room/src/views/ConfirmationView.vue new file mode 100644 index 0000000000000000000000000000000000000000..25c7bcd46d4e2f3d8397b43e848e6b8b2c5a8d83 --- /dev/null +++ b/FrontendFolder/switch-room/src/views/ConfirmationView.vue @@ -0,0 +1,81 @@ +<template> + <div><h1>You finished all process</h1></div> + <div class="progress-bar"> + <div class="circle">1</div> + <progress class="file" value="100" max="100" style="color: blue"></progress> + <div class="circle">2</div> + </div> + <div class="card"> + <div class="container"> + <h4><b>You have successfully sign a document</b></h4> + <p>System has already received your response</p> + <p>Please wait for the other side</p> + <p>You can check the result page later</p> + <button @click="go()">Go to the result page</button> + </div> + </div> +</template> + +<script setup lang="ts"> +import { useRouter } from "vue-router"; +const router = useRouter(); +function go() { + router.push("/results"); +} +</script> + +<style scoped> +.card { + /* Add shadows to create the "card" effect */ + box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); + transition: 0.3s; + justify-content: center; +} + +/* On mouse-over, add a deeper shadow */ +.card:hover { + box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2); +} + +/* Add some padding inside the card container */ +.container { + padding: 2px 16px; +} + +.progress-bar { + display: flex; + justify-content: center; + margin-top: 1%; + width: 100%; +} + +.progress-bar > * { + width: 33%; +} +.circle { + width: 30px; + height: 30px; + -webkit-border-radius: 25px; + -moz-border-radius: 25px; + border-radius: 25px; + background: blue; + font-size: larger; + color: black; +} + +.circle2 { + width: 30px; + height: 30px; + -webkit-border-radius: 25px; + -moz-border-radius: 25px; + border-radius: 25px; + background: black; + font-size: larger; + color: white; +} + +.file { + margin-left: 2px; + margin-right: 2px; +} +</style> diff --git a/FrontendFolder/switch-room/src/views/MatchedView.vue b/FrontendFolder/switch-room/src/views/MatchedView.vue index b0706b641529cd02848d9638ad4a22b2442cf00a..d37157ad2b8a6b021a73e9388bf754c4ad031957 100644 --- a/FrontendFolder/switch-room/src/views/MatchedView.vue +++ b/FrontendFolder/switch-room/src/views/MatchedView.vue @@ -16,8 +16,8 @@ <match-wish-list :wishlist="wishlist"></match-wish-list> </div> <div class="div4"> - <button>Sign Agreement</button> - <button>It is not suitable</button> + <button @click="agree(ofId, wId)">Sign Agreement</button> + <button @click="disagree(ofId, wId)">It is not suitable</button> </div> </div> </div> @@ -26,16 +26,31 @@ <script setup lang="ts"> import { ref, watch } from "vue"; import { useRoute } from "vue-router"; +import { useRouter } from "vue-router"; import * as FetchOfferService from "@/services/FetchOfferService"; import * as FetchWishListService from "@/services/FetchWishListService"; +import * as DisagreeService from "@/services/DisagreeService"; import { OfferFormModel } from "@/models/OfferFormModel"; import { WishlistItemModel } from "@/models/WishlistItemModel"; import MatchOffer from "@/components/MatchOffer.vue"; import MatchWishList from "@/components/MatchWishList.vue"; const route = useRoute(); +const router = useRouter(); const offer = ref(OfferFormModel); const wishlist = ref(WishlistItemModel); +import { useJudgementStore } from "@/store/judgementStore"; + +const judgementStore = useJudgementStore(); + +let ofId = -1; +let wId = -1; + +function getCookie(userId: string) { + const value = `; ${document.cookie}`; + const parts: string[] = value.split(`; ${userId}=`); + if (parts.length === 2) return parts?.pop()?.split(";").shift(); +} async function fetchOffer(offerId: number) { const response = await FetchOfferService.getOffersFromServerWithID(offerId); @@ -51,6 +66,31 @@ async function fetchWishList(wishlistId: number) { wishlist.value = response.data; } +async function postData(data: any) { + const response = await DisagreeService.postDisagreeToServer(data); +} + +function agree(oId: number, wId: number) { + console.log(oId); + router.push({ + name: "AgreementPage", + params: { offerId: oId, wishlistId: wId }, + }); +} + +function disagree(oId: number, wId: number) { + const userIdString: string = getCookie("userId"); + let userIdNumber = +userIdString; + const data = { + userId: userIdNumber, + offerId: oId, + wishlistId: wId, + see: judgementStore.judgement, + }; + postData(JSON.stringify(data)); + router.push("/confirmationFail"); +} + watch( () => route.name, (values) => { @@ -58,6 +98,8 @@ watch( const offerIdNumber = +offerIdName; const wishlistIdName = route.params.wishlistId; const wishlistIdNumber = +wishlistIdName; + ofId = offerIdNumber; + wId = wishlistIdNumber; fetchOffer(offerIdNumber); fetchWishList(wishlistIdNumber); }, diff --git a/FrontendFolder/switch-room/src/views/ResultsView.vue b/FrontendFolder/switch-room/src/views/ResultsView.vue new file mode 100644 index 0000000000000000000000000000000000000000..604458e34c35df7a196b9d7b5a917fe6e0e00527 --- /dev/null +++ b/FrontendFolder/switch-room/src/views/ResultsView.vue @@ -0,0 +1,40 @@ +<template> + <h1>Result List</h1> + <h2><b>You can find the results here</b></h2> + <div v-for="interaction in interactions"> + <result-card :interaction="interaction"></result-card> + </div> +</template> + +<script setup lang="ts"> +import ResultCard from "@/components/ResultCard.vue"; +import { ref, watch } from "vue"; +import { useRoute } from "vue-router"; +import * as PhoneService from "@/services/PhoneService"; +import { InteractionModel } from "@/models/InteractionModel"; + +const route = useRoute(); +const interactions = ref([] as InteractionModel[]); +function getCookie(userId: string) { + const value = `; ${document.cookie}`; + const parts: string[] = value.split(`; ${userId}=`); + if (parts.length === 2) return parts?.pop()?.split(";").shift(); +} +async function fetchInteraction(userId: number) { + const response = await PhoneService.fetchFromServer(userId); + interactions.value = response.data; + console.log("what happened"); + console.log(response.data); +} +watch( + () => route.name, + (values) => { + const userIdString: string = getCookie("userId"); + let userIdNumber = +userIdString; + fetchInteraction(userIdNumber); + }, + { immediate: true } +); +</script> + +<style scoped></style> diff --git a/FrontendFolder/switch-room/src/views/SendView.vue b/FrontendFolder/switch-room/src/views/SendView.vue new file mode 100644 index 0000000000000000000000000000000000000000..683e720bf32ee3c80106c53d36eb989e1419b657 --- /dev/null +++ b/FrontendFolder/switch-room/src/views/SendView.vue @@ -0,0 +1,108 @@ +<template> + <div><h1>The progress of sending the phone number</h1></div> + <div class="progress-bar"> + <div class="circle">1</div> + <progress class="file" value="100" max="100" style="color: blue"></progress> + <div class="circle2">2</div> + </div> + + <p>Please Enter Your Mobile Phone Number</p> + + <div class="phone-number"> + <input + v-model="send.phone" + id="" + class="phone-style" + type="text" + name="phoneNumber" + required + /> + </div> + <button @click="sendPhone()" class="submit">submit</button> +</template> + +<script setup lang="ts"> +import { reactive } from "vue"; +import { useRoute } from "vue-router"; +import { useRouter } from "vue-router"; +import * as PhoneService from "@/services/PhoneService"; +import { useInteractionStore } from "@/store/interactionStore"; +import { useJudgementStore } from "@/store/judgementStore"; + +const interactionStore = useInteractionStore(); +const judgementStore = useJudgementStore(); +const send = reactive({ + phone: "", +}); + +const route = useRoute(); +const router = useRouter(); + +function getCookie(userId: string) { + const value = `; ${document.cookie}`; + const parts: string[] = value.split(`; ${userId}=`); + if (parts.length === 2) return parts?.pop()?.split(";").shift(); +} + +const sendPhone = async () => { + const userIdString: string = getCookie("userId"); + let userIdNumber = +userIdString; + const sendData = { + phone: send.phone, + userId: userIdNumber, + offerId: route.params.offerId, + wishlistId: route.params.wishlistId, + see: judgementStore.judgement, + }; + await interactionStore.fetchInteractionData(JSON.stringify(sendData)); + router.push("/confirmation"); +}; +</script> + +<style scoped> +.progress-bar { + display: flex; + justify-content: center; + margin-top: 1%; + width: 100%; +} + +.progress-bar > * { + width: 33%; +} +.circle { + width: 30px; + height: 30px; + -webkit-border-radius: 25px; + -moz-border-radius: 25px; + border-radius: 25px; + background: blue; + font-size: larger; + color: black; +} + +.submit { + margin-top: 2%; + justify-content: center; +} + +.phone-style { + margin-top: 2%; +} + +.circle2 { + width: 30px; + height: 30px; + -webkit-border-radius: 25px; + -moz-border-radius: 25px; + border-radius: 25px; + background: black; + font-size: larger; + color: white; +} + +.file { + margin-left: 2px; + margin-right: 2px; +} +</style>