Skip to content

Commit

Permalink
Delete Handler Implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
nirnejak committed May 25, 2024
1 parent 991c870 commit aee02e8
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,23 @@ func UpdateStock(c *gin.Context) {
func DeleteStock(c *gin.Context) {
symbol := c.Param("symbol")

// Implementation for deleting a stock from the database
db := GetDB()
result, err := db.Exec("DELETE FROM snp_500_financials WHERE symbol = ?", symbol)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

rowsAffected, err := result.RowsAffected()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

if rowsAffected == 0 {
c.JSON(http.StatusNotFound, gin.H{"error": "Stock Not Found"})
return
}

c.JSON(http.StatusOK, gin.H{
"symbol": symbol,
Expand Down

0 comments on commit aee02e8

Please sign in to comment.