This repository has been archived by the owner on Dec 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from walnuts1018/init-backend
Init backend
- Loading branch information
Showing
13 changed files
with
678 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package config | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log/slog" | ||
"os" | ||
"reflect" | ||
|
||
"github.com/joho/godotenv" | ||
) | ||
|
||
type Config_t struct { | ||
PostgresAdminUser string `env:"POSTGRES_ADMIN_USER"` | ||
PostgresAdminPassword string `env:"POSTGRES_ADMIN_PASSWORD"` | ||
PostgresUser string `env:"POSTGRES_USER"` | ||
PostgresPassword string `env:"POSTGRES_PASSWORD"` | ||
PostgresDb string `env:"POSTGRES_DB"` | ||
PostgresHost string `env:"POSTGRES_HOST"` | ||
PostgresPort string `env:"POSTGRES_PORT"` | ||
|
||
ServerPort string | ||
} | ||
|
||
var Config = Config_t{} | ||
|
||
func LoadConfig() error { | ||
serverport := flag.String("port", "8080", "server port") | ||
flag.Parse() | ||
Config.ServerPort = *serverport | ||
|
||
err := godotenv.Load(".env") | ||
if err != nil { | ||
slog.Debug("Error loading .env file") | ||
} | ||
|
||
t := reflect.TypeOf(Config) | ||
for i := 0; i < t.NumField(); i++ { | ||
fieldName := t.Field(i).Name | ||
tag, ok := t.Field(i).Tag.Lookup("env") | ||
if !ok { | ||
continue | ||
} | ||
v, ok := os.LookupEnv(tag) | ||
if !ok { | ||
return fmt.Errorf("%s is not set", tag) | ||
} | ||
reflect.ValueOf(&Config).Elem().FieldByName(fieldName).SetString(v) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package domain | ||
|
||
type DB interface { | ||
NewUser(user User) error | ||
GetUser(id string) (User, error) | ||
UpdateUser(user User) error | ||
NewMoneyPool(moneyPool MoneyPool) error | ||
GetMoneyPool(id string) (MoneyPool, error) | ||
GetMoneyPoolsByUsers(user User) ([]MoneyPool, error) | ||
UpdateMoneyPool(moneyPool MoneyPool) error | ||
NewTransaction(transaction Transaction) error | ||
GetTransaction(transactionID string, hint GetTransactionHints) (Transaction, error) | ||
GetTransactionsByMoneyPool(moneyPoolID string, hint GetTransactionHints) ([]Transaction, error) | ||
GetTransactionsByUser(userID string, hint GetTransactionHints) ([]Transaction, error) | ||
UpdateTransaction(transaction Transaction) error | ||
NewItem(item Item) error | ||
GetItem(id string) (Item, error) | ||
GetItemsByUser(userID string) ([]Item, error) | ||
UpdateItem(item Item) error | ||
IsItemExist(itemID string) (bool, error) | ||
NewStore(store Store) error | ||
GetStore(id string) (Store, error) | ||
GetStoresByUser(userID string) ([]Store, error) | ||
UpdateStore(store Store) error | ||
IsStoreExist(storeID string) (bool, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package domain | ||
|
||
import "time" | ||
|
||
type Transaction struct { | ||
ID string `db:"id"` | ||
MoneyPoolID string `db:"money_pool_id"` | ||
TransactionDate time.Time `db:"transaction_date"` | ||
Title string `db:"title"` | ||
Amount float64 `db:"amount"` //金額 | ||
Labels []string `db:"labels"` | ||
IsWorldPublic bool `db:"is_world_public"` | ||
ShareUserIDs []string `db:"share_user_ids"` | ||
Expectation bool `db:"expectation"` | ||
StoreID string `db:"store_id"` | ||
ItemIDs []string `db:"item_ids"` | ||
Description string `db:"description"` | ||
} | ||
|
||
type User struct { | ||
ID string `db:"id"` | ||
MoneyPoolIDs []string `db:"money_pool_ids"` | ||
} | ||
|
||
type Store struct { | ||
ID string `db:"id"` | ||
Name string `db:"name"` | ||
UserID string `db:"user_id"` | ||
} | ||
|
||
type MoneyPool struct { | ||
ID string `db:"id"` | ||
Name string `db:"name"` | ||
Color string `db:"color"` | ||
IsWorldPublic bool `db:"is_world_public"` | ||
ShareUserIDs []string `db:"share_user_ids"` | ||
} | ||
|
||
type Item struct { | ||
ID string `db:"id"` | ||
Name string `db:"name"` | ||
PricePerUnit float64 `db:"price_per_unit"` | ||
UserID string `db:"user_id"` | ||
} | ||
|
||
type GetTransactionHints struct { | ||
PartitioningKeys []string // YYYY-MM | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```mermaid | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package handler | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/walnuts1018/openchokin/back/usecase" | ||
) | ||
|
||
var ( | ||
uc *usecase.Usecase | ||
) | ||
|
||
func NewHandler(usecase *usecase.Usecase) (*gin.Engine, error) { | ||
uc = usecase | ||
r := gin.Default() | ||
v1 := r.Group("/v1") | ||
{ | ||
v1.GET("/slack/profile", func(ctx *gin.Context) { fmt.Printf("%v", uc) }) | ||
} | ||
return r, nil | ||
} |
Oops, something went wrong.