Skip to content

feat(notification): implement UpdateAdminNotification and rename admin RPCs - #2721

Merged
hvn2k1 merged 1 commit into
mainfrom
update-admin-noti
Jul 27, 2026
Merged

feat(notification): implement UpdateAdminNotification and rename admin RPCs#2721
hvn2k1 merged 1 commit into
mainfrom
update-admin-noti

Conversation

@hvn2k1

@hvn2k1 hvn2k1 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Part of #2215

What this PR does

Implements the UpdateAdminNotification RPC — system admins can edit a draft's localizations (tags, title, Markdown content); published notifications cannot be edited. It also renames the remaining admin RPCs to the *AdminNotification convention with /v1/admin_notification* routes, completing the split started by ListDraftAdminNotifications (#2710).

Background / Why this PR is needed

Continues the notification center backend (RFC 0047). The admin surface needed a consistent naming scheme separate from the viewer APIs before more admin RPCs land, so the rename ships together with the first RPC affected by it.

RPC Route
CreateAdminNotification POST /v1/admin_notification
UpdateAdminNotification PATCH /v1/admin_notification
PublishAdminNotification (stub) POST /v1/admin_notification/publish
DeleteAdminNotification (stub) DELETE /v1/admin_notification

Viewer RPCs (ListNotifications, GetNotification, unread count, mark-as-read) keep their /v1/notification(s) routes.

Points

  • The request's localizations array is a full replacement of the draft's localization set (delete-and-reinsert in one transaction), sharing the create API's validation via validateLocalizations. last_edited_by and updated_at are stamped; created_by/created_at are untouched.
  • Update runs get → status check → write inside a single transaction: unknown id returns NotFound, a published notification returns FailedPrecondition ("published notifications cannot be edited") per the RFC's no-editing-after-publish rule.
  • The new GetAdminNotification storage method (single row + all localizations, COALESCE for the nullable published_by) is intentionally reusable for the upcoming GetNotification and PublishAdminNotification implementations.
  • The RPC/message renames are breaking proto changes recorded via protolock force-commit; no released client depends on them since the service is still unreleased (all previously implemented RPCs shipped in unreleased feat(notification): implement CreateNotification API #2708/feat(notification): implement ListDraftAdminNotifications API #2710).

Copilot AI review requested due to automatic review settings July 27, 2026 03:34
@hvn2k1 hvn2k1 changed the title feat: implement update admin notification feat(notification): implement UpdateAdminNotification and rename admin RPCs Jul 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements the admin “update draft notification” capability in the Notification service, including new admin-specific RPC/message names and REST paths, plus the storage/domain plumbing to persist updates.

Changes:

  • Renames admin notification RPCs/messages to *AdminNotification* and moves admin REST endpoints under /v1/admin_notification* (proto, gateway, swagger, proto.lock).
  • Adds storage read/update operations for admin notifications (MySQL/Postgres), including SQL for selecting/updating notifications and replacing localizations.
  • Implements UpdateAdminNotification in the service layer, with request validation and transaction handling; adds domain-level Notification.Update(...) helper and tests.

Reviewed changes

Copilot reviewed 18 out of 22 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
proto/proto.lock Regenerates locked proto descriptors reflecting renamed admin RPCs/messages.
proto/notification/service.proto Renames admin RPCs/messages and defines UpdateAdminNotification request/response schema and HTTP mappings.
proto/notification/service.pb.gw.go Regenerates grpc-gateway handlers for new admin endpoints.
pkg/notification/storage/postgres/sql/update_notification.sql Adds SQL to update last_edited_by and updated_at.
pkg/notification/storage/postgres/sql/select_notification.sql Adds SQL to fetch a notification by id for admin update flow.
pkg/notification/storage/postgres/sql/delete_notification_localizations.sql Adds SQL to delete localizations before full replacement.
pkg/notification/storage/postgres/notification.go Adds GetAdminNotification and UpdateAdminNotification implementations and embeds new SQL.
pkg/notification/storage/postgres/notification_test.go Adds unit tests for get/update admin notification storage behaviors.
pkg/notification/storage/notification.go Extends NotificationStorage interface for admin get/update and adds unexpected-rows error.
pkg/notification/storage/mysql/sql/update_notification.sql MySQL variant of update SQL.
pkg/notification/storage/mysql/sql/select_notification.sql MySQL variant of select SQL.
pkg/notification/storage/mysql/sql/delete_notification_localizations.sql MySQL variant of delete-localizations SQL.
pkg/notification/storage/mysql/notification.go Adds GetAdminNotification and UpdateAdminNotification implementations and embeds new SQL.
pkg/notification/storage/mysql/notification_test.go Adds unit tests for get/update admin notification storage behaviors.
pkg/notification/storage/mock/notification.go Updates generated storage mock with new interface methods.
pkg/notification/domain/notification.go Adds Notification.Update(...) helper to stamp editor/time and replace localizations.
pkg/notification/domain/notification_test.go Adds unit test coverage for Notification.Update(...).
pkg/notification/api/error.go Adds gRPC status helpers for id-required/not-found/already-published cases.
pkg/notification/api/api.go Implements UpdateAdminNotification and refactors localization validation reuse.
pkg/notification/api/api_test.go Adds service-level test coverage for update admin notification scenarios.
api-description/web-api.swagger.yaml Updates swagger to expose new admin endpoints and schemas.
Files not reviewed (2)
  • pkg/notification/storage/mock/notification.go: Generated file
  • proto/notification/service.pb.gw.go: Generated file
Comments suppressed due to low confidence (4)

pkg/notification/storage/postgres/notification_test.go:372

  • MockRow.Scan is called with 8 destination arguments in GetAdminNotification, but this expectation only provides a single matcher, so the gomock call won't match.
				row := mock.NewMockRow(mockController)
				row.EXPECT().Scan(gomock.Any()).DoAndReturn(func(args ...interface{}) error {

pkg/notification/storage/postgres/notification_test.go:505

  • UpdateAdminNotification executes ExecContext with 3 SQL parameters (last_edited_by, updated_at, id), but this expectation only matches a single variadic argument, so the gomock call won't match.
				s.qe.(*mock.MockQueryExecer).EXPECT().ExecContext(
					gomock.Any(), updateNotificationSQL, gomock.Any(),
				).Return(result, nil)

pkg/notification/storage/mysql/notification_test.go:372

  • MockRow.Scan is called with 8 destination arguments in GetAdminNotification, but this expectation only provides a single matcher, so the gomock call won't match.
				row := mock.NewMockRow(mockController)
				row.EXPECT().Scan(gomock.Any()).DoAndReturn(func(args ...interface{}) error {

pkg/notification/storage/mysql/notification_test.go:505

  • UpdateAdminNotification executes ExecContext with 3 SQL parameters (last_edited_by, updated_at, id), but this expectation only matches a single variadic argument, so the gomock call won't match.
				s.qe.(*mock.MockQueryExecer).EXPECT().ExecContext(
					gomock.Any(), updateNotificationSQL, gomock.Any(),
				).Return(result, nil)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/notification/api/api.go
Comment thread pkg/notification/storage/postgres/notification_test.go
Comment thread pkg/notification/storage/postgres/notification_test.go
Comment thread pkg/notification/storage/mysql/notification_test.go
Comment thread pkg/notification/storage/mysql/notification_test.go
@hvn2k1
hvn2k1 marked this pull request as ready for review July 27, 2026 04:24
@hvn2k1
hvn2k1 requested review from cre8ivejp and t-kikuc as code owners July 27, 2026 04:24

@t-kikuc t-kikuc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hvn2k1
hvn2k1 merged commit c946f12 into main Jul 27, 2026
14 checks passed
@hvn2k1
hvn2k1 deleted the update-admin-noti branch July 27, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants