Skip to content

Commit

Permalink
finished all
Browse files Browse the repository at this point in the history
  • Loading branch information
upangka committed May 22, 2023
1 parent 2c1fbe9 commit cca8652
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
14 changes: 11 additions & 3 deletions ddd/multi-layers/src/main/java/org/hzz/controller/UserApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import io.swagger.v3.oas.annotations.ExternalDocumentation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.NotImplementedException;
import org.hzz.domain.common.Result;
import org.hzz.domain.dto.UserDTO;
import org.hzz.domain.vo.UserVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;

Expand All @@ -19,7 +22,10 @@
@Validated
public interface UserApi {

@Operation(summary = "查询用户信息",description = "根据用户id查询用户信息")
@Operation(summary = "查询用户信息", description = "根据用户id查询用户信息")
@ApiResponse(responseCode = "200", description = "查询成功"
/**, content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Result.class))
}*/)
@GetMapping("/queryById")
default Result<UserVO> queryById(
@Valid @NotNull @RequestParam(name="userid",required = false)
Expand All @@ -28,7 +34,9 @@ default Result<UserVO> queryById(
}


@Operation(summary = "保存用户信息",description = "保存用户信息到数据库")
@Operation(summary = "保存用户信息", description = "保存用户信息到数据库")
@ApiResponse(responseCode = "200", description = "保存成功"
, content = {@Content(mediaType = "application/json")})
@PostMapping("/save")
default public Result<String> save(@Valid @RequestBody UserDTO userDTO) {
throw new NotImplementedException("接口未实现");
Expand Down
30 changes: 22 additions & 8 deletions ddd/multi-layers/src/main/java/org/hzz/domain/common/Result.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
package org.hzz.domain.common;

import java.util.LinkedHashMap;
import com.alibaba.fastjson2.annotation.JSONField;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

public class Result<T> extends LinkedHashMap<String, Object> {
@Data
public class Result<T> {

@Schema(description = "返回码",example = "200")
@JSONField(ordinal = 0)
private String code;

@Schema(description = "返回信息",example = "success")
@JSONField(ordinal = 1)
private String msg;

@Schema(description = "返回数据")
@JSONField(ordinal = 2)
private T data;
public static <T> Result<T> success(T data){
Result<T> result = new Result<>();
result.put("code", "200");
result.put("msg", "success");
result.put("data", data);
result.setCode("200");
result.setMsg("success");
result.setData(data);
return result;
}

public static <T> Result<T> error(T data, String code, String msg){
Result<T> result = new Result<>();
result.put("code", code);
result.put("msg", msg);
result.put("error", data);
result.setCode(code);
result.setMsg(msg);
result.setData(data);
return result;
}
}
5 changes: 5 additions & 0 deletions ddd/multi-layers/src/main/java/org/hzz/domain/vo/UserVO.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package org.hzz.domain.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
public class UserVO {

@Schema(description = "用户名",example = "q10viking",title = "用户名t")
private String name;

@Schema(description = "密码",example = "123456")
private String password;
}
24 changes: 24 additions & 0 deletions ddd/multi-layers/src/main/resources/static/redoc-ui/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Redoc</title>
<!-- needed for adaptive design -->
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">

<!--
Redoc doesn't change outer page styles
-->
<style>
body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<redoc spec-url='http://localhost:8080/api/v3/api-docs'></redoc>
<script src="https://cdn.redoc.ly/redoc/v2.0.0/bundles/redoc.standalone.js"> </script>
</body>
</html>

0 comments on commit cca8652

Please sign in to comment.