add stats repo.

This commit is contained in:
2022-04-30 14:12:30 +02:00
parent a249110622
commit 39bc4fe7e3
19 changed files with 1058 additions and 120 deletions
+32
View File
@@ -64,3 +64,35 @@ type Project struct {
Description string `json:"description"`
Requirements []ProjectRequirement `json:"requirements"`
}
func (project *Project) Update(update ProjectUpdate) {
if update.OwnerID != nil {
project.OwnerID = *update.OwnerID
}
if update.Name != nil {
project.Name = *update.Name
}
if update.Description != nil {
project.Description = *update.Description
}
if update.Status != nil {
project.Status = *update.Status
}
}
func (project *Project) Requirement(id int) *ProjectRequirement {
for i, requirement := range project.Requirements {
if requirement.ID == id {
return &project.Requirements[i]
}
}
return nil
}
type ProjectUpdate struct {
Name *string `json:"name,omitempty"`
OwnerID *string `json:"ownerId,omitempty"`
Status *Status `json:"status,omitempty"`
Description *string `json:"description,omitempty"`
}
+33 -1
View File
@@ -20,6 +20,38 @@ type Stat struct {
AllowedAmounts map[string]int `json:"allowedAmounts"`
}
func (stat *Stat) Update(update StatUpdate) {
if update.Name != nil {
stat.Name = *update.Name
}
if update.Description != nil {
stat.Description = *update.Description
}
if update.Weight != nil {
stat.Weight = *update.Weight
}
for key, value := range update.AllowedAmounts {
if stat.AllowedAmounts == nil {
stat.AllowedAmounts = make(map[string]int, len(update.AllowedAmounts))
}
if value <= 0 {
delete(stat.AllowedAmounts, key)
} else {
stat.AllowedAmounts[key] = value
}
}
if len(stat.AllowedAmounts) == 0 {
stat.AllowedAmounts = nil
}
}
type StatUpdate struct {
Name *string `json:"name"`
Description *string `json:"description"`
Weight *float64 `json:"weight"`
AllowedAmounts map[string]int `json:"allowedAmounts"`
}
func (stat *Stat) AllowsAmount(amount int) bool {
if stat == nil {
return false
@@ -35,4 +67,4 @@ func (stat *Stat) AllowsAmount(amount int) bool {
}
return false
}
}