Skip to content

Commit 70b4934

Browse files
committed
Merge branch 'issuecommentid-replace' into dev
2 parents 520be46 + aece30f commit 70b4934

File tree

16 files changed

+82
-58
lines changed

16 files changed

+82
-58
lines changed

aiplan.go/internal/aiplan/business/issue.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import (
99
"github.com/aisa-it/aiplan/aiplan.go/internal/aiplan/dao"
1010
errStack "github.com/aisa-it/aiplan/aiplan.go/internal/aiplan/stack-error"
1111
"github.com/aisa-it/aiplan/aiplan.go/internal/aiplan/types"
12+
"github.com/gofrs/uuid"
1213
)
1314

1415
// CreateIssueComment создает новый комментарий к задаче. Метод принимает задачу, пользователя, текст комментария, комментарий для базы данных, ID для ответа на комментарий и дополнительные метаданные. Возвращает ошибку, если произошла ошибка.
15-
func (b *Business) CreateIssueComment(issue dao.Issue, user dao.User, text string, replyToId *string, fromTg bool, meta ...string) error {
16+
func (b *Business) CreateIssueComment(issue dao.Issue, user dao.User, text string, replyToId uuid.UUID, fromTg bool, meta ...string) error {
1617
// Check rights
1718
var permitted bool
1819
if err := b.db.Model(&dao.ProjectMember{}).
@@ -32,7 +33,7 @@ func (b *Business) CreateIssueComment(issue dao.Issue, user dao.User, text strin
3233

3334
issueId := issue.ID.String()
3435
comment := dao.IssueComment{
35-
Id: dao.GenID(),
36+
Id: dao.GenUUID(),
3637
WorkspaceId: issue.WorkspaceId,
3738
ProjectId: issue.ProjectId,
3839
IssueId: issueId,
@@ -42,8 +43,8 @@ func (b *Business) CreateIssueComment(issue dao.Issue, user dao.User, text strin
4243
if len(meta) > 0 {
4344
comment.IntegrationMeta = strings.Join(meta, ",")
4445
}
45-
if replyToId != nil {
46-
comment.ReplyToCommentId = replyToId
46+
if !replyToId.IsNil() {
47+
comment.ReplyToCommentId = uuid.NullUUID{UUID: replyToId, Valid: true}
4748
}
4849
if err := b.db.Create(&comment).Error; err != nil {
4950
return err

aiplan.go/internal/aiplan/dao/aiplan.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ func GenID() string {
3535
return u2.String()
3636
}
3737

38-
// GenUUID генерирует уникальный идентификатор в формате UUID. Не принимает параметров и возвращает строку, представляющую собой UUID.
38+
// GenUUID генерирует уникальный идентификатор в формате UUID. Не принимает параметров и возвращает UUID.
3939
//
4040
// Возвращает:
41-
// - uuid.UUID: сгенерированный UUID.
41+
// - uuid.UUID: UUID, представляющий собой уникальный идентификатор.
4242
func GenUUID() uuid.UUID {
4343
u2, _ := uuid.NewV4()
4444
return u2
@@ -83,13 +83,13 @@ type FileAsset struct {
8383
CreatedById *string `json:"created_by,omitempty" extensions:"x-nullable"`
8484

8585
WorkspaceId *string `json:"workspace,omitempty"`
86-
IssueId uuid.NullUUID `json:"issue,omitempty" gorm:"foreignKey:ID"`
87-
CommentId *string `json:"comment,omitempty" gorm:"foreignKey:IdActivity" extensions:"x-nullable"`
86+
IssueId uuid.NullUUID `json:"issue" gorm:"foreignKey:ID"`
87+
CommentId *uuid.UUID `json:"comment,omitempty" gorm:"foreignKey:IdActivity" extensions:"x-nullable"`
8888

89-
DocId uuid.NullUUID `json:"doc,omitempty" gorm:"foreignKey:ID;type:uuid"`
90-
DocCommentId uuid.NullUUID `json:"doc_comment,omitempty" gorm:"type:uuid"`
89+
DocId uuid.NullUUID `json:"doc" gorm:"foreignKey:ID;type:uuid"`
90+
DocCommentId uuid.NullUUID `json:"doc_comment" gorm:"type:uuid"`
9191

92-
FormId uuid.NullUUID `json:"form,omitempty" gorm:"foreignKey:ID;type:uuid"`
92+
FormId uuid.NullUUID `json:"form" gorm:"foreignKey:ID;type:uuid"`
9393

9494
Name string `json:"name" gorm:"index"`
9595
FileSize int `json:"size"`

aiplan.go/internal/aiplan/dao/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ type DocComment struct {
381381
// comment_json jsonb IS_NULL:NO
382382
CommentType int `json:"comment_type" gorm:"default:1"`
383383
IntegrationMeta string `json:"-" gorm:"index:integration_doc,priority:2"`
384-
ReplyToCommentId uuid.NullUUID `json:"reply_to_comment_id,omitempty"`
384+
ReplyToCommentId uuid.NullUUID `json:"reply_to_comment_id"`
385385
OriginalComment *DocComment `json:"original_comment,omitempty" gorm:"foreignKey:ReplyToCommentId" extensions:"x-nullable"`
386386

387387
Workspace *Workspace `json:"-" gorm:"foreignKey:WorkspaceId" extensions:"x-nullable"`

aiplan.go/internal/aiplan/dao/issue.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ func (issue *Issue) BeforeDelete(tx *gorm.DB) error {
585585
return err
586586
}
587587

588-
var commentId []string
588+
var commentId []uuid.UUID
589589

590590
for _, comment := range comments {
591591
commentId = append(commentId, comment.Id)
@@ -1281,7 +1281,7 @@ type IssueLabel struct {
12811281
func (IssueLabel) TableName() string { return "issue_labels" }
12821282

12831283
type IssueComment struct {
1284-
Id string `json:"id" gorm:"primaryKey"`
1284+
Id uuid.UUID `json:"id" gorm:"primaryKey"`
12851285
CreatedAt time.Time `json:"created_at"`
12861286
UpdatedAt time.Time `json:"updated_at"`
12871287
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
@@ -1299,7 +1299,7 @@ type IssueComment struct {
12991299
CommentStripped string `json:"comment_stripped"`
13001300

13011301
IntegrationMeta string `json:"-" gorm:"index:integration,priority:2"`
1302-
ReplyToCommentId *string `json:"reply_to_comment_id,omitempty" extensions:"x-nullable"`
1302+
ReplyToCommentId uuid.NullUUID `json:"reply_to_comment_id" extensions:"x-nullable"`
13031303
OriginalComment *IssueComment `json:"original_comment,omitempty" gorm:"foreignKey:ReplyToCommentId" extensions:"x-nullable"`
13041304

13051305
// Id in system, from that comment was imported
@@ -1333,7 +1333,7 @@ type IssueCommentExtendFields struct {
13331333
}
13341334

13351335
func (i IssueComment) GetId() string {
1336-
return i.Id
1336+
return i.Id.String()
13371337
}
13381338

13391339
func (i IssueComment) GetString() string {
@@ -1369,7 +1369,7 @@ func (i *IssueComment) ToLightDTO() *dto.IssueCommentLight {
13691369
}
13701370
i.SetUrl()
13711371
return &dto.IssueCommentLight{
1372-
Id: i.Id,
1372+
Id: i.Id.String(),
13731373
CommentStripped: i.CommentStripped,
13741374
CommentHtml: i.CommentHtml.Body,
13751375
URL: types.JsonURL{i.URL},
@@ -1416,7 +1416,7 @@ type CommentReaction struct {
14161416
CreatedAt time.Time `json:"created_at"`
14171417
UpdatedAt time.Time `json:"updated_at"`
14181418
UserId string `json:"user_id"`
1419-
CommentId string `json:"comment_id" gorm:"index"`
1419+
CommentId uuid.UUID `json:"comment_id" gorm:"index"`
14201420
Reaction string `json:"reaction"`
14211421

14221422
User *User `json:"-" gorm:"foreignKey:UserId" extensions:"x-nullable"`
@@ -1445,7 +1445,7 @@ func (cr CommentReaction) ToDTO() *dto.CommentReaction {
14451445
Id: cr.Id,
14461446
CreatedAt: cr.CreatedAt,
14471447
UpdatedAt: cr.UpdatedAt,
1448-
CommentId: cr.CommentId,
1448+
CommentId: cr.CommentId.String(),
14491449
UserId: cr.UserId,
14501450
Reaction: cr.Reaction,
14511451
}

aiplan.go/internal/aiplan/dao/user.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ type UserNotifications struct {
345345
EntityActivityId *string `json:"entity_activity,omitempty"`
346346
EntityActivity *EntityActivity `json:"entity_activity_detail,omitempty" gorm:"foreignKey:EntityActivityId" extensions:"x-nullable"`
347347

348-
CommentId *string `json:"comment_id,omitempty"`
348+
CommentId *uuid.UUID `json:"comment_id,omitempty"`
349349
Comment *IssueComment `json:"comment,omitempty" gorm:"foreignKey:CommentId" extensions:"x-nullable"`
350350

351351
WorkspaceId *string `json:"workspace_id,omitempty"`
@@ -399,7 +399,7 @@ func (un *UserNotifications) ToLightDTO() *dto.UserNotificationsLight {
399399
Msg: un.Msg,
400400
AuthorId: un.AuthorId,
401401
EntityActivityId: un.EntityActivityId,
402-
CommentId: un.CommentId,
402+
CommentId: convertUUIDToStringPtr(un.CommentId),
403403
WorkspaceId: un.WorkspaceId,
404404
IssueId: un.IssueId,
405405
}
@@ -452,6 +452,16 @@ func (un *UserNotifications) AfterFind(tx *gorm.DB) (err error) {
452452
Filter *SearchFilter `json:"filter" gorm:"foreignKey:FilterId"`
453453
}*/
454454

455+
// convertUUIDToStringPtr преобразует *uuid.UUID в *string.
456+
// Если входной указатель nil, возвращает nil.
457+
func convertUUIDToStringPtr(uuidPtr *uuid.UUID) *string {
458+
if uuidPtr == nil {
459+
return nil
460+
}
461+
str := uuidPtr.String()
462+
return &str
463+
}
464+
455465
func GetUsers(db *gorm.DB) []User {
456466
var res []User
457467
db.Find(&res)

aiplan.go/internal/aiplan/dto/issue.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"time"
1313

1414
"github.com/aisa-it/aiplan/aiplan.go/internal/aiplan/types"
15+
"github.com/gofrs/uuid"
1516
)
1617

1718
type LabelLight struct {
@@ -104,7 +105,7 @@ type IssueComment struct {
104105
WorkspaceId string `json:"workspace_id"`
105106
IssueId string `json:"issue_id"`
106107

107-
ReplyToCommentId *string `json:"reply_to_comment_id,omitempty" extensions:"x-nullable"`
108+
ReplyToCommentId uuid.NullUUID `json:"reply_to_comment_id" extensions:"x-nullable"`
108109
OriginalComment *IssueComment `json:"original_comment,omitempty" extensions:"x-nullable"`
109110

110111
Actor *UserLight `json:"actor_detail" extensions:"x-nullable"`

aiplan.go/internal/aiplan/http-issue-migrate.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (s *Services) migrateIssues(c echo.Context) error {
155155
}
156156

157157
idsMap := make(map[uuid.UUID]uuid.UUID)
158-
idsCommentMap := make(map[string]string)
158+
idsCommentMap := make(map[uuid.UUID]uuid.UUID)
159159
linkedIds := make(map[string]struct{})
160160
var srcIssueUUId uuid.UUID
161161
var familyIds, newFamilyIds []string
@@ -213,7 +213,7 @@ func (s *Services) migrateIssues(c echo.Context) error {
213213
return EError(c, err)
214214
}
215215
for _, comment := range comments {
216-
idsCommentMap[comment.Id] = dao.GenID()
216+
idsCommentMap[comment.Id] = dao.GenUUID()
217217
}
218218

219219
if createEntities {
@@ -599,7 +599,7 @@ func (s *Services) migrateIssuesByLabel(c echo.Context) error {
599599
}
600600

601601
idsMap := make(map[uuid.UUID]uuid.UUID)
602-
idsCommentMap := make(map[string]string)
602+
idsCommentMap := make(map[uuid.UUID]uuid.UUID)
603603
linkedIds := make(map[string]struct{})
604604

605605
var targetIds, newTargetIds []string
@@ -656,7 +656,7 @@ func (s *Services) migrateIssuesByLabel(c echo.Context) error {
656656
return EError(c, err)
657657
}
658658
for _, comment := range comments {
659-
idsCommentMap[comment.Id] = dao.GenID()
659+
idsCommentMap[comment.Id] = dao.GenUUID()
660660
}
661661

662662
if createEntities {
@@ -1253,7 +1253,7 @@ func migrateIssueMove(issue IssueCheckResult, user dao.User, tx *gorm.DB, idsMap
12531253
return nil
12541254
}
12551255

1256-
func migrateIssueCopy(issue IssueCheckResult, user dao.User, tx *gorm.DB, idsMap map[uuid.UUID]uuid.UUID, idsCommentMap map[string]string, single bool) error {
1256+
func migrateIssueCopy(issue IssueCheckResult, user dao.User, tx *gorm.DB, idsMap map[uuid.UUID]uuid.UUID, idsCommentMap map[uuid.UUID]uuid.UUID, single bool) error {
12571257
srcIssue := issue.SrcIssue
12581258

12591259
if issue.Migrate {
@@ -1383,7 +1383,7 @@ func migrateIssueCopy(issue IssueCheckResult, user dao.User, tx *gorm.DB, idsMap
13831383
// Comments, reactions
13841384
{
13851385
var comments []dao.IssueComment
1386-
var commentIds []string
1386+
var commentIds []uuid.UUID
13871387

13881388
if err := tx.Where("issue_id = ?", srcIssue.ID).Find(&comments).Error; err != nil {
13891389
return err
@@ -1394,9 +1394,9 @@ func migrateIssueCopy(issue IssueCheckResult, user dao.User, tx *gorm.DB, idsMap
13941394
comments[i].Id = idsCommentMap[comments[i].Id]
13951395
comments[i].IssueId = targetIssue.ID.String()
13961396
comments[i].ProjectId = issue.TargetProject.ID
1397-
if comments[i].ReplyToCommentId != nil {
1398-
replyId := idsCommentMap[*comments[i].ReplyToCommentId]
1399-
comments[i].ReplyToCommentId = &replyId
1397+
if comments[i].ReplyToCommentId.Valid {
1398+
replyId := idsCommentMap[comments[i].ReplyToCommentId.UUID]
1399+
comments[i].ReplyToCommentId = uuid.NullUUID{UUID: replyId, Valid: true}
14001400
}
14011401
}
14021402

aiplan.go/internal/aiplan/http-issue.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,7 +2472,7 @@ func (s *Services) createIssueComment(c echo.Context) error {
24722472
}
24732473

24742474
if err := s.db.Transaction(func(tx *gorm.DB) error {
2475-
comment.Id = dao.GenID()
2475+
comment.Id = dao.GenUUID()
24762476
comment.ProjectId = project.ID
24772477
comment.Project = &project
24782478
comment.IssueId = issue.ID.String()
@@ -2519,12 +2519,12 @@ func (s *Services) createIssueComment(c echo.Context) error {
25192519

25202520
var authorOriginalComment *dao.User
25212521
var replyNotMember bool
2522-
if comment.ReplyToCommentId != nil {
2522+
if comment.ReplyToCommentId.Valid {
25232523
if err := tx.Where(
25242524
"id = (?)", tx.
25252525
Select("actor_id").
25262526
Model(&dao.IssueComment{}).
2527-
Where("id = ?", comment.ReplyToCommentId)).
2527+
Where("id = ?", comment.ReplyToCommentId.UUID)).
25282528
First(&authorOriginalComment).Error; err != nil {
25292529
return err
25302530
}
@@ -2736,12 +2736,12 @@ func (s *Services) updateIssueComment(c echo.Context) error {
27362736

27372737
var authorOriginalComment *dao.User
27382738
var replyNotMember bool
2739-
if comment.ReplyToCommentId != nil {
2739+
if comment.ReplyToCommentId.Valid {
27402740
if err := tx.Where(
27412741
"id = (?)", tx.
27422742
Select("actor_id").
27432743
Model(&dao.IssueComment{}).
2744-
Where("id = ?", comment.ReplyToCommentId)).
2744+
Where("id = ?", comment.ReplyToCommentId.UUID)).
27452745
First(&authorOriginalComment).Error; err != nil {
27462746
return err
27472747
}
@@ -2762,7 +2762,8 @@ func (s *Services) updateIssueComment(c echo.Context) error {
27622762
replyNotMember = true
27632763
}
27642764
if !replyNotMember {
2765-
comment.Id = commentId
2765+
commentUUID := uuid.Must(uuid.FromString(commentId))
2766+
comment.Id = commentUUID
27662767
comment.IssueId = issue.ID.String()
27672768
comment.WorkspaceId = issue.WorkspaceId
27682769
comment.Issue = &issue
@@ -2913,11 +2914,12 @@ func (s *Services) addCommentReaction(c echo.Context) error {
29132914
}
29142915

29152916
// Создаем новую реакцию
2917+
commentUUID := uuid.Must(uuid.FromString(commentId))
29162918
reaction := dao.CommentReaction{
29172919
Id: dao.GenID(),
29182920
CreatedAt: time.Now(),
29192921
UserId: user.ID,
2920-
CommentId: commentId,
2922+
CommentId: commentUUID,
29212923
Reaction: reactionRequest.Reaction,
29222924
}
29232925

aiplan.go/internal/aiplan/integrations/github.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
tracker "github.com/aisa-it/aiplan/aiplan.go/internal/aiplan/activity-tracker"
1818
"github.com/aisa-it/aiplan/aiplan.go/internal/aiplan/business"
19+
"github.com/gofrs/uuid"
1920

2021
"github.com/aisa-it/aiplan/aiplan.go/internal/aiplan/dao"
2122
filestorage "github.com/aisa-it/aiplan/aiplan.go/internal/aiplan/file-storage"
@@ -197,7 +198,7 @@ func (ghi *GithubIntegration) GithubPushEvent(event GithubPushEvent, workspace d
197198
commit.Message,
198199
)
199200

200-
err := ghi.bl.CreateIssueComment(issue, *ghi.User, msg, nil, false, commit.Id)
201+
err := ghi.bl.CreateIssueComment(issue, *ghi.User, msg, uuid.Nil, false, commit.Id)
201202
if err != nil {
202203
logGithub.Error("Create issue comment from webhook", "err", err)
203204
continue

aiplan.go/internal/aiplan/integrations/gitlab.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
tracker "github.com/aisa-it/aiplan/aiplan.go/internal/aiplan/activity-tracker"
1818
"github.com/aisa-it/aiplan/aiplan.go/internal/aiplan/business"
19+
"github.com/gofrs/uuid"
1920

2021
filestorage "github.com/aisa-it/aiplan/aiplan.go/internal/aiplan/file-storage"
2122
"github.com/aisa-it/aiplan/aiplan.go/internal/aiplan/types"
@@ -188,7 +189,7 @@ func (gi *GitlabIntegration) GitlabPushEvent(event GitlabPushEvent, workspace da
188189
commit.Message,
189190
)
190191

191-
err := gi.bl.CreateIssueComment(issue, *gi.User, msg, nil, false, commit.ID)
192+
err := gi.bl.CreateIssueComment(issue, *gi.User, msg, uuid.Nil, false, commit.ID)
192193
if err != nil {
193194
log.Error("Create issue comment from webhook", "err", err)
194195
continue

0 commit comments

Comments
 (0)