feat(announcements): add admin/user announcement system
Implements announcements end-to-end (admin CRUD + read status, user list + mark read) with OR-of-AND targeting. Also breaks the ent<->service import cycle by moving schema-facing constants/targeting into a new domain package.
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/Wei-Shaw/sub2api/ent/announcementread"
|
||||
"github.com/Wei-Shaw/sub2api/ent/apikey"
|
||||
"github.com/Wei-Shaw/sub2api/ent/group"
|
||||
"github.com/Wei-Shaw/sub2api/ent/promocodeusage"
|
||||
@@ -269,6 +270,21 @@ func (_c *UserCreate) AddAssignedSubscriptions(v ...*UserSubscription) *UserCrea
|
||||
return _c.AddAssignedSubscriptionIDs(ids...)
|
||||
}
|
||||
|
||||
// AddAnnouncementReadIDs adds the "announcement_reads" edge to the AnnouncementRead entity by IDs.
|
||||
func (_c *UserCreate) AddAnnouncementReadIDs(ids ...int64) *UserCreate {
|
||||
_c.mutation.AddAnnouncementReadIDs(ids...)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddAnnouncementReads adds the "announcement_reads" edges to the AnnouncementRead entity.
|
||||
func (_c *UserCreate) AddAnnouncementReads(v ...*AnnouncementRead) *UserCreate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
}
|
||||
return _c.AddAnnouncementReadIDs(ids...)
|
||||
}
|
||||
|
||||
// AddAllowedGroupIDs adds the "allowed_groups" edge to the Group entity by IDs.
|
||||
func (_c *UserCreate) AddAllowedGroupIDs(ids ...int64) *UserCreate {
|
||||
_c.mutation.AddAllowedGroupIDs(ids...)
|
||||
@@ -618,6 +634,22 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.AnnouncementReadsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.AnnouncementReadsTable,
|
||||
Columns: []string{user.AnnouncementReadsColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(announcementread.FieldID, field.TypeInt64),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := _c.mutation.AllowedGroupsIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
|
||||
Reference in New Issue
Block a user