Browse Source

add some backend code.

mian
Gisle Aune 3 years ago
parent
commit
22e8290371
  1. 5
      .gitignore
  2. 8
      frontend/.gitignore
  3. 3
      go.mod
  4. 37
      internal/database/database.go
  5. 1
      internal/models/date.go
  6. 17
      internal/models/item.go
  7. 15
      internal/models/project.go
  8. 22
      internal/models/scope.go
  9. 21
      internal/models/stat.go
  10. 23
      internal/models/status.go

5
.gitignore

@ -1,8 +1,7 @@
.DS_Store
node_modules
/build /build
/.svelte-kit
/package /package
.env .env
.env.* .env.*
!.env.example !.env.example
.idea
.vscode

8
frontend/.gitignore

@ -0,0 +1,8 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example

3
go.mod

@ -0,0 +1,3 @@
module git.aiterp.net/stufflog3/stufflog3-api
go 1.17

37
internal/database/database.go

@ -0,0 +1,37 @@
package database
import (
"context"
"git.aiterp.net/stufflog3/stufflog3-api/internal/models"
"time"
)
type Database interface {
Scopes() ScopeRepository
Stats(scopeID int) StatRepository
}
type ScopeRepository interface {
Find(ctx context.Context, id int) (*models.Scope, error)
List(ctx context.Context, userID string) ([]models.ScopeEntry, error)
Create(ctx context.Context, scope models.ScopeEntry, owner models.ScopeMember) (*models.Scope, error)
Update(ctx context.Context, scope models.ScopeEntry) error
Delete(ctx context.Context, scope models.Scope) error
UpdateMember(ctx context.Context, scope models.Scope, member models.ScopeMember) (*models.Scope, error)
DeleteMember(ctx context.Context, scope models.Scope, userID string) (*models.Scope, error)
}
type StatRepository interface {
Find(ctx context.Context, id int) (*models.Stat, error)
List(ctx context.Context) ([]models.Stat, error)
Create(ctx context.Context, stat models.Stat) (*models.Stat, error)
Update(ctx context.Context, stat models.Stat) error
Delete(ctx context.Context, stat models.Stat) error
}
type ItemRepository interface {
Find(ctx context.Context, id int) (*models.Item, error)
List(ctx context.Context) ([]models.Item, error)
ListAcquired(ctx context.Context, from, to time.Time) ([]models.Item, error)
Create(ctx context.Context, stat models.Stat) (*models.Item, error)
}

1
internal/models/date.go

@ -0,0 +1 @@
package models

17
internal/models/item.go

@ -0,0 +1,17 @@
package models
import "time"
type Item struct {
ID int
ProjectRequirementID *int
OwnerID string
Name string
Description string
OwnerName string
CreatedTime time.Time
AcquiredTime *time.Time
ScheduledDate *time.Time
Stats StatProgressEntry[]
}

15
internal/models/project.go

@ -0,0 +1,15 @@
package models
type ProjectEntry struct {
ID int `json:"id"`
Name string `json:"name"`
Status Status `json:"status"`
}
type ProjectRequirement struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Status Status `json:"status"`
Stats []StatProgressEntry `json:"stats"`
}

22
internal/models/scope.go

@ -0,0 +1,22 @@
package models
type ScopeEntry struct {
ID string `json:"id"`
Name string `json:"name"`
Abbreviation string `json:"abbreviation"`
}
type ScopeMember struct {
ID string `json:"id"`
Name string `json:"name"`
Owner bool `json:"owner"`
}
type Scope struct {
ScopeEntry
DisplayName string `json:"displayName"`
Members []ScopeMember `json:"members"`
Projects []ProjectEntry `json:"projects"`
Stat []Stat `json:"stat"`
}

21
internal/models/stat.go

@ -0,0 +1,21 @@
package models
type StatEntry struct {
ID string `json:"id"`
Name string `json:"name"`
Weight float64 `json:"weight"`
}
type StatProgressEntry struct {
StatEntry
Acquired int `json:"acquired"`
Required int `json:"required"`
}
type Stat struct {
StatEntry
Description string `json:"description"`
AllowedAmounts map[string]int `json:"allowedAmounts"`
}

23
internal/models/status.go

@ -0,0 +1,23 @@
package models
type Status int
const (
Blocked Status = 0
Available Status = 1
Background Status = 2
Active Status = 3
Completed Status = 4
Failed Status = 5
Dropped Status = 6
)
var StatusLabels = map[Status]string{
Blocked: "Blocked",
Available: "Available",
Background: "Background",
Active: "Active",
Completed: "Completed",
Failed: "Failed",
Dropped: "Dropped",
}
Loading…
Cancel
Save