Skip to content

Commit

Permalink
refactor: group types in unified section
Browse files Browse the repository at this point in the history
  • Loading branch information
HamoonZamiri committed Oct 26, 2024
1 parent b251517 commit 380f513
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 76 deletions.
59 changes: 28 additions & 31 deletions backend/goals/handler/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,39 @@ import (
"github.com/google/uuid"
)

type GoalHandler struct {
goalService service.GoalService
traceLogger stacktrace.TraceLogger
}
type (
GoalHandler struct {
goalService service.GoalService
traceLogger stacktrace.TraceLogger
}
CreateGoalRequest struct {
Title string `json:"title"`
Description string `json:"description"`
CategoryId string `json:"category_id"`
}
CreateGoalCategoryRequest struct {
Title string `json:"title"`
XpPerGoal int `json:"xp_per_goal"`
}
UpdateGoalCategoryRequest struct {
Title options.Option[string] `json:"title"`
XpPerGoal options.Option[int] `json:"xp_per_goal"`
}
UpdateGoalRequest struct {
Title options.Option[string] `json:"title"`
Description options.Option[string] `json:"description"`
CategoryId options.Option[string] `json:"category_id"`
Status options.Option[string] `json:"status"`
}
DeleteGoalRequest struct {
GoalId string `json:"goal_id"`
}
)

func NewGoalHandler(goalService service.GoalService, traceLogger stacktrace.TraceLogger) *GoalHandler {
return &GoalHandler{goalService, traceLogger}
}

type CreateGoalRequest struct {
Title string `json:"title"`
Description string `json:"description"`
CategoryId string `json:"category_id"`
}

type CreateGoalCategoryRequest struct {
Title string `json:"title"`
XpPerGoal int `json:"xp_per_goal"`
}

type UpdateGoalCategoryRequest struct {
Title options.Option[string] `json:"title"`
XpPerGoal options.Option[int] `json:"xp_per_goal"`
}

type UpdateGoalRequest struct {
Title options.Option[string] `json:"title"`
Description options.Option[string] `json:"description"`
CategoryId options.Option[string] `json:"category_id"`
Status options.Option[string] `json:"status"`
}

type DeleteGoalRequest struct {
GoalId string `json:"goal_id"`
}

const (
TEXT_MAX_LEN = 255
XP_MAX_PER_GOAL = 100
Expand Down
23 changes: 12 additions & 11 deletions backend/goals/stores/category_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ import (
"github.com/jmoiron/sqlx"
)

type GoalCategoryStore interface {
CreateGoalCategory(title string, xpPerGoal int, userId uuid.UUID) (*entities.GoalCategory, error)
GetGoalCategoriesByUserId(userId uuid.UUID) ([]*entities.GoalCategory, error)
GetGoalCategoryById(categoryId uuid.UUID) (*entities.GoalCategory, error)
UpdateGoalCategoryById(categoryId uuid.UUID, updates map[string]any) (*entities.GoalCategory, error)
DeleteGoalCategoryById(categoryId uuid.UUID) error
}

type goalCategoryStore struct {
db *sqlx.DB
}
type (
GoalCategoryStore interface {
CreateGoalCategory(title string, xpPerGoal int, userId uuid.UUID) (*entities.GoalCategory, error)
GetGoalCategoriesByUserId(userId uuid.UUID) ([]*entities.GoalCategory, error)
GetGoalCategoryById(categoryId uuid.UUID) (*entities.GoalCategory, error)
UpdateGoalCategoryById(categoryId uuid.UUID, updates map[string]any) (*entities.GoalCategory, error)
DeleteGoalCategoryById(categoryId uuid.UUID) error
}
goalCategoryStore struct {
db *sqlx.DB
}
)

func NewGoalCategoryStore(db *sqlx.DB) GoalCategoryStore {
return &goalCategoryStore{db: db}
Expand Down
39 changes: 19 additions & 20 deletions backend/users/handler/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@ import (
"strings"
)

type SignupRequest struct {
Email string `json:"email"`
Password string `json:"password"`
}

type LoginRequest struct {
Email string `json:"email"`
Password string `json:"password"`
}

type RefreshRequest struct {
UserId string `json:"user_id"`
RefreshToken string `json:"refresh_token"`
}

type UpdateRequest struct {
Xp options.Option[int] `json:"xp"`
LevelId options.Option[int] `json:"level_id"`
CashAvailable options.Option[int] `json:"cash_available"`
}
type (
SignupRequest struct {
Email string `json:"email"`
Password string `json:"password"`
}
LoginRequest struct {
Email string `json:"email"`
Password string `json:"password"`
}
RefreshRequest struct {
UserId string `json:"user_id"`
RefreshToken string `json:"refresh_token"`
}
UpdateRequest struct {
Xp options.Option[int] `json:"xp"`
LevelId options.Option[int] `json:"level_id"`
CashAvailable options.Option[int] `json:"cash_available"`
}
)

const (
PASSWORD_MIN_LEN = 8
Expand Down
29 changes: 15 additions & 14 deletions backend/users/stores/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@ import (
"github.com/jmoiron/sqlx"
)

type UserStore interface {
CreateUser(email, password string) (*entities.User, error)
GetUserByEmail(email string) (*entities.User, error)
UpdateRefreshToken(id, refreshToken string) (*entities.User, error)
GetUserById(id string) (*entities.User, error)
DeleteUserById(id string) error
UpdateUserById(id uuid.UUID, updates map[string]any) (*entities.User, error)

GetLevelById(id int) (*entities.Level, error)
}
type (
UserStore interface {
CreateUser(email, password string) (*entities.User, error)
GetUserByEmail(email string) (*entities.User, error)
UpdateRefreshToken(id, refreshToken string) (*entities.User, error)
GetUserById(id string) (*entities.User, error)
DeleteUserById(id string) error
UpdateUserById(id uuid.UUID, updates map[string]any) (*entities.User, error)

GetLevelById(id int) (*entities.Level, error)
}
userStore struct {
db *sqlx.DB
}
)

const DEFAULT_LEVEL = 1

type userStore struct {
db *sqlx.DB
}

func NewUserStore(db *sqlx.DB) UserStore {
return &userStore{db: db}
}
Expand Down

0 comments on commit 380f513

Please sign in to comment.