Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
ispiroglu committed May 15, 2024
1 parent 5ff5952 commit 08d384b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 89 deletions.
98 changes: 17 additions & 81 deletions config/building_measurement_types/en.json
Original file line number Diff line number Diff line change
@@ -1,84 +1,20 @@
{
"Coal and Coke": [
"Anthracite Coal",
"Bituminous Coal",
"Sub-bituminous Coal",
"Lignite Coal",
"Mixed (Commercial Sector)",
"Mixed (Electric Power Sector)",
"Mixed (Industrial Coking)",
"Mixed (Industrial Sector)",
"Coal Coke"
],
"Other Fuels - Solid": [
"Municipal Solid Waste",
"Petroleum Coke (Solid)",
"Plastics",
"Tires"
],
"Biomass Fuels - Solid": [
"Agricultural Byproducts",
"Peat",
"Solid Byproducts",
"Wood and Wood Residuals"
],
"Natural Gas": [
"Natural Gas"
],
"Other Fuels - Gaseous": [
"Blast Furnace Gas",
"Coke Oven Gas",
"Fuel Gas",
"Propane Gas"
],
"Biomass Fuels - Gaseous": [
"Landfill Gas",
"Other Biomass Gases"
],
"Petroleum Products": [
"Asphalt and Road Oil",
"Aviation Gasoline",
"Butane",
"Butylene",
"Crude Oil",
"Distillate Fuel Oil No. 1",
"Distillate Fuel Oil No. 2",
"Distillate Fuel Oil No. 4",
"Ethane",
"Ethylene",
"Heavy Gas Oils",
"Isobutane",
"Isobutylene",
"Kerosene",
"Kerosene-Type Jet Fuel",
"Liquefied Petroleum Gases (LPG)",
"Lubricants",
"Motor Gasoline",
"Naphtha (<401 deg F)",
"Natural Gasoline",
"Other Oil (>401 deg F)",
"Pentanes Plus",
"Petrochemical Feedstocks",
"Petroleum Coke",
"Propane",
"Propylene",
"Residual Fuel Oil No. 5",
"Residual Fuel Oil No. 6",
"Special Naphtha",
"Unfinished Oils",
"Used Oil"
],
"Biomass Fuels - Liquid": [
"Biodiesel (100%)",
"Ethanol (100%)",
"Rendered Animal Fat",
"Vegetable Oil"
],
"Biomass Fuels - Kraft Pulping Liquor, by Wood Furnish": [
"North American Softwood",
"North American Hardwood",
"Bagasse",
"Bamboo",
"Straw"
"Electricity": ["Electricity"],
"District heating and cooling": ["District Heating", "District Cooling"],
"Fossil fuels": ["Natural Gas",
"Liquid Gas",
"Heating Oil",
"Diesel",
"Gasoline",
"Lignite",
"Coal",
"Other Fossil Fuels"
],
"Renewable energies": ["Biogas",
"Plant Oil",
"Biofuel",
"Other Biomass",
"Solar Thermal",
"Geothermal"
]
}
2 changes: 1 addition & 1 deletion internal/domain/building/application/measure_building.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (h *measureBuildingCommandHandler) Handle(ctx context.Context, cmd *aggrega
return errors.Errorf("building with id %s does not exist", cmd.AggregateId.String())
}

if err := a.MeasureBuildingCommandHandler(cmd); err != nil {
if err := a.MeasureBuildingCommandHandler(ctx, cmd); err != nil {
h.l.Error("failed to measure building", zap.Error(err), zap.String("id", cmd.AggregateId.String()))
return err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/domain/building/core/aggregate/command_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ type MeasureBuildingCommand struct {
Measurements []*model.Measurement
}

func (b *BuildingAggregate) MeasureBuildingCommandHandler(cmd *MeasureBuildingCommand) error {
func (b *BuildingAggregate) MeasureBuildingCommandHandler(ctx context.Context, cmd *MeasureBuildingCommand) error {

if err := validateMeasurement(cmd.Measurements); err != nil {
return err
}

for _, m := range cmd.Measurements {
event, err := events.NewBuildingMeasuredEvent(b.AggregateBase, m)
event, err := events.NewBuildingMeasuredEvent(ctx, b.AggregateBase, m)
if err != nil {
return err
}
Expand Down
16 changes: 11 additions & 5 deletions internal/domain/building/core/events/building_measured_event.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package events

import (
"fmt"
"github.com/iancoleman/strcase"
"context"
"secap-input/internal/common/eventsourcing"
"secap-input/internal/domain/building/core/model"
)
Expand All @@ -13,17 +12,24 @@ type BuildingMeasuredEvent struct {

const BuildingMeasuredEventType = "building.measured"

func NewBuildingMeasuredEvent(a *eventsourcing.AggregateBase, measurement *model.Measurement) (*eventsourcing.Event, error) {
func NewBuildingMeasuredEvent(ctx context.Context, a *eventsourcing.AggregateBase, measurement *model.Measurement) (*eventsourcing.Event, error) {
//measurement.MeasurementTypeHeader = model.MeasurementTypeHeader(strcase.ToCamel(string(measurement.MeasurementTypeHeader)))
//measurement.MeasurementType = model.MeasurementType(strcase.ToCamel(string(measurement.MeasurementType)))
eventData := &BuildingMeasuredEvent{
Measurement: measurement,
}

eventType := fmt.Sprintf("%s.%s", BuildingMeasuredEventType, strcase.ToCamel(string(measurement.MeasurementType)))
//eventType := fmt.Sprintf("%s.%s", BuildingMeasuredEventType, strcase.ToCamel(string(measurement.MeasurementType)))

event := eventsourcing.NewEvent(a, eventType)
event := eventsourcing.NewEvent(a, BuildingMeasuredEventType)
if err := event.SetEventData(eventData); err != nil {
return nil, err
}

md := eventsourcing.NewEventMetadataFromContext(ctx)
if err := event.SetMetaData(md); err != nil {
return nil, err
}

return event, nil
}

0 comments on commit 08d384b

Please sign in to comment.