コード例 #1
0
  @Test
  @Transactional
  public void updateCoupon() throws Exception {
    // Initialize the database
    couponRepository.saveAndFlush(coupon);

    int databaseSizeBeforeUpdate = couponRepository.findAll().size();

    // Update the coupon
    coupon.setCode(UPDATED_CODE);
    coupon.setPassword(UPDATED_PASSWORD);
    coupon.setCategory(UPDATED_CATEGORY);
    coupon.setStatus(STATUS.Unused);
    restCouponMockMvc
        .perform(
            put("/api/coupons")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(coupon)))
        .andExpect(status().isOk());

    // Validate the Coupon in the database
    List<Coupon> coupons = couponRepository.findAll();
    assertThat(coupons).hasSize(databaseSizeBeforeUpdate);
    Coupon testCoupon = coupons.get(coupons.size() - 1);
    assertThat(testCoupon.getCode()).isEqualTo(UPDATED_CODE);
    assertThat(testCoupon.getPassword()).isEqualTo(UPDATED_PASSWORD);
    assertThat(testCoupon.getCategory()).isEqualTo(UPDATED_CATEGORY);
    assertThat(testCoupon.getStatus()).isEqualTo(UPDATED_STATUS);
  }
コード例 #2
0
  /** 得到提货码 */
  @RequestMapping("/coupon")
  public String getCoupon(HttpServletRequest request, Model model) throws Exception {

    String openId = request.getParameter("openid");
    logger.debug("获取提货码 openId:" + openId);
    /* 判断是否已被注册 */
    CUser user = cUserService.findOneByOpenId(openId);
    if (user != null) {
      /* 已被注册 */
      logger.debug("------userId:" + user.getId());
      model.addAttribute("msg", "您已领取过提货码:");
      model.addAttribute("coupon", user.getCoupons().get(0).getCode());
      return "1436858491142/success";
    } else {
      /* 没被注册,绑定一个提货码 */
      Coupon coupon = cUserService.registerActivity("" + System.currentTimeMillis(), openId);
      logger.debug("------coupon:" + coupon.getCode());
      model.addAttribute("msg", "恭喜,您获得一枚提取码:");
      model.addAttribute("coupon", coupon.getCode());
      return "1436858491142/success";
    }
  }
コード例 #3
0
  /** 输入用户信息得到提货码 */
  @RequestMapping("/register")
  public String register(HttpServletRequest request, Model model) throws Exception {

    String mobile = request.getParameter("username");
    String openId = request.getParameter("openid");

    logger.info("mobile: " + mobile + " openId: " + openId);
    /* 判断是否已被注册 */
    if (!cUserService.verfiyMobileAndOpenId(mobile, openId))
      /* 已被注册 */
      return "fail";
    else {
      /* 没被注册,绑定一个提货码 */
      Coupon coupon = cUserService.registerActivity(mobile, openId);
      model.addAttribute("coupon", coupon.getCode());
      return "succeed";
    }
  }
コード例 #4
0
  /** 查询赠卷? (查询赠卷按钮连接的url) */
  @RequestMapping("/query")
  public String query(HttpServletRequest request, Model model) throws Exception {
    /* 通过code得到登录用户信息 */
    String code = request.getParameter("code");

    WxMpOAuth2AccessToken wxMpOAuth2AccessToken =
        WeChatConnector.getMpService().oauth2getAccessToken(code);
    WxMpUser wxMpUser =
        WeChatConnector.getMpService().oauth2getUserInfo(wxMpOAuth2AccessToken, null);

    String openId = wxMpUser.getOpenId();

    Coupon coupon = cUserService.queryActivity(openId);
    if (null == coupon) return "fail";
    else {
      model.addAttribute("coupon", coupon.getCode());
      return "succeed";
    }
  }
コード例 #5
0
  @Test
  @Transactional
  public void createCoupon() throws Exception {
    int databaseSizeBeforeCreate = couponRepository.findAll().size();

    // Create the Coupon
    restCouponMockMvc
        .perform(
            post("/api/coupons")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(coupon)))
        .andExpect(status().isCreated());

    // Validate the Coupon in the database
    List<Coupon> coupons = couponRepository.findAll();
    assertThat(coupons).hasSize(databaseSizeBeforeCreate + 1);
    Coupon testCoupon = coupons.get(coupons.size() - 1);
    assertThat(testCoupon.getCode()).isEqualTo(DEFAULT_CODE);
    assertThat(testCoupon.getPassword()).isEqualTo(DEFAULT_PASSWORD);
    assertThat(testCoupon.getCategory()).isEqualTo(DEFAULT_CATEGORY);
    assertThat(testCoupon.getStatus()).isEqualTo(DEFAULT_STATUS);
  }