Backend: add Subscription CRUD
This commit is contained in:
@@ -84,10 +84,9 @@ func (mc *MembershipController) UpdateHandler(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Register Subscription
|
||||
logger.Info.Printf("Registering subscription %v", regData.Subscription.Name)
|
||||
// id, err := mc.Service.UpdateSubscription(®Data.Subscription)
|
||||
id := 1
|
||||
// update Subscription
|
||||
logger.Info.Printf("Updating subscription %v", regData.Subscription.Name)
|
||||
id, err := mc.Service.UpdateSubscription(®Data.Subscription)
|
||||
if err != nil {
|
||||
logger.Error.Printf("Couldn't update Membershipmodel: %v", err)
|
||||
if strings.Contains(err.Error(), "UNIQUE constraint failed") {
|
||||
@@ -103,6 +102,33 @@ func (mc *MembershipController) UpdateHandler(c *gin.Context) {
|
||||
"id": id,
|
||||
})
|
||||
}
|
||||
|
||||
func (mc *MembershipController) DeleteSubscription(c *gin.Context) {
|
||||
var membershipdata MembershipData
|
||||
requestUser, err := mc.UserController.ExtractUserFromContext(c)
|
||||
if err != nil {
|
||||
utils.RespondWithError(c, err, "Error extracting user from context in subscription UpdateHandler", http.StatusBadRequest, "general", "server.validation.no_auth_tokenw")
|
||||
return
|
||||
}
|
||||
|
||||
if !utils.HasPrivilige(requestUser, constants.Priviliges.Update) {
|
||||
utils.RespondWithError(c, errors.ErrNotAuthorized, "Not allowed to update subscription", http.StatusForbidden, "user", "server.error.unauthorized")
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.ShouldBindJSON(&membershipdata); err != nil {
|
||||
utils.HandleValidationError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := mc.Service.DeleteSubscription(&membershipdata.Subscription); err != nil {
|
||||
utils.RespondWithError(c, err, "Error during subscription Deletion", http.StatusExpectationFailed, "subscription", "server.error.not_possible")
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Subscription deleted successfully"})
|
||||
}
|
||||
|
||||
func (mc *MembershipController) GetSubscriptions(c *gin.Context) {
|
||||
subscriptions, err := mc.Service.GetSubscriptions(nil)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user