Skip to content

Commit

Permalink
Tring to fix codeQL errors
Browse files Browse the repository at this point in the history
  • Loading branch information
manjushsh committed Jan 5, 2025
1 parent 74672e5 commit 802eb44
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions server/controllers/controller.album.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func PostAlbums(c *gin.Context) {
// GetAlbumByID locates the album whose ID value matches the id parameter sent by the client.
func GetAlbumByID(c *gin.Context) {
id := c.Param("id")
// check if ID is valid. saftey check.
// check if ID is valid. safety check.
if !services.IsValidUUID(id) {
c.IndentedJSON(http.StatusBadRequest, gin.H{"message": "invalid album ID"})
return
Expand All @@ -94,7 +94,8 @@ func GetAlbumByID(c *gin.Context) {
defer mongoInstance.Disconnect()

var album models.Album
err := mongoInstance.FindOne("albums", bson.M{"id": id}).Decode(&album)
filter := bson.M{"id": id}
err := mongoInstance.FindOne("albums", filter).Decode(&album)
if err != nil {
c.IndentedJSON(http.StatusNotFound, gin.H{"message": "album not found"})
return
Expand All @@ -106,7 +107,7 @@ func GetAlbumByID(c *gin.Context) {
// UpdateAlbum updates an existing album with the provided ID.
func UpdateAlbum(c *gin.Context) {
id := c.Param("id")
// check if ID is valid. saftey check.
// check if ID is valid. safety check.
if !services.IsValidUUID(id) {
c.IndentedJSON(http.StatusBadRequest, gin.H{"message": "invalid album ID"})
return
Expand Down Expand Up @@ -144,7 +145,7 @@ func UpdateAlbum(c *gin.Context) {
// DeleteAlbum marks an album as deleted with the provided ID.
func DeleteAlbum(c *gin.Context) {
id := c.Param("id")
// check if ID is valid. saftey check.
// check if ID is valid. safety check.
if !services.IsValidUUID(id) {
c.IndentedJSON(http.StatusBadRequest, gin.H{"message": "invalid album ID"})
return
Expand Down
6 changes: 4 additions & 2 deletions server/controllers/controller.auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func Login(c *gin.Context) {
defer mongoInstance.Disconnect()

var foundUser models.Auth
err := mongoInstance.FindOne("users", bson.M{"username": loginRequest.Username, "isdeleted": false}).Decode(&foundUser)
filter := bson.D{{Key: "username", Value: loginRequest.Username}, {Key: "isdeleted", Value: false}}
err := mongoInstance.FindOne("users", filter).Decode(&foundUser)
if err != nil {
services.HandleError(c, err, http.StatusInternalServerError, "Invalid credentials - No User Found")
return
Expand Down Expand Up @@ -181,7 +182,8 @@ func DeleteUser(c *gin.Context) {
}
defer mongoInstance.Disconnect()

result, err := mongoInstance.Delete("users", bson.M{"username": username})
filter := bson.M{"username": username}
result, err := mongoInstance.Delete("users", filter)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to delete user"})
return
Expand Down

0 comments on commit 802eb44

Please sign in to comment.