-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: auth, code snippet version, security
- Loading branch information
Showing
26 changed files
with
560 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# CHANGELOG | ||
|
||
## Version 0.0.1 | ||
|
||
#### NOTE: the code snippet schema changed. | ||
|
||
For creating the code snippet, there should be two requests: | ||
|
||
1) POST /api/v1/code_snippet -> Title, UserID (optional) | ||
2) POST /api/v1/code_snippet_version -> CodeSnippetID, ProgramLanguageID, Text | ||
|
||
This is done for being able to have versioning for the code snippets. | ||
|
||
Features List: | ||
|
||
- Code Snippets: Added GET /api/v1/user_code_snippets to retrieve user code snippets | ||
- Code Snippets: Added POST /api/v1/review_comment to create reviews for code snippets | ||
- Code Snippets: Added POST /api/v1/code_snippet_version to create a new version of the code snippet | ||
- Authorization: Added POST /api/v1/register and POST /api/v1/login | ||
- Authorization: Added JWT token generation and check for login / signup | ||
- Authorization: Added validation of username and password | ||
- Security: Added security middleware | ||
- Database: Programming languages are inserted with the first migration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package handler | ||
|
||
import ( | ||
"github.com/abinba/codereview/database" | ||
"github.com/abinba/codereview/model" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
// CreateCodeSnippet godoc | ||
// @Summary Create a code snippet | ||
// @Description Create a code snippet | ||
// @Tags Code Snippets | ||
// @Accept json | ||
// @Produce json | ||
// @Param code_snippet body CodeSnippetVersion true "Code Snippet information to create" | ||
// @Success 201 {object} model.CodeSnippet | ||
// @Router /api/v1/code_snippet/ [post] | ||
func CreateCodeSnippetVersion(c *fiber.Ctx) error { | ||
db := database.DB.Db | ||
|
||
code_snippet := new(model.CodeSnippetVersion) | ||
if err := c.BodyParser(code_snippet); err != nil { | ||
return c.Status(400).JSON(fiber.Map{ | ||
"status": "error", "message": "Could not parse request", "data": err, | ||
}) | ||
} | ||
|
||
if result := db.Create(&code_snippet); result.Error != nil { | ||
return c.Status(500).JSON(fiber.Map{ | ||
"status": "error", "message": "Could not create code snippet version", "data": result.Error, | ||
}) | ||
} | ||
|
||
return c.Status(201).JSON(fiber.Map{ | ||
"status": "success", "message": "Code Snippet Version has been created", "data": code_snippet, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package handler | ||
|
||
import ( | ||
"github.com/abinba/codereview/database" | ||
"github.com/abinba/codereview/model" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
// CreateReviewComment creates a review comment. | ||
// @Summary Create a review comment | ||
// @Description Adds a new review comment to the database. | ||
// @Tags Review Comments | ||
// @Accept json | ||
// @Produce json | ||
// @Param review_comment body ReviewComment true "Review comment information to create" | ||
// @Success 201 {object} model.ReviewComment | ||
// @Router /api/v1/review_comment/ [post] | ||
func CreateReviewComment(c *fiber.Ctx) error { | ||
db := database.DB.Db | ||
|
||
review_comment := new(model.ReviewComment) | ||
if err := c.BodyParser(review_comment); err != nil { | ||
return c.Status(400).JSON(fiber.Map{ | ||
"status": "error", "message": "Could not parse request", "data": err, | ||
}) | ||
} | ||
|
||
if result := db.Create(&review_comment); result.Error != nil { | ||
return c.Status(500).JSON(fiber.Map{ | ||
"status": "error", "message": "Could not create review comment", "data": result.Error, | ||
}) | ||
} | ||
|
||
return c.Status(201).JSON(fiber.Map{ | ||
"status": "success", "message": "Review comment has been created", "data": review_comment, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package handler | ||
|
||
import ( | ||
"github.com/abinba/codereview/database" | ||
"github.com/abinba/codereview/model" | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/google/uuid" | ||
) | ||
|
||
// GetUserCodeSnippets godoc | ||
// @Summary Get user's code snippets | ||
// @Description Retrieve all code snippets created by a specific user | ||
// @Tags User Code Snippets | ||
// @Accept json | ||
// @Produce json | ||
// @Param user_id path string true "User ID" | ||
// @Success 200 {array} model.CodeSnippet | ||
// @Router /api/v1/user_code_snippets/{user_id} [get] | ||
func GetUserCodeSnippets(c *fiber.Ctx) error { | ||
db := database.DB.Db | ||
userID := c.Params("id") | ||
|
||
var userUUID uuid.UUID | ||
if err := userUUID.UnmarshalText([]byte(userID)); err != nil { | ||
return c.Status(400).JSON(fiber.Map{ | ||
"status": "error", "message": "Invalid user ID format", "data": nil, | ||
}) | ||
} | ||
|
||
var code_snippets []model.CodeSnippet | ||
db.Where("user_id = ?", userUUID).Preload("CodeSnippetVersions").Preload("User").Find(&code_snippets) | ||
|
||
if len(code_snippets) == 0 { | ||
return c.Status(404).JSON(fiber.Map{ | ||
"status": "error", "message": "No code snippets found for the user", "data": nil, | ||
}) | ||
} | ||
|
||
return c.Status(200).JSON(fiber.Map{ | ||
"status": "success", "message": "User code snippets found", "data": code_snippets, | ||
}) | ||
} |
Oops, something went wrong.