-
Notifications
You must be signed in to change notification settings - Fork 172
PR from E2552 to E2557 #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bf07582
79b1cfa
646da19
5306624
2a84b20
bbb73e4
10a6cdc
bea6385
8de3e25
aab5d91
0b97d14
c9f4dbc
e627fb8
8e1d078
91848b2
eb67061
f9ee2fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| ruby-3.4.5 | ||
| ruby-3.4.5 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| class ProjectTopicsController < ApplicationController | ||
| before_action :set_project_topic, only: %i[ show update ] | ||
|
|
||
| # GET /project_topics?assignment_id=&topic_ids[]= | ||
| def index | ||
| if params[:assignment_id].nil? | ||
| render json: { message: 'Assignment ID is required!' }, status: :unprocessable_entity | ||
| else | ||
| @project_topics = ProjectTopic.find_by_assignment_and_topic_ids(params[:assignment_id], params[:topic_ids]) | ||
| render json: @project_topics.map(&:to_json_with_computed_data), status: :ok | ||
| end | ||
| end | ||
|
|
||
| # POST /project_topics | ||
| def create | ||
| result = ProjectTopic.create_topic_with_assignment( | ||
| project_topic_params, | ||
| params[:project_topic][:assignment_id], | ||
| params[:micropayment] | ||
| ) | ||
|
|
||
| if result[:success] | ||
| render json: { message: result[:message] }, status: :created | ||
| else | ||
| render json: { message: result[:message] }, status: :unprocessable_entity | ||
| end | ||
| end | ||
|
|
||
| # PATCH/PUT /project_topics/1 | ||
| def update | ||
| result = @project_topic.update_topic(project_topic_params) | ||
|
|
||
| if result[:success] | ||
| render json: { message: result[:message] }, status: :ok | ||
| else | ||
| render json: { message: result[:message] }, status: :unprocessable_entity | ||
| end | ||
| end | ||
|
|
||
| # Show a ProjectTopic by ID | ||
| def show | ||
| render json: @project_topic, status: :ok | ||
| end | ||
|
|
||
| # Destroy ProjectTopics by assignment_id and optional topic_ids | ||
| def destroy | ||
| if params[:assignment_id].nil? | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't need this check, the project topic always belong to an assignment |
||
| render json: { message: 'Assignment ID is required!' }, status: :unprocessable_entity | ||
| else | ||
| result = ProjectTopic.delete_by_assignment_and_topic_ids(params[:assignment_id], params[:topic_ids]) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to loop over all topic ids and call delete method for each topic id |
||
|
|
||
| if result[:success] | ||
| render json: { message: result[:message] }, status: :no_content | ||
| else | ||
| render json: { message: result[:message] }, status: :unprocessable_entity | ||
| end | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| # Use callbacks to share common setup or constraints between actions. | ||
| def set_project_topic | ||
| @project_topic = ProjectTopic.find(params[:id]) | ||
| end | ||
|
|
||
| # Only allow a list of trusted parameters through. | ||
| def project_topic_params | ||
| params.require(:project_topic).permit(:topic_identifier, :category, :topic_name, :max_choosers, :assignment_id, :description, :link) | ||
| end | ||
| end | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for micropayment field