Skip to content
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

[FEATURE] Feedback system #31

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/target
*.db
.env

.idea/
.vscode/settings.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions migrations/20240823213817_add_feedback.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Add down migration script here

DROP TABLE IF EXISTS mod_feedback;
DROP TYPE IF EXISTS feedback_type;
DROP INDEX IF EXISTS idx_mod_feedback_mod_version_id;
DROP INDEX IF EXISTS idx_mod_feedback_reviewer_id;
27 changes: 27 additions & 0 deletions migrations/20240823213817_add_feedback.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- Add up migration script here

CREATE TYPE feedback_type AS ENUM
('Positive', 'Negative', 'Suggestion', 'Note');

CREATE TABLE mod_feedback
(
id SERIAL PRIMARY KEY NOT NULL,
mod_version_id INTEGER NOT NULL,
reviewer_id INTEGER NOT NULL,
feedback TEXT COLLATE pg_catalog."default" NOT NULL DEFAULT 'No feedback provided.'::text,
SorkoPiko marked this conversation as resolved.
Show resolved Hide resolved
decision BOOLEAN NOT NULL DEFAULT false,
qimiko marked this conversation as resolved.
Show resolved Hide resolved
type feedback_type NOT NULL,
CONSTRAINT mod_feedback_mod_id_reviewer_id_key UNIQUE (mod_version_id, reviewer_id),
CONSTRAINT mod_feedback_mod_version_id_fkey FOREIGN KEY (mod_version_id)
REFERENCES public.mod_versions (id)
ON DELETE CASCADE,
CONSTRAINT mod_feedback_reviewer_id_fkey FOREIGN KEY (reviewer_id)
REFERENCES public.developers (id)
ON DELETE CASCADE
);
SorkoPiko marked this conversation as resolved.
Show resolved Hide resolved

CREATE INDEX idx_mod_feedback_mod_version_id
ON public.mod_feedback (mod_version_id);

CREATE INDEX idx_mod_feedback_reviewer_id
ON public.mod_feedback (reviewer_id);
137 changes: 135 additions & 2 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ paths:
tags:
- mods
summary: Add a developer to a mod
description: This endpoint is only used for adding a developer to a mod. Must be the owner the mod to access this endpoint.
description: This endpoint is only used for adding a developer to a mod. Must be the owner of the mod to access this endpoint.
security:
- bearerAuth: []

Expand Down Expand Up @@ -628,6 +628,89 @@ paths:
"500":
$ref: "#/components/responses/InternalServerError"

/v1/mods/{id}/versions/{version}/feedback:
get:
tags:
- mods
summary: Get feedback for a specific version of a mod
security:
- bearerAuth: []
parameters:
- $ref: "#/components/parameters/ModID"
- $ref: "#/components/parameters/ModVersion"
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/ModFeedback"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFoundError"
"500":
$ref: "#/components/responses/InternalServerError"

post:
tags:
- mods
summary: Add feedback for a specific version of a mod
security:
- bearerAuth: []
parameters:
- $ref: "#/components/parameters/ModID"
- $ref: "#/components/parameters/ModVersion"
requestBody:
content:
application/json:
schema:
type: object
properties:
feedback_type:
type: string
enum:
- Positive
- Negative
- Suggestion
- Note
description: Type of feedback - positive/negative modifies score, note is mod dev only
example: Positive
feedback:
type: string
description: The feedback given by the reviewer
example: "This mod is great!"
responses:
"204":
description: No Content (Feedback added)
"400":
$ref: "#/components/responses/BadRequest"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFoundError"
"500":
$ref: "#/components/responses/InternalServerError"

delete:
tags:
- mods
summary: Delete feedback for a specific version of a mod
security:
- bearerAuth: []
parameters:
- $ref: "#/components/parameters/ModID"
- $ref: "#/components/parameters/ModVersion"
responses:
"204":
description: No Content (Feedback deleted)
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFoundError"
"500":
$ref: "#/components/responses/InternalServerError"

components:
securitySchemes:
bearerAuth:
Expand Down Expand Up @@ -973,6 +1056,56 @@ components:
- android32
- android64
- ios

Reviewer:
type: object
properties:
id:
type: integer
description: The developer ID of the reviewer
display_name:
type: string
description: The display name of the reviewer
admin:
type: boolean
description: Whether the reviewer is an admin

ModFeedbackOne:
type: object
properties:
reviewer:
$ref: "#/components/schemas/Reviewer"
description: The reviewer that gave the feedback
feedback_type:
type: string
enum:
- Positive
- Negative
- Suggestion
- Note
description: Type of feedback - positive/negative modifies score, note is mod dev only
feedback:
type: string
description: The feedback given by the reviewer
decision:
type: boolean
description: Whether or not this feedback was used to make a decision

ModFeedback:
type: object
properties:
score:
type: integer
description: The score of the mod, calculated as a sum of all feedback where positive is 1 and negative is -1
mod_id:
$ref: "#/components/schemas/ModID"
mod_version:
$ref: "#/components/schemas/ModVersionString"
feedback:
type: array
items:
$ref: "#/components/schemas/ModFeedbackOne"

parameters:
ModID:
name: id
Expand Down Expand Up @@ -1079,4 +1212,4 @@ components:
error:
type: string
payload:
type: "null"
type: "null"
1 change: 1 addition & 0 deletions src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pub mod mod_versions;
pub mod mods;
pub mod tags;
pub mod stats;
pub(crate) mod mod_feedback;
Loading