Skip to content

Commit

Permalink
[bugfix] rename include_types[] to types[] (superseriousbusiness#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmethurst authored Jun 18, 2024
1 parent d2b3d37 commit 4ce5c37
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions internal/api/client/notifications/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const (
BasePathWithID = BasePath + "/:" + IDKey
BasePathWithClear = BasePath + "/clear"

// IncludeTypesKey names an array param specifying notification types to include.
IncludeTypesKey = "include_types[]"
// TypesKey names an array param specifying notification types to include.
TypesKey = "types[]"
// ExcludeTypesKey names an array param specifying notification types to exclude.
ExcludeTypesKey = "exclude_types[]"
MaxIDKey = "max_id"
Expand Down
2 changes: 1 addition & 1 deletion internal/api/client/notifications/notificationsget.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (m *Module) NotificationsGETHandler(c *gin.Context) {
c.Query(SinceIDKey),
c.Query(MinIDKey),
limit,
c.QueryArray(IncludeTypesKey),
c.QueryArray(TypesKey),
c.QueryArray(ExcludeTypesKey),
)
if errWithCode != nil {
Expand Down
18 changes: 9 additions & 9 deletions internal/api/client/notifications/notificationsget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (suite *NotificationsTestSuite) getNotifications(
maxID string,
minID string,
limit int,
includeTypes []string,
types []string,
excludeTypes []string,
expectedHTTPStatus int,
expectedBody string,
Expand All @@ -71,8 +71,8 @@ func (suite *NotificationsTestSuite) getNotifications(
if limit != 0 {
query.Set(notifications.LimitKey, strconv.Itoa(limit))
}
if len(includeTypes) > 0 {
query[notifications.IncludeTypesKey] = includeTypes
if len(types) > 0 {
query[notifications.TypesKey] = types
}
if len(excludeTypes) > 0 {
query[notifications.ExcludeTypesKey] = excludeTypes
Expand Down Expand Up @@ -123,7 +123,7 @@ func (suite *NotificationsTestSuite) TestGetNotificationsSingle() {
maxID := ""
minID := ""
limit := 10
includeTypes := []string(nil)
types := []string(nil)
excludeTypes := []string(nil)
expectedHTTPStatus := http.StatusOK
expectedBody := ""
Expand All @@ -135,7 +135,7 @@ func (suite *NotificationsTestSuite) TestGetNotificationsSingle() {
maxID,
minID,
limit,
includeTypes,
types,
excludeTypes,
expectedHTTPStatus,
expectedBody,
Expand Down Expand Up @@ -181,7 +181,7 @@ func (suite *NotificationsTestSuite) TestGetNotificationsExcludeOneType() {
maxID := ""
minID := ""
limit := 10
includeTypes := []string(nil)
types := []string(nil)
excludeTypes := []string{"follow_request"}
expectedHTTPStatus := http.StatusOK
expectedBody := ""
Expand All @@ -193,7 +193,7 @@ func (suite *NotificationsTestSuite) TestGetNotificationsExcludeOneType() {
maxID,
minID,
limit,
includeTypes,
types,
excludeTypes,
expectedHTTPStatus,
expectedBody,
Expand All @@ -220,7 +220,7 @@ func (suite *NotificationsTestSuite) TestGetNotificationsIncludeOneType() {
maxID := ""
minID := ""
limit := 10
includeTypes := []string{"favourite"}
types := []string{"favourite"}
excludeTypes := []string(nil)
expectedHTTPStatus := http.StatusOK
expectedBody := ""
Expand All @@ -232,7 +232,7 @@ func (suite *NotificationsTestSuite) TestGetNotificationsIncludeOneType() {
maxID,
minID,
limit,
includeTypes,
types,
excludeTypes,
expectedHTTPStatus,
expectedBody,
Expand Down
6 changes: 3 additions & 3 deletions internal/db/bundb/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (n *notificationDB) GetAccountNotifications(
sinceID string,
minID string,
limit int,
includeTypes []string,
types []string,
excludeTypes []string,
) ([]*gtsmodel.Notification, error) {
// Ensure reasonable
Expand Down Expand Up @@ -238,9 +238,9 @@ func (n *notificationDB) GetAccountNotifications(
frontToBack = false // page up
}

if len(includeTypes) > 0 {
if len(types) > 0 {
// Include only requested notification types.
q = q.Where("? IN (?)", bun.Ident("notification.notification_type"), bun.In(includeTypes))
q = q.Where("? IN (?)", bun.Ident("notification.notification_type"), bun.In(types))
}

if len(excludeTypes) > 0 {
Expand Down
4 changes: 2 additions & 2 deletions internal/db/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type Notification interface {
// GetAccountNotifications returns a slice of notifications that pertain to the given accountID.
//
// Returned notifications will be ordered ID descending (ie., highest/newest to lowest/oldest).
// If includeTypes is empty, *all* notification types will be included.
GetAccountNotifications(ctx context.Context, accountID string, maxID string, sinceID string, minID string, limit int, includeTypes []string, excludeTypes []string) ([]*gtsmodel.Notification, error)
// If types is empty, *all* notification types will be included.
GetAccountNotifications(ctx context.Context, accountID string, maxID string, sinceID string, minID string, limit int, types []string, excludeTypes []string) ([]*gtsmodel.Notification, error)

// GetNotificationByID returns one notification according to its id.
GetNotificationByID(ctx context.Context, id string) (*gtsmodel.Notification, error)
Expand Down
4 changes: 2 additions & 2 deletions internal/processing/timeline/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (p *Processor) NotificationsGet(
sinceID string,
minID string,
limit int,
includeTypes []string,
types []string,
excludeTypes []string,
) (*apimodel.PageableResponse, gtserror.WithCode) {
notifs, err := p.state.DB.GetAccountNotifications(
Expand All @@ -51,7 +51,7 @@ func (p *Processor) NotificationsGet(
sinceID,
minID,
limit,
includeTypes,
types,
excludeTypes,
)
if err != nil && !errors.Is(err, db.ErrNoEntries) {
Expand Down

0 comments on commit 4ce5c37

Please sign in to comment.