Merge remote-tracking branch 'origin/standalone_develop' into standalone_develop

This commit is contained in:
“xxq250” 2022-11-08 15:33:54 +08:00
commit f4794f6489
7 changed files with 78 additions and 4 deletions

View File

@ -0,0 +1,16 @@
class Api::V1::Users::FeedbacksController < Api::V1::BaseController
before_action :load_observe_user
before_action :check_auth_for_observe_user
def create
@result = Api::V1::Users::Feedbacks::CreateService.call(@observe_user, feedback_params)
return render_error("反馈意见创建失败.") if @result.nil?
return render_ok
end
private
def feedback_params
params.permit(:content)
end
end

20
app/models/feedback.rb Normal file
View File

@ -0,0 +1,20 @@
# == Schema Information
#
# Table name: feedbacks
#
# id :integer not null, primary key
# user_id :integer
# content :text(65535)
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_feedbacks_on_user_id (user_id)
#
class Feedback < ApplicationRecord
belongs_to :user
end

View File

@ -0,0 +1,26 @@
class Api::V1::Users::Feedbacks::CreateService < ApplicationService
include ActiveModel::Model
attr_reader :user, :content
attr_accessor :feedback
validates :content, presence: true
def initialize(user, params)
@user = user
@content = params[:content]
end
def call
raise Error, errors.full_messages.join(",") unless valid?
begin
@feedback = Feedback.new(user: user, content: content)
@feedback.save!
return @feedback.valid? ? @feedback : nil
rescue
raise Error, "服务器错误,请联系系统管理员!"
end
end
end

View File

@ -5,7 +5,6 @@
<th width="6%">ID</th>
<th width="20%" class="text-left">项目名称</th>
<th width="5%">公开</th>
<th width="5%">精选</th>
<th width="5%">推荐</th>
<th width="5%">Issues</th>
<th width="5%">资源</th>
@ -27,7 +26,6 @@
<%= link_to(project.name, "/#{project&.owner&.login}/#{project.identifier}", target: '_blank') %>
</td>
<td><%= project.is_public ? '√' : '' %></td>
<td><%= project.is_pinned ? '√' : '' %></td>
<td><%= project.recommend ? '√' : '' %></td>
<td><%= project.issues.size %></td>
<td><%= project.attachments.size %></td>
@ -40,8 +38,6 @@
<td><%= project.created_on&.strftime('%Y-%m-%d %H:%M') %></td>
<td class="action-container">
<% if project.is_public %>
<%= javascript_void_link '精选', class: 'action pinned-action', data: { id: project.id }, style: project.is_pinned ? 'display: none;' : '' %>
<%= javascript_void_link '取消精选', class: 'action unpinned-action', data: { id: project.id }, style: project.is_pinned ? '' : 'display: none;' %>
<%= javascript_void_link '推荐', class: 'action recommend-action', data: { id: project.id }, style: project.recommend ? 'display: none;' : '' %>
<%= javascript_void_link '取消推荐', class: 'action unrecommend-action', data: { id: project.id }, style: project.recommend ? '' : 'display: none;' %>
<%= link_to "设置推荐等级", edit_admins_project_path(project.id), remote: true, class: "action edit-recommend-action", style: project.recommend ? '' : 'display: none;' %>

View File

@ -0,0 +1,5 @@
'zh-CN':
activemodel:
attributes:
api/v1/users/feedbacks/create_service:
content: "反馈意见"

View File

@ -13,6 +13,7 @@ defaults format: :json do
end
scope module: :users do
resources :projects, only: [:index]
resources :feedbacks, only: [:create]
end
scope ':repo' do

View File

@ -0,0 +1,10 @@
class CreateFeedbacks < ActiveRecord::Migration[5.2]
def change
create_table :feedbacks do |t|
t.references :user
t.text :content
t.timestamps
end
end
end