diff --git a/application.yaml b/application.yaml index 234797a..d8e86d5 100644 --- a/application.yaml +++ b/application.yaml @@ -4,7 +4,7 @@ server: writeTimeout: 5s mysql: - dsn: "root:mysql_78GywN@tcp(111.228.49.52:3306)/db?parseTime=true&loc=Local" + dsn: "root:mysql_78GywN@tcp(111.228.49.52:3306)/epic_db?parseTime=true&loc=Local" redis: addr: "111.228.49.52" @@ -13,7 +13,7 @@ redis: log: level: info - format: json + format: console cron: enabled: true diff --git a/go.mod b/go.mod index 03ef6e8..21a4b89 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.24.11 require ( github.com/go-sql-driver/mysql v1.9.3 github.com/labstack/echo/v4 v4.15.0 + github.com/pkg/errors v0.9.1 github.com/redis/go-redis/v9 v9.17.2 github.com/robfig/cron/v3 v3.0.1 github.com/spf13/viper v1.21.0 diff --git a/go.sum b/go.sum index adc3dd6..87002dc 100644 --- a/go.sum +++ b/go.sum @@ -65,6 +65,8 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/redis/go-redis/v9 v9.17.2 h1:P2EGsA4qVIM3Pp+aPocCJ7DguDHhqrXNhVcEp4ViluI= diff --git a/internal/controller/hero_controller.go b/internal/controller/hero_controller.go index b0a38fe..657adb9 100644 --- a/internal/controller/hero_controller.go +++ b/internal/controller/hero_controller.go @@ -43,7 +43,7 @@ func (h *HeroController) GetByID(c echo.Context) error { hero, err := h.svc.GetByID(c.Request().Context(), id) if err != nil { if err == sql.ErrNoRows { - return echo.NewHTTPError(http.StatusNotFound, "hero not found") + return c.JSON(http.StatusOK, vo.OK(nil)) } return err } diff --git a/internal/domain/entity/epic_artifact_info.go b/internal/domain/entity/epic_artifact_info.go index 44656af..06d6b82 100644 --- a/internal/domain/entity/epic_artifact_info.go +++ b/internal/domain/entity/epic_artifact_info.go @@ -2,6 +2,8 @@ package entity import ( "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" "entgo.io/ent/schema/field" ) @@ -9,8 +11,10 @@ type EpicArtifactInfo struct { ent.Schema } -func (EpicArtifactInfo) Table() string { - return "epic_artifact_info" +func (EpicArtifactInfo) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "epic_artifact_info"}, + } } func (EpicArtifactInfo) Fields() []ent.Field { diff --git a/internal/domain/entity/epic_gvg_attack_teams.go b/internal/domain/entity/epic_gvg_attack_teams.go index f7e8c8f..25b3490 100644 --- a/internal/domain/entity/epic_gvg_attack_teams.go +++ b/internal/domain/entity/epic_gvg_attack_teams.go @@ -2,6 +2,8 @@ package entity import ( "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" "entgo.io/ent/schema/field" ) @@ -9,8 +11,10 @@ type EpicGvgAttackTeams struct { ent.Schema } -func (EpicGvgAttackTeams) Table() string { - return "epic_gvg_attack_teams" +func (EpicGvgAttackTeams) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "epic_gvg_attack_teams"}, + } } func (EpicGvgAttackTeams) Fields() []ent.Field { diff --git a/internal/domain/entity/epic_gvg_defense_attack_mapping.go b/internal/domain/entity/epic_gvg_defense_attack_mapping.go index 0c240b8..4f2749a 100644 --- a/internal/domain/entity/epic_gvg_defense_attack_mapping.go +++ b/internal/domain/entity/epic_gvg_defense_attack_mapping.go @@ -2,6 +2,8 @@ package entity import ( "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" "entgo.io/ent/schema/field" ) @@ -9,8 +11,10 @@ type EpicGvgDefenseAttackMapping struct { ent.Schema } -func (EpicGvgDefenseAttackMapping) Table() string { - return "epic_gvg_defense_attack_mapping" +func (EpicGvgDefenseAttackMapping) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "epic_gvg_defense_attack_mapping"}, + } } func (EpicGvgDefenseAttackMapping) Fields() []ent.Field { diff --git a/internal/domain/entity/epic_gvg_defense_teams.go b/internal/domain/entity/epic_gvg_defense_teams.go index aba51c6..9e4697f 100644 --- a/internal/domain/entity/epic_gvg_defense_teams.go +++ b/internal/domain/entity/epic_gvg_defense_teams.go @@ -2,6 +2,8 @@ package entity import ( "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" "entgo.io/ent/schema/field" ) @@ -9,8 +11,10 @@ type EpicGvgDefenseTeams struct { ent.Schema } -func (EpicGvgDefenseTeams) Table() string { - return "epic_gvg_defense_teams" +func (EpicGvgDefenseTeams) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "epic_gvg_defense_teams"}, + } } func (EpicGvgDefenseTeams) Fields() []ent.Field { diff --git a/internal/domain/entity/epic_hero_info.go b/internal/domain/entity/epic_hero_info.go index 51f4d41..9630570 100644 --- a/internal/domain/entity/epic_hero_info.go +++ b/internal/domain/entity/epic_hero_info.go @@ -2,6 +2,8 @@ package entity import ( "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" "entgo.io/ent/schema/field" ) @@ -9,8 +11,10 @@ type EpicHeroInfo struct { ent.Schema } -func (EpicHeroInfo) Table() string { - return "epic_hero_info" +func (EpicHeroInfo) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "epic_hero_info"}, + } } func (EpicHeroInfo) Fields() []ent.Field { diff --git a/internal/domain/entity/epic_hero_user_build.go b/internal/domain/entity/epic_hero_user_build.go index 706392a..539d9ae 100644 --- a/internal/domain/entity/epic_hero_user_build.go +++ b/internal/domain/entity/epic_hero_user_build.go @@ -2,6 +2,8 @@ package entity import ( "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" "entgo.io/ent/schema/field" ) @@ -9,8 +11,10 @@ type EpicHeroUserBuild struct { ent.Schema } -func (EpicHeroUserBuild) Table() string { - return "epic_hero_user_build" +func (EpicHeroUserBuild) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "epic_hero_user_build"}, + } } func (EpicHeroUserBuild) Fields() []ent.Field { diff --git a/internal/domain/entity/epic_i18n_mappings.go b/internal/domain/entity/epic_i18n_mappings.go index 774841b..f813471 100644 --- a/internal/domain/entity/epic_i18n_mappings.go +++ b/internal/domain/entity/epic_i18n_mappings.go @@ -2,6 +2,8 @@ package entity import ( "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" "entgo.io/ent/schema/field" ) @@ -9,8 +11,10 @@ type EpicI18NMappings struct { ent.Schema } -func (EpicI18NMappings) Table() string { - return "epic_i18n_mappings" +func (EpicI18NMappings) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "epic_i18n_mappings"}, + } } func (EpicI18NMappings) Fields() []ent.Field { diff --git a/internal/domain/entity/fribble_hero_set.go b/internal/domain/entity/fribble_hero_set.go index baebed1..d8d0deb 100644 --- a/internal/domain/entity/fribble_hero_set.go +++ b/internal/domain/entity/fribble_hero_set.go @@ -2,6 +2,8 @@ package entity import ( "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" "entgo.io/ent/schema/field" ) @@ -9,8 +11,10 @@ type FribbleHeroSet struct { ent.Schema } -func (FribbleHeroSet) Table() string { - return "fribble_hero_set" +func (FribbleHeroSet) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "fribble_hero_set"}, + } } func (FribbleHeroSet) Fields() []ent.Field { diff --git a/internal/domain/entity/gear_set_info.go b/internal/domain/entity/gear_set_info.go index 6dbb8d3..da13f44 100644 --- a/internal/domain/entity/gear_set_info.go +++ b/internal/domain/entity/gear_set_info.go @@ -2,6 +2,8 @@ package entity import ( "entgo.io/ent" + "entgo.io/ent/dialect/entsql" + "entgo.io/ent/schema" "entgo.io/ent/schema/field" ) @@ -9,8 +11,10 @@ type GearSetInfo struct { ent.Schema } -func (GearSetInfo) Table() string { - return "gear_set_info" +func (GearSetInfo) Annotations() []schema.Annotation { + return []schema.Annotation{ + entsql.Annotation{Table: "gear_set_info"}, + } } func (GearSetInfo) Fields() []ent.Field { diff --git a/internal/domain/vo/response.go b/internal/domain/vo/response.go index 86bcd44..363eff0 100644 --- a/internal/domain/vo/response.go +++ b/internal/domain/vo/response.go @@ -3,7 +3,7 @@ package vo type Response struct { Code string `json:"code"` Message string `json:"message"` - Data any `json:"data,omitempty"` + Data any `json:"data"` } func OK(data any) Response { @@ -18,5 +18,6 @@ func Error(message string) Response { return Response{ Code: "ERROR", Message: message, + Data: nil, } } diff --git a/internal/ent/epicartifactinfo/epicartifactinfo.go b/internal/ent/epicartifactinfo/epicartifactinfo.go index 23e57b7..58823d8 100644 --- a/internal/ent/epicartifactinfo/epicartifactinfo.go +++ b/internal/ent/epicartifactinfo/epicartifactinfo.go @@ -40,7 +40,7 @@ const ( // FieldImageURL holds the string denoting the image_url field in the database. FieldImageURL = "image_url" // Table holds the table name of the epicartifactinfo in the database. - Table = "epic_artifact_infos" + Table = "epic_artifact_info" ) // Columns holds all SQL columns for epicartifactinfo fields. diff --git a/internal/ent/epicgvgdefenseattackmapping/epicgvgdefenseattackmapping.go b/internal/ent/epicgvgdefenseattackmapping/epicgvgdefenseattackmapping.go index 36edde6..db62ac4 100644 --- a/internal/ent/epicgvgdefenseattackmapping/epicgvgdefenseattackmapping.go +++ b/internal/ent/epicgvgdefenseattackmapping/epicgvgdefenseattackmapping.go @@ -36,7 +36,7 @@ const ( // FieldDeleted holds the string denoting the deleted field in the database. FieldDeleted = "deleted" // Table holds the table name of the epicgvgdefenseattackmapping in the database. - Table = "epic_gvg_defense_attack_mappings" + Table = "epic_gvg_defense_attack_mapping" ) // Columns holds all SQL columns for epicgvgdefenseattackmapping fields. diff --git a/internal/ent/epicheroinfo/epicheroinfo.go b/internal/ent/epicheroinfo/epicheroinfo.go index d8ba67b..90476be 100644 --- a/internal/ent/epicheroinfo/epicheroinfo.go +++ b/internal/ent/epicheroinfo/epicheroinfo.go @@ -48,7 +48,7 @@ const ( // FieldUpdateTimeSet holds the string denoting the update_time_set field in the database. FieldUpdateTimeSet = "update_time_set" // Table holds the table name of the epicheroinfo in the database. - Table = "epic_hero_infos" + Table = "epic_hero_info" ) // Columns holds all SQL columns for epicheroinfo fields. diff --git a/internal/ent/epicherouserbuild/epicherouserbuild.go b/internal/ent/epicherouserbuild/epicherouserbuild.go index ce11526..8d4ef8e 100644 --- a/internal/ent/epicherouserbuild/epicherouserbuild.go +++ b/internal/ent/epicherouserbuild/epicherouserbuild.go @@ -32,7 +32,7 @@ const ( // FieldDeleted holds the string denoting the deleted field in the database. FieldDeleted = "deleted" // Table holds the table name of the epicherouserbuild in the database. - Table = "epic_hero_user_builds" + Table = "epic_hero_user_build" ) // Columns holds all SQL columns for epicherouserbuild fields. diff --git a/internal/ent/fribbleheroset/fribbleheroset.go b/internal/ent/fribbleheroset/fribbleheroset.go index 4e5de04..1f10d84 100644 --- a/internal/ent/fribbleheroset/fribbleheroset.go +++ b/internal/ent/fribbleheroset/fribbleheroset.go @@ -30,7 +30,7 @@ const ( // FieldSuccessGet holds the string denoting the success_get field in the database. FieldSuccessGet = "success_get" // Table holds the table name of the fribbleheroset in the database. - Table = "fribble_hero_sets" + Table = "fribble_hero_set" ) // Columns holds all SQL columns for fribbleheroset fields. diff --git a/internal/ent/gearsetinfo/gearsetinfo.go b/internal/ent/gearsetinfo/gearsetinfo.go index 53daff2..26a70bb 100644 --- a/internal/ent/gearsetinfo/gearsetinfo.go +++ b/internal/ent/gearsetinfo/gearsetinfo.go @@ -56,7 +56,7 @@ const ( // FieldTenantID holds the string denoting the tenant_id field in the database. FieldTenantID = "tenant_id" // Table holds the table name of the gearsetinfo in the database. - Table = "gear_set_infos" + Table = "gear_set_info" ) // Columns holds all SQL columns for gearsetinfo fields. diff --git a/internal/ent/migrate/schema.go b/internal/ent/migrate/schema.go index bbba931..d346d96 100644 --- a/internal/ent/migrate/schema.go +++ b/internal/ent/migrate/schema.go @@ -3,13 +3,14 @@ package migrate import ( + "entgo.io/ent/dialect/entsql" "entgo.io/ent/dialect/sql/schema" "entgo.io/ent/schema/field" ) var ( - // EpicArtifactInfosColumns holds the columns for the "epic_artifact_infos" table. - EpicArtifactInfosColumns = []*schema.Column{ + // EpicArtifactInfoColumns holds the columns for the "epic_artifact_info" table. + EpicArtifactInfoColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "artifact_name", Type: field.TypeString, Size: 255}, {Name: "artifact_code", Type: field.TypeString, Size: 255}, @@ -26,11 +27,11 @@ var ( {Name: "artifact_name_en", Type: field.TypeString, Size: 255}, {Name: "image_url", Type: field.TypeString, Size: 255}, } - // EpicArtifactInfosTable holds the schema information for the "epic_artifact_infos" table. - EpicArtifactInfosTable = &schema.Table{ - Name: "epic_artifact_infos", - Columns: EpicArtifactInfosColumns, - PrimaryKey: []*schema.Column{EpicArtifactInfosColumns[0]}, + // EpicArtifactInfoTable holds the schema information for the "epic_artifact_info" table. + EpicArtifactInfoTable = &schema.Table{ + Name: "epic_artifact_info", + Columns: EpicArtifactInfoColumns, + PrimaryKey: []*schema.Column{EpicArtifactInfoColumns[0]}, } // EpicGvgAttackTeamsColumns holds the columns for the "epic_gvg_attack_teams" table. EpicGvgAttackTeamsColumns = []*schema.Column{ @@ -48,8 +49,8 @@ var ( Columns: EpicGvgAttackTeamsColumns, PrimaryKey: []*schema.Column{EpicGvgAttackTeamsColumns[0]}, } - // EpicGvgDefenseAttackMappingsColumns holds the columns for the "epic_gvg_defense_attack_mappings" table. - EpicGvgDefenseAttackMappingsColumns = []*schema.Column{ + // EpicGvgDefenseAttackMappingColumns holds the columns for the "epic_gvg_defense_attack_mapping" table. + EpicGvgDefenseAttackMappingColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "defense_id", Type: field.TypeInt64}, {Name: "attack_id", Type: field.TypeInt64}, @@ -64,11 +65,11 @@ var ( {Name: "update_time", Type: field.TypeTime, Nullable: true}, {Name: "deleted", Type: field.TypeBool}, } - // EpicGvgDefenseAttackMappingsTable holds the schema information for the "epic_gvg_defense_attack_mappings" table. - EpicGvgDefenseAttackMappingsTable = &schema.Table{ - Name: "epic_gvg_defense_attack_mappings", - Columns: EpicGvgDefenseAttackMappingsColumns, - PrimaryKey: []*schema.Column{EpicGvgDefenseAttackMappingsColumns[0]}, + // EpicGvgDefenseAttackMappingTable holds the schema information for the "epic_gvg_defense_attack_mapping" table. + EpicGvgDefenseAttackMappingTable = &schema.Table{ + Name: "epic_gvg_defense_attack_mapping", + Columns: EpicGvgDefenseAttackMappingColumns, + PrimaryKey: []*schema.Column{EpicGvgDefenseAttackMappingColumns[0]}, } // EpicGvgDefenseTeamsColumns holds the columns for the "epic_gvg_defense_teams" table. EpicGvgDefenseTeamsColumns = []*schema.Column{ @@ -86,8 +87,8 @@ var ( Columns: EpicGvgDefenseTeamsColumns, PrimaryKey: []*schema.Column{EpicGvgDefenseTeamsColumns[0]}, } - // EpicHeroInfosColumns holds the columns for the "epic_hero_infos" table. - EpicHeroInfosColumns = []*schema.Column{ + // EpicHeroInfoColumns holds the columns for the "epic_hero_info" table. + EpicHeroInfoColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "hero_name", Type: field.TypeString, Size: 255}, {Name: "hero_code", Type: field.TypeString, Size: 255}, @@ -108,14 +109,14 @@ var ( {Name: "content_json_set", Type: field.TypeString, Size: 255}, {Name: "update_time_set", Type: field.TypeTime, Nullable: true}, } - // EpicHeroInfosTable holds the schema information for the "epic_hero_infos" table. - EpicHeroInfosTable = &schema.Table{ - Name: "epic_hero_infos", - Columns: EpicHeroInfosColumns, - PrimaryKey: []*schema.Column{EpicHeroInfosColumns[0]}, + // EpicHeroInfoTable holds the schema information for the "epic_hero_info" table. + EpicHeroInfoTable = &schema.Table{ + Name: "epic_hero_info", + Columns: EpicHeroInfoColumns, + PrimaryKey: []*schema.Column{EpicHeroInfoColumns[0]}, } - // EpicHeroUserBuildsColumns holds the columns for the "epic_hero_user_builds" table. - EpicHeroUserBuildsColumns = []*schema.Column{ + // EpicHeroUserBuildColumns holds the columns for the "epic_hero_user_build" table. + EpicHeroUserBuildColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "artifact_code", Type: field.TypeString, Size: 255}, {Name: "hero_code", Type: field.TypeString, Size: 255}, @@ -128,11 +129,11 @@ var ( {Name: "update_time", Type: field.TypeTime, Nullable: true}, {Name: "deleted", Type: field.TypeBool}, } - // EpicHeroUserBuildsTable holds the schema information for the "epic_hero_user_builds" table. - EpicHeroUserBuildsTable = &schema.Table{ - Name: "epic_hero_user_builds", - Columns: EpicHeroUserBuildsColumns, - PrimaryKey: []*schema.Column{EpicHeroUserBuildsColumns[0]}, + // EpicHeroUserBuildTable holds the schema information for the "epic_hero_user_build" table. + EpicHeroUserBuildTable = &schema.Table{ + Name: "epic_hero_user_build", + Columns: EpicHeroUserBuildColumns, + PrimaryKey: []*schema.Column{EpicHeroUserBuildColumns[0]}, } // EpicI18nMappingsColumns holds the columns for the "epic_i18n_mappings" table. EpicI18nMappingsColumns = []*schema.Column{ @@ -155,8 +156,8 @@ var ( Columns: EpicI18nMappingsColumns, PrimaryKey: []*schema.Column{EpicI18nMappingsColumns[0]}, } - // FribbleHeroSetsColumns holds the columns for the "fribble_hero_sets" table. - FribbleHeroSetsColumns = []*schema.Column{ + // FribbleHeroSetColumns holds the columns for the "fribble_hero_set" table. + FribbleHeroSetColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "hero_code", Type: field.TypeString, Size: 255}, {Name: "json_content", Type: field.TypeString, Size: 255}, @@ -168,14 +169,14 @@ var ( {Name: "deleted", Type: field.TypeBool}, {Name: "success_get", Type: field.TypeInt}, } - // FribbleHeroSetsTable holds the schema information for the "fribble_hero_sets" table. - FribbleHeroSetsTable = &schema.Table{ - Name: "fribble_hero_sets", - Columns: FribbleHeroSetsColumns, - PrimaryKey: []*schema.Column{FribbleHeroSetsColumns[0]}, + // FribbleHeroSetTable holds the schema information for the "fribble_hero_set" table. + FribbleHeroSetTable = &schema.Table{ + Name: "fribble_hero_set", + Columns: FribbleHeroSetColumns, + PrimaryKey: []*schema.Column{FribbleHeroSetColumns[0]}, } - // GearSetInfosColumns holds the columns for the "gear_set_infos" table. - GearSetInfosColumns = []*schema.Column{ + // GearSetInfoColumns holds the columns for the "gear_set_info" table. + GearSetInfoColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt64, Increment: true}, {Name: "level", Type: field.TypeInt}, {Name: "gear_id", Type: field.TypeInt64}, @@ -200,25 +201,52 @@ var ( {Name: "deleted", Type: field.TypeBool}, {Name: "tenant_id", Type: field.TypeInt64}, } - // GearSetInfosTable holds the schema information for the "gear_set_infos" table. - GearSetInfosTable = &schema.Table{ - Name: "gear_set_infos", - Columns: GearSetInfosColumns, - PrimaryKey: []*schema.Column{GearSetInfosColumns[0]}, + // GearSetInfoTable holds the schema information for the "gear_set_info" table. + GearSetInfoTable = &schema.Table{ + Name: "gear_set_info", + Columns: GearSetInfoColumns, + PrimaryKey: []*schema.Column{GearSetInfoColumns[0]}, } // Tables holds all the tables in the schema. Tables = []*schema.Table{ - EpicArtifactInfosTable, + EpicArtifactInfoTable, EpicGvgAttackTeamsTable, - EpicGvgDefenseAttackMappingsTable, + EpicGvgDefenseAttackMappingTable, EpicGvgDefenseTeamsTable, - EpicHeroInfosTable, - EpicHeroUserBuildsTable, + EpicHeroInfoTable, + EpicHeroUserBuildTable, EpicI18nMappingsTable, - FribbleHeroSetsTable, - GearSetInfosTable, + FribbleHeroSetTable, + GearSetInfoTable, } ) func init() { + EpicArtifactInfoTable.Annotation = &entsql.Annotation{ + Table: "epic_artifact_info", + } + EpicGvgAttackTeamsTable.Annotation = &entsql.Annotation{ + Table: "epic_gvg_attack_teams", + } + EpicGvgDefenseAttackMappingTable.Annotation = &entsql.Annotation{ + Table: "epic_gvg_defense_attack_mapping", + } + EpicGvgDefenseTeamsTable.Annotation = &entsql.Annotation{ + Table: "epic_gvg_defense_teams", + } + EpicHeroInfoTable.Annotation = &entsql.Annotation{ + Table: "epic_hero_info", + } + EpicHeroUserBuildTable.Annotation = &entsql.Annotation{ + Table: "epic_hero_user_build", + } + EpicI18nMappingsTable.Annotation = &entsql.Annotation{ + Table: "epic_i18n_mappings", + } + FribbleHeroSetTable.Annotation = &entsql.Annotation{ + Table: "fribble_hero_set", + } + GearSetInfoTable.Annotation = &entsql.Annotation{ + Table: "gear_set_info", + } } diff --git a/internal/exception/handler.go b/internal/exception/handler.go index 1ce6ce7..b267c62 100644 --- a/internal/exception/handler.go +++ b/internal/exception/handler.go @@ -1,14 +1,16 @@ package exception import ( + "fmt" "net/http" "github.com/labstack/echo/v4" + "go.uber.org/zap" "epic-ent/internal/domain/vo" ) -func RegisterErrorHandler(e *echo.Echo) { +func RegisterErrorHandler(e *echo.Echo, logger *zap.Logger) { e.HTTPErrorHandler = func(err error, c echo.Context) { code := http.StatusInternalServerError msg := err.Error() @@ -19,6 +21,14 @@ func RegisterErrorHandler(e *echo.Echo) { } } + verbose := fmt.Sprintf("%+v", err) + logger.With( + zap.Int("status", code), + zap.String("path", c.Path()), + zap.String("method", c.Request().Method), + zap.Error(err), + ).Error(verbose) + _ = c.JSON(code, vo.Error(msg)) } } diff --git a/internal/infra/log/logger.go b/internal/infra/log/logger.go index 5a6383d..9446be1 100644 --- a/internal/infra/log/logger.go +++ b/internal/infra/log/logger.go @@ -15,9 +15,21 @@ func NewLogger(cfg *config.Config) (*zap.Logger, error) { zapCfg := zap.NewProductionConfig() zapCfg.Level = zap.NewAtomicLevelAt(level) + zapCfg.EncoderConfig.CallerKey = "caller" + zapCfg.EncoderConfig.StacktraceKey = "stacktrace" if cfg.Log.Format == "console" { - zapCfg.Encoding = "console" + devCfg := zap.NewDevelopmentConfig() + devCfg.Level = zap.NewAtomicLevelAt(level) + devCfg.EncoderConfig.CallerKey = "caller" + devCfg.EncoderConfig.StacktraceKey = "stacktrace" + return devCfg.Build( + zap.AddCaller(), + zap.AddStacktrace(zapcore.ErrorLevel), + ) } - return zapCfg.Build() + return zapCfg.Build( + zap.AddCaller(), + zap.AddStacktrace(zapcore.ErrorLevel), + ) } diff --git a/internal/repository/hero_repo.go b/internal/repository/hero_repo.go index a7a81e0..5bd7dd0 100644 --- a/internal/repository/hero_repo.go +++ b/internal/repository/hero_repo.go @@ -5,6 +5,8 @@ import ( "database/sql" "time" + "github.com/pkg/errors" + "epic-ent/internal/domain/dto" "epic-ent/internal/domain/vo" "epic-ent/internal/ent" @@ -49,7 +51,7 @@ func (r *HeroRepository) Create(ctx context.Context, req dto.HeroCreateRequest) hero, err := create.Save(ctx) if err != nil { - return vo.Hero{}, err + return vo.Hero{}, errors.Wrap(err, "create hero") } return toVO(hero), nil @@ -63,7 +65,10 @@ func (r *HeroRepository) GetByID(ctx context.Context, id int64) (vo.Hero, error) ). Only(ctx) if err != nil { - return vo.Hero{}, err + if ent.IsNotFound(err) { + return vo.Hero{}, sql.ErrNoRows + } + return vo.Hero{}, errors.Wrap(err, "get hero by id") } return toVO(hero), nil @@ -151,7 +156,7 @@ func (r *HeroRepository) Update(ctx context.Context, id int64, req dto.HeroUpdat affected, err := update.Save(ctx) if err != nil { - return vo.Hero{}, err + return vo.Hero{}, errors.Wrap(err, "update hero") } if affected == 0 { return vo.Hero{}, sql.ErrNoRows @@ -170,7 +175,7 @@ func (r *HeroRepository) Delete(ctx context.Context, id int64) error { SetUpdateTime(time.Now()). Save(ctx) if err != nil { - return err + return errors.Wrap(err, "delete hero") } if affected == 0 { return sql.ErrNoRows