@ -2,6 +2,7 @@ package rest
import (
"fmt"
domainGroup "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/group"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/whatsapp"
@ -22,6 +23,9 @@ func InitRestGroup(app *fiber.App, service domainGroup.IGroupService) Group {
app . Post ( "/group/participants/remove" , rest . DeleteParticipants )
app . Post ( "/group/participants/promote" , rest . PromoteParticipants )
app . Post ( "/group/participants/demote" , rest . DemoteParticipants )
app . Get ( "/group/participants/requested" , rest . RequestedParticipants )
app . Post ( "/group/participants/requested/approve" , rest . ApproveRequestedParticipants )
app . Post ( "/group/participants/requested/reject" , rest . RejectRequestedParticipants )
return rest
}
@ -77,83 +81,78 @@ func (controller *Group) CreateGroup(c *fiber.Ctx) error {
} ,
} )
}
func ( controller * Group ) AddParticipants ( c * fiber . Ctx ) error {
var request domainGroup . ParticipantRequest
err := c . BodyParser ( & request )
utils . PanicIfNeeded ( err )
whatsapp . SanitizePhone ( & request . GroupID )
return controller . manageParticipants ( c , whatsmeow . ParticipantChangeAdd , "Success add participants" )
}
request . Action = whatsmeow . ParticipantChangeAdd
func ( controller * Group ) DeleteParticipants ( c * fiber . Ctx ) error {
return controller . manageParticipants ( c , whatsmeow . ParticipantChangeRemove , "Success delete participants" )
}
result , err := controller . Service . ManageParticipant ( c . UserContext ( ) , request )
utils . PanicIfNeeded ( err )
func ( controller * Group ) PromoteParticipants ( c * fiber . Ctx ) error {
return controller . manageParticipants ( c , whatsmeow . ParticipantChangePromote , "Success promote participants" )
}
return c . JSON ( utils . ResponseData {
Status : 200 ,
Code : "SUCCESS" ,
Message : "Success add participants" ,
Results : result ,
} )
func ( controller * Group ) DemoteParticipants ( c * fiber . Ctx ) error {
return controller . manageParticipants ( c , whatsmeow . ParticipantChangeDemote , "Success demote participants" )
}
func ( controller * Group ) Delete Participants( c * fiber . Ctx ) error {
var request domainGroup . ParticipantRequest
err := c . Bod yParser( & request )
func ( controller * Group ) RequestedParticipants ( c * fiber . Ctx ) error {
var request domainGroup . GetGroupRequestParticipantsRequest
err := c . Quer yParser( & request )
utils . PanicIfNeeded ( err )
whatsapp . SanitizePhone ( & request . GroupID )
request . Action = whatsmeow . ParticipantChangeRemove
result , err := controller . Service . ManageParticipant ( c . UserContext ( ) , request )
result , err := controller . Service . GetGroupRequestParticipants ( c . UserContext ( ) , request )
utils . PanicIfNeeded ( err )
return c . JSON ( utils . ResponseData {
Status : 200 ,
Code : "SUCCESS" ,
Message : "Success delete participants" ,
Message : "Success getting list requested participants" ,
Results : result ,
} )
}
func ( controller * Group ) PromoteParticipants ( c * fiber . Ctx ) error {
func ( controller * Group ) ApproveRequestedParticipants ( c * fiber . Ctx ) error {
return controller . handleRequestedParticipants ( c , whatsmeow . ParticipantChangeApprove , "Success approve requested participants" )
}
func ( controller * Group ) RejectRequestedParticipants ( c * fiber . Ctx ) error {
return controller . handleRequestedParticipants ( c , whatsmeow . ParticipantChangeReject , "Success reject requested participants" )
}
// Generalized participant management handler
func ( controller * Group ) manageParticipants ( c * fiber . Ctx , action whatsmeow . ParticipantChange , successMsg string ) error {
var request domainGroup . ParticipantRequest
err := c . BodyParser ( & request )
utils . PanicIfNeeded ( err )
whatsapp . SanitizePhone ( & request . GroupID )
request . Action = whatsmeow . ParticipantChangePromote
request . Action = action
result , err := controller . Service . ManageParticipant ( c . UserContext ( ) , request )
utils . PanicIfNeeded ( err )
return c . JSON ( utils . ResponseData {
Status : 200 ,
Code : "SUCCESS" ,
Message : "Success promote participants" ,
Message : successMsg ,
Results : result ,
} )
}
func ( controller * Group ) DemoteParticipants ( c * fiber . Ctx ) error {
var request domainGroup . ParticipantRequest
// Generalized requested participants handler
func ( controller * Group ) handleRequestedParticipants ( c * fiber . Ctx , action whatsmeow . ParticipantRequestChange , successMsg string ) error {
var request domainGroup . GroupRequestParticipantsRequest
err := c . BodyParser ( & request )
utils . PanicIfNeeded ( err )
whatsapp . SanitizePhone ( & request . GroupID )
request . Action = whatsmeow . ParticipantChangeDemote
result , err := controller . Service . ManageParticipant ( c . UserContext ( ) , request )
request . Action = action
result , err := controller . Service . ManageGroupRequestParticipants ( c . UserContext ( ) , request )
utils . PanicIfNeeded ( err )
return c . JSON ( utils . ResponseData {
Status : 200 ,
Code : "SUCCESS" ,
Message : "Success demote participants" ,
Message : successMsg ,
Results : result ,
} )
}