gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

notificationsclear.go (2388B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package notifications
     19 
     20 import (
     21 	"net/http"
     22 
     23 	"github.com/gin-gonic/gin"
     24 	apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
     25 	"github.com/superseriousbusiness/gotosocial/internal/gtserror"
     26 	"github.com/superseriousbusiness/gotosocial/internal/oauth"
     27 )
     28 
     29 // NotificationsClearPOSTHandler swagger:operation POST /api/v1/notifications/clear clearNotifications
     30 //
     31 // Clear/delete all notifications for currently authorized user.
     32 //
     33 // Will return an empty object `{}` to indicate success.
     34 //
     35 //	---
     36 //	tags:
     37 //	- notifications
     38 //
     39 //	produces:
     40 //	- application/json
     41 //
     42 //	security:
     43 //	- OAuth2 Bearer:
     44 //		- read:notifications
     45 //
     46 //	responses:
     47 //		'200':
     48 //			schema:
     49 //				type: object
     50 //		'400':
     51 //			description: bad request
     52 //		'401':
     53 //			description: unauthorized
     54 //		'404':
     55 //			description: not found
     56 //		'406':
     57 //			description: not acceptable
     58 //		'500':
     59 //			description: internal server error
     60 func (m *Module) NotificationsClearPOSTHandler(c *gin.Context) {
     61 	authed, err := oauth.Authed(c, true, true, true, true)
     62 	if err != nil {
     63 		apiutil.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGetV1)
     64 		return
     65 	}
     66 
     67 	if _, err := apiutil.NegotiateAccept(c, apiutil.JSONAcceptHeaders...); err != nil {
     68 		apiutil.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGetV1)
     69 		return
     70 	}
     71 
     72 	errWithCode := m.processor.Timeline().NotificationsClear(c.Request.Context(), authed)
     73 	if errWithCode != nil {
     74 		apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
     75 		return
     76 	}
     77 
     78 	c.JSON(http.StatusOK, struct{}{})
     79 }