Skip to content
Snippets Groups Projects
Commit d32a5941 authored by fz2907's avatar fz2907
Browse files

Merge remote-tracking branch 'origin/sprint_3' into sprint_3

parents 493cc427 9f4d2d00
No related branches found
No related tags found
1 merge request!37Start AgreedMatchPage to show the ongoing matches and history matches for user...
Showing
with 203 additions and 24 deletions
...@@ -5,10 +5,7 @@ import org.slf4j.LoggerFactory; ...@@ -5,10 +5,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import vt.CS5934.SwitchRoom.models.InteractionModel; import vt.CS5934.SwitchRoom.models.*;
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.InteractionService;
import vt.CS5934.SwitchRoom.services.MatchedWishlistRecordService; import vt.CS5934.SwitchRoom.services.MatchedWishlistRecordService;
import vt.CS5934.SwitchRoom.utility.LookupTables; import vt.CS5934.SwitchRoom.utility.LookupTables;
...@@ -106,7 +103,8 @@ public class InteractiveController { ...@@ -106,7 +103,8 @@ public class InteractiveController {
public ResponseModel getInteraction(@PathVariable Integer userId) { public ResponseModel getInteraction(@PathVariable Integer userId) {
logger.info("You reached the getInteraction() function."); logger.info("You reached the getInteraction() function.");
try{ try{
InteractionModel[] tranBack = interactionService.findAllInteractionsFromDB(userId); // InteractionModel[] tranBack = interactionService.findAllInteractionsFromDB(userId);
InteractionCombinedModel tranBack = interactionService.findAllInteractionsFromDB(userId);
return new ResponseModel( return new ResponseModel(
"This is a Interaction array response", "This is a Interaction array response",
HttpStatus.OK, HttpStatus.OK,
......
...@@ -8,6 +8,7 @@ import org.springframework.data.repository.query.Param; ...@@ -8,6 +8,7 @@ import org.springframework.data.repository.query.Param;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import vt.CS5934.SwitchRoom.models.InteractionCombinedModel;
import vt.CS5934.SwitchRoom.models.ResponseModel; import vt.CS5934.SwitchRoom.models.ResponseModel;
import vt.CS5934.SwitchRoom.models.UserModel; import vt.CS5934.SwitchRoom.models.UserModel;
import vt.CS5934.SwitchRoom.services.Token; import vt.CS5934.SwitchRoom.services.Token;
...@@ -238,4 +239,22 @@ public class UserController { ...@@ -238,4 +239,22 @@ public class UserController {
return response; return response;
} }
@GetMapping("/{userId}")
public ResponseModel getSpecificUser(@PathVariable Integer userId) {
logger.info("You reached the getSpecificUser() function.");
System.out.println("this is the specific user id " + userId);
try{
UserModel back = userService.findSpecificUser(userId);
return new ResponseModel(
"This is a Interaction array response",
HttpStatus.OK,
back);
}catch (Exception e){
return new ResponseModel(
"Error occur on get All ExampleModels, Error info is: " + e,
HttpStatus.OK,
null);
}
}
} }
package vt.CS5934.SwitchRoom.models;
public class InteractionCombinedModel {
private InteractionModel[] list1;
private InteractionModel[] list2;
private UserModel[] user1;
private UserModel[] user2;
public InteractionCombinedModel(InteractionModel[] list1, InteractionModel[] list2, UserModel[] user1, UserModel[] user2) {
this.list1 = list1;
this.list2 = list2;
this.user1 = user1;
this.user2 = user2;
}
public InteractionModel[] getList1() {
return list1;
}
public void setList1(InteractionModel[] list1) {
this.list1 = list1;
}
public InteractionModel[] getList2() {
return list2;
}
public void setList2(InteractionModel[] list2) {
this.list2 = list2;
}
public UserModel[] getUser1() {
return user1;
}
public void setUser1(UserModel[] user1) {
this.user1 = user1;
}
public UserModel[] getUser2() {
return user2;
}
public void setUser2(UserModel[] user2) {
this.user2 = user2;
}
}
...@@ -44,7 +44,7 @@ public interface MatchedWishlistRecordRepository extends JpaRepository<MatchedWi ...@@ -44,7 +44,7 @@ public interface MatchedWishlistRecordRepository extends JpaRepository<MatchedWi
void deleteMatchedWishlistRecordModelByOfferIdAndWishlistItemId(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> findAllByOfferIdAndOfferResult(Long offerId, LookupTables.MATCHING_RECORD_USER_RESULT offerResult);
List<MatchedWishlistRecordModel> findAllByWishlistItemIdAndWishlistResultAndOfferResult(Long wishlistItemId, LookupTables.MATCHING_RECORD_USER_RESULT offerResult, LookupTables.MATCHING_RECORD_USER_RESULT wishlistResult); List<MatchedWishlistRecordModel> findAllByWishlistItemIdAndWishlistResult(Long wishlistItemId, LookupTables.MATCHING_RECORD_USER_RESULT wishlistResult);
} }
...@@ -28,7 +28,7 @@ public class DealWithWishlist { ...@@ -28,7 +28,7 @@ public class DealWithWishlist {
List<MatchedWishlistRecordModel> finalAns = new ArrayList<>(); List<MatchedWishlistRecordModel> finalAns = new ArrayList<>();
for(int i = 0; i < list.size(); i++) { for(int i = 0; i < list.size(); i++) {
// System.out.println(list.get(i).getWishlistItemId() + " come on"); // 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); List<MatchedWishlistRecordModel> ans = matchedWishlistRecordRepository.findAllByWishlistItemIdAndWishlistResult(list.get(i).getWishlistItemId(), LookupTables.MATCHING_RECORD_USER_RESULT.Waiting);
// System.out.println(ans); // System.out.println(ans);
finalAns.addAll(ans); finalAns.addAll(ans);
} }
......
...@@ -4,6 +4,7 @@ import org.slf4j.Logger; ...@@ -4,6 +4,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import vt.CS5934.SwitchRoom.models.InteractionCombinedModel;
import vt.CS5934.SwitchRoom.models.InteractionModel; import vt.CS5934.SwitchRoom.models.InteractionModel;
import vt.CS5934.SwitchRoom.models.UserModel; import vt.CS5934.SwitchRoom.models.UserModel;
import vt.CS5934.SwitchRoom.repositories.InteractionRepository; import vt.CS5934.SwitchRoom.repositories.InteractionRepository;
...@@ -24,6 +25,9 @@ public class InteractionService { ...@@ -24,6 +25,9 @@ public class InteractionService {
@Autowired @Autowired
InteractionRepository interactionRepository; InteractionRepository interactionRepository;
@Autowired
UserRepository userRepository;
public InteractionModel addDataToDB(Integer userId1, Integer userId2, String phone1, String phone2, Boolean judgement, String offerId, String wishlistId){ public InteractionModel addDataToDB(Integer userId1, Integer userId2, String phone1, String phone2, Boolean judgement, String offerId, String wishlistId){
logger.info("Reached addNewExampleModelToDB()"); logger.info("Reached addNewExampleModelToDB()");
...@@ -43,14 +47,26 @@ public class InteractionService { ...@@ -43,14 +47,26 @@ public class InteractionService {
return updateData; return updateData;
} }
public InteractionModel[] findAllInteractionsFromDB(Integer userId) { public InteractionCombinedModel findAllInteractionsFromDB(Integer userId) {
InteractionModel[] res1 = interactionRepository.findInteractionModelsByUserId1(userId); InteractionModel[] res1 = interactionRepository.findInteractionModelsByUserId1(userId);
InteractionModel[] res2 = interactionRepository.findInteractionModelsByUserId2(userId); InteractionModel[] res2 = interactionRepository.findInteractionModelsByUserId2(userId);
int fal = res1.length; UserModel[] user1 = new UserModel[res1.length];
int sal = res2.length; UserModel[] user2 = new UserModel[res2.length];
InteractionModel[] res = new InteractionModel[fal + sal]; for(int i = 0; i < res1.length; i++) {
System.arraycopy(res1, 0, res, 0, fal); UserModel user = userRepository.findByUserId(res1[i].getUserId2());
System.arraycopy(res2, 0, res, fal, sal); user1[i] = user;
}
for(int j = 0; j < res2.length; j++) {
UserModel user = userRepository.findByUserId(res2[j].getUserId1());
user2[j] = user;
}
InteractionCombinedModel res = new InteractionCombinedModel(res1, res2, user1, user2);
// 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; return res;
} }
} }
...@@ -43,7 +43,7 @@ public class MatchedWishlistRecordService { ...@@ -43,7 +43,7 @@ public class MatchedWishlistRecordService {
public List<MatchedWishlistRecordModel> getOfferListWithIDFromDB(long id){ public List<MatchedWishlistRecordModel> getOfferListWithIDFromDB(long id){
logger.info("Reached getOfferListIDFromDB()"); logger.info("Reached getOfferListIDFromDB()");
return matchedWishlistRecordRepository.findAllByOfferIdAndOfferResultAndWishlistResult(id, LookupTables.MATCHING_RECORD_USER_RESULT.Waiting, LookupTables.MATCHING_RECORD_USER_RESULT.Waiting); return matchedWishlistRecordRepository.findAllByOfferIdAndOfferResult(id, LookupTables.MATCHING_RECORD_USER_RESULT.Waiting);
} }
public MatchedWishlistRecordModel getHistoryFromDB(Long offerId, Long wishlistItemId) { public MatchedWishlistRecordModel getHistoryFromDB(Long offerId, Long wishlistItemId) {
......
...@@ -217,4 +217,9 @@ public class UserService { ...@@ -217,4 +217,9 @@ public class UserService {
return false; return false;
} }
} }
public UserModel findSpecificUser(int userId) {
UserModel specificUser = userRepository.findByUserId(userId);
return specificUser;
}
} }
<template> <template>
<div class="card"> <div class="card">
<div class="container"> <div class="container">
<h3>Please use the phone number here to contact with another resident</h3> <h3>
Please use the following information to contact with another resident
</h3>
<div v-if="interaction.judgement"> <div v-if="interaction.judgement">
<p>Phone Number 1: {{ interaction.phone1 }}</p> <p>Name: {{ user1.firstname }} {{ user1.lastname }}</p>
<p>Phone Number 2: {{ interaction.phone2 }}</p> <p>Email: {{ user1.email }}</p>
<p>Phone: {{ interaction.phone2 }}</p>
</div> </div>
<div v-else> <div v-else>
<p>Another resident don't want to switch with you.</p> <p>Another resident don't want to switch with you.</p>
...@@ -14,10 +17,17 @@ ...@@ -14,10 +17,17 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { defineProps } from "vue"; import { defineProps, watch } from "vue";
import { InteractionModel } from "@/models/InteractionModel"; import { InteractionModel } from "@/models/InteractionModel";
import { useRoute } from "vue-router";
import { UserModel } from "@/models/UserModel";
import { inject } from "vue";
const route = useRoute();
const props = defineProps<{ const props = defineProps<{
interaction: InteractionModel; interaction: InteractionModel;
// specificUser: UserModel;
user1: UserModel;
}>(); }>();
</script> </script>
......
<template>
<div class="card">
<div class="container">
<h3>
Please use the following information to contact with another resident
</h3>
<div v-if="interaction.judgement">
<p>Name: {{ user2.firstname }} {{ user2.lastname }}</p>
<p>Email: {{ user2.email }}</p>
<p>Phone: {{ interaction.phone1 }}</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, watch } from "vue";
import { InteractionModel } from "@/models/InteractionModel";
import { UserModel } from "@/models/UserModel";
const props = defineProps<{
interaction: InteractionModel;
user2: UserModel;
}>();
</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>
...@@ -32,6 +32,11 @@ function getProfile() { ...@@ -32,6 +32,11 @@ function getProfile() {
return serverHttpService.Get(baseUrl + urlPath); return serverHttpService.Get(baseUrl + urlPath);
} }
function getSpecificProfile(userId: any) {
const urlPath = "/" + userId;
return serverHttpService.Get(baseUrl + urlPath);
}
export { export {
postUserDataToServer, postUserDataToServer,
loginUser, loginUser,
...@@ -39,5 +44,6 @@ export { ...@@ -39,5 +44,6 @@ export {
resetPassword, resetPassword,
forgotPassword, forgotPassword,
forgotPasswordCreateNew, forgotPasswordCreateNew,
getProfile getProfile,
getSpecificProfile,
}; };
<template> <template>
<h1>Result List</h1> <h1>Result List</h1>
<h2><b>You can find the results here</b></h2> <h2><b>You can find the results here</b></h2>
<div v-for="interaction in interactions"> <div v-for="(interaction, index) in interaction1" :key="index">
<result-card :interaction="interaction"></result-card> <result-card :interaction="interaction" :user1="user1[index]"></result-card>
</div>
<div v-for="(interaction, index) in interaction2">
<result-card-second
:interaction="interaction"
:user2="user2[index]"
></result-card-second>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import ResultCard from "@/components/ResultCard.vue"; import ResultCard from "@/components/ResultCard.vue";
import ResultCardSecond from "@/components/ResultCardSecond.vue";
import { ref, watch } from "vue"; import { ref, watch } from "vue";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import * as PhoneService from "@/services/PhoneService"; import * as PhoneService from "@/services/PhoneService";
import * as UserService from "@/services/UserService";
import { InteractionModel } from "@/models/InteractionModel"; import { InteractionModel } from "@/models/InteractionModel";
import { UserModel } from "@/models/UserModel";
import { provide } from "vue";
const route = useRoute(); const route = useRoute();
const interactions = ref([] as InteractionModel[]); const interaction1 = ref([] as InteractionModel[]);
const interaction2 = ref([] as InteractionModel[]);
const user1 = ref([] as UserModel[]);
const user2 = ref([] as UserModel[]);
function getCookie(userId: string) { function getCookie(userId: string) {
const value = `; ${document.cookie}`; const value = `; ${document.cookie}`;
const parts: string[] = value.split(`; ${userId}=`); const parts: string[] = value.split(`; ${userId}=`);
...@@ -22,16 +36,31 @@ function getCookie(userId: string) { ...@@ -22,16 +36,31 @@ function getCookie(userId: string) {
} }
async function fetchInteraction(userId: number) { async function fetchInteraction(userId: number) {
const response = await PhoneService.fetchFromServer(userId); const response = await PhoneService.fetchFromServer(userId);
interactions.value = response.data; // interactions.value = response.data;
interaction1.value = response.data.list1;
interaction2.value = response.data.list2;
user1.value = response.data.user1;
user2.value = response.data.user2;
console.log("what happened"); console.log("what happened");
console.log(response.data); console.log(response.data);
} }
// async function fetchSpecificUsers() {
// for (let i = 0; i < interaction1.value.length; i++) {
// const specificUserId = interaction1.value[i].userId2;
// const response = await UserService.getSpecificProfile(specificUserId);
// await specificUsers.value.push(await response.data);
// }
// console.log("what happened");
// console.log(specificUsers.value);
// }
watch( watch(
() => route.name, () => route.name,
(values) => { (values) => {
const userIdString: string = getCookie("userId"); const userIdString: string = getCookie("userId");
let userIdNumber = +userIdString; let userIdNumber = +userIdString;
fetchInteraction(userIdNumber); fetchInteraction(userIdNumber);
// await fetchSpecificUsers();
}, },
{ immediate: true } { immediate: true }
); );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment