halo/application
guqing fb2bc4252d
refactor: add parameter verification to the visit counter API (#3546)
#### What type of PR is this?
/kind improvement
/area core
/milestone 2.4.x

#### What this PR does / why we need it:
对访问量统计的 API 增加数据合法性校验
点赞同理

see #3530 for more details

how to test it?
1. 访问文章和页面可以统计访问量
2. 使用访问以下 API 添加模拟使用错误数据不会在 Counter 模型添加记录
```shell
curl 'http://localhost:8090/apis/api.halo.run/v1alpha1/trackers/counter' -u 'your-username:your-password'  \
--header 'Content-Type: application/json' \
--data '{
    "group": "fake.halo.run",
    "plural": "posts",
    "name": "fake-name",
    "hostname": "localhost",
    "screen": "1920x1080",
    "language": "zh-CN",
    "url": "/archives/hello-halo",
    "referrer": "http://localhost:8090/"
}'
```
期望出现日志:
```
2023-03-21T12:37:08.391+08:00 DEBUG 7036 --- [task-4] r.h.app.metrics.VisitedEventReconciler   : Skip visit event for: GroupPluralName[group=fake.halo.run, plural=posts, name=fake-name]
```
并且
```
curl 'http://localhost:8090/apis/metrics.halo.run/v1alpha1/counters' -u 'your-username:your-password'
```
不会出现上述错误数据的记录
#### Which issue(s) this PR fixes:

Fixes #3530

#### Does this PR introduce a user-facing change?

```release-note
对访问量统计的 API 增加数据合法性校验
```
2023-03-27 08:04:17 +00:00
..
src refactor: add parameter verification to the visit counter API (#3546) 2023-03-27 08:04:17 +00:00
build.gradle Refactor project structure for a better development (#3552) 2023-03-23 08:02:33 +00:00