get individual domain block, delete a block

This commit is contained in:
tsmethurst 2021-07-05 13:09:24 +02:00
commit 8475898b75
18 changed files with 213 additions and 16 deletions

View file

@ -9,9 +9,10 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
func (m *Module) DomainBlocksGETHandler(c *gin.Context) {
// DomainBlockGETHandler returns one existing domain block, identified by its id.
func (m *Module) DomainBlockGETHandler(c *gin.Context) {
l := m.log.WithFields(logrus.Fields{
"func": "DomainBlocksPOSTHandler",
"func": "DomainBlockGETHandler",
"request_uri": c.Request.RequestURI,
"user_agent": c.Request.UserAgent(),
"origin_ip": c.ClientIP(),
@ -30,6 +31,12 @@ func (m *Module) DomainBlocksGETHandler(c *gin.Context) {
return
}
domainBlockID := c.Param(IDKey)
if domainBlockID == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "no domain block id provided"})
return
}
export := false
exportString := c.Query(ExportQueryKey)
if exportString != "" {
@ -42,12 +49,12 @@ func (m *Module) DomainBlocksGETHandler(c *gin.Context) {
export = i
}
domainBlocks, err := m.processor.AdminDomainBlocksGet(authed, export)
domainBlock, err := m.processor.AdminDomainBlockGet(authed, domainBlockID, export)
if err != nil {
l.Debugf("error getting domain blocks: %s", err)
l.Debugf("error getting domain block: %s", err)
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, domainBlocks)
c.JSON(http.StatusOK, domainBlock)
}