Skip to content

Commit f6e439d

Browse files
author
liulang
committed
Merge branch 'master' of https://github.com/cntehang/dev-docs
2 parents 4c5895d + 6f8bfb6 commit f6e439d

10 files changed

+394
-2
lines changed

backend/resources/swagger.jpg

242 KB
Loading

backend/swagger-usage-guideline.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Swagger-usage-guideline
2+
3+
- swagger 文档应成为前端调用后端接口的手册,在此对 swagger 使用进行规范,方便前后端交互。
4+
5+
## API 名称和说明
6+
7+
- 在 Controller 中对外暴露的方法上加上如下注解
8+
9+
```java
10+
@ApiOperation(value = "API名称", notes = "API说明")
11+
```
12+
13+
- 若该 API 有需要指出的异常情况,则在 notes 中加以说明,如下:
14+
15+
```java
16+
@ApiOperation(
17+
value = "员工登陆",
18+
notes = "根据用户名和密码进行登陆认证</br>"
19+
+ "code = 1: 密码错误</br>"
20+
+ "code = 2: 用户名不存在"
21+
)
22+
```
23+
24+
- 有一种对返回值的写法如下,其会将 code 视为 Http Status Code,并不适合我们的情况,故不采用
25+
26+
```java
27+
@ApiResponses(value = {
28+
@ApiResponse(code = 1, message = "密码错误"),
29+
@ApiResponse(code = 2, message = "用户名不存在")
30+
})
31+
```
32+
33+
34+
35+
## 请求参数说明
36+
37+
- 参数若为类对象:
38+
39+
- 类名上需加如下注释,用于说明此对象参数的名称:
40+
41+
```java
42+
@ApiModel(value = "登陆信息")
43+
```
44+
45+
- 类中字段需在 @ApiModelProperty 注解中加如下说明:
46+
- value:表示字段名
47+
- example:表示该字段的示例值,在测试时很有帮助
48+
- required: 若为必携带的参数,则为true
49+
50+
```java
51+
@ApiModelProperty(value = "用户名,可以为手机/邮箱", example = "[email protected]", required = true)
52+
```
53+
54+
- 若为普通参数:
55+
- 在方法的请求参数前,与 @RequestParam并列
56+
57+
```java
58+
@ApiParam(value = “用户ID”, example = "1100020")
59+
```
60+
61+
## 返回值说明
62+
63+
- 与请求参数如出一辙
64+
- 暂未看到返回非对象的注解方法,不过返回非对象的情况很少,基本可以忽略
65+
66+
## Sagger 配置类示例
67+
68+
```java
69+
@Configuration
70+
@EnableSwagger2
71+
public class SwaggerConfig {
72+
73+
/**
74+
* swagger配置
75+
* @return swagger相关配置
76+
*/
77+
@Bean
78+
public Docket createRestApi() {
79+
return new Docket(DocumentationType.SWAGGER_2)
80+
.apiInfo(apiInfo())
81+
.select()
82+
.apis(RequestHandlerSelectors.basePackage("com.tehang.tmc.services.application.rest.front.corp"))
83+
.paths(PathSelectors.any())
84+
.build();
85+
}
86+
87+
private ApiInfo apiInfo() {
88+
return new ApiInfoBuilder()
89+
.title("TMC Services")
90+
.description("出行从未如此简单")
91+
.contact(new Contact("TMC group", "https://www.teyixing.com", "[email protected]"))
92+
.version("1.0")
93+
.build();
94+
}
95+
96+
}
97+
```
98+
99+
## Swagger 文档界面说明
100+
![swagger文档界面说明](./resources/swagger.jpg)

developer-working-guide.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# 程序员工作指南
2+
3+
持续的、高质效的软件开发能力是现代企业的核心竞争力。用软件创造未来的程序员责任重大,任劳任怨。可是环顾四周,多数软件团队的研发能力相对计算机的巨大潜力和广泛的业务需求有巨大鸿沟,开发效率低,软件的质量令人忧伤。稍感安慰的是半个多世纪的编程历史积累了一些最佳实践(best practices)。遵守基于这些最佳实践的规则能大大改善程序员的工作效率。
4+
5+
## 1 前提
6+
7+
程序员的工作规则是基于如下的前提:
8+
9+
1. 真实和持久的幸福源于和一群优秀的同事达成共识、接受挑战、创造和分享非凡价值。
10+
11+
1. 软件就是业务,软件开发是不间断的持续过程,直到企业/程序员/用户的生命尽头。在心智和身体上都需要有长远准备。
12+
13+
1. 每个程序员都是业务的驱动者,拥有推动业务需要的所有知情权、资源和权利。
14+
15+
1. 每一行语句都会有 10 次以上的修改,可维护性是根本。
16+
17+
1. Bug 不可避免,但是很丢人,严重的错误是灾难性的。
18+
19+
1. 沟通合作、达成共识比想象的困难和必要,需要学习和建立机制。
20+
21+
1. 小就是美,便于理解和重用。
22+
23+
## 2 基本规则
24+
25+
### 2.1 对每个错误需要回答怎么不再犯
26+
27+
不再犯同样的错误是最有效的工作方法。
28+
29+
### 2.2 每周 40 小时工作,20 小时学习
30+
31+
清醒的头脑和不断学习是持续高效的基本保证。偶尔的冲刺可以用 20 小时的学习时间来工作,但是不应该成为常态。不鼓励熬夜,禁止每周工作超过 60 个小时。
32+
33+
### 2.3 每周锻炼 4 次,每次 1 个小时以上
34+
35+
体魄健康,头脑才灵。
36+
37+
### 2.4 达成共识
38+
39+
在业务和技术领域的决策、设计、代码等都有审查(review)。事关重要的都要达成共识 -- 经过大家充分讨论和理解优劣点。
40+
41+
### 2.5 程序员是业务专家
42+
43+
技术的目的是为了业务。熟悉业务和市场趋势才能创造最大价值。
44+
45+
## 3 团队规则
46+
47+
### 3.1 赋能个人
48+
49+
每个人都可以看到做事所需要的业务和技术信息、代码、资源。可以参与所有层级的决策。必要时第一线可以调动全公司资源来达成目标。
50+
51+
### 3.2 达成共识
52+
53+
决策是集体智慧的结果。相关人员都有发言权并充分参与讨论,每个人都清晰理解决策的过程、利弊考量和结果。
54+
55+
### 3.3 分享团队管理职责
56+
57+
团队的沟通、进度更新、不重犯错的方法、业务的改善等等,都是每个人的责任。大家分享团队管理职责,轮流主持各种会议。团队的每个问题都是我的问题。
58+
59+
### 3.4 认真的审核
60+
61+
设计文档与代码的审核是高效的质量保证。同时也是学习和沟通的好机会。
62+
63+
### 3.5 程序员参与产品设计并计划开发进度
64+
65+
程序员是业务专家和实现者。值得信赖和激发最大潜力。
66+
67+
### 3.5 持续编写相关技术文档
68+
69+
开发过程中随时编写相关技术文档,包括软件设计文档,技术选型,最佳实践,常见问题等。这样便于维护和分享。
70+
71+
### 3.6 提倡异步通信
72+
73+
程序员被打断一次平均需要 20 分钟才能恢复高效工作状态。尽量采用短信、邮件、Bug 库、代码库事件等异步通信方式沟通或约定面对面交流时间。
74+
75+
## 4 编码规则
76+
77+
### 4.1 自动化的测试是开发编码的一部分
78+
79+
没有自动测试的代码不算完成。自动化的测试为十次以上的重构带来至关重要的质量保证。
80+
81+
### 4.2 持续重构
82+
83+
看到需要改进的代码就立刻重构,目的是保持代码结构的清晰。大概编码的 20% 时间是用于重构的。反之,如果不良代码持续累积,系统变大之后发生质变,很可能无法正常工作或难以修改。同样的修复,后期维护成本是前期的数倍,而且影响更大更难控制。
84+
85+
### 4.3 每个函数不要超过 10 条语句
86+
87+
便于理解和重用。不超过 10 的规则也适用于一个目录不超过 10 个文件或其他类似可拆分的场合。
88+
89+
### 4.4 大的功能需要先设计再编码
90+
91+
对于稍微复杂的、费时超过一个工作日的功能,先写设计文档。这样通常更快而且质量更好。
92+
93+
### 4.5 一个函数的所有语句都在单一抽象层(Single Level Abstraction)
94+
95+
保持程序的结构清晰,而且也容易理解。
96+
97+
### 4.6 重复一次以后再抽象
98+
99+
不要一开始就预想各种使用场景来做抽象,低效而且误导。重复一次以后再抽象会更高效。
100+
101+
### 4.7 软件文档和注释
102+
103+
每个共用函数和模块都应该有相应 API 文档。源代码有适当的注释。
104+
105+
### 4.8 软件运行日志(Log)是程序的一部份
106+
107+
日志对运维和错误调试至关重要。其层级(Level)和相关信息需要仔细规划。

frontend/angular-best-practices.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Angular Best Practices
2+
3+
Here is a set of best practices using Angular
4+
5+
## Forms
6+
7+
As hinted by the offical Angular document, use the new Reactive Form, not Template Form. Template forms are asynchornous and event-driven. They are also not as flexible as reactive forms. Reactive fomrs have the following benefits:
8+
9+
- Synchronous form controls are easier to unit test
10+
- Forms and models are closely aligned
11+
- Group form controls together at different levels using group and array.
12+
- Validate form controls at any level and dynamically
13+
14+
Use the following style to create a form:
15+
16+
```ts
17+
constructor(private formBuilder: FormBuilder) {}
18+
19+
ngOnInit() {
20+
this.createForm()
21+
}
22+
23+
createForm() {
24+
this.myForm = this.formBuilder.group(...)
25+
}
26+
```
27+
28+
For most simple scenarios, use `FormBuilder` to create a form. For a complicated form, create `FormGroup` and `FormControl` directly.

frontend/code-documentation.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Code Documentation
2+
3+
All Angular-based projects use [CompoDoc](https://compodoc.app/) as code documentation tool to generate project document.
4+
5+
## What to Document
6+
7+
Document non-trivial modules, components, methods and important class memebers. Feel free to use Chinese, but please use English for technical terms.
8+
9+
Use `/docs` folder for additional project documents such as design document, implementation explanation etc.
10+
11+
Generate documents to `/dist/documentation` folder. The command is `npx compodoc -p tsconfig.json -n 'My App Documentation' --includes ./docs -d dist/documentation`.
12+
13+
建议项目的开发、设计文档放到 `docs`目录下面。产生的文档统一输出到 `dist/documentation`目录。
14+
15+
To see the output, use `-w -s -o` options with `compodoc`.
16+
17+
## How to Write Document
18+
19+
Compodoc uses JSDoc comments for documentation.
20+
21+
### JSDoc Comments
22+
23+
The documentation should use one of the following styles:
24+
25+
```ts
26+
/**
27+
* One line comment.
28+
*/
29+
30+
/**
31+
* First line followed by a blank line.
32+
*
33+
* Second line
34+
*/
35+
36+
/**
37+
* First line.
38+
* Second line.
39+
*/
40+
```
41+
42+
### JSDoc Tags
43+
44+
The following tags are supported in CompoDoc. 注意参数的注释不要写数据类型。JSDoc 可以从函数声明得到。
45+
46+
```ts
47+
/**
48+
* A summary of the function。函数总结
49+
* @param target The target to process. 这里不用写参数类型。
50+
* @returns The processed target number
51+
*/
52+
function processTarget(target: string): number
53+
54+
/**
55+
* 不用给下面的代码产生文档
56+
* @ignore
57+
*/
58+
59+
/**
60+
* 参考相关的文档。
61+
* see link {@link Todo}
62+
* see link {@link Todo|TodoClass}
63+
* see link [Todo]{@link Todo}
64+
* see link [Google]{@link http://www.google.com}
65+
* see link {@link http://www.apple.com|Apple}
66+
* see link {@link https://github.com GitHub}
67+
*/
68+
69+
/**
70+
* Example usage。使用举例。
71+
*
72+
* @example
73+
* <mwl-calendar-day-view
74+
* [viewDate]="viewDate"
75+
* [events]="events">
76+
* </mwl-calendar-day-view>
77+
*/
78+
```
79+
80+
### Routing Documentation
81+
82+
CompoDoc requires a const of type `Routes`, that is a parameter of `RouterModule.forRoot()) to generate routing document. Following is an example:
83+
84+
```ts
85+
const appRoutes: Routes = [
86+
{ path: 'about', component: AboutComponent },
87+
{ path: '', component: HomeComponent },
88+
]
89+
RouterModule.forRoot(appRoutes)
90+
```
91+
92+
### Documentation of module and component
93+
94+
每个项目有想过的设计文档和一些关键点的说明,放在 `docs`目录下面。
95+
96+
Add a `.md` file to the module or component with the same file name (except `.ts`). For example, for `my.component.ts`, add a `my.component.md` to document it with a file.
97+
98+
### Additional documentation
99+
100+
Adding additional markdown document files in a folder named `docs`. Then add a `summary.json` file as the following to give the structure of the additonal files:
101+
102+
```json
103+
[
104+
{
105+
"title": "A TITLE",
106+
"file": "a-file.md"
107+
},
108+
{
109+
"title": "A TITLE",
110+
"file": "a-file.md",
111+
"children": [
112+
{
113+
"title": "A TITLE",
114+
"file": "a-sub-folder/a-file.md"
115+
}
116+
]
117+
}
118+
]
119+
```
120+
121+
Use `--includes` flag to include the addtional files in the final documentation.
122+
123+
## Resources
124+
125+
- [CompoDoc Website](https://compodoc.app/)
126+
- [A Live Demo](https://compodoc.github.io/compodoc-demo-todomvc-angular/)
127+
- [The Live Demo Source Code](https://github.com/compodoc/compodoc-demo-todomvc-angular)
128+
- [A tutorial of an Ionic project](https://compodoc.app/guides/tutorial.html)
129+
- [Another video tutorial](https://youtu.be/90lnNtPmL8Y)

frontend/frontend-project-guideline.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The following are some commons user settings for VS Code IDE.
3131

3232
### 常用的 Extensions
3333

34-
- [Angular 6 Snippets](https://marketplace.visualstudio.com/items?itemName=Mikael.Angular-BeastCode): TypeScript, HTML, Angular Material, RxJS 等的 snippets.
34+
- [Angular 6 Snippets](https://marketplace.visualstudio.com/items?itemName=johnpapa.Angular2): TypeScript and HTML snippets.
3535
- [Bracket Pair Colorizer](https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer): 给予匹配的括号`()`, `{}`, `[]`不同颜色。
3636
- [Debugger for Chrome](https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome): a debug tool for Chrome.
3737
- [Kary Pro Colors](https://marketplace.visualstudio.com/items?itemName=karyfoundation.theme-karyfoundation-themes): 配置主题和颜色。

frontend/typescript-coding-standard.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ The coding guidelines are defined in the next section. There are two tools used
4646
1. When stating a rule, the subject should be in the singular (e.g. "An external module cannot..." instead of "External modules cannot...").
4747
1. Use present tense.
4848

49+
### 2.6 Angular and others
50+
51+
The Google Angular team has [a style guide](https://angular.io/guide/styleguide) that has many rules applicable for other front end develpment. Some useful rules include naming, small functions, single responsible principle, filename and etc.
52+
4953
## 3 TS Compiler Options
5054

5155
First of all, set the following compiler options in `tsconfig.json` to enforce strict type checking and error detection.

0 commit comments

Comments
 (0)