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

commit

上级 9a5594d1
...@@ -18,7 +18,7 @@ public class CommentLikeController { ...@@ -18,7 +18,7 @@ public class CommentLikeController {
@PostMapping(value ="/saveCommentLike/{liked}") @PostMapping(value ="/saveCommentLike/{liked}")
public CommentLike saveReply(@PathVariable("liked") boolean liked, @ModelAttribute("CommentLike") CommentLike like){ public CommentLike saveCommentLike(@PathVariable("liked") boolean liked, @ModelAttribute("CommentLike") CommentLike like){
if( liked ) if( liked )
return repository.save(like); return repository.save(like);
else{ else{
......
package com.example.afrishop_v3.controllers;
import com.example.afrishop_v3.models.Complain;
import com.example.afrishop_v3.repository.ComplainRepository;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class ComplainController {
private final ComplainRepository repository;
public ComplainController(ComplainRepository repository) {
this.repository = repository;
}
@PostMapping(value ="/saveComplain")
public Complain saveProduct(@ModelAttribute("Complain") Complain complain){
return repository.save(complain);
}
@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) {
return repository.findAll(PageRequest.of(pageNo, pageSize)).toList();
}
}
package com.example.afrishop_v3.controllers;
import com.example.afrishop_v3.base.Result;
import com.example.afrishop_v3.models.TbCfStationItem;
import com.example.afrishop_v3.repository.TbCfGoodstypeEntityRepository;
import com.example.afrishop_v3.repository.TbCfStationItemRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import static org.springframework.data.domain.Sort.Order.asc;
import static org.springframework.data.domain.Sort.Order.desc;
@RestController
@RequestMapping("/goodsType")
public class GoodsTypeController {
private static Logger logger = LoggerFactory.getLogger(GoodsTypeController.class);
private final TbCfGoodstypeEntityRepository repository;
private final TbCfStationItemRepository itemRepository;
public GoodsTypeController(TbCfGoodstypeEntityRepository repository, TbCfStationItemRepository itemRepository) {
this.repository = repository;
this.itemRepository = itemRepository;
}
@RequestMapping("/getGoodsTypeList")
@GetMapping
public Result getGoodsTypeList() {
return new Result<>(repository.findAll());
}
@RequestMapping("/getItemStationList")
@GetMapping
public Result getItemStationList(@RequestParam(required = false) Integer pageNum,
@RequestParam(required = false) Integer pageSize,
@RequestParam(required = false) String categoryId,
@RequestParam(required = false) String order
) {
if (pageNum == null) {
pageNum = 1;
}
if (pageSize == null) {
pageSize = 6;
}
if( categoryId != null){
itemRepository.findByItemCategory(categoryId,PageRequest.of(pageNum, pageSize,sort(order)));
}
Page<TbCfStationItem> all = itemRepository.findAll(PageRequest.of(pageNum, pageSize,sort(order)));
return new Result<>(all);
}
private Sort sort(String order){
String col = "discountPrice";
return Sort.by( "desc".equals(order) ? desc(col) : asc(col));
}
}
...@@ -15,7 +15,7 @@ public class HashtagController { ...@@ -15,7 +15,7 @@ public class HashtagController {
this.repository = repository; this.repository = repository;
} }
@GetMapping(value = "/listHashtags") @GetMapping(value = "/home/listHashtags")
//@PreAuthorize("hasAuthority('ADMIN_USER') or hasAuthority('STANDARD_USER')") //@PreAuthorize("hasAuthority('ADMIN_USER') or hasAuthority('STANDARD_USER')")
public List<Hashtag> getList(@RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) { public List<Hashtag> getList(@RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
return repository.findAll(PageRequest.of(pageNo, pageSize)).toList(); return repository.findAll(PageRequest.of(pageNo, pageSize)).toList();
......
...@@ -14,6 +14,7 @@ import java.util.Optional; ...@@ -14,6 +14,7 @@ import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@RestController @RestController
@RequestMapping("/discover/networking")
public class NetworkController { public class NetworkController {
private final NetworkRepository repository; private final NetworkRepository repository;
private final UserRepository userRepository; private final UserRepository userRepository;
......
...@@ -83,13 +83,6 @@ public class PostController { ...@@ -83,13 +83,6 @@ public class PostController {
return id == null ? postList : postList(postList, id); return id == null ? postList : postList(postList, id);
} }
@GetMapping("/listPosts/recommend")
public List<Post> postList2(@RequestParam(value = "userId") String id, @RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
Optional<TbCfUserInfo> byId = userRepository.findById(id);
//if( !byId.isPresent() ) return new ArrayList<>();
List<Post> postList = repository.findAllByOrderByIdDesc(PageRequest.of(pageNo, pageSize)).toList();
return id == null ? postList : postList(postList, id);
}
@GetMapping("/visit/{postId}") @GetMapping("/visit/{postId}")
public Visit visitPage(@PathVariable(value = "postId") long id) { public Visit visitPage(@PathVariable(value = "postId") long id) {
......
package com.example.afrishop_v3.controllers;
import com.example.afrishop_v3.models.Reply;
import com.example.afrishop_v3.repository.ReplyRepository;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/discover/replies")
public class ReplyController {
private final ReplyRepository repository;
public ReplyController(ReplyRepository repository) {
this.repository = repository;
}
@GetMapping(value = "/RepliesByCommentId/{commentId}")
//@PreAuthorize("hasAuthority('ADMIN_USER') or hasAuthority('STANDARD_USER')")
public List<Reply> getList(@PathVariable(value = "commentId") long id, @RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
return repository.findAllByCommentId(id, PageRequest.of(pageNo, pageSize)).toList();
}
@PostMapping(value ="/saveReply")
public Reply saveReply(@ModelAttribute("Reply") Reply reply){
return repository.save(reply);
}
}
...@@ -20,14 +20,18 @@ public class TbCfHomePageEntityController { ...@@ -20,14 +20,18 @@ public class TbCfHomePageEntityController {
private final TbCfStoreRepository storeRepository; private final TbCfStoreRepository storeRepository;
private final TbCfPosterRepository posterRepository; private final TbCfPosterRepository posterRepository;
private final TbCfColumnRepository columnRepository; private final TbCfColumnRepository columnRepository;
private final UserRepository userRepository;
private final PostRepository postRepository;
public TbCfHomePageEntityController(TbCfHomePageRepository repository, TbCfSortRepository sortRepository, TbCfClassificationRepository classificationRepository, TbCfStoreRepository storeRepository, TbCfPosterRepository posterRepository, TbCfColumnRepository columnRepository) { public TbCfHomePageEntityController(TbCfHomePageRepository repository, TbCfSortRepository sortRepository, TbCfClassificationRepository classificationRepository, TbCfStoreRepository storeRepository, TbCfPosterRepository posterRepository, TbCfColumnRepository columnRepository, UserRepository userRepository, PostRepository postRepository) {
this.repository = repository; this.repository = repository;
this.sortRepository = sortRepository; this.sortRepository = sortRepository;
this.classificationRepository = classificationRepository; this.classificationRepository = classificationRepository;
this.storeRepository = storeRepository; this.storeRepository = storeRepository;
this.posterRepository = posterRepository; this.posterRepository = posterRepository;
this.columnRepository = columnRepository; this.columnRepository = columnRepository;
this.userRepository = userRepository;
this.postRepository = postRepository;
} }
@GetMapping("/startPage/img") @GetMapping("/startPage/img")
...@@ -42,6 +46,16 @@ public class TbCfHomePageEntityController { ...@@ -42,6 +46,16 @@ public class TbCfHomePageEntityController {
return new Result<>(storeRepository.findAll(PageRequest.of(pageNum,pageSize))); return new Result<>(storeRepository.findAll(PageRequest.of(pageNum,pageSize)));
} }
@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) {
Optional<TbCfUserInfo> byId = userRepository.findById(id);
//if( !byId.isPresent() ) return new ArrayList<>();
return postRepository.findAllByOrderByIdDesc(PageRequest.of(pageNo, pageSize)).toList();
}
@GetMapping("/home/middleColumn") @GetMapping("/home/middleColumn")
public Result getMiddleColumn( @RequestParam(value = "limit", defaultValue = "4") Integer limit){ public Result getMiddleColumn( @RequestParam(value = "limit", defaultValue = "4") Integer limit){
Result result = new Result<>(); Result result = new Result<>();
......
...@@ -29,7 +29,7 @@ public class UserController { ...@@ -29,7 +29,7 @@ public class UserController {
this.user = user; this.user = user;
} }
public static boolean isEmailValid(String email) { private static boolean isEmailValid(String email) {
String expression = "^[\\w.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$"; String expression = "^[\\w.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE); Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(email); Matcher matcher = pattern.matcher(email);
...@@ -152,10 +152,29 @@ public class UserController { ...@@ -152,10 +152,29 @@ public class UserController {
} }
@GetMapping("userById/{id}") @GetMapping("/userById/{id}")
public Result userById(@PathVariable("id") String id){ public Result userById(@PathVariable("id") String id){
Optional<TbCfUserInfo> byId = repository.findById(id); Optional<TbCfUserInfo> byId = repository.findById(id);
return byId.map(userInfo -> new Result<>(userInfo, "Success")).orElseGet(() -> new Result<>(ResultCodeEnum.VALIDATE_ERROR.getCode(), "Not found !")); return byId.map(userInfo -> new Result<>(userInfo, "Success")).orElseGet(() -> new Result<>(ResultCodeEnum.VALIDATE_ERROR.getCode(), "Not found !"));
} }
@GetMapping(value = "/userByCode/{code}")
public Result getUserByCode(@PathVariable("code") String code) {
Optional<TbCfUserInfo> byCode = repository.findByCode(code);
boolean present = byCode.isPresent();
return new Result<>(present ? byCode.get() : null,present ? 1 : 0, present ? "Successfully" : "Invitation code not found");
}
@GetMapping(value = "/edit/slogan")
public Result editSlogan(@RequestBody TbCfUserInfo tbCfUserInfo) {
TbCfUserInfo user = this.user.user();
if( user != null && tbCfUserInfo != null){
user.setSlogan(tbCfUserInfo.getSlogan());
}
return new Result<>(user);
}
} }
package com.example.afrishop_v3.controllers;
import com.example.afrishop_v3.base.Result;
import com.example.afrishop_v3.models.Bonus;
import com.example.afrishop_v3.models.TbCfUserInfo;
import com.example.afrishop_v3.repository.BonusRepository;
import com.example.afrishop_v3.repository.UserRepository;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
@RestController
@RequestMapping("/discover/withdraw")
public class WithdrawController {
private final BonusRepository repository;
private final UserRepository userRepository;
public WithdrawController(BonusRepository repository, UserRepository userRepository) {
this.repository = repository;
this.userRepository = userRepository;
}
@GetMapping(value = "/withdrawsByUserId/{userId}")
//@PreAuthorize("hasAuthority('ADMIN_USER') or hasAuthority('STANDARD_USER')")
public List<Bonus> getList(@PathVariable(value = "userId") String id, @RequestParam(value = "pageNo") Integer pageNo, @RequestParam(value = "pageSize") Integer pageSize) {
return repository.findAllByUserInfo_UserIdAndWithdraw(id,true, PageRequest.of(pageNo, pageSize)).toList();
}
@PostMapping(value = "/saveWithdraw")
public Result saveWithdraw(@ModelAttribute("Bonus") Bonus withdraw) {
int code = 1;
String message = "Withdraw request received";
if( withdraw.getUserId() == null ){
message = "Service Error";
code = 0;
}
Optional<TbCfUserInfo> byId = userRepository.findById(withdraw.getUserId());
if( !byId.isPresent() ){
code = 0;
message = "Service Error";
}
if( byId.isPresent() && byId.get().getWallet() < withdraw.getAmount() ){
code = 0;
message = "Insufficient balance";
}
if( code == 1 ){
withdraw.reverseAmount();
withdraw = repository.save(withdraw);
}
return new Result<>(withdraw,code,message);
}
}
package com.example.afrishop_v3.models;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
@Entity
@Getter
@Setter
public class Complain extends Model {
@ManyToOne
private TbCfUserInfo userInfo;
@ManyToOne
private Post post;
private String type;
private String description;
}
...@@ -50,6 +50,7 @@ public class TbCfItemSkus{ ...@@ -50,6 +50,7 @@ public class TbCfItemSkus{
/** /**
* 价格 * 价格
*/ */
@JsonProperty(value = "price")
private BigDecimal skuPrice; private BigDecimal skuPrice;
/** /**
* 属性IDS * 属性IDS
...@@ -58,6 +59,7 @@ public class TbCfItemSkus{ ...@@ -58,6 +59,7 @@ public class TbCfItemSkus{
/** /**
* 数量 * 数量
*/ */
@JsonProperty(value = "count")
private Integer skuCount; private Integer skuCount;
/** /**
* 排序号 * 排序号
...@@ -84,7 +86,7 @@ public class TbCfItemSkus{ ...@@ -84,7 +86,7 @@ public class TbCfItemSkus{
List<SkuDetail> detailList = new ArrayList<>(); List<SkuDetail> detailList = new ArrayList<>();
for (String s : split){ for (String s : split){
if( index > split2.length ) break; if( index > split2.length ) break;
detailList.add(new SkuDetail(s,split2[index])); detailList.add(new SkuDetail(s.trim(),split2[index].trim()));
index++; index++;
} }
return detailList; return detailList;
......
...@@ -30,6 +30,7 @@ public class TbCfUserInfo { ...@@ -30,6 +30,7 @@ public class TbCfUserInfo {
* 用户id * 用户id
*/ */
@Id @Id
@Column(length = 64)
private String userId; private String userId;
/** /**
* 用户编号 * 用户编号
...@@ -221,6 +222,14 @@ public class TbCfUserInfo { ...@@ -221,6 +222,14 @@ public class TbCfUserInfo {
return token; return token;
} }
public void setSlogan(String slogan) {
this.slogan = slogan;
}
public String getSlogan(){
return slogan;
}
public void setToken(String token) { public void setToken(String token) {
this.token = token; this.token = token;
} }
...@@ -247,6 +256,13 @@ public class TbCfUserInfo { ...@@ -247,6 +256,13 @@ public class TbCfUserInfo {
return userId; return userId;
} }
@JsonProperty
public double getWallet() {
return bonus + withdraw;
}
/** /**
* 设置:用户编号 * 设置:用户编号
*/ */
......
package com.example.afrishop_v3.repository;
import com.example.afrishop_v3.models.Complain;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface ComplainRepository extends PagingAndSortingRepository<Complain,Long> {
}
package com.example.afrishop_v3.repository;
import com.example.afrishop_v3.models.TbCfGoodstype;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface TbCfGoodstypeEntityRepository extends PagingAndSortingRepository<TbCfGoodstype,String> {
}
...@@ -17,5 +17,6 @@ public interface TbCfStationItemRepository extends PagingAndSortingRepository<Tb ...@@ -17,5 +17,6 @@ public interface TbCfStationItemRepository extends PagingAndSortingRepository<Tb
@Query(value = "select a from #{#entityName} a WHERE a.itemId <> :itemId and (a.itemDescritionId = :descriptionId or a.itemCategorytwo = :categoryTwo or a.itemCategory = :category )") @Query(value = "select a from #{#entityName} a WHERE a.itemId <> :itemId and (a.itemDescritionId = :descriptionId or a.itemCategorytwo = :categoryTwo or a.itemCategory = :category )")
Page<TbCfStationItem> getRecommendItems(@Param("itemId") String itemId,@Param("descriptionId") String descriptionId,@Param("categoryTwo") String categoryTwo,@Param("category") String category, Pageable pageable); Page<TbCfStationItem> getRecommendItems(@Param("itemId") String itemId,@Param("descriptionId") String descriptionId,@Param("categoryTwo") String categoryTwo,@Param("category") String category, Pageable pageable);
Page<TbCfStationItem> findAllByItemNameContainingOrItemTagsContaining(String itemName, String itemTags, Pageable pageable); Page<TbCfStationItem> findAllByItemNameContainingOrItemTagsContaining(String itemName, String itemTags, Pageable pageable);
Page<TbCfStationItem> findByItemCategory(String itemName, Pageable pageable);
List<TbCfStationItem> findAllByItemDescritionId(String id); List<TbCfStationItem> findAllByItemDescritionId(String id);
} }
...@@ -58,7 +58,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -58,7 +58,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
http.cors().and().csrf().disable() http.cors().and().csrf().disable()
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and() .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and() .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests().antMatchers("/api/auth/**", "/itemStation/**", "/startPage/**", "/home/**", "/spider/**", "/store/**", "/shopify/**").permitAll() .authorizeRequests().antMatchers("/api/auth/**", "/itemStation/**", "/startPage/**", "/goodsType/**", "/home/**", "/spider/**", "/store/**", "/shopify/**").permitAll()
.antMatchers("/api/test/**").permitAll() .antMatchers("/api/test/**").permitAll()
.anyRequest().authenticated(); .anyRequest().authenticated();
......
server.servlet.context-path=/zion server.servlet.context-path=/zion
spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:165.22.82.105}:3306/chinafrica?useUnicode=true&connectionCollation=utf8_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC spring.datasource.url=jdbc:mysql://${MYSQL_HOST:47.106.242.175}:3306/chinafrica?useUnicode=true&connectionCollation=utf8mb4_general_ci&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=clement123 spring.datasource.password=diaoyun666
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.datasource.connectionInitSql: SET NAMES 'utf8mb4' spring.datasource.connectionInitSql: SET NAMES 'utf8mb4'
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect #spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论