diff --git a/app/controllers/users/system_notification_histories_controller.rb b/app/controllers/users/system_notification_histories_controller.rb new file mode 100644 index 000000000..70e91fbb9 --- /dev/null +++ b/app/controllers/users/system_notification_histories_controller.rb @@ -0,0 +1,15 @@ +class Users::SystemNotificationHistoriesController < Users::BaseController + before_action :private_user_resources!, only: [:create] + def create + @history = observed_user.system_notification_histories.new(system_notification_id: params[:system_notification_id]) + if @history.save + render_ok + else + Rails.logger.info @history.errors.as_json + render_error(@history.errors.full_messages.join(",")) + end + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) + end +end \ No newline at end of file diff --git a/app/docs/slate/source/includes/_users.md b/app/docs/slate/source/includes/_users.md index 9d6b80927..594ce725a 100644 --- a/app/docs/slate/source/includes/_users.md +++ b/app/docs/slate/source/includes/_users.md @@ -199,6 +199,36 @@ await octokit.request('GET /api/users/:login/messages.json') Success Data. +## 用户阅读系统通知 +用户阅读系统通知 + +> 示例: + +```shell +curl -X POST http://localhost:3000/api/users/yystopf/system_notification_histories.json +``` + +```javascript +await octokit.request('GET /api/users/:login/system_notification_histories.json') +``` + +### HTTP 请求 +`POST /api/users/:login/system_notification_histories.json` + +### 请求字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|system_notification_id |integer |阅读的系统通知id | + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "success" +} +``` + ## 发送消息 发送消息, 目前只支持atme diff --git a/app/models/system_notification_history.rb b/app/models/system_notification_history.rb index 8723ca917..b629babdf 100644 --- a/app/models/system_notification_history.rb +++ b/app/models/system_notification_history.rb @@ -18,4 +18,6 @@ class SystemNotificationHistory < ApplicationRecord belongs_to :system_notification belongs_to :user + + validates :system_notification_id, uniqueness: { scope: :user_id, message: '只能阅读一次'} end diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index c8d4c89eb..3b0935e07 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -59,7 +59,7 @@ json.setting do if @top_system_notification.present? json.system_notification do - json.(@top_system_notification, :subject, :sub_subject, :content) + json.(@top_system_notification, :id, :subject, :sub_subject, :content) json.is_read @top_system_notification.read_member?(current_user.id) end else diff --git a/config/locales/system_notification_histories/zh-CN.yml b/config/locales/system_notification_histories/zh-CN.yml new file mode 100644 index 000000000..8dd7b49db --- /dev/null +++ b/config/locales/system_notification_histories/zh-CN.yml @@ -0,0 +1,6 @@ +zh-CN: + activerecord: + attributes: + system_notification_history: + system_notification: "系统通知" + system_notification_id: "系统通知" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index b940ed700..92061df93 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -263,6 +263,7 @@ Rails.application.routes.draw do end scope module: :users do + resources :system_notification_histories, only: [:create] resources :applied_messages, only: [:index] resources :applied_transfer_projects, only: [:index] do member do diff --git a/public/docs/api.html b/public/docs/api.html index 8368e8fae..0f1121781 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -348,6 +348,9 @@
  • 用户消息列表
  • +
  • + 用户阅读系统通知 +
  • 发送消息
  • @@ -1328,7 +1331,39 @@ Success — a happy kitten is an authenticated kitten! -

    发送消息

    +

    用户阅读系统通知

    +

    用户阅读系统通知

    + +
    +

    示例:

    +
    +
    curl -X POST http://localhost:3000/api/users/yystopf/system_notification_histories.json
    +
    await octokit.request('GET /api/users/:login/system_notification_histories.json')
    +

    HTTP 请求

    +

    POST /api/users/:login/system_notification_histories.json

    +

    请求字段说明:

    + + + + + + + + + + + + +
    参数类型字段说明
    system_notification_idinteger阅读的系统通知id
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "success"
    +}
    +

    发送消息

    发送消息, 目前只支持atme

    @@ -1336,9 +1371,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/:login/messages.json
     
    await octokit.request('POST /api/users/:login/messages.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST api/users/yystopf/messages.json

    -

    请求字段说明:

    +

    请求字段说明:

    @@ -1397,9 +1432,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/:login/messages/read.json
     
    await octokit.request('POST /api/users/:login/messages/read.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST api/users/yystopf/messages/read.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1438,9 +1473,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X DELETE http://localhost:3000/api/users/:login/messages.json
     
    await octokit.request('DELETE /api/users/:login/messages.json')
    -

    HTTP 请求

    +

    HTTP 请求

    DELETE api/users/yystopf/messages.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1479,9 +1514,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X PATCH/PUT http://localhost:3000/api/users/yystopf.json
     
    await octokit.request('PATCH/PUT /api/users/:login.json')
    -

    HTTP 请求

    +

    HTTP 请求

    PATCH/PUT /api/users/:login.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1577,7 +1612,7 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/is_pinned_projects.json
     
    await octokit.request('GET /api/users/:login/is_pinned_projects.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET api/users/:login/is_pinned_projects.json

    返回字段说明:

    参数
    @@ -1764,9 +1799,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/is_pinned_projects/pin.json
     
    await octokit.request('GET /api/users/:login/is_pinned_projects/pin.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST /api/users/:login/is_pinned_projects/pin.json

    -

    请求字段说明:

    同时设定多个星标项目

    +

    请求字段说明:

    同时设定多个星标项目

    @@ -1810,9 +1845,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X PATCH http://localhost:3000/api/users/yystopf/is_pinned_projects/11.json
     
    await octokit.request('PATCH/PUT /api/users/:login/is_pinned_projects/:id.json')
    -

    HTTP 请求

    +

    HTTP 请求

    PATCH/PUT /api/users/:login/is_pinned_projects/:id.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1851,7 +1886,7 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/statistics/activity.json
     
    await octokit.request('GET /api/users/:login/statistics/activity.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/statistics/activity.json

    返回字段说明:

    参数
    @@ -1940,9 +1975,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/headmaps.json
     
    await octokit.request('GET /api/users/:login/headmaps.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET api/users/:login/headmaps.json

    -

    请求字段说明:

    +

    请求字段说明:

    @@ -2085,9 +2120,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/project_trends.json
     
    await octokit.request('GET /api/users/:login/project_trends.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET api/users/:login/project_trends.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2402,9 +2437,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/statistics/develop.json
     
    await octokit.request('GET /api/users/:login/statistics/develop.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/statistics/develop.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2545,9 +2580,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/statistics/role.json
     
    await octokit.request('GET /api/users/:login/statistics/role.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/statistics/role.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2627,9 +2662,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/statistics/major.json
     
    await octokit.request('GET /api/users/:login/statistics/major.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/statistics/major.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2688,9 +2723,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/applied_messages.json
     
    await octokit.request('GET /api/users/:login/applied_messages.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_messages.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2967,9 +3002,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/applied_transfer_projects.json
     
    await octokit.request('GET /api/users/:login/applied_transfer_projects.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_transfer_projects.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3159,9 +3194,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/applied_transfer_projects/2/accept.json
     
    await octokit.request('GET /api/users/:login/applied_transfer_projects/:id/accept.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_transfer_projects/:id/accept.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3350,9 +3385,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/applied_transfer_projects/2/refuse.json
     
    await octokit.request('GET /api/users/:login/applied_transfer_projects/:id/refuse.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_transfer_projects/:id/refuse.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3541,9 +3576,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/applied_projects.json
     
    await octokit.request('GET /api/users/:login/applied_projects.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_projects.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3701,9 +3736,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/applied_projects/2/accept.json
     
    await octokit.request('GET /api/users/:login/applied_projects/:id/accept.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_projects/:id/accept.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3860,9 +3895,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/applied_projects/2/refuse.json
     
    await octokit.request('GET /api/users/:login/applied_projects/:id/refuse.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_projects/:id/refuse.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    参数