smol refactors

absences
William Perron 2 years ago
parent 0497f10e9c
commit aa90a44117

@ -0,0 +1,52 @@
package themis
import "fmt"
type ClaimType string
func ClaimTypeFromString(s string) (ClaimType, error) {
switch s {
case CLAIM_TYPE_AREA:
return CLAIM_TYPE_AREA, nil
case CLAIM_TYPE_REGION:
return CLAIM_TYPE_REGION, nil
case CLAIM_TYPE_TRADE:
return CLAIM_TYPE_TRADE, nil
}
return "", fmt.Errorf("no claim type matching '%s'", s)
}
func (ct ClaimType) String() string {
switch ct {
case CLAIM_TYPE_AREA:
return "Area"
case CLAIM_TYPE_REGION:
return "Region"
case CLAIM_TYPE_TRADE:
return "Trade Node"
}
return ""
}
const (
CLAIM_TYPE_AREA = "area"
CLAIM_TYPE_REGION = "region"
CLAIM_TYPE_TRADE = "trade"
)
var claimTypeToColumn = map[ClaimType]string{
CLAIM_TYPE_AREA: "area",
CLAIM_TYPE_REGION: "region",
CLAIM_TYPE_TRADE: "trade_node",
}
type Claim struct {
ID int
Player string
Name string
Type ClaimType
}
func (c Claim) String() string {
return fmt.Sprintf("id=%d player=%s claim_type=%s name=%s", c.ID, c.Player, c.Type, c.Name)
}

@ -0,0 +1,16 @@
package themis
import (
"errors"
"fmt"
)
var ErrNoSuchClaim = errors.New("no such claim")
type ErrConflict struct {
Conflicts []Conflict
}
func (ec ErrConflict) Error() string {
return fmt.Sprintf("found %d conflicting provinces", len(ec.Conflicts))
}

@ -4,7 +4,6 @@ import (
"context" "context"
"database/sql" "database/sql"
_ "embed" _ "embed"
"errors"
"fmt" "fmt"
"strings" "strings"
@ -14,63 +13,6 @@ import (
//go:embed migrations/init.sql //go:embed migrations/init.sql
var initScript string var initScript string
type ClaimType string
func ClaimTypeFromString(s string) (ClaimType, error) {
switch s {
case CLAIM_TYPE_AREA:
return CLAIM_TYPE_AREA, nil
case CLAIM_TYPE_REGION:
return CLAIM_TYPE_REGION, nil
case CLAIM_TYPE_TRADE:
return CLAIM_TYPE_TRADE, nil
}
return "", fmt.Errorf("no claim type matching '%s'", s)
}
func (ct ClaimType) String() string {
switch ct {
case CLAIM_TYPE_AREA:
return "Area"
case CLAIM_TYPE_REGION:
return "Region"
case CLAIM_TYPE_TRADE:
return "Trade Node"
}
return ""
}
const (
CLAIM_TYPE_AREA = "area"
CLAIM_TYPE_REGION = "region"
CLAIM_TYPE_TRADE = "trade"
)
var claimTypeToColumn = map[ClaimType]string{
CLAIM_TYPE_AREA: "area",
CLAIM_TYPE_REGION: "region",
CLAIM_TYPE_TRADE: "trade_node",
}
type Claim struct {
ID int
Player string
Name string
Type ClaimType
}
func (c Claim) String() string {
return fmt.Sprintf("id=%d player=%s claim_type=%s name=%s", c.ID, c.Player, c.Type, c.Name)
}
type ErrConflict struct {
Conflicts []Conflict
}
func (ec ErrConflict) Error() string {
return fmt.Sprintf("found %d conflicting provinces", len(ec.Conflicts))
}
type Store struct { type Store struct {
db *sql.DB db *sql.DB
} }
@ -274,8 +216,6 @@ func (s *Store) DescribeClaim(ctx context.Context, ID int) (ClaimDetail, error)
}, nil }, nil
} }
var ErrNoSuchClaim = errors.New("no such claim")
func (s *Store) DeleteClaim(ctx context.Context, ID int, userId string) error { func (s *Store) DeleteClaim(ctx context.Context, ID int, userId string) error {
stmt, err := s.db.PrepareContext(ctx, "DELETE FROM claims WHERE id = ? AND userid = ?") stmt, err := s.db.PrepareContext(ctx, "DELETE FROM claims WHERE id = ? AND userid = ?")
if err != nil { if err != nil {

Loading…
Cancel
Save