Skip to content

Commit bbc2b9d

Browse files
refactor bugs
1 parent 82885db commit bbc2b9d

File tree

59 files changed

+1504
-516
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1504
-516
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ dist-ssr
2525
*.njsproj
2626
*.sln
2727
*.sw?
28+
backend/secrets/*.json
29+
frontend/Dockerfile
30+
frontend/nginx.conf
31+
frontend/schema.sql

backend/internal/app/auth/domain.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type GithubUserResponse struct {
3737
AvatarUrl string `json:"avatar_url"`
3838
Email string `json:"email"`
3939
IsAdmin bool `json:"is_admin"`
40+
IsBlocked bool `json:"is_blocked"`
4041
}
4142

4243
type AdminLoginRequest struct {

backend/internal/app/auth/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (s *service) GithubOAuthLoginCallback(ctx context.Context, code string) (st
7878
}
7979
}
8080

81-
jwtToken, err := jwt.GenerateJWT(userData.Id, userInfo.IsAdmin, s.appCfg)
81+
jwtToken, err := jwt.GenerateJWT(userData.Id, userInfo.IsAdmin, userData.IsBlocked, s.appCfg)
8282
if err != nil {
8383
slog.Error("error generating jwt", "error", err)
8484
return "", apperrors.ErrInternalServer
@@ -118,7 +118,7 @@ func (s *service) VerifyAdminCredentials(ctx context.Context, adminCredentials A
118118
return Admin{}, apperrors.ErrInvalidCredentials
119119
}
120120

121-
jwtToken, err := jwt.GenerateJWT(adminInfo.Id, adminInfo.IsAdmin, s.appCfg)
121+
jwtToken, err := jwt.GenerateJWT(adminInfo.Id, adminInfo.IsAdmin, adminInfo.IsBlocked, s.appCfg)
122122
if err != nil {
123123
slog.Error("failed to generate jwt token", "error", err)
124124
return Admin{}, apperrors.ErrInternalServer

backend/internal/app/contribution/service.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88

99
"github.com/joshsoftware/code-curiosity-2025/internal/app/bigquery"
10+
"github.com/joshsoftware/code-curiosity-2025/internal/app/goal"
1011
repoService "github.com/joshsoftware/code-curiosity-2025/internal/app/repository"
1112
"github.com/joshsoftware/code-curiosity-2025/internal/app/transaction"
1213
"github.com/joshsoftware/code-curiosity-2025/internal/app/user"
@@ -59,6 +60,7 @@ type service struct {
5960
repositoryService repoService.Service
6061
userService user.Service
6162
transactionService transaction.Service
63+
goalService goal.Service
6264
httpClient *http.Client
6365
}
6466

@@ -76,13 +78,14 @@ type Service interface {
7678
ConfigureContributionTypeScore(ctx context.Context, configureContributionTypeScore []ConfigureContributionTypeScore) ([]ContributionScore, error)
7779
}
7880

79-
func NewService(bigqueryService bigquery.Service, contributionRepository repository.ContributionRepository, repositoryService repoService.Service, userService user.Service, transactionService transaction.Service, httpClient *http.Client) Service {
81+
func NewService(bigqueryService bigquery.Service, contributionRepository repository.ContributionRepository, repositoryService repoService.Service, userService user.Service, transactionService transaction.Service, goalService goal.Service, httpClient *http.Client) Service {
8082
return &service{
8183
bigqueryService: bigqueryService,
8284
contributionRepository: contributionRepository,
8385
repositoryService: repositoryService,
8486
userService: userService,
8587
transactionService: transactionService,
88+
goalService: goalService,
8689
httpClient: httpClient,
8790
}
8891
}
@@ -271,6 +274,24 @@ func (s *service) HandleContributionCreation(ctx context.Context, repositoryID i
271274
return Contribution{}, err
272275
}
273276

277+
err = s.goalService.SyncUserGoalProgressWithContributions(ctx, user.Id)
278+
if err != nil {
279+
slog.Error("error syncing goal progress with contibutions", "error", err)
280+
return obtainedContribution, err
281+
}
282+
283+
err = s.goalService.AllocateBadge(ctx, user.Id)
284+
if err != nil {
285+
slog.Error("error allocating badge", "error", err)
286+
return obtainedContribution, err
287+
}
288+
289+
_, err = s.goalService.CreateUserGoalSummary(ctx, user.Id)
290+
if err != nil {
291+
slog.Error("error creating goal summary for user", "error", err)
292+
return obtainedContribution, err
293+
}
294+
274295
return obtainedContribution, nil
275296
}
276297

backend/internal/app/cronJob/dailyJob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func NewDailyJob(contributionService contribution.Service) *DailyJob {
1919
}
2020

2121
func (d *DailyJob) Schedule(s *CronSchedular) error {
22-
_, err := s.cron.AddFunc("0 1 * * *", func() { d.Execute(context.Background(), d.run) })
22+
_, err := s.cron.AddFunc("0 7 * * *", func() { d.Execute(context.Background(), d.run) })
2323
if err != nil {
2424
return err
2525
}

backend/internal/app/cronJob/init.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ type CronSchedular struct {
1414
}
1515

1616
func NewCronSchedular() *CronSchedular {
17-
location, err := time.LoadLocation("Asia/Kolkata")
18-
if err != nil {
19-
slog.Error("failed to load IST timezone", "error", err)
20-
}
21-
17+
//CHANGE AND SET TO UTC TIMEZONE
2218
return &CronSchedular{
23-
cron: cron.New(cron.WithLocation(location)),
19+
cron: cron.New(cron.WithLocation(time.UTC)),
2420
}
2521
}
2622

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package cronJob
2+
3+
import (
4+
"context"
5+
6+
"github.com/joshsoftware/code-curiosity-2025/internal/app/goal"
7+
)
8+
9+
type MonthlyJob struct {
10+
CronJob
11+
goalService goal.Service
12+
}
13+
14+
func NewMonthlyJob(goalService goal.Service) *MonthlyJob {
15+
return &MonthlyJob{
16+
goalService: goalService,
17+
CronJob: CronJob{Name: "Update User Goal Status"},
18+
}
19+
}
20+
21+
func (m *MonthlyJob) Schedule(s *CronSchedular) error {
22+
_, err := s.cron.AddFunc("0 10 2 * *", func() { m.Execute(context.Background(), m.run) })
23+
if err != nil {
24+
return err
25+
}
26+
27+
return nil
28+
}
29+
30+
func (m *MonthlyJob) run(ctx context.Context) {
31+
m.goalService.UpdateUserGoalStatusMonthly(ctx)
32+
}

backend/internal/app/dependencies.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func InitDependencies(db *sqlx.DB, appCfg config.AppConfig, client config.Bigque
4747
authService := auth.NewService(userService, appCfg)
4848
bigqueryService := bigquery.NewService(client, userRepository)
4949
transactionService := transaction.NewService(transactionRepository, userService)
50-
contributionService := contribution.NewService(bigqueryService, contributionRepository, repositoryService, userService, transactionService, httpClient)
50+
contributionService := contribution.NewService(bigqueryService, contributionRepository, repositoryService, userService, transactionService, goalService, httpClient)
5151

5252
authHandler := auth.NewHandler(authService, appCfg)
5353
userHandler := user.NewHandler(userService)

backend/internal/app/goal/domain.go

Lines changed: 90 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,111 @@ package goal
22

33
import "time"
44

5-
type Goal struct {
5+
const (
6+
GoalStatusInProgress = "inProgress"
7+
GoalStatusCompleted = "completed"
8+
GoalStatusIncomplete = "incomplete"
9+
)
10+
11+
const (
12+
GoalLevelBeginner = "Beginner"
13+
GoalLevelIntermediate = "Intermediate"
14+
GoalLevelAdvanced = "Advanced"
15+
GoalLevelCustom = "Custom"
16+
)
17+
18+
type GoalLevel struct {
619
Id int `json:"id"`
720
Level string `json:"level"`
821
CreatedAt time.Time `json:"createdAt"`
922
UpdatedAt time.Time `json:"updatedAt"`
1023
}
1124

12-
type GoalContribution struct {
25+
type GoalLevelName struct {
26+
Level string `json:"level"`
27+
}
28+
29+
type UserGoal struct {
30+
Id int `json:"id"`
31+
UserId int `json:"userId"`
32+
GoalLevelId int `json:"goalLevelId"`
33+
Status string `json:"status"`
34+
MonthStartedAt time.Time `json:"monthStartedAt"`
35+
CreatedAt time.Time `json:"createdAt"`
36+
UpdatedAt time.Time `json:"updatedAt"`
37+
}
38+
39+
type UserGoalTarget struct {
40+
Id int `json:"id"`
41+
UserGoalId int `json:"userGoalId"`
42+
ContributionScoreId int `json:"contributionScoreId"`
43+
Target int `json:"target"`
44+
CreatedAt time.Time `json:"createdAt"`
45+
UpdatedAt time.Time `json:"updatedAt"`
46+
}
47+
48+
type UserGoalProgress struct {
49+
UserGoalTargetId int `json:"userGoalTargetId"`
50+
ContributionId int `json:"contributionId"`
51+
}
52+
53+
type Contribution struct {
1354
Id int `json:"id"`
14-
GoalId int `json:"goalId"`
55+
UserId int `json:"userId"`
56+
RepositoryId int `json:"repositoryId"`
1557
ContributionScoreId int `json:"contributionScoreId"`
16-
TargetCount int `json:"targetCount"`
17-
IsCustom bool `json:"isCustom"`
18-
SetByUserId int `json:"setByUserId"`
58+
ContributionType string `json:"contributionType"`
59+
BalanceChange int `json:"balanceChange"`
60+
ContributedAt time.Time `json:"contributedAt"`
61+
GithubEventId string `json:"githubEventId"`
1962
CreatedAt time.Time `json:"createdAt"`
2063
UpdatedAt time.Time `json:"updatedAt"`
2164
}
2265

23-
type CustomGoalLevelTarget struct {
66+
type CreateUserGoalRequest struct {
67+
Level string `json:"level"`
68+
CustomTargets []CustomTargetRequest `json:"customTargets,omitempty"`
69+
}
70+
71+
type CustomTargetRequest struct {
2472
ContributionType string `json:"contributionType"`
2573
Target int `json:"target"`
2674
}
2775

28-
type UserGoalLevelProgress struct {
76+
type GetUserCurrentGoalStatusResponse struct {
77+
UserGoalId int `json:"userGoalId"`
78+
Level string `json:"level"`
79+
Status string `json:"status"`
80+
MonthStartedAt time.Time `json:"monthStartedAt"`
81+
CreatedAt time.Time `json:"createdAt"`
82+
UpdatedAt time.Time `json:"updatedAt"`
83+
GoalTargetProgress []UserGoalTargetProgress `json:"goalTargetProgress"`
84+
}
85+
86+
type UserGoalTargetProgress struct {
2987
ContributionType string `json:"contributionType"`
30-
TargetCount int `json:"targetCount"`
31-
AchievedCount int `json:"achievedCount"`
88+
Target int `json:"target"`
89+
Progress int `json:"progress"`
90+
}
91+
92+
type UserGoalIdRequest struct {
93+
UserGoalId int `json:"userGoalId"`
3294
}
95+
96+
type GoalSummary struct {
97+
Id int `json:"id"`
98+
UserId int `json:"userId"`
99+
SnapshotDate time.Time `json:"snapshotDate"`
100+
IncompleteGoalsCount int `json:"incompleteGoalsCount"`
101+
TargetSet int `json:"targetSet"`
102+
TargetCompleted int `json:"targetCompleted"`
103+
CreatedAt time.Time `json:"createdAt"`
104+
UpdatedAt time.Time `json:"updatedAt"`
105+
}
106+
107+
// type MonthlyGoalSummary struct {
108+
// Day time.Time `json:"Day"`
109+
// IncompleteGoalsCount int `json:"IncompleteGoalsCount"`
110+
// TargetSet int `json:"TargetSet"`
111+
// TargetCompleted int `json:"TargetCompleted"`
112+
// }

0 commit comments

Comments
 (0)