mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-22 12:45:46 +08:00
ADD project detail api
This commit is contained in:
@@ -107,6 +107,33 @@ class ProjectsController < ApplicationController
|
||||
@projects = Project.recommend.includes(:repository, :project_category, owner: :user_extension).limit(5)
|
||||
end
|
||||
|
||||
def about
|
||||
@project_detail = @project.project_detail
|
||||
@attachments = Array(@project_detail&.attachments) if request.get?
|
||||
ActiveRecord::Base.transaction do
|
||||
if request.post?
|
||||
authorizate_user_can_edit_project!
|
||||
unless @project_detail.present?
|
||||
@project_detail = ProjectDetail.new(
|
||||
content: params[:content],
|
||||
project_id: @project.id)
|
||||
else
|
||||
@project_detail.content = params[:content]
|
||||
end
|
||||
if @project_detail.save!
|
||||
attachment_ids = Array(params[:attachment_ids])
|
||||
logger.info "=============> #{Array(params[:attachment_ids])}"
|
||||
@attachments = Attachment.where(id: attachment_ids).select(:id, :container_id, :container_type)
|
||||
@attachments.update_all(
|
||||
container_id: @project_detail.id,
|
||||
container_type: @project_detail.model_name.name,
|
||||
author_id: current_user.id,
|
||||
description: "")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def project_params
|
||||
|
||||
@@ -32,6 +32,7 @@ class Project < ApplicationRecord
|
||||
has_many :versions, -> { order("versions.created_on DESC, versions.name DESC") }, dependent: :destroy
|
||||
has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
|
||||
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
|
||||
has_one :project_detail, dependent: :destroy
|
||||
|
||||
after_save :check_project_members
|
||||
scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :user_id, :forked_count, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)}
|
||||
|
||||
4
app/models/project_detail.rb
Normal file
4
app/models/project_detail.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class ProjectDetail < ApplicationRecord
|
||||
belongs_to :project, optional: true
|
||||
has_many :attachments, as: :container, dependent: :destroy
|
||||
end
|
||||
5
app/views/projects/about.json.jbuilder
Normal file
5
app/views/projects/about.json.jbuilder
Normal file
@@ -0,0 +1,5 @@
|
||||
json.content @project_detail&.content
|
||||
json.identifier @project.identifier
|
||||
json.attachments @attachments do |attach|
|
||||
json.partial! "attachments/attachment_simple", locals: {attachment: attach}
|
||||
end
|
||||
Reference in New Issue
Block a user