Skip to content
Snippets Groups Projects
Commit 05c460fd authored by zhengbo's avatar zhengbo
Browse files

new update

parent f80beaee
No related branches found
No related tags found
2 merge requests!34Sprint 2 done,!311. add vuex
......@@ -5,11 +5,10 @@ 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.ExampleModel;
import vt.CS5934.SwitchRoom.models.MatchedWishlistRecordModel;
import vt.CS5934.SwitchRoom.models.ResponseModel;
import vt.CS5934.SwitchRoom.models.UserModel;
import vt.CS5934.SwitchRoom.models.*;
import vt.CS5934.SwitchRoom.services.DealWithWishlist;
import vt.CS5934.SwitchRoom.services.MatchedWishlistRecordService;
import vt.CS5934.SwitchRoom.services.OfferWishlistLookUpService;
import vt.CS5934.SwitchRoom.services.UserService;
import java.util.List;
......@@ -33,6 +32,19 @@ public class NotificationController {
@Autowired
MatchedWishlistRecordService matchedWishlistRecordService;
/**
* 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
OfferWishlistLookUpService offerWishlistLookUpService;
/**
* 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
DealWithWishlist dealWithWishlist;
/**
* You can use logger.[trace,debug,info,warn,error]("messages") to log into file
*/
......@@ -45,10 +57,10 @@ public class NotificationController {
@GetMapping("/{userId}")
public ResponseModel getNotification(@PathVariable long userId) {
logger.info("You reached the getNotification() function.");
System.out.println(userId);
// System.out.println(userId);
try{
List<MatchedWishlistRecordModel> offerNotifications = matchedWishlistRecordService.getOfferListWithIDFromDB(userId);
System.out.println(offerNotifications);
// System.out.println(offerNotifications);
// List<ExampleModel> exampleModels = exampleService.getAllExampleModelsFromDB();
return new ResponseModel(
"This this a notification String response",
......@@ -61,4 +73,33 @@ public class NotificationController {
null);
}
}
/**
* This function will handle the post function and change the JSON body into data class
*/
@CrossOrigin(
allowCredentials = "true",
origins = {"http://localhost:8080/"}
)
@GetMapping("/wish/{userId}")
public ResponseModel getNotificationwish(@PathVariable long userId) {
logger.info("You reached the getNotificationwish() function.");
// 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();
return new ResponseModel(
"This this a notification String response",
HttpStatus.OK,
wishlists);
}catch (Exception e){
return new ResponseModel(
"Error occur on get All ExampleModels, Error info is: " + e,
HttpStatus.OK,
null);
}
}
}
......@@ -18,4 +18,13 @@ public interface MatchedWishlistRecordRepository extends JpaRepository<MatchedWi
* @return ExampleModel object
*/
List<MatchedWishlistRecordModel> findByOfferId(long userId);
/**
* 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 wishlistItemId the id in table you are looking for
* @return ExampleModel object
*/
List<MatchedWishlistRecordModel> findByWishlistItemId(long wishlistItemId);
}
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.MatchedWishlistRecordModel;
import vt.CS5934.SwitchRoom.models.UserOfferWishlistLookUpModel;
import vt.CS5934.SwitchRoom.repositories.MatchedWishlistRecordRepository;
import vt.CS5934.SwitchRoom.repositories.UserOfferWishlistLookUpRepository;
import java.util.ArrayList;
import java.util.List;
@Service
public class DealWithWishlist {
/**
* You can use logger.[trace,debug,info,warn,error]("messages") to log into file
*/
private final Logger logger = LoggerFactory.getLogger(ExampleService.class);
@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.findByWishlistItemId(list.get(i).getWishlistItemId());
System.out.println(ans);
finalAns.addAll(ans);
}
return finalAns;
}
}
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.ExampleModel;
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 java.util.*;
@Service
public class OfferWishlistLookUpService {
/**
* You can use logger.[trace,debug,info,warn,error]("messages") to log into file
*/
private final Logger logger = LoggerFactory.getLogger(ExampleService.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
UserOfferWishlistLookUpRepository userOfferWishlistLookUpRepository;
public List<UserOfferWishlistLookUpModel> getOfferWishlistLookUpWithIDFromDB(long id){
logger.info("Reached getWishlistLookUpWithIDFromDB()");
return userOfferWishlistLookUpRepository.findAllByUserId(id);
}
}
......@@ -15,6 +15,15 @@
You have a offer matched (click to check details)
</router-link>
</el-dropdown-item>
<el-dropdown-item v-for="offer in offers2" :key="offer.offerId">
<router-link
:to="
'/matched-result/' + offer.offerId + '/' + offer.wishlistItemId
"
>
You have a wishlist matched (click to check details)
</router-link>
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
......@@ -25,6 +34,8 @@ import { ref, watch } from "vue";
import { OfferNotification } from "@/models/OfferNotification";
import * as NotificationService from "@/services/NotificationService";
import { useRoute } from "vue-router";
import { onMounted } from "vue";
const route = useRoute();
function getCookie(userId: string) {
......@@ -34,12 +45,22 @@ function getCookie(userId: string) {
}
const offers = ref([] as OfferNotification[]);
const offers2 = ref([] as OfferNotification[]);
async function fetchNotification(userId: number) {
const response = await NotificationService.getNotificationFromServerWithID(
userId
);
console.log(response);
// const response2 =
// await NotificationService.getNotificationwishFromServerWithID(userId);
// console.log(response2);
offers.value = response.data;
// offers2.value = response2.data;
}
async function fetchNotificationwish(userId: number) {
const response2 =
await NotificationService.getNotificationwishFromServerWithID(userId);
offers2.value = response2.data;
}
watch(
......@@ -47,8 +68,8 @@ watch(
(values) => {
const userIdString: string = getCookie("userId");
let userIdNumber = +userIdString;
console.log(userIdNumber);
fetchNotification(userIdNumber);
fetchNotificationwish(userIdNumber);
},
{ immediate: true }
);
......
......@@ -7,4 +7,9 @@ function getNotificationFromServerWithID(userId: number) {
return serverHttpService.Get(baseUrl + urlPath);
}
export { getNotificationFromServerWithID };
function getNotificationwishFromServerWithID(userId: number) {
const urlPath = "/wish/" + userId;
return serverHttpService.Get(baseUrl + urlPath);
}
export { getNotificationFromServerWithID, getNotificationwishFromServerWithID };
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