@@ -4,11 +4,13 @@ import (
4
4
"context"
5
5
6
6
"github.com/izumin5210/grapi/pkg/grapiserver"
7
- "google.golang.org/grpc/codes"
8
- "google.golang.org/grpc/status"
7
+ "google.golang.org/grpc/grpclog"
9
8
10
9
api_pb "github.com/ProgrammingLab/prolab-accounts/api"
10
+ "github.com/ProgrammingLab/prolab-accounts/app/config"
11
11
"github.com/ProgrammingLab/prolab-accounts/app/di"
12
+ "github.com/ProgrammingLab/prolab-accounts/infra/record"
13
+ "github.com/ProgrammingLab/prolab-accounts/model"
12
14
)
13
15
14
16
// ContributionConllectionServiceServer is a composite interface of api_pb.ContributionConllectionServiceServer and grapiserver.Server.
@@ -18,17 +20,67 @@ type ContributionConllectionServiceServer interface {
18
20
}
19
21
20
22
// NewContributionConllectionServiceServer creates a new ContributionConllectionServiceServer instance.
21
- func NewContributionConllectionServiceServer (store di.StoreComponent ) ContributionConllectionServiceServer {
23
+ func NewContributionConllectionServiceServer (store di.StoreComponent , cfg * config. Config ) ContributionConllectionServiceServer {
22
24
return & contributionConllectionServiceServerImpl {
23
25
StoreComponent : store ,
26
+ cfg : cfg ,
24
27
}
25
28
}
26
29
27
30
type contributionConllectionServiceServerImpl struct {
28
31
di.StoreComponent
32
+ cfg * config.Config
29
33
}
30
34
31
35
func (s * contributionConllectionServiceServerImpl ) ListContributionConllections (ctx context.Context , req * api_pb.ListContributionConllectionsRequest ) (* api_pb.ListContributionConllectionsResponse , error ) {
32
- // TODO: Not yet implemented.
33
- return nil , status .Error (codes .Unimplemented , "TODO: You should implement it!" )
36
+ gs := s .GitHubStore (ctx )
37
+ grpclog .Info (req .GetUsersCount ())
38
+ cols , err := gs .ListContributionCollections (int (req .GetUsersCount ()))
39
+ if err != nil {
40
+ return nil , err
41
+ }
42
+
43
+ resp := contributionConllectionsToResponse (cols , s .cfg )
44
+ return & api_pb.ListContributionConllectionsResponse {
45
+ ContributionConllections : resp ,
46
+ }, nil
47
+ }
48
+
49
+ func contributionConllectionsToResponse (cols []* model.GitHubContributionCollection , cfg * config.Config ) []* api_pb.ContributionConllection {
50
+ resp := make ([]* api_pb.ContributionConllection , 0 , len (cols ))
51
+ for _ , c := range cols {
52
+ rc := contributionConllectionToResponse (c , cfg )
53
+ if rc == nil {
54
+ continue
55
+ }
56
+ resp = append (resp , rc )
57
+ }
58
+
59
+ return resp
60
+ }
61
+
62
+ func contributionConllectionToResponse (col * model.GitHubContributionCollection , cfg * config.Config ) * api_pb.ContributionConllection {
63
+ if len (col .Days ) == 0 {
64
+ return nil
65
+ }
66
+
67
+ u := col .Days [0 ].R .User
68
+ return & api_pb.ContributionConllection {
69
+ User : userToResponse (u , false , cfg ),
70
+ TotalCount : int32 (col .TotalCount ),
71
+ Days : contributionDaysToResponse (col .Days ),
72
+ }
73
+ }
74
+
75
+ func contributionDaysToResponse (days []* record.GithubContributionDay ) []* api_pb.ContributionDay {
76
+ resp := make ([]* api_pb.ContributionDay , 0 , len (days ))
77
+ for _ , d := range days {
78
+ rd := & api_pb.ContributionDay {
79
+ Date : timeToResponse (d .Date ),
80
+ Count : int32 (d .Count ),
81
+ }
82
+ resp = append (resp , rd )
83
+ }
84
+
85
+ return resp
34
86
}
0 commit comments