Add proposal approval api endpoint
Change-Id: I3ab864af51735ee7c484df9c66d0b3ec2f6acb36
diff --git a/server/api/proposal.go b/server/api/proposal.go
new file mode 100644
index 0000000..2adc126
--- /dev/null
+++ b/server/api/proposal.go
@@ -0,0 +1,43 @@
+package api
+
+import (
+ "fmt"
+ "net/http"
+
+ "github.com/gin-gonic/gin"
+)
+
+func (apiObj *API) initProposal() {
+ apiObj.Proposal = apiObj.APIRoot.Group("/proposal")
+ apiObj.Proposal.POST("/approve", proposalApprovalHandler)
+}
+
+func proposalApprovalHandler(c *gin.Context) {
+ app, err := getApp(c)
+ if err != nil {
+ responseFormat(c, http.StatusInternalServerError, err.Error())
+ return
+ }
+
+ // Read the raw body for signature validation
+ body, err := c.GetRawData()
+ if err != nil {
+ responseFormat(c, http.StatusBadRequest, "Failed to read request body")
+ return
+ }
+
+ // Get the signature from headers
+ signature := c.GetHeader("X-Hub-Signature-256")
+ if signature == "" {
+ // Fallback to the older signature header
+ signature = c.GetHeader("X-Hub-Signature")
+ }
+
+ err = app.ProposalApproval(body, signature)
+ if err != nil {
+ responseFormat(c, http.StatusBadRequest, fmt.Sprintf("Failed to process webhook: %v", err))
+ return
+ }
+
+ responseFormat(c, http.StatusOK, "Proposal approved successfully")
+}