@@ -20,6 +20,8 @@ type commonGetterIn struct {
2020 RepoDiscuss * repo.Discussion
2121 RepoGroupItems * repo.GroupItem
2222 RepoUserThird * repo.UserThird
23+ RepoDoc * repo.KBDocument
24+ RepoForum * repo.Forum
2325}
2426
2527type commonGetter struct {
@@ -30,7 +32,7 @@ func newCommonGetter(in commonGetterIn) *commonGetter {
3032 return & commonGetter {in : in }
3133}
3234
33- func (c * commonGetter ) Message (ctx context.Context , dissID uint , userID uint ) (* Common , error ) {
35+ func (c * commonGetter ) DiscussMessage (ctx context.Context , dissID uint , userID uint ) (* Common , error ) {
3436 var discuss struct {
3537 CreatedAt model.Timestamp `gorm:"type:timestamp with time zone"`
3638 ForumID uint
@@ -44,6 +46,12 @@ func (c *commonGetter) Message(ctx context.Context, dissID uint, userID uint) (*
4446 return nil , err
4547 }
4648
49+ var forum model.Forum
50+ err = c .in .RepoForum .GetByID (ctx , & forum , discuss .ForumID )
51+ if err != nil {
52+ return nil , err
53+ }
54+
4755 var groupItems []struct {
4856 Name string
4957 }
@@ -72,13 +80,9 @@ func (c *commonGetter) Message(ctx context.Context, dissID uint, userID uint) (*
7280 return nil , err
7381 }
7482
75- discussURL := ""
76- var publicAddress model.PublicAddress
77- err = c .in .RepoSystem .GetValueByKey (ctx , & publicAddress , model .SystemKeyPublicAddress )
78- if err != nil && ! errors .Is (err , database .ErrRecordNotFound ) {
83+ discussURL , err := c .publicAddress (ctx , path .Join (forum .RouteName , discuss .UUID ))
84+ if err != nil {
7985 return nil , err
80- } else if err == nil {
81- discussURL = publicAddress .FullURL (path .Join ("forum" , strconv .FormatUint (uint64 (discuss .ForumID ), 10 ), "discuss" , discuss .UUID ))
8286 }
8387
8488 messageThirds := make ([]commonUserThird , len (userThirds ))
@@ -107,6 +111,42 @@ func (c *commonGetter) Message(ctx context.Context, dissID uint, userID uint) (*
107111 }, nil
108112}
109113
114+ func (c * commonGetter ) publicAddress (ctx context.Context , path string ) (string , error ) {
115+ var publicAddress model.PublicAddress
116+ err := c .in .RepoSystem .GetValueByKey (ctx , & publicAddress , model .SystemKeyPublicAddress )
117+ if err != nil {
118+ if ! errors .Is (err , database .ErrRecordNotFound ) {
119+ return "" , err
120+ }
121+
122+ return "" , nil
123+ }
124+
125+ return publicAddress .FullURL (path ), nil
126+ }
127+
128+ func (c * commonGetter ) DocMessage (ctx context.Context , kbID uint , docID uint ) (* commonDoc , error ) {
129+ var doc model.KBDocument
130+ err := c .in .RepoDoc .GetByID (ctx , & doc , kbID , docID )
131+ if err != nil {
132+ return nil , err
133+ }
134+
135+ docURL , err := c .publicAddress (ctx , "admin/ai/qa" )
136+ if err != nil {
137+ return nil , err
138+ }
139+ if docURL != "" {
140+ docURL = docURL + "?id=" + strconv .FormatUint (uint64 (kbID ), 10 )
141+ }
142+
143+ return & commonDoc {
144+ ID : doc .ID ,
145+ Title : doc .Title ,
146+ URL : docURL ,
147+ }, nil
148+ }
149+
110150func NewTestCommon () Common {
111151 return Common {
112152 User : commonUser {
0 commit comments