Skip to content

Commit

Permalink
✨增加多种功能
Browse files Browse the repository at this point in the history
  • Loading branch information
mewhz authored and hz wang committed Apr 25, 2023
1 parent a7b9c26 commit 5bb9991
Show file tree
Hide file tree
Showing 95 changed files with 19,420 additions and 460 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
target

.idea
*.iml
27 changes: 12 additions & 15 deletions pastecode-system/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<artifactId>PasteCode</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>PasteCode</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
Expand All @@ -28,10 +27,11 @@
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
<version>3.5.2</version>
</dependency>

<dependency>
Expand All @@ -49,27 +49,24 @@
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.6</version>
<version>5.8.15</version>
</dependency>

<!-- Sa-Token 权限认证,在线文档:https://sa-token.cc -->
<!-- https://mvnrepository.com/artifact/cglib/cglib -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot-starter</artifactId>
<version>1.32.0</version>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.3.0</version>
</dependency>

<dependency>
<groupId>net.datafaker</groupId>
<artifactId>datafaker</artifactId>
<version>1.8.1</version>
</dependency>


</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mewhz.paste;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ public BaseResponse(int responseCode, String responseMessage) {
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public static <T> BaseResponse<T> success(T responseData) {
return new BaseResponse<>(0, responseData, "ok");
}

// public static <T> BaseResponse<T> success() {
//
// }

/**
* 登录错误
* @param responseMessage 返回的错误信息
Expand All @@ -29,6 +33,10 @@ public static <T> BaseResponse<T> codeError(String responseMessage) {
return new BaseResponse<>(40020, responseMessage);
}

public static <T> BaseResponse<T> registerError(String responseMessage) {
return new BaseResponse<>(40030, responseMessage);
}

/**
* 未知错误
* @return 错误代码与未知错误
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mewhz.paste.constant;

/**
* @author mewhz
*/
public interface CodeConstant {

/**
* 代码返回时每页的数量
*/
Long CODE_PAGE_NUM = 3L;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.mewhz.paste.constant;

/**
* @author mewhz
*/
public interface UserConstant {

/**
* 邮箱存在时提示的语句
*/
String EMAIL_ERROR_MESSAGE = "邮箱已存在!";

/**
* 用户注册时账号长度
*/
Integer USER_ACCOUNT_LENGTH = 8;

/**
* 注册时第一位为零时重试次数
*/

Integer ACCOUNT_RETRY_NUM = 10;

/**
* 注册时账号循环次数
*/
Integer ACCOUNT_RETRY_CYCLE = 1000;

/**
* 用户返回时每页的数量
*/
Long USER_PAGE_NUM = 5L;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.mewhz.paste.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.bean.BeanUtil;
import com.mewhz.paste.model.entity.Code;
import com.mewhz.paste.model.vo.*;
import com.mewhz.paste.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
* @author mewhz
Expand All @@ -18,46 +19,73 @@
@RequestMapping("/code")
public class CodeController {

@Autowired
@Resource
private CodeService codeService;


@GetMapping("/")
public List<Code> findAll(){
return codeService.list();
public ResultVO<List<Code>> findAll(){
return ResultVO.ok(codeService.list());
}

@PostMapping("/")
public Map<String, Object> save(@RequestBody Code code){
Map<String, Object> result = new HashMap<>();
codeService.save(code);

System.out.println(code);

result.put("status", 200);
result.put("msg", "success");
result.put("codeId", code.getCodeId());
return result;
public ResultVO<CodeInfoVO> saveCode(@RequestBody CodeSubmitVO codeSubmitVO){
return ResultVO.ok(codeService.saveCode(codeSubmitVO));
}

@SaCheckLogin
@GetMapping("/id/{id}")
public Code findById(@PathVariable("id") Integer id){
return codeService.getById(id);
@GetMapping("/id/{codeId}")
public ResultVO<CodeInfoVO> findByCodeId(@PathVariable("codeId") Integer codeId){
return ResultVO.ok(codeService.findByCodeId(codeId));
}

@GetMapping("/title/{codeTitle}")
public List<Code> findByCodeTitle(@PathVariable String codeTitle){
return codeService.findByCodeTitle(codeTitle);
public ResultVO<List<CodeInfoVO>> findByCodeTitle(@PathVariable String codeTitle){
return ResultVO.ok(codeService.findByCodeTitle(codeTitle));
}

@GetMapping("/page/{codeTitle}/{current}")
public List<Code> findByCodeTitlePage(@PathVariable Integer current, @PathVariable String codeTitle) {
return codeService.findByCodeTitlePage(current, codeTitle);
public ResultVO<List<CodeInfoVO>> findByCodeTitlePage(@PathVariable Integer current, @PathVariable String codeTitle) {
return ResultVO.ok(codeService.findByCodeTitlePage(current, codeTitle));
}

@GetMapping("/page/total/{codeTitle}")
public Long getCodeTitleTotal(@PathVariable String codeTitle) {
return codeService.getCodeTitleTotal(codeTitle);
public ResultVO<Long> getCodeTitleTotal(@PathVariable String codeTitle) {
return ResultVO.ok(codeService.getCodeTitleTotal(codeTitle));
}

@GetMapping("/share/{userId}")
public ResultVO<List<CodeInfoVO>> getUserShareCode(@PathVariable Integer userId) {
return ResultVO.ok(codeService.userShareCode(userId));
}

@GetMapping("/list")
public ResultVO<ResultPageVO<CodeInfoVO>> getList(CodeSearchVO codeSearchVO) {
return ResultVO.ok(codeService.getList(codeSearchVO));
}

@PostMapping("/delete")
public ResultVO<Boolean> delete(@RequestBody Code code) {
return ResultVO.ok(codeService.removeById(code));
}

@PostMapping("/update")
public ResultVO<Boolean> update(@RequestBody Code code) {
return ResultVO.ok(codeService.updateById(code));
}

@GetMapping("/download/{codeId}")
public void download(HttpServletResponse response, @PathVariable Integer codeId) throws IOException {
codeService.download(response, codeId);
}

@GetMapping("/getStatusList/{userId}")
public ResultVO<List<CodeStatusInfo>> getStatusList(@PathVariable Integer userId) {
return ResultVO.ok(codeService.getStatusList(userId));
}

@GetMapping("/getUserCollectList/{userId}")
public ResultVO<List<CodeStatusInfo>> getUserCollectList(@PathVariable Integer userId) {
return ResultVO.ok(codeService.userCollectCode(userId));
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.mewhz.paste.controller;

import com.mewhz.paste.model.entity.Code;
import com.mewhz.paste.model.entity.User;
import com.mewhz.paste.model.vo.ResultVO;
import com.mewhz.paste.model.vo.UserRegisterVO;
import com.mewhz.paste.service.CodeService;
import com.mewhz.paste.service.UserService;
import lombok.SneakyThrows;
import net.datafaker.Faker;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
* @author mewhz
*/
@RestController
@RequestMapping("/heart")
public class HeartController {

@Resource
private CodeService codeService;

// @GetMapping("/login")
// public SaTokenInfo login() {
// StpUtil.login(1001);
// return StpUtil.getTokenInfo();
// }
//
// @GetMapping("/info")
// public boolean isLogin() {
// return StpUtil.isLogin();
// }
//
// @GetMapping("/logout")
// public String logout(){
// StpUtil.logout();
// return "success";
// }
//
// @SaCheckLogin
// @GetMapping("/token")
// public String token() {
// return "Hello World";
// }

// @Resource
// UserService userService;
//
// @GetMapping("/")
// public void fakerUser() {
//
// for (int i = 0; i < 20; i ++) {
// UserRegisterVO userRegisterVO = new UserRegisterVO();
//
// Faker faker = new Faker();
//
//
// userRegisterVO.setUserName(faker.random().hex());
// userRegisterVO.setUserEmail(faker.random().hex() + "@163.com");
// userRegisterVO.setUserPassword("123456");
//
// userService.register(userRegisterVO);
// }
//
// }

@SneakyThrows
@GetMapping("/download/{codeId}")
public void download(HttpServletResponse response, @PathVariable String codeId) {
response.reset();
response.setContentType("application/octet-stream");
response.setHeader("Content-disposition",
"attachment;filename=file_" + System.currentTimeMillis() + ".txt");

Code code = codeService.getById(codeId);

byte[] bytes = code.getCodeText().getBytes();

System.out.println(bytes.length);

response.getOutputStream().write(bytes);

}
}
Loading

0 comments on commit 5bb9991

Please sign in to comment.