add path param lure customization

Signed-off-by: RonniSkansing <rskansing@gmail.com>
This commit is contained in:
RonniSkansing
2026-07-27 17:57:53 +02:00
parent dfcfafd502
commit fd7ca01b22
29 changed files with 1818 additions and 75 deletions
+43
View File
@@ -927,6 +927,49 @@ func (c *Campaign) UpdateByID(g *gin.Context) {
c.Response.OK(g, gin.H{})
}
// setLureCodeRequest is the body for assigning an operator chosen lure code.
type setLureCodeRequest struct {
Code string `json:"code"`
// Reclaim releases the code from whichever recipient currently holds it.
// The caller sets this only after being shown which campaign that is.
Reclaim bool `json:"reclaim"`
}
// SetLureCode assigns an operator chosen lure code to a single campaign recipient
func (c *Campaign) SetLureCode(g *gin.Context) {
// handle session
session, _, ok := c.handleSession(g)
if !ok {
return
}
// parse request
id, ok := c.handleParseIDParam(g)
if !ok {
return
}
var req setLureCodeRequest
if ok := c.handleParseRequest(g, &req); !ok {
return
}
conflict, err := c.CampaignService.SetLureCodeByCampaignRecipientID(
g.Request.Context(),
session,
id,
req.Code,
req.Reclaim,
)
// a taken code is an expected outcome the operator can resolve, so it is
// reported with the current owner rather than as a plain failure
if errors.Is(err, service.ErrLureCodeTaken) {
c.Response.Conflict(g, "Lure code is already in use", conflict)
return
}
if ok := c.handleErrors(g, err); !ok {
return
}
c.Response.OK(g, gin.H{})
}
// SetSentAtByCampaignRecipientID sets the sent at time for a campaign recipient
func (c *Campaign) SetSentAtByCampaignRecipientID(g *gin.Context) {
// handle session