Skip to content

Commit

Permalink
stylecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
FoseFx committed Dec 27, 2024
1 parent 78e9f4c commit 1a8b07d
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 214 deletions.
18 changes: 9 additions & 9 deletions services/tasks-svc/internal/bed/bed.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,34 @@ func (s ServiceServer) CreateBed(ctx context.Context, req *pb.CreateBedRequest)
bedRepo := bed_repo.New(hwdb.GetDB())

// parse inputs
roomId, err := uuid.Parse(req.GetRoomId())
roomID, err := uuid.Parse(req.GetRoomId())
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}

// check permissions
user := commonperm.UserFromCtx(ctx)
check := hwauthz.NewPermissionCheck(user, roomPerm.RoomCanUserCreateBed, roomPerm.Room(roomId))
check := hwauthz.NewPermissionCheck(user, roomPerm.RoomCanUserCreateBed, roomPerm.Room(roomID))
if err := s.authz.Must(ctx, check); err != nil {
return nil, err
}

// do query
bed, err := bedRepo.CreateBed(ctx, bed_repo.CreateBedParams{
RoomID: roomId,
RoomID: roomID,
Name: req.GetName(),
})
err = hwdb.Error(ctx, err,
hwdb.WithOnFKViolation("beds_room_id_fkey", func(pgErr *pgconn.PgError) error {
return hwerr.NewStatusError(ctx,
codes.InvalidArgument,
pgErr.Error(),
locale.InvalidRoomIdError(ctx),
locale.InvalidRoomIDError(ctx),
&errdetails.BadRequest{
FieldViolations: []*errdetails.BadRequest_FieldViolation{
{
Field: "room_id",
Description: hwlocale.Localize(ctx, locale.InvalidRoomIdError(ctx)),
Description: hwlocale.Localize(ctx, locale.InvalidRoomIDError(ctx)),
},
},
})
Expand All @@ -109,7 +109,7 @@ func (s ServiceServer) CreateBed(ctx context.Context, req *pb.CreateBedRequest)

// update permission graph
relationship := hwauthz.NewRelationship(
roomPerm.Room(roomId),
roomPerm.Room(roomID),
perm.BedRoom,
perm.Bed(bed.ID),
)
Expand Down Expand Up @@ -177,12 +177,12 @@ func (s ServiceServer) GetBedByPatient(
) (*pb.GetBedByPatientResponse, error) {
bedRepo := bed_repo.New(hwdb.GetDB())

patientId, err := uuid.Parse(req.GetPatientId())
patientID, err := uuid.Parse(req.GetPatientId())
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}

result, err := hwdb.Optional(bedRepo.GetBedWithRoomByPatient)(ctx, patientId)
result, err := hwdb.Optional(bedRepo.GetBedWithRoomByPatient)(ctx, patientID)
err = hwdb.Error(ctx, err)
if err != nil {
return nil, err
Expand All @@ -192,7 +192,7 @@ func (s ServiceServer) GetBedByPatient(
user := commonperm.UserFromCtx(ctx)
checks := make([]hwauthz.PermissionCheck, 0)
checks = append(checks,
hwauthz.NewPermissionCheck(user, patientPerm.PatientCanUserGet, patientPerm.Patient(patientId)))
hwauthz.NewPermissionCheck(user, patientPerm.PatientCanUserGet, patientPerm.Patient(patientID)))

if result != nil {
checks = append(checks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (p *Projection) initEventListeners() {
}

// Event handlers
func (a *Projection) onPatientCreated(ctx context.Context, evt hwes.Event) (error, *esdb.NackAction) {
func (p *Projection) onPatientCreated(ctx context.Context, evt hwes.Event) (error, *esdb.NackAction) {
log := zlog.Ctx(ctx)

var payload patientEventsV1.PatientCreatedEvent
Expand All @@ -67,7 +67,7 @@ func (a *Projection) onPatientCreated(ctx context.Context, evt hwes.Event) (erro
}
organizationID := *evt.OrganizationID

err = a.patientRepo.CreatePatient(ctx, patient_repo.CreatePatientParams{
err = p.patientRepo.CreatePatient(ctx, patient_repo.CreatePatientParams{
ID: patientID,
HumanReadableIdentifier: payload.HumanReadableIdentifier,
Notes: payload.Notes,
Expand All @@ -83,7 +83,7 @@ func (a *Projection) onPatientCreated(ctx context.Context, evt hwes.Event) (erro
return nil, nil
}

func (a *Projection) onBedAssigned(ctx context.Context, evt hwes.Event) (error, *esdb.NackAction) {
func (p *Projection) onBedAssigned(ctx context.Context, evt hwes.Event) (error, *esdb.NackAction) {
log := zlog.Ctx(ctx)

var payload patientEventsV1.BedAssignedEvent
Expand All @@ -92,14 +92,14 @@ func (a *Projection) onBedAssigned(ctx context.Context, evt hwes.Event) (error,
return err, hwutil.PtrTo(esdb.NackActionPark)
}

bedId, err := hwutil.ParseNullUUID(&payload.BedID)
bedID, err := hwutil.ParseNullUUID(&payload.BedID)
if err != nil {
return err, hwutil.PtrTo(esdb.NackActionPark)
}

err = a.patientRepo.UpdatePatientBedId(ctx, patient_repo.UpdatePatientBedIdParams{
err = p.patientRepo.UpdatePatientBedId(ctx, patient_repo.UpdatePatientBedIdParams{
ID: evt.AggregateID,
BedID: bedId,
BedID: bedID,
UpdatedAt: hwdb.TimeToTimestamp(evt.Timestamp),
Consistency: int64(evt.GetVersion()), //nolint:gosec
})
Expand All @@ -110,8 +110,8 @@ func (a *Projection) onBedAssigned(ctx context.Context, evt hwes.Event) (error,
return nil, nil
}

func (a *Projection) onBedUnassigned(ctx context.Context, evt hwes.Event) (error, *esdb.NackAction) {
err := a.patientRepo.UpdatePatientBedId(ctx, patient_repo.UpdatePatientBedIdParams{
func (p *Projection) onBedUnassigned(ctx context.Context, evt hwes.Event) (error, *esdb.NackAction) {
err := p.patientRepo.UpdatePatientBedId(ctx, patient_repo.UpdatePatientBedIdParams{
ID: evt.AggregateID,
BedID: uuid.NullUUID{},
UpdatedAt: hwdb.TimeToTimestamp(evt.Timestamp),
Expand All @@ -124,8 +124,8 @@ func (a *Projection) onBedUnassigned(ctx context.Context, evt hwes.Event) (error
return nil, nil
}

func (a *Projection) onPatientDischarged(ctx context.Context, evt hwes.Event) (error, *esdb.NackAction) {
err := a.patientRepo.UpdatePatient(ctx, patient_repo.UpdatePatientParams{
func (p *Projection) onPatientDischarged(ctx context.Context, evt hwes.Event) (error, *esdb.NackAction) {
err := p.patientRepo.UpdatePatient(ctx, patient_repo.UpdatePatientParams{
ID: evt.AggregateID,
IsDischarged: hwutil.PtrTo(true),
UpdatedAt: hwdb.TimeToTimestamp(evt.Timestamp),
Expand All @@ -138,7 +138,7 @@ func (a *Projection) onPatientDischarged(ctx context.Context, evt hwes.Event) (e
return nil, nil
}

func (a *Projection) onNotesUpdated(ctx context.Context, evt hwes.Event) (error, *esdb.NackAction) {
func (p *Projection) onNotesUpdated(ctx context.Context, evt hwes.Event) (error, *esdb.NackAction) {
log := zlog.Ctx(ctx)

var payload patientEventsV1.NotesUpdatedEvent
Expand All @@ -147,7 +147,7 @@ func (a *Projection) onNotesUpdated(ctx context.Context, evt hwes.Event) (error,
return err, hwutil.PtrTo(esdb.NackActionPark)
}

err := a.patientRepo.UpdatePatient(ctx, patient_repo.UpdatePatientParams{
err := p.patientRepo.UpdatePatient(ctx, patient_repo.UpdatePatientParams{
ID: evt.AggregateID,
Notes: &payload.Notes,
UpdatedAt: hwdb.TimeToTimestamp(evt.Timestamp),
Expand All @@ -160,7 +160,7 @@ func (a *Projection) onNotesUpdated(ctx context.Context, evt hwes.Event) (error,
return nil, nil
}

func (a *Projection) onHumanReadableIdentifierUpdated(ctx context.Context, evt hwes.Event) (error, *esdb.NackAction) {
func (p *Projection) onHumanReadableIdentifierUpdated(ctx context.Context, evt hwes.Event) (error, *esdb.NackAction) {
log := zlog.Ctx(ctx)

var payload patientEventsV1.HumanReadableIdentifierUpdatedEvent
Expand All @@ -169,7 +169,7 @@ func (a *Projection) onHumanReadableIdentifierUpdated(ctx context.Context, evt h
return err, hwutil.PtrTo(esdb.NackActionPark)
}

err := a.patientRepo.UpdatePatient(ctx, patient_repo.UpdatePatientParams{
err := p.patientRepo.UpdatePatient(ctx, patient_repo.UpdatePatientParams{
ID: evt.AggregateID,
HumanReadableIdentfier: &payload.HumanReadableIdentifier,
UpdatedAt: hwdb.TimeToTimestamp(evt.Timestamp),
Expand All @@ -182,8 +182,8 @@ func (a *Projection) onHumanReadableIdentifierUpdated(ctx context.Context, evt h
return nil, nil
}

func (a *Projection) onPatientReadmitted(ctx context.Context, evt hwes.Event) (error, *esdb.NackAction) {
err := a.patientRepo.UpdatePatient(ctx, patient_repo.UpdatePatientParams{
func (p *Projection) onPatientReadmitted(ctx context.Context, evt hwes.Event) (error, *esdb.NackAction) {
err := p.patientRepo.UpdatePatient(ctx, patient_repo.UpdatePatientParams{
ID: evt.AggregateID,
IsDischarged: hwutil.PtrTo(false),
UpdatedAt: hwdb.TimeToTimestamp(evt.Timestamp),
Expand All @@ -196,8 +196,8 @@ func (a *Projection) onPatientReadmitted(ctx context.Context, evt hwes.Event) (e
return nil, nil
}

func (a *Projection) onPatientDeleted(ctx context.Context, evt hwes.Event) (error, *esdb.NackAction) {
err := a.patientRepo.DeletePatient(ctx, evt.AggregateID)
func (p *Projection) onPatientDeleted(ctx context.Context, evt hwes.Event) (error, *esdb.NackAction) {
err := p.patientRepo.DeletePatient(ctx, evt.AggregateID)
if err := hwdb.Error(ctx, err); err != nil {
return err, hwutil.PtrTo(esdb.NackActionRetry)
}
Expand Down
4 changes: 2 additions & 2 deletions services/tasks-svc/locale/locale.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
var localeFS embed.FS
var lazy = hwlocale.NewLazyLocaleBundle(&localeFS)

func InvalidRoomIdError(ctx context.Context) hwlocale.Locale {
func InvalidRoomIDError(ctx context.Context) hwlocale.Locale {
return hwlocale.Locale{
Bundle: lazy.Bundle(ctx),
Config: &i18n.LocalizeConfig{MessageID: "InvalidRoomIdError"},
Config: &i18n.LocalizeConfig{MessageID: "InvalidRoomIDError"},
}
}
30 changes: 15 additions & 15 deletions services/tasks-svc/stories/BedCRUD_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ func TestCreateUpdateGetBed(t *testing.T) {

// first, prepare room
wardID, _ := prepareWard(t, ctx, "1")
roomId, _ := prepareRoom(t, ctx, wardID, "1")
roomID, _ := prepareRoom(t, ctx, wardID, "1")

//
// create new bed
//
createReq := &pb.CreateBedRequest{
RoomId: roomId,
RoomId: roomID,
Name: t.Name() + " bed",
}
createRes, err := bedClient.CreateBed(ctx, createReq)
Expand Down Expand Up @@ -82,11 +82,11 @@ func TestGetBedByPatient(t *testing.T) {

// first, prepare room
wardID, _ := prepareWard(t, ctx, "1")
roomId, roomConsistency := prepareRoom(t, ctx, wardID, "")
roomID, roomConsistency := prepareRoom(t, ctx, wardID, "")

// creating two beds
unrelatedBedID, _ := prepareBed(t, ctx, roomId, "unrelated")
patientsBedID, bedConsistency := prepareBed(t, ctx, roomId, "patient")
unrelatedBedID, _ := prepareBed(t, ctx, roomID, "unrelated")
patientsBedID, bedConsistency := prepareBed(t, ctx, roomID, "patient")

// create a patient
patientID := preparePatient(t, ctx, "")
Expand All @@ -113,7 +113,7 @@ func TestGetBedByPatient(t *testing.T) {
assert.Equal(t, patientsBedID, res.Bed.Id)
assert.Equal(t, bedConsistency, res.Bed.Consistency)

assert.Equal(t, roomId, res.Room.Id)
assert.Equal(t, roomID, res.Room.Id)
assert.Equal(t, roomConsistency, res.Room.Consistency)
}

Expand All @@ -135,13 +135,13 @@ func TestGetBeds(t *testing.T) {

for i, bedSfxs := range suffixMatrix {
roomSuffix := strconv.Itoa(i + 1)
roomId, _ := prepareRoom(t, ctx, wardID, roomSuffix)
roomBedsMap[roomId] = make([]string, 0)
roomID, _ := prepareRoom(t, ctx, wardID, roomSuffix)
roomBedsMap[roomID] = make([]string, 0)
for _, bedSuffix := range bedSfxs {
bedId, bedConsistency := prepareBed(t, ctx, roomId, bedSuffix)
bedRoomMap[bedId] = roomId
bedConsistencyMap[bedId] = bedConsistency
roomBedsMap[roomId] = append(roomBedsMap[roomId], bedId)
bedID, bedConsistency := prepareBed(t, ctx, roomID, bedSuffix)
bedRoomMap[bedID] = roomID
bedConsistencyMap[bedID] = bedConsistency
roomBedsMap[roomID] = append(roomBedsMap[roomID], bedID)
}
}

Expand All @@ -165,15 +165,15 @@ func TestGetBeds(t *testing.T) {

// Part 2: GetBedsByRoom

for roomId, expectedBedIDs := range roomBedsMap {
res, err := bedClient.GetBedsByRoom(ctx, &pb.GetBedsByRoomRequest{RoomId: roomId})
for roomID, expectedBedIDs := range roomBedsMap {
res, err := bedClient.GetBedsByRoom(ctx, &pb.GetBedsByRoomRequest{RoomId: roomID})
require.NoError(t, err, "could not get beds for room 1")

assert.Len(t, res.Beds, len(expectedBedIDs))

bedIds := hwutil.Map(res.Beds, func(bed *pb.GetBedsByRoomResponse_Bed) string {
return bed.Id
})
assert.Subset(t, expectedBedIDs, bedIds, "actual bedIDs are not a subset of expected for room %s", roomId)
assert.Subset(t, expectedBedIDs, bedIds, "actual bedIDs are not a subset of expected for room %s", roomID)
}
}
Loading

0 comments on commit 1a8b07d

Please sign in to comment.