提交 c5560c52 authored 作者: Whispa's avatar Whispa

changes and add more comments

上级 4e812bd6
......@@ -46,7 +46,7 @@ public class AdvertisementController {
@RequestParam(value = "pageNum", defaultValue = "0") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "12") Integer pageSize,
@RequestParam(value = "order", required = false) String order) {
LinkedHashMap advertisementMap = new LinkedHashMap();
LinkedHashMap<String,Object> advertisementMap = new LinkedHashMap<>();
//广告投放信息主体
Optional<Advertisement> firstByAdLink = advertisementRepository.findFirstByAdLink(link);
if (firstByAdLink.isPresent()) {
......@@ -70,7 +70,7 @@ public class AdvertisementController {
advertisementMap.put("itemList", itemList);
}
return new Result(advertisementMap);
return new Result<>(advertisementMap);
}
private Sort sort(String order) {
......
......@@ -68,10 +68,13 @@ public class AuthController extends Controller {
this.jwtUtils = jwtUtils;
}
//Sign in using email/phone and password
@PostMapping("/signin")
public Result authenticateUser(@RequestBody LoginRequest loginRequest) {
Optional<TbCfUserInfo> byAccount = userRepository.findFirstByAccount(loginRequest.getAccount());
Result<Object> notFound = new Result<>(ResultCodeEnum.VALIDATE_ERROR.getCode(), "User not found");
if (!byAccount.isPresent()) {
//
// boolean b = userRepository.existsByAccount(loginRequest.getAccount());
......@@ -106,6 +109,8 @@ public class AuthController extends Controller {
return new Result(ResultCodeEnum.VALIDATE_ERROR.getCode(), "Invalid username or password");
}
//Generate token
SecurityContextHolder.getContext().setAuthentication(authentication);
String jwt = jwtUtils.generateJwtToken(authentication);
......@@ -133,6 +138,7 @@ public class AuthController extends Controller {
return new Result<>(userInfo);
}
//Verify sent user code
@GetMapping("/verifyCode/{account}/{code}")
public Result<Boolean> validateCode(@PathVariable("account") String account,
@PathVariable("code") String code) {
......@@ -142,6 +148,7 @@ public class AuthController extends Controller {
TbCfUserInfo userInfo = userInfoOptional.get();
//check validity
if (code.equals(userInfo.getVerificationCode())) {
return new Result<>(true, "Verification code is right !!!");
}
......@@ -149,6 +156,7 @@ public class AuthController extends Controller {
return new Result<>(false, ResultCodeEnum.VALIDATE_ERROR.getCode(), "Verification code is wrong !!!");
}
//Register new user with email
@PostMapping("/signup")
public Result<?> registerUser(@RequestBody TbCfUserInfo signUpRequest) {
try {
......@@ -181,6 +189,7 @@ public class AuthController extends Controller {
boolean byEmail = userRepository.existsByFirebaseUid(email);
boolean byEmail2 = userRepository.existsByAccount(email);
//Check if email exists
if (byEmail || byEmail2) {
return new Result(ResultCodeEnum.VALIDATE_ERROR.getCode(), "Error: Email is already in use!");
}
......@@ -476,6 +485,7 @@ public class AuthController extends Controller {
}
}
// Copy code from old user_info table or generate new one
private void fixCode(TbCfUserInfo user) {
if (user.getCode() == null) {
......@@ -511,6 +521,7 @@ public class AuthController extends Controller {
}
}
//Auto newtork register
private void addToNetwork(TbCfUserInfo user) {
Network top = networkRepository.findTopByOrderByIdDesc();
......@@ -526,6 +537,7 @@ public class AuthController extends Controller {
}
}
//fill basic information for new user
private void fillUserNecessayInfo(TbCfUserInfo tbCfUserInfoVo) {
if (tbCfUserInfoVo.getAvatar() == null) tbCfUserInfoVo.setAvatar(domainProperties.getProperty("user.avatar"));
tbCfUserInfoVo.setUserNo(IdUtil.createIdByDate());
......
......@@ -54,12 +54,14 @@ public class BonusController extends Controller {
return repository.findAllByUserInfo_UserIdOrderByCreateDateDesc(id, PageRequest.of(pageNo, pageSize)).toList();
}
//Get paginated list of bonus by authorized user
@GetMapping(value = "/list")
//@PreAuthorize("hasAuthority('ADMIN_USER') or hasAuthority('STANDARD_USER')")
public List<Bonus> getListByUser(@RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
return repository.findAllByUserInfo_UserIdOrderByCreateDateDesc(user.userId(), PageRequest.of(pageNo, pageSize)).toList();
}
//Get bonuses in current month
@GetMapping(value = "/list/currentMonth")
//@PreAuthorize("hasAuthority('ADMIN_USER') or hasAuthority('STANDARD_USER')")
public Map<String, Object> getListByUserAndCurrentMonth( @RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
......@@ -76,6 +78,7 @@ public class BonusController extends Controller {
int year = localDate.getYear();
Optional<TbCfUserInfo> byId = userRepository.findById(id);
if (!byId.isPresent()) return null;
//Calculate sum of bonus in single month
Query nativeQuery = entityManager.createNativeQuery("select IFNULL(sum(b.amount),0.0) as data FROM bonus b where b.user_info_user_id=:user and month (b.create_date) = :month and year(b.create_date) = :year ");
nativeQuery.setParameter("user", id);
nativeQuery.setParameter("month", month);
......@@ -87,6 +90,7 @@ public class BonusController extends Controller {
return hashMap;
}
//Get bonuses from previous month
@GetMapping(value = "/list/prevMonth")
//@PreAuthorize("hasAuthority('ADMIN_USER') or hasAuthority('STANDARD_USER')")
public Map<String, Object> getListByUserAndPreviousMonth(@RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
......@@ -103,6 +107,7 @@ public class BonusController extends Controller {
int year = localDate.getYear();
Optional<TbCfUserInfo> byId = userRepository.findById(id);
if (!byId.isPresent()) return null;
//Calculate sum of bonus in single month
Query nativeQuery = entityManager.createNativeQuery("select IFNULL(sum(b.amount),0.0) as data FROM bonus b where b.user_info_user_id=:user and month (b.create_date) = :month and year(b.create_date) = :year ");
nativeQuery.setParameter("user", id);
nativeQuery.setParameter("month", month);
......@@ -130,6 +135,7 @@ public class BonusController extends Controller {
int year = localDate.getYear();
Optional<TbCfUserInfo> byId = userRepository.findById(id);
if (!byId.isPresent()) return null;
//Calculate sum of bonus for today
Query nativeQuery = entityManager.createNativeQuery("select IFNULL(sum(b.amount),0.0) as data FROM bonus b where b.user_info_user_id=:user and dayofyear(b.create_date) = :day and year(b.create_date) = :year ");
nativeQuery.setParameter("user", id);
nativeQuery.setParameter("day", dayOfYear);
......
......@@ -39,7 +39,7 @@ public class CartController extends Controller {
this.user = user;
}
//Change number of the cart item
@PutMapping("/num/{cartId}/{itemNum}")
public Result changeItemNum(@PathVariable String cartId, @PathVariable int itemNum) {
Optional<TbCfCartRecordR> byId = repository.findById(cartId);
......@@ -53,6 +53,7 @@ public class CartController extends Controller {
return new Result<>(ResultCodeEnum.SERVICE_ERROR.getCode(), "Failed");
}
//Add single item to the cart
@PostMapping
public Result addToCart(@RequestBody TbCfCartRecordR itemDetail) {
......@@ -158,6 +159,7 @@ public class CartController extends Controller {
return new Result<>(repository.findAllByUserIdOrderByCreateTimeDesc(user.userId()));
}
//Delete by array of cart ids
@DeleteMapping("/delete")
public Result deleteItems(@RequestBody String[] ids) {
if (ids != null) {
......@@ -168,7 +170,7 @@ public class CartController extends Controller {
ResultCodeEnum.SERVICE_ERROR.getDesc());
}
//Insert
private void insertRecord(TbCfCartRecordR itemDetail, String userId) {
itemDetail.setCartRecordId(uid());
itemDetail.setCheckFlag(StateConstant.INVALID);
......
......@@ -19,6 +19,7 @@ public class CommentController {
this.user = user;
}
//paginated comments list by post id
@GetMapping(value = "/commentsByPostId/{postId}")
//@PreAuthorize("hasAuthority('ADMIN_USER') or hasAuthority('STANDARD_USER')")
public List<Comment> getList(@PathVariable(value = "postId") String id, @RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
......
......@@ -23,7 +23,7 @@ public class ComplainController {
}
//Get list of complains
@GetMapping(value = "/complains")
//@PreAuthorize("hasAuthority('ADMIN_USER') or hasAuthority('STANDARD_USER')")
public List<Complain> getList(@RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
......
......@@ -122,6 +122,7 @@ abstract class Controller {
}
//Check firebase authentication token
protected boolean validateFirebaseToken(String token) {
FirebaseApp firebaseApp = getApp();
......
......@@ -22,7 +22,7 @@ public class CouponController {
this.user = user;
}
//Get coupons list by authenticated user
@GetMapping
public Result getUserCoupons() {
return queryCouponByUserId(user.userId());
......@@ -44,7 +44,7 @@ public class CouponController {
return new Result<>(hashMap);
}
//Find single coupon by coupon id
@GetMapping("{couponId}")
public Result queryCouponDetails(@PathVariable("couponId") String couponId) {
......
package com.example.afrishop_v3.controllers;
import com.example.afrishop_v3.base.Result;
import com.example.afrishop_v3.models.TbCfCube;
import com.example.afrishop_v3.models.TbCfStationItem;
import com.example.afrishop_v3.repository.TbCfCubeRepository;
import com.example.afrishop_v3.repository.TbCfStationItemRepository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @Auther: wudepeng
* @Date: 2020/07/07
* @Description:魔方管理类
*/
//@Api(value = "cubeController", description = "魔方管理")
@RestController
@RequestMapping("/cube")
public class CubeController {
private final TbCfCubeRepository cubeRepository;
private final TbCfStationItemRepository itemRepository;
public CubeController(TbCfCubeRepository cubeRepository, TbCfStationItemRepository itemRepository) {
this.cubeRepository = cubeRepository;
this.itemRepository = itemRepository;
}
//获取所有的魔方
//返回所有魔方的商品信息
@GetMapping
public Result getAllCubeItems() {
Iterable<TbCfCube> all = cubeRepository.findAll();
all.forEach(v->{
String itemIds = v.getItemIds();
if( itemIds != null){
String[] split = itemIds.split(";");
if(split.length > 0){
List<TbCfStationItem> allByItemIdIn = itemRepository.findAllByItemIdIn(split);
v.setItemList(allByItemIdIn);
}
}
});
return new Result<>(all);
}
}
......@@ -24,16 +24,19 @@ public class FollowingController {
this.userRepository = userRepository;
}
//List followed users by user id
@GetMapping("listFollowers/{userId}")
public List<TbCfUserInfo> getList(@PathVariable("userId") String id){
return repository.findAllByFollowedInfoUserId(id).stream().map(Following::getFollowerInfo).collect(Collectors.toList());
}
//List following users by user id
@GetMapping("listFollowing/{userId}")
public List<TbCfUserInfo> getListFollowing(@PathVariable("userId") String id){
return repository.findAllByFollowerInfoUserId(id).stream().map(Following::getFollowedInfo).collect(Collectors.toList());
}
//Follow action
@GetMapping("follow/user/{follower}/{followed}/{status}")
public Following followingStatus(@PathVariable("follower") String follower, @PathVariable("followed") String followed, @PathVariable("status") boolean status){
Following following = new Following();
......
......@@ -16,12 +16,14 @@ public class HashtagController {
this.repository = repository;
}
//Get paginated list of hashtags
@GetMapping(value = "/home/listHashtags")
//@PreAuthorize("hasAuthority('ADMIN_USER') or hasAuthority('STANDARD_USER')")
public List<Hashtag> getList(@RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
return repository.findAll(PageRequest.of(pageNo, pageSize, Sort.by(Sort.Order.desc("count")))).toList();
}
//Search hash tags
@GetMapping(value = "/searchHashtags/{query}")
//@PreAuthorize("hasAuthority('ADMIN_USER') or hasAuthority('STANDARD_USER')")
public List<Hashtag> getSearch(@PathVariable(value = "query") String query, @RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
......@@ -29,6 +31,7 @@ public class HashtagController {
}
//Create new hash tag
@PostMapping(value = "/saveHashTag")
public Hashtag saveProduct(@ModelAttribute("Hashtag") Hashtag hashtag) {
if( repository.existsByName(hashtag.getName()))
......
......@@ -19,6 +19,7 @@ import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
//Google image search
@RestController
@RequestMapping("search/image")
public class ImageSearchController extends Controller {
......@@ -35,11 +36,14 @@ public class ImageSearchController extends Controller {
}
//Get url image details (GOOGLE API)
@GetMapping
public Result main(@RequestParam("url") String url) {
return new Result<>(getItemLabels(url));
}
//Search by image url
@GetMapping("searchUrl")
public Result searchByUrl(@RequestParam("url") String url, @RequestParam(value = "pageNo",defaultValue = "0",required = false) Integer pageNo, @RequestParam(value = "pageSize",required = false,defaultValue = "12") Integer pageSize) {
......@@ -53,7 +57,7 @@ public class ImageSearchController extends Controller {
return new Result<>(map);
}
//Search by uploaded image
@PostMapping("/upload")
public Result handleFileUpload(@RequestParam("file") MultipartFile file, @RequestParam(value = "pageNo",defaultValue = "0",required = false) Integer pageNo, @RequestParam(value = "pageSize",required = false,defaultValue = "12") Integer pageSize){
if( file != null ){
......@@ -70,7 +74,7 @@ public class ImageSearchController extends Controller {
return new Result<>(new ArrayList<>());
}
//Index item image information
@GetMapping("indexing")
public Result itemIndexing(@RequestParam("itemId") String itemId) {
......
......@@ -25,16 +25,17 @@ public class ItemLikeController {
this.user = user;
}
//Like comment
@PutMapping("like/{comment_id}")
public Result likeComment(@PathVariable("comment_id") String commentId ){
try {
Optional<TbCfItemComment> commentOptional = commentRepository.findById(commentId);
//Check if comment exists
if( !commentOptional.isPresent() )
return new Result(ResultCodeEnum.VALIDATE_ERROR.getCode(),"Item comment not found !");
TbCfUserInfo user = this.user.user();
String userId = user.getUserId();
//Check if comment is already liked
boolean exists = repository.existsByCommentIdAndUserUserId(commentId, userId);
if( exists ){
......
......@@ -18,14 +18,14 @@ public class LikeController {
this.repository = repository;
}
//Get List of Likes by post id
@GetMapping(value = "/likesByPostId/{postId}")
//@PreAuthorize("hasAuthority('ADMIN_USER') or hasAuthority('STANDARD_USER')")
public List<PostLike> getList(@PathVariable(value = "postId") String id, @RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
return repository.findAllByPost_Id(id, PageRequest.of(pageNo, pageSize)).toList();
}
//Like a post
@PostMapping(value = "/saveLike/{status}")
public Result saveProduct(@PathVariable(value = "status") boolean status, @ModelAttribute("PostLike") PostLike like) {
if (status) {
......
......@@ -29,6 +29,7 @@ public class NetworkController {
}
//Save network by user id
@PostMapping(value = "/saveNetwork")
public Network saveNetwork(@ModelAttribute("Network") Network network) {
......@@ -41,7 +42,7 @@ public class NetworkController {
else return repository.save(network);
}
//Save network by invitation code
@PostMapping(value = "/saveNetwork2")
public Network saveNetwork2(@ModelAttribute("Network") Network network) {
......@@ -61,7 +62,7 @@ public class NetworkController {
return null;
}
//Get user network list
@GetMapping(value = "/networksByUserId/{userId}")
//@PreAuthorize("hasAuthority('ADMIN_USER') or hasAuthority('STANDARD_USER')")
public List<TbCfUserInfo> getList(@PathVariable(value = "userId") String id, @RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
......
......@@ -167,6 +167,7 @@ public class OrderController extends Controller {
order.setCouponId(toitableId);
//Check if any coupon selected
if (toitableId != null && !toitableId.isEmpty()) {
Optional<TbCfToicoupon> couponOptional = toicouponRepository.findById(toitableId);
......@@ -184,6 +185,7 @@ public class OrderController extends Controller {
return new Result<>(order);
}
//Get server current time
@GetMapping(value = "currentTime")
public Result<Date> getTime() {
return new Result<>(new Date());
......@@ -191,7 +193,7 @@ public class OrderController extends Controller {
@PostMapping("/place")
@Transactional
@Transactional // Transaction for rollback if any failure
public Result<TbCfOrder> placeOrder(@RequestBody OrderRequest tbCfOrder,
@RequestParam(value = "toitableId", required = false) String toitableId,
@RequestParam(value = "itemId", required = false) String itemId,
......@@ -245,7 +247,7 @@ public class OrderController extends Controller {
allByUserId.add(getCart(stationItem, itemSku, itemNum, skuObj.getSkuPrice(), itemSkuId, skuObj.getSkuImg()));
} else {
System.out.println(Arrays.toString(tbCfOrder.getIds()));
//System.out.println(Arrays.toString(tbCfOrder.getIds()));
allByUserId = cartRepository.findAllByCartRecordIdIn(tbCfOrder.getIds());
// for (TbCfCartRecordR cart : allByUserId) {
// String id = cart.getItemId();
......@@ -287,6 +289,7 @@ public class OrderController extends Controller {
order.setDeliveryName(address.getDeliveryName());
order.setDeliveryPhone(address.getPhone());
//Get default template
Optional<TbCfExpressTemplate> templateOptional = templateRepository.findFirstByIsDefault(1);
templateOptional.ifPresent(order::setDefaultTemplate);
order.setOrderId(IdUtil.createIdbyUUID());
......@@ -318,6 +321,7 @@ public class OrderController extends Controller {
TbCfOrder save = repository.save(order);
//implementation of coupon use
if (tbCfToicoupon != null) {
tbCfToicoupon.setEnableFlag(0);
toicouponRepository.save(tbCfToicoupon);
......@@ -330,9 +334,11 @@ public class OrderController extends Controller {
String[] strings = collect.toArray(new String[]{});
if (payNow) {
//Inventory reduction for pay now item
cartRepository.updateItemQuantity_(itemId, itemNum);
cartRepository.updateSkuQuantity_(itemSkuId, itemNum);
} else {
//Inventory reduction for cart items
cartRepository.updateSkuQuantity(strings);
cartRepository.updateItemQuantity(strings);
}
......@@ -341,7 +347,7 @@ public class OrderController extends Controller {
// implementation of coupon use
//Send notification to eligible devices
if (user.hasFcm()) {
sendNotification(user.getFcm(), "Order alert !!", "Order of $" + order.getRealityPay() + " has been created , proceed with payment");
}
......@@ -389,7 +395,7 @@ public class OrderController extends Controller {
@GetMapping("/cancelOrder")
@Transactional
@Transactional // transaction for rollback if something failed
public Result cancelOrder(@RequestParam("orderId") String orderId,
@RequestParam("reason") String reason) {
Optional<TbCfOrder> byId = repository.findById(orderId);
......@@ -407,7 +413,7 @@ public class OrderController extends Controller {
toicouponRepository.save(toicoupon);
}
}
//Return order items to the inventory
repository.returnItemQuantity(orderId);
repository.returnSkuQuantity(orderId);
......@@ -521,9 +527,9 @@ public class OrderController extends Controller {
public Map<String, Object> queryUserAvailableCoupons(BigDecimal orderPrice) {
Map<String, Object> couponMap = new HashMap<>();
//可使用的优惠券
LinkedList<TbCfToicoupon> availableCoupon = new LinkedList();
LinkedList<TbCfToicoupon> availableCoupon = new LinkedList<>();
//不可使用的优惠券
LinkedList<TbCfToicoupon> unAvailableCoupon = new LinkedList();
LinkedList<TbCfToicoupon> unAvailableCoupon = new LinkedList<>();
List<TbCfToicoupon> couponList = couponRepository.queryUserAvailableCoupon(user.userId());
couponList.forEach(coupon -> {
boolean available = orderPrice.compareTo(coupon.withAmount()) >= 0;
......
......@@ -81,6 +81,7 @@ public class PostController {
if (!byName.isPresent()) return new ArrayList<>();
//return found result
return repository.findAllByOrderByCreateDateDesc(byName.get(), PageRequest.of(pageNo, pageSize)).toList();
}
......@@ -192,7 +193,7 @@ public class PostController {
}
//Check if post is liked by user
private List<Post> postList(List<Post> postList, String userId) {
for (Post post : postList) {
post.liked = likeRepository.existsByUserInfo_UserIdAndPost_Id(userId, post.getId());
......@@ -201,12 +202,13 @@ public class PostController {
return postList;
}
//List posts for specific user
@GetMapping("/listPostsByUser/{userId}")
public List<Post> postListBy(@PathVariable(value = "userId") String id, @RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
List<Post> postList = repository.findAllByUserInfoUserIdOrderByCreateDateDesc(id, PageRequest.of(pageNo, pageSize)).toList();
return this.postList(postList, id);
}
//Search post
@GetMapping("/searchPost/{query}")
public List<Post> postListSearchBy(@PathVariable(value = "query") String query, @RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
return repository.findAllByDescriptionContainingOrTitleContainingOrUserInfoNickContaining(query,query,query, PageRequest.of(pageNo, pageSize)).toList();
......@@ -214,6 +216,7 @@ public class PostController {
}
@GetMapping("/delete/post/{postId}")
@Transactional //manage transaction for many queries
public String del(@PathVariable("postId") String id) {
try {
......@@ -245,6 +248,7 @@ public class PostController {
List<String> thumbList = new ArrayList<>();
if (thumbs != null) {
//Check if has video thumbs
for (MultipartFile file : thumbs) {
// StringBuilder sb = new StringBuilder();
// sb.append("data:image/png;base64,");
......@@ -263,6 +267,7 @@ public class PostController {
}
}
if (files != null) {
//Upload files list
for (MultipartFile file : files) {
//StringBuilder sb = new StringBuilder();
// sb.append("data:image/png;base64,");
......@@ -292,6 +297,7 @@ public class PostController {
ObjectMapper mapper = new ObjectMapper();
List<JsonTag> tags = null;
List<Hashtag> hashtags = null;
//read item tags and hashtags from json
try {
tags = mapper.readValue(ePost.getTags(), new TypeReference<List<JsonTag>>() {
});
......
......@@ -63,7 +63,7 @@ public class SearchController {
List<TbCfSearch> list = repository.getAllByUserIdOrderByCreateTimeDesc(user.userId());
return new Result<>(list);
}
//Delete items by collections of ids
@DeleteMapping("/deleteRecords")
public Result deleteRecords(@RequestBody String[] ids) {
if (ids != null) {
......@@ -73,7 +73,7 @@ public class SearchController {
return new Result(ResultCodeEnum.SERVICE_ERROR.getCode(),
ResultCodeEnum.SERVICE_ERROR.getDesc());
}
//Empty entire user search history
@DeleteMapping("/cleanSearch")
public Result deleteRecords() {
repository.deleteAllByUserId(user.userId());
......
......@@ -38,6 +38,7 @@ public class ShopifyController {
if( userOptional.isPresent() ){
TbCfUserInfo user = userOptional.get();
Page<CommentCount> page = repository.findAllByItemIdAndUser(itemId, user, request);
//Iterate to check if item is liked by selected user
page.getContent().forEach(v-> v.getItemComment().setLike(v.getCommented() != null && v.getCommented() > 0));
Page<TbCfItemComment> map = page.map(CommentCount::getItemComment);
return new Result<>(map);
......
......@@ -50,7 +50,7 @@ public class TbCfHomePageEntityController extends Controller {
return new Result<>(storeRepository.findAll(PageRequest.of(pageNum,pageSize)));
}
//Fetch recommended items
@GetMapping("home/listPosts/recommend")
public List<Post> postList2(@RequestParam(value = "userId",required = false) String id, @RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
......@@ -79,12 +79,14 @@ public class TbCfHomePageEntityController extends Controller {
return null;
}
//List users who are eligible to receive firebase cloud messages to their devices
@GetMapping("/home/clientWithFcm")
public Result getClientList( @RequestParam(value = "pageNo",required = false,defaultValue = "20") Integer pageNo, @RequestParam(value = "pageSize",required = false,defaultValue = "20") Integer pageSize){
List<TbCfUserInfo> allByFcmIsNotNull = userRepository.findAllByFcmIsNotNullOrderByLastLoginTimeDesc(PageRequest.of(pageNo, pageSize));
return new Result<>(allByFcmIsNotNull.stream().map(TbCfUserInfo::smallMap).collect(Collectors.toList()));
}
//Send notification to the user by his code
@GetMapping("/home/sendNotification/byCode/{code}")
public Result sendFcm(@PathVariable("code") String id,@RequestParam("content") String content,@RequestParam("title") String title){
Optional<TbCfUserInfo> byId = userRepository.findByCode(id);
......
......@@ -33,9 +33,9 @@ public class TermController {
public Result getAllTerms() {
//1.查询所有一级条款
List<Term> termList = termRepository.findByParentId("0");
List<Map> list = new ArrayList();
List<Map> list = new ArrayList<>();
termList.forEach(term -> {
Map<String, Object> map = new HashMap();
Map<String, Object> map = new HashMap<>();
//2.根据一级条款Id查询子条款
List<Term> childrenList = termRepository.findByParentId(term.getId());
map.put("parent", term);
......@@ -43,7 +43,7 @@ public class TermController {
list.add(map);
});
return new Result(list);
return new Result<>(list);
}
......@@ -54,7 +54,7 @@ public class TermController {
.setMessage("The parameter cannot be null");
}
return new Result(termRepository.findById(termId));
return new Result<>(termRepository.findById(termId));
}
}
......@@ -43,7 +43,7 @@ public class UserController extends Controller {
this.encoder = encoder;
this.emailHelper = emailHelper;
}
//Update email or phone number
@PutMapping("bindPhoneOrEmail")
public Result bindPhoneOrEmail(@RequestParam(value = "email",required = false) String email,@RequestParam(value = "code",required = false) String code,@RequestParam(value = "phone",required = false) String phone){
TbCfUserInfo user = this.user.user();
......
......@@ -65,4 +65,20 @@ public class Advertisement {
*/
private String remark;
public String getId() {
return id;
}
public Date getCreateTime() {
return createTime;
}
public Date getEndTime() {
return endTime;
}
public void setStatus(Integer status) {
this.status = status;
}
}
......@@ -112,6 +112,7 @@ public class TbCfCartRecordR {
this.itemImg = itemImg;
}
//get update item price instead of static one
public BigDecimal getItemPrice() {
return skuPrice != null ? skuPrice : realItemPrice !=null ? realItemPrice : itemPrice;
}
......
package com.example.afrishop_v3.models;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 魔方实体
* 表名 tb_cf_cube
*
* @author lipengjun
* @date 2020-07-07 10:40:24
*/
@Entity
@Data
public class TbCfCube {
/**
* 魔方ID
*/
@Id
private String id;
/**
* 魔方标题
*/
private String cubeTitle;
/**
* 标题图片
*/
private String headerImage;
/**
* 商品ID集合
*/
private String itemIds;
/**
* 排序
*/
private Integer sort;
/**
* 是否启用 0:不启用 1:启用
*/
private Integer isEnabled;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
@Transient
private List<TbCfStationItem> itemList = new ArrayList<>();
/**
* 设置:魔方ID
*/
public void setId(String id) {
this.id = id;
}
/**
* 获取:魔方ID
*/
public String getId() {
return id;
}
public void setItemList(List<TbCfStationItem> itemList) {
this.itemList = itemList;
}
/**
* 设置:魔方标题
*/
public void setCubeTitle(String cubeTitle) {
this.cubeTitle = cubeTitle;
}
/**
* 获取:魔方标题
*/
public String getCubeTitle() {
return cubeTitle;
}
/**
* 设置:标题图片
*/
public void setHeaderImage(String headerImage) {
this.headerImage = headerImage;
}
/**
* 获取:标题图片
*/
public String getHeaderImage() {
return headerImage;
}
/**
* 设置:商品ID集合
*/
public void setItemIds(String itemIds) {
this.itemIds = itemIds;
}
/**
* 获取:商品ID集合
*/
public String getItemIds() {
return itemIds;
}
/**
* 设置:排序
*/
public void setSort(Integer sort) {
this.sort = sort;
}
/**
* 获取:排序
*/
public Integer getSort() {
return sort;
}
/**
* 设置:是否启用 0:不启用 1:启用
*/
public void setIsEnabled(Integer isEnabled) {
this.isEnabled = isEnabled;
}
/**
* 获取:是否启用 0:不启用 1:启用
*/
public Integer getIsEnabled() {
return isEnabled;
}
/**
* 设置:创建时间
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
/**
* 获取:创建时间
*/
public Date getCreateTime() {
return createTime;
}
/**
* 设置:更新时间
*/
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
/**
* 获取:更新时间
*/
public Date getUpdateTime() {
return updateTime;
}
}
......@@ -155,24 +155,24 @@ public class TbCfUserInfo {
private Long codeCount;
@Formula(value = "(SELECT IFNULL(COUNT(c.id),0) FROM following c WHERE c.followed_info_user_id=user_id)")
private int followers;
private int followers;//Count users following
@Formula(value = "(SELECT IFNULL(COUNT(c.id),0) FROM post_data c WHERE c.id IN (SELECT l.post_id FROM post_like_v2 l WHERE l.user_info_user_id=user_id))")
private int likes;
private int likes;//Counts user's liked posts
@Formula(value = "(SELECT IFNULL(COUNT(c.id),0) FROM following c WHERE c.follower_info_user_id=user_id)")
private int following;
private int following;//Count users followers
@Formula(value = "(SELECT IFNULL(COUNT(c.id),0) FROM post_data c WHERE c.user_info_user_id=user_id)")
private int posts;
private int posts;//Count users posts
@Formula(value = "(SELECT IFNULL(SUM(c.amount),0.0) FROM bonus c WHERE c.user_info_user_id=user_id and c.is_withdraw=false)")
private double bonus;
private double bonus;//Sum up all collected bonuses
@Formula(value = "(SELECT IFNULL(SUM(c.amount),0.0) FROM bonus c WHERE c.user_info_user_id=user_id and c.is_withdraw=true)")
private double withdraw;
private double withdraw;//sum withdrawn amount on his account
@Formula(value = "(SELECT IFNULL(COUNT(c.id),0) FROM visit c INNER JOIN post_data p ON p.id=c.post_id WHERE p.user_info_user_id=user_id)")
private int visits;
private int visits;//Count user's visits
@Formula(value = "(SELECT IFNULL(COUNT(c.id),0) FROM network c WHERE c.user_info_user_id=user_id)")
private int networks;
private int networks; //count users networks
@Formula(value = "(SELECT IFNULL(COUNT(c.id),0) FROM network c WHERE c.network_info_user_id=user_id)")
private int invitation;
private int invitation;// count users invitations
@Transient
@JsonProperty
......
package com.example.afrishop_v3.repository;
import com.example.afrishop_v3.models.TbCfCube;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface TbCfCubeRepository extends PagingAndSortingRepository<TbCfCube,String> {
}
......@@ -47,4 +47,6 @@ public interface TbCfStationItemRepository extends PagingAndSortingRepository<Tb
List<TbCfStationItem> findTop4ByItemCategoryOrderByCreateTime(String category);
List<TbCfStationItem> findAllByItemIdIn(String[] ids);
}
......@@ -66,7 +66,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests().antMatchers("/api/auth/**", "/search/image/**", "/itemStation/**", "/startPage/**",
"/goodsType/**", "/home/**", "/spider/**", "/store/**", "/shopify/**", "/community/**", "/version/**",
"/flutterwave/notify/**", "/dpo/notify/**", "/advertisement/**", "/website/**","/paypal/**","/discover/bonus/**","/problem/**").permitAll()
"/flutterwave/notify/**", "/dpo/notify/**", "/advertisement/**", "/website/**","/paypal/**","/discover/bonus/**","/problem/**","/cube/**").permitAll()
.antMatchers("/api/test/**").permitAll()
.anyRequest().authenticated();
......
......@@ -16,4 +16,16 @@ public class Category {
private String id;
private String category;
private List<TbCfDescripiton> categoryList;
public void setCategory(String category) {
this.category = category;
}
public void setId(String id) {
this.id = id;
}
public void setCategoryList(List<TbCfDescripiton> categoryList) {
this.categoryList = categoryList;
}
}
......@@ -14,12 +14,12 @@ import java.util.List;
@RestController
@RequestMapping("/website/column2")
public class ColumnController {
public class Column2Controller {
private final TbCfGoodstypeRepository repository;
private final TbCfGoodstwotypeRepository goodstwotypeRepository;
public ColumnController(TbCfGoodstypeRepository repository, TbCfGoodstwotypeRepository goodstwotypeRepository) {
public Column2Controller(TbCfGoodstypeRepository repository, TbCfGoodstwotypeRepository goodstwotypeRepository) {
this.repository = repository;
this.goodstwotypeRepository = goodstwotypeRepository;
}
......
......@@ -49,7 +49,7 @@ public class ColumnController {
@GetMapping("/column")
public Result findTopCategory() {
return new Result(repository.findAll());
return new Result<>(repository.findAll());
}
/**
......@@ -57,7 +57,7 @@ public class ColumnController {
*/
@GetMapping("/column/{id}")
public Result findCategoryChildrens(@PathVariable("id") String id) {
LinkedList<Category> categoryList = new LinkedList();
LinkedList<Category> categoryList = new LinkedList<>();
//二级分类
List<TbCfGoodstwotype> secondaryCategory = secondaryRepository.findAllByGoodstypeId(id);
......@@ -72,7 +72,7 @@ public class ColumnController {
categoryList.add(c);
});
return new Result(categoryList);
return new Result<>(categoryList);
}
......@@ -92,7 +92,7 @@ public class ColumnController {
goodsType.setStationlist(station);
listStation.add(goodsType);
}
return new Result(listStation);
return new Result<>(listStation);
}
......
......@@ -5,7 +5,7 @@ server:
spring:
datasource:
url: jdbc:mysql://159.138.48.71:3306/test?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
url: jdbc:mysql://159.138.48.71:3306/chinafrica_ref?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
username: root
driver-class-name: com.mysql.cj.jdbc.Driver
password: Diaoyunnuli.8
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论