Skip to content

Commit be05cf2

Browse files
committed
feat: sqs로 event message 핸들
1 parent 7bd6cd9 commit be05cf2

File tree

21 files changed

+479
-38
lines changed

21 files changed

+479
-38
lines changed

config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ type KhumuConfig struct {
4444
Sns struct {
4545
TopicArn string `yaml:"topic_arn"`
4646
} `yaml:"sns"`
47+
Sqs struct {
48+
QueueURL string
49+
}
4750
Redis struct {
4851
Addr string `yaml:"addr"`
4952
} `yaml:"redis"`

container/container.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,36 @@ import (
1010
"github.com/khu-dev/khumu-comment/usecase"
1111
"go.uber.org/dig"
1212
"log"
13+
"os"
1314
)
1415

15-
func Build() *dig.Container {
16+
func Build(termSig <-chan os.Signal) *dig.Container {
1617
c := dig.New()
1718

18-
// Provide DB Connection
19+
// os의 signal을 받아서 종료할 수 있게해주는 channel
20+
err := c.Provide(func() <-chan os.Signal {
21+
return termSig
22+
})
1923

20-
err := c.Provide(repository.NewEnt)
24+
// Provide DB Connection
25+
err = c.Provide(repository.NewEnt)
2126
if err != nil {
2227
log.Panic(err)
2328
}
2429

30+
// 캐시에 동기적으로 write할 지 비동기적으로 write할지
2531
err = c.Provide(func() repository.SynchronousCacheWrite { return false })
2632
if err != nil {
2733
log.Panic(err)
2834
}
2935
// sns
30-
err = c.Provide(message.NewSnsClient)
36+
err = c.Provide(message.NewSnsMessagePublisher)
37+
if err != nil {
38+
log.Panic(err)
39+
}
40+
41+
// sqs
42+
err = c.Provide(message.NewSqsMessageHandler)
3143
if err != nil {
3244
log.Panic(err)
3345
}

data/comment.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@ type CommentInput struct {
1515
}
1616

1717
type CommentOutput struct {
18-
ID int `json:"id"`
19-
Kind string `json:"kind"`
20-
State string `json:"state"`
21-
Author *SimpleKhumuUserOutput `json:"author"`
22-
Article *int `json:"article"`
23-
StudyArticle *int `json:"study_article"`
24-
Parent *int `json:"parent"`
25-
Content string `json:"content"`
26-
Children []*CommentOutput `json:"children"`
27-
IsAuthor bool `json:"is_author"`
28-
IsWrittenByArticleAuthor bool `json:"is_written_by_article_author"`
29-
LikeCommentCount int `json:"like_comment_count"`
30-
Liked bool `json:"liked"`
31-
CreatedAt string `json:"created_at"`
18+
ID int `json:"id"`
19+
Kind string `json:"kind"`
20+
State string `json:"state"`
21+
Author *SimpleKhumuUserDto `json:"author"`
22+
Article *int `json:"article"`
23+
StudyArticle *int `json:"study_article"`
24+
Parent *int `json:"parent"`
25+
Content string `json:"content"`
26+
Children []*CommentOutput `json:"children"`
27+
IsAuthor bool `json:"is_author"`
28+
IsWrittenByArticleAuthor bool `json:"is_written_by_article_author"`
29+
LikeCommentCount int `json:"like_comment_count"`
30+
Liked bool `json:"liked"`
31+
CreatedAt string `json:"created_at"`
3232
}
3333

3434
type LikeCommentInput struct {

data/khumuuser.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
package data
22

3-
type SimpleKhumuUserOutput struct {
3+
// 댓글 DTO의 작성자로 제공될 타입
4+
type SimpleKhumuUserDto struct {
5+
Username string `json:"username"`
6+
Nickname string `json:"nickname"`
7+
Status string `json:"status"`
8+
}
9+
10+
// command-center 에게 이벤트로서 전달받는 KhumuUser 타입
11+
type CommandCenterKhumuUserDto struct {
412
Username string `json:"username"`
513
Nickname string `json:"nickname"`
614
Status string `json:"status"`

data/mapper/comment.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ func CommentModelToOutput(src *ent.Comment, dest *data.CommentOutput) *data.Comm
2727
dest.Content = src.Content
2828
dest.Kind = src.Kind
2929
dest.State = src.State
30+
if src.Edges.Author != nil {
31+
if src.Edges.Article != nil && src.Edges.Article.Edges.Author != nil {
32+
dest.IsWrittenByArticleAuthor = src.Edges.Author.ID == src.Edges.Article.Edges.Author.ID
33+
}
34+
}
3035
// children은 그냥 빈 배열로 저장.
3136
// 필요한 경우
3237
dest.Children = []*data.CommentOutput{}

data/mapper/khumuuser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import (
77

88
// 새로운 SimpleKhumuUserOutput을 생성한다
99
// 원래 KhumuUser 참조 X
10-
func KhumuUserModelToSimpleOutput(src *ent.KhumuUser, dest *data.SimpleKhumuUserOutput) *data.SimpleKhumuUserOutput {
10+
func KhumuUserModelToSimpleOutput(src *ent.KhumuUser, dest *data.SimpleKhumuUserDto) *data.SimpleKhumuUserDto {
1111
if src == nil {
1212
return nil
1313
}
1414

1515
if dest == nil {
16-
dest = &data.SimpleKhumuUserOutput{}
16+
dest = &data.SimpleKhumuUserDto{}
1717
}
1818

1919
if src.Status == "deleted" {

ent/khumuuser.go

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ent/khumuuser/khumuuser.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ent/khumuuser/where.go

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ent/khumuuser_create.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)