From 1a8b07dc7050092b13ed9c26c6e08d5d7a2505a5 Mon Sep 17 00:00:00 2001 From: Max Baumann Date: Fri, 27 Dec 2024 14:55:23 +0100 Subject: [PATCH] stylecheck --- services/tasks-svc/internal/bed/bed.go | 18 +-- .../patient_postgres_projection.go | 36 ++--- services/tasks-svc/locale/locale.go | 4 +- services/tasks-svc/stories/BedCRUD_test.go | 30 ++-- .../tasks-svc/stories/PatientCRUD_test.go | 128 +++++++++--------- services/tasks-svc/stories/RoomCRUD_test.go | 8 +- services/tasks-svc/stories/TaskCRUD_test.go | 46 +++---- .../stories/TaskTemplateCRUD_test.go | 24 ++-- services/tasks-svc/stories/WardCRUD_test.go | 20 +-- services/tasks-svc/stories/setup_test.go | 4 +- services/user-svc/internal/hwkc/client.go | 52 +++---- .../user-svc/internal/hwkc/noop_client.go | 4 +- .../internal/organization/organization.go | 50 +++---- services/user-svc/internal/user/user.go | 4 +- 14 files changed, 214 insertions(+), 214 deletions(-) diff --git a/services/tasks-svc/internal/bed/bed.go b/services/tasks-svc/internal/bed/bed.go index 30d0b5984..cbb91b2cb 100644 --- a/services/tasks-svc/internal/bed/bed.go +++ b/services/tasks-svc/internal/bed/bed.go @@ -65,21 +65,21 @@ 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, @@ -87,12 +87,12 @@ func (s ServiceServer) CreateBed(ctx context.Context, req *pb.CreateBedRequest) 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)), }, }, }) @@ -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), ) @@ -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 @@ -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, diff --git a/services/tasks-svc/internal/patient/projections/patientPostgresProjection/patient_postgres_projection.go b/services/tasks-svc/internal/patient/projections/patientPostgresProjection/patient_postgres_projection.go index 558a63ca6..637d334a7 100644 --- a/services/tasks-svc/internal/patient/projections/patientPostgresProjection/patient_postgres_projection.go +++ b/services/tasks-svc/internal/patient/projections/patientPostgresProjection/patient_postgres_projection.go @@ -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 @@ -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, @@ -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 @@ -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 }) @@ -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), @@ -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), @@ -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 @@ -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), @@ -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 @@ -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), @@ -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), @@ -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) } diff --git a/services/tasks-svc/locale/locale.go b/services/tasks-svc/locale/locale.go index d1f83f8f2..14a596aa4 100644 --- a/services/tasks-svc/locale/locale.go +++ b/services/tasks-svc/locale/locale.go @@ -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"}, } } diff --git a/services/tasks-svc/stories/BedCRUD_test.go b/services/tasks-svc/stories/BedCRUD_test.go index dbd39237b..c966660f7 100644 --- a/services/tasks-svc/stories/BedCRUD_test.go +++ b/services/tasks-svc/stories/BedCRUD_test.go @@ -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) @@ -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, "") @@ -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) } @@ -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) } } @@ -165,8 +165,8 @@ 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)) @@ -174,6 +174,6 @@ func TestGetBeds(t *testing.T) { 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) } } diff --git a/services/tasks-svc/stories/PatientCRUD_test.go b/services/tasks-svc/stories/PatientCRUD_test.go index 0ef9460e3..0dc970b1f 100644 --- a/services/tasks-svc/stories/PatientCRUD_test.go +++ b/services/tasks-svc/stories/PatientCRUD_test.go @@ -36,13 +36,13 @@ func TestCreateUpdateGetPatient(t *testing.T) { hwtesting.WaitForProjectionsToSettle() - patientId := createRes.GetId() + patientID := createRes.GetId() // // get new patient // - getPatientRes, err := patientClient.GetPatient(ctx, &pb.GetPatientRequest{Id: patientId}) + getPatientRes, err := patientClient.GetPatient(ctx, &pb.GetPatientRequest{Id: patientID}) require.NoError(t, err, "could not get after creation") assert.Equal(t, createReq.GetHumanReadableIdentifier(), getPatientRes.GetHumanReadableIdentifier()) @@ -54,7 +54,7 @@ func TestCreateUpdateGetPatient(t *testing.T) { // updateReq := &pb.UpdatePatientRequest{ - Id: patientId, + Id: patientID, HumanReadableIdentifier: hwutil.PtrTo(t.Name() + " patient 1"), Consistency: &getPatientRes.Consistency, } @@ -67,7 +67,7 @@ func TestCreateUpdateGetPatient(t *testing.T) { // get updated patient // - getPatientRes, err = patientClient.GetPatient(ctx, &pb.GetPatientRequest{Id: patientId}) + getPatientRes, err = patientClient.GetPatient(ctx, &pb.GetPatientRequest{Id: patientID}) require.NoError(t, err, "could not get after update") assert.Equal(t, updateReq.GetHumanReadableIdentifier(), getPatientRes.GetHumanReadableIdentifier()) @@ -77,7 +77,7 @@ func TestCreateUpdateGetPatient(t *testing.T) { // discharge patient // - dischargeRes, err := patientClient.DischargePatient(ctx, &pb.DischargePatientRequest{Id: patientId}) + dischargeRes, err := patientClient.DischargePatient(ctx, &pb.DischargePatientRequest{Id: patientID}) require.NoError(t, err) assert.NotEqual(t, getPatientRes.Consistency, dischargeRes.Consistency) @@ -87,7 +87,7 @@ func TestCreateUpdateGetPatient(t *testing.T) { // get discharged patient // - getPatientDetailsRes, err := patientClient.GetPatientDetails(ctx, &pb.GetPatientDetailsRequest{Id: patientId}) + getPatientDetailsRes, err := patientClient.GetPatientDetails(ctx, &pb.GetPatientDetailsRequest{Id: patientID}) require.NoError(t, err, "could not get after discharge") assert.True(t, getPatientDetailsRes.IsDischarged) @@ -97,7 +97,7 @@ func TestCreateUpdateGetPatient(t *testing.T) { // re-admit patient // - readmitRes, err := patientClient.ReadmitPatient(ctx, &pb.ReadmitPatientRequest{PatientId: patientId}) + readmitRes, err := patientClient.ReadmitPatient(ctx, &pb.ReadmitPatientRequest{PatientId: patientID}) require.NoError(t, err) assert.NotEqual(t, getPatientRes.Consistency, readmitRes.Consistency) @@ -105,7 +105,7 @@ func TestCreateUpdateGetPatient(t *testing.T) { // get re-admitted patient // - getPatientDetailsRes, err = patientClient.GetPatientDetails(ctx, &pb.GetPatientDetailsRequest{Id: patientId}) + getPatientDetailsRes, err = patientClient.GetPatientDetails(ctx, &pb.GetPatientDetailsRequest{Id: patientID}) require.NoError(t, err, "could not get after re-admit") assert.False(t, getPatientDetailsRes.IsDischarged) @@ -116,12 +116,12 @@ func TestCreateUpdateGetPatient(t *testing.T) { // wardID, _ := prepareWard(t, ctx, "") - roomId, _ := prepareRoom(t, ctx, wardID, "") - bedId, _ := prepareBed(t, ctx, roomId, "") + roomID, _ := prepareRoom(t, ctx, wardID, "") + bedID, _ := prepareBed(t, ctx, roomID, "") assignRes, err := patientClient.AssignBed(ctx, &pb.AssignBedRequest{ - Id: patientId, - BedId: bedId, + Id: patientID, + BedId: bedID, Consistency: &getPatientRes.Consistency, }) require.NoError(t, err) @@ -131,16 +131,16 @@ func TestCreateUpdateGetPatient(t *testing.T) { // get assigned patient // - getPatientRes, err = patientClient.GetPatient(ctx, &pb.GetPatientRequest{Id: patientId}) + getPatientRes, err = patientClient.GetPatient(ctx, &pb.GetPatientRequest{Id: patientID}) require.NoError(t, err, "could not get after bed assignment") zlog.Debug().Interface("patient", getPatientRes).Msg("patient") assert.NotNil(t, getPatientRes.Bed) - assert.Equal(t, bedId, getPatientRes.Bed.Id) + assert.Equal(t, bedID, getPatientRes.Bed.Id) assert.NotNil(t, getPatientRes.Room) - assert.Equal(t, roomId, getPatientRes.Room.Id) + assert.Equal(t, roomID, getPatientRes.Room.Id) assert.Equal(t, wardID, getPatientRes.Room.WardId) assert.Equal(t, assignRes.Consistency, getPatientRes.Consistency) @@ -150,7 +150,7 @@ func TestCreateUpdateGetPatient(t *testing.T) { // unassignRes, err := patientClient.UnassignBed(ctx, &pb.UnassignBedRequest{ - Id: patientId, + Id: patientID, Consistency: &getPatientRes.Consistency, }) require.NoError(t, err) @@ -160,7 +160,7 @@ func TestCreateUpdateGetPatient(t *testing.T) { // get unassigned patient // - getPatientRes, err = patientClient.GetPatient(ctx, &pb.GetPatientRequest{Id: patientId}) + getPatientRes, err = patientClient.GetPatient(ctx, &pb.GetPatientRequest{Id: patientID}) require.NoError(t, err, "could not get after bed assignment") zlog.Debug().Interface("patient", getPatientRes).Msg("patient") @@ -181,8 +181,8 @@ func TestGetPatientByBed(t *testing.T) { // wardID, _ := prepareWard(t, ctx, "") - roomId, _ := prepareRoom(t, ctx, wardID, "") - bedId, _ := prepareBed(t, ctx, roomId, "") + roomID, _ := prepareRoom(t, ctx, wardID, "") + bedID, _ := prepareBed(t, ctx, roomID, "") createReq := &pb.CreatePatientRequest{ HumanReadableIdentifier: t.Name() + " patient", @@ -191,11 +191,11 @@ func TestGetPatientByBed(t *testing.T) { createRes, err := patientClient.CreatePatient(ctx, createReq) require.NoError(t, err, "could not create patient") - patientId := createRes.GetId() + patientID := createRes.GetId() assRes, err := patientClient.AssignBed(ctx, &pb.AssignBedRequest{ - Id: patientId, - BedId: bedId, + Id: patientID, + BedId: bedID, Consistency: &createRes.Consistency, }) require.NoError(t, err) @@ -205,12 +205,12 @@ func TestGetPatientByBed(t *testing.T) { // getRes, err := patientClient.GetPatientByBed(ctx, &pb.GetPatientByBedRequest{ - BedId: bedId, + BedId: bedID, }) require.NoError(t, err) assert.Equal(t, createRes.Id, getRes.Id) - assert.Equal(t, bedId, getRes.BedId) + assert.Equal(t, bedID, getRes.BedId) assert.Equal(t, createReq.GetHumanReadableIdentifier(), getRes.GetHumanReadableIdentifier()) assert.Equal(t, createReq.GetNotes(), getRes.GetNotes()) assert.Equal(t, assRes.GetConsistency(), getRes.GetConsistency()) @@ -226,9 +226,9 @@ func TestGetPatientsByWard(t *testing.T) { // wardID, _ := prepareWard(t, ctx, "") - roomId, _ := prepareRoom(t, ctx, wardID, "") - bedId1, _ := prepareBed(t, ctx, roomId, "1") - bedId2, _ := prepareBed(t, ctx, roomId, "2") + roomID, _ := prepareRoom(t, ctx, wardID, "") + bedID1, _ := prepareBed(t, ctx, roomID, "1") + bedID2, _ := prepareBed(t, ctx, roomID, "2") createReq1 := &pb.CreatePatientRequest{ HumanReadableIdentifier: t.Name() + " patient 1", @@ -237,12 +237,12 @@ func TestGetPatientsByWard(t *testing.T) { createRes1, err := patientClient.CreatePatient(ctx, createReq1) require.NoError(t, err, "could not create patient") - patientId1 := createRes1.GetId() + patientID1 := createRes1.GetId() hwtesting.WaitForProjectionsToSettle() assRes1, err := patientClient.AssignBed(ctx, &pb.AssignBedRequest{ - Id: patientId1, - BedId: bedId1, + Id: patientID1, + BedId: bedID1, Consistency: &createRes1.Consistency, }) require.NoError(t, err) @@ -257,11 +257,11 @@ func TestGetPatientsByWard(t *testing.T) { hwtesting.WaitForProjectionsToSettle() - patientId2 := createRes2.GetId() + patientID2 := createRes2.GetId() assRes2, err := patientClient.AssignBed(ctx, &pb.AssignBedRequest{ - Id: patientId2, - BedId: bedId2, + Id: patientID2, + BedId: bedID2, Consistency: &createRes2.Consistency, }) require.NoError(t, err) @@ -286,13 +286,13 @@ func TestGetPatientsByWard(t *testing.T) { } assert.Equal(t, createRes1.Id, patient1.Id) - assert.Equal(t, &bedId1, patient1.BedId) + assert.Equal(t, &bedID1, patient1.BedId) assert.Equal(t, createReq1.HumanReadableIdentifier, patient1.HumanReadableIdentifier) assert.Equal(t, *createReq1.Notes, patient1.Notes) assert.Equal(t, assRes1.Consistency, patient1.Consistency) assert.Equal(t, createRes2.Id, patient2.Id) - assert.Equal(t, &bedId2, patient2.BedId) + assert.Equal(t, &bedID2, patient2.BedId) assert.Equal(t, createReq2.HumanReadableIdentifier, patient2.HumanReadableIdentifier) assert.Equal(t, *createReq2.Notes, patient2.Notes) assert.Equal(t, assRes2.Consistency, patient2.Consistency) @@ -321,24 +321,24 @@ func TestGetPatientAssignmentByWard(t *testing.T) { for i, bedSfxs := range suffixMatrix { roomSuffix := strconv.Itoa(i + 1) - roomId, roomConsistency := prepareRoom(t, ctx, wardID, roomSuffix) - roomIds = append(roomIds, roomId) - roomConsistencies[roomId] = roomConsistency - bedsForRoom[roomId] = make([]string, 0) + roomID, roomConsistency := prepareRoom(t, ctx, wardID, roomSuffix) + roomIds = append(roomIds, roomID) + roomConsistencies[roomID] = roomConsistency + bedsForRoom[roomID] = make([]string, 0) for _, bedSuffix := range bedSfxs { - bedId, bedConsistency := prepareBed(t, ctx, roomId, bedSuffix) - bedConsistencies[bedId] = bedConsistency - bedsForRoom[roomId] = append(bedsForRoom[roomId], bedId) + bedID, bedConsistency := prepareBed(t, ctx, roomID, bedSuffix) + bedConsistencies[bedID] = bedConsistency + bedsForRoom[roomID] = append(bedsForRoom[roomID], bedID) - patientId := preparePatient(t, ctx, bedSuffix) + patientID := preparePatient(t, ctx, bedSuffix) res, err := patientClient.AssignBed(ctx, &pb.AssignBedRequest{ - Id: patientId, - BedId: bedId, + Id: patientID, + BedId: bedID, }) require.NoError(t, err) - patientConsistencies[patientId] = res.Consistency - patientForBed[bedId] = patientId + patientConsistencies[patientID] = res.Consistency + patientForBed[bedID] = patientID } } @@ -545,8 +545,8 @@ func TestGetPatientDetails(t *testing.T) { // wardID, _ := prepareWard(t, ctx, "") - roomId, _ := prepareRoom(t, ctx, wardID, "") - bedId, _ := prepareBed(t, ctx, roomId, "") + roomID, _ := prepareRoom(t, ctx, wardID, "") + bedID, _ := prepareBed(t, ctx, roomID, "") createReq := &pb.CreatePatientRequest{ HumanReadableIdentifier: t.Name() + " patient", @@ -557,11 +557,11 @@ func TestGetPatientDetails(t *testing.T) { hwtesting.WaitForProjectionsToSettle() - patientId := createRes.GetId() + patientID := createRes.GetId() assRes, err := patientClient.AssignBed(ctx, &pb.AssignBedRequest{ - Id: patientId, - BedId: bedId, + Id: patientID, + BedId: bedID, Consistency: &createRes.Consistency, }) require.NoError(t, err) @@ -591,7 +591,7 @@ func TestGetPatientDetails(t *testing.T) { taskRes, err := taskClient.CreateTask(ctx, &pb.CreateTaskRequest{ Name: t.Name() + " task " + taskSuffix, Description: nil, - PatientId: patientId, + PatientId: patientID, Public: hwutil.PtrTo(true), DueAt: nil, // behold: peak enginering: @@ -612,7 +612,7 @@ func TestGetPatientDetails(t *testing.T) { // getRes, err := patientClient.GetPatientDetails(ctx, &pb.GetPatientDetailsRequest{ - Id: patientId, + Id: patientID, }) require.NoError(t, err) @@ -634,8 +634,8 @@ func TestGetPatientDetails(t *testing.T) { return tsk.Id })) - assert.Equal(t, roomId, getRes.GetRoom().GetId()) - assert.Equal(t, bedId, getRes.GetBed().GetId()) + assert.Equal(t, roomID, getRes.GetRoom().GetId()) + assert.Equal(t, bedID, getRes.GetBed().GetId()) assert.False(t, getRes.GetIsDischarged()) assert.Equal(t, assRes.GetConsistency(), getRes.GetConsistency()) } @@ -655,9 +655,9 @@ func TestGetRecentPatients(t *testing.T) { patientClient := pb.NewPatientServiceClient(hwtesting.GetGrpcConn(userID.String())) wardID, _ := prepareWard(t, ctx, "") - roomId, roomConsistency := prepareRoom(t, ctx, wardID, "") - bedId, bedConsitency := prepareBed(t, ctx, roomId, "") - patientWithBedId := "" + roomID, roomConsistency := prepareRoom(t, ctx, wardID, "") + bedID, bedConsitency := prepareBed(t, ctx, roomID, "") + patientWithBedID := "" N := 11 // cap is ten @@ -677,11 +677,11 @@ func TestGetRecentPatients(t *testing.T) { if i == N { assRes, err := patientClient.AssignBed(ctx, &pb.AssignBedRequest{ Id: patientRes.Id, - BedId: bedId, + BedId: bedID, Consistency: &patientRes.Consistency, }) require.NoError(t, err) - patientWithBedId = patientRes.Id + patientWithBedID = patientRes.Id consistencies[patientRes.Id] = assRes.Consistency } @@ -698,10 +698,10 @@ func TestGetRecentPatients(t *testing.T) { assert.Len(t, recent.RecentPatients, 10) foundIds := hwutil.Map(recent.RecentPatients, func(p *pb.GetRecentPatientsResponse_Patient) string { id := p.Id - if id == patientWithBedId { - assert.Equal(t, bedId, p.Bed.Id) + if id == patientWithBedID { + assert.Equal(t, bedID, p.Bed.Id) assert.Equal(t, bedConsitency, p.Bed.Consistency) - assert.Equal(t, roomId, p.Room.Id) + assert.Equal(t, roomID, p.Room.Id) assert.Equal(t, roomConsistency, p.Room.Consistency) } assert.Equal(t, consistencies[p.Id], p.Consistency) diff --git a/services/tasks-svc/stories/RoomCRUD_test.go b/services/tasks-svc/stories/RoomCRUD_test.go index cd9721cdd..04a20ca9e 100644 --- a/services/tasks-svc/stories/RoomCRUD_test.go +++ b/services/tasks-svc/stories/RoomCRUD_test.go @@ -93,10 +93,10 @@ func TestGetRooms(t *testing.T) { wardID, _ := prepareWard(t, ctx, wardSuffix) wardRoomsMap[wardID] = make([]string, 0) for _, bedSuffix := range roomSfxs { - roomId, roomConsistency := prepareRoom(t, ctx, wardID, bedSuffix) - roomWardMap[roomId] = wardID - roomConsistencyMap[roomId] = roomConsistency - wardRoomsMap[wardID] = append(wardRoomsMap[wardID], roomId) + roomID, roomConsistency := prepareRoom(t, ctx, wardID, bedSuffix) + roomWardMap[roomID] = wardID + roomConsistencyMap[roomID] = roomConsistency + wardRoomsMap[wardID] = append(wardRoomsMap[wardID], roomID) } } diff --git a/services/tasks-svc/stories/TaskCRUD_test.go b/services/tasks-svc/stories/TaskCRUD_test.go index 02508b62c..a5b647284 100644 --- a/services/tasks-svc/stories/TaskCRUD_test.go +++ b/services/tasks-svc/stories/TaskCRUD_test.go @@ -23,7 +23,7 @@ func TestCreateUpdateGetTask(t *testing.T) { taskClient := taskServiceClient() // prepare patient - patientId := preparePatient(t, ctx, "") + patientID := preparePatient(t, ctx, "") dueDate := time.Now().Add(time.Hour).UTC() @@ -37,7 +37,7 @@ func TestCreateUpdateGetTask(t *testing.T) { createReq := &pb.CreateTaskRequest{ Name: t.Name() + " task", Description: hwutil.PtrTo("Some Description"), - PatientId: patientId, + PatientId: patientID, Public: hwutil.PtrTo(true), DueAt: timestamppb.New(dueDate), InitialStatus: nil, @@ -51,13 +51,13 @@ func TestCreateUpdateGetTask(t *testing.T) { require.NoError(t, err, "could not create") - taskId := createRes.GetId() + taskID := createRes.GetId() hwtesting.WaitForProjectionsToSettle() // get new task - task, err := taskClient.GetTask(ctx, &pb.GetTaskRequest{Id: taskId}) + task, err := taskClient.GetTask(ctx, &pb.GetTaskRequest{Id: taskID}) require.NoError(t, err) assert.Equal(t, createReq.GetName(), task.GetName()) @@ -69,7 +69,7 @@ func TestCreateUpdateGetTask(t *testing.T) { assert.WithinDuration(t, dueDate, task.GetDueAt().AsTime(), time.Second) // actually we differ by some microseconds assert.Equal(t, "", task.GetAssignedUserId()) - assert.Equal(t, patientId, task.GetPatient().GetId()) + assert.Equal(t, patientID, task.GetPatient().GetId()) assert.Len(t, task.GetSubtasks(), 2) found := 0 @@ -94,7 +94,7 @@ func TestCreateUpdateGetTask(t *testing.T) { // updateReq := &pb.UpdateTaskRequest{ - Id: taskId, + Id: taskID, Name: hwutil.PtrTo("New Name"), Description: nil, DueAt: nil, @@ -111,7 +111,7 @@ func TestCreateUpdateGetTask(t *testing.T) { // get updated task - task, err = taskClient.GetTask(ctx, &pb.GetTaskRequest{Id: taskId}) + task, err = taskClient.GetTask(ctx, &pb.GetTaskRequest{Id: taskID}) require.NoError(t, err) assert.Equal(t, updateReq.GetName(), task.GetName()) @@ -123,7 +123,7 @@ func TestCreateUpdateGetTask(t *testing.T) { // createStRes, err := taskClient.CreateSubtask(ctx, &pb.CreateSubtaskRequest{ - TaskId: taskId, + TaskId: taskID, Subtask: &pb.CreateSubtaskRequest_Subtask{ Name: "ST 3", }, @@ -135,7 +135,7 @@ func TestCreateUpdateGetTask(t *testing.T) { // get updated task - task, err = taskClient.GetTask(ctx, &pb.GetTaskRequest{Id: taskId}) + task, err = taskClient.GetTask(ctx, &pb.GetTaskRequest{Id: taskID}) require.NoError(t, err) assert.Len(t, task.GetSubtasks(), 3) @@ -157,7 +157,7 @@ func TestCreateUpdateGetTask(t *testing.T) { // update subtask updateStRes, err := taskClient.UpdateSubtask(ctx, &pb.UpdateSubtaskRequest{ - TaskId: taskId, + TaskId: taskID, SubtaskId: createStRes.GetSubtaskId(), Subtask: &pb.UpdateSubtaskRequest_Subtask{ Done: hwutil.PtrTo(true), @@ -170,7 +170,7 @@ func TestCreateUpdateGetTask(t *testing.T) { // get updated task - task, err = taskClient.GetTask(ctx, &pb.GetTaskRequest{Id: taskId}) + task, err = taskClient.GetTask(ctx, &pb.GetTaskRequest{Id: taskID}) require.NoError(t, err) assert.Contains(t, hwutil.Map(task.Subtasks, func(st *pb.GetTaskResponse_SubTask) string { @@ -188,7 +188,7 @@ func TestCreateUpdateGetTask(t *testing.T) { assignedUser := uuid.New() assignRes, err := taskClient.AssignTask(ctx, &pb.AssignTaskRequest{ - TaskId: taskId, + TaskId: taskID, UserId: assignedUser.String(), Consistency: &task.Consistency, }) @@ -199,7 +199,7 @@ func TestCreateUpdateGetTask(t *testing.T) { // get updated task - task, err = taskClient.GetTask(ctx, &pb.GetTaskRequest{Id: taskId}) + task, err = taskClient.GetTask(ctx, &pb.GetTaskRequest{Id: taskID}) require.NoError(t, err) assert.Equal(t, assignedUser.String(), task.GetAssignedUserId()) @@ -210,7 +210,7 @@ func TestCreateUpdateGetTask(t *testing.T) { // unassignRes, err := taskClient.UnassignTask(ctx, &pb.UnassignTaskRequest{ - TaskId: taskId, + TaskId: taskID, UserId: assignedUser.String(), Consistency: &task.Consistency, }) @@ -221,7 +221,7 @@ func TestCreateUpdateGetTask(t *testing.T) { // get updated task - task, err = taskClient.GetTask(ctx, &pb.GetTaskRequest{Id: taskId}) + task, err = taskClient.GetTask(ctx, &pb.GetTaskRequest{Id: taskID}) require.NoError(t, err) assert.Equal(t, "", task.GetAssignedUserId()) @@ -232,7 +232,7 @@ func TestCreateUpdateGetTask(t *testing.T) { // rmDueRes, err := taskClient.RemoveTaskDueDate(ctx, &pb.RemoveTaskDueDateRequest{ - TaskId: taskId, + TaskId: taskID, }) require.NoError(t, err) @@ -241,7 +241,7 @@ func TestCreateUpdateGetTask(t *testing.T) { // get updated task - task, err = taskClient.GetTask(ctx, &pb.GetTaskRequest{Id: taskId}) + task, err = taskClient.GetTask(ctx, &pb.GetTaskRequest{Id: taskID}) require.NoError(t, err) assert.Nil(t, task.GetDueAt()) @@ -252,7 +252,7 @@ func TestGetTasksByPatient(t *testing.T) { taskClient := taskServiceClient() ctx := context.Background() - patientId := preparePatient(t, ctx, "") + patientID := preparePatient(t, ctx, "") suffixMap := [][]string{ {"1 A", "1 B", "1 C"}, // Task 1 @@ -276,7 +276,7 @@ func TestGetTasksByPatient(t *testing.T) { taskRes, err := taskClient.CreateTask(ctx, &pb.CreateTaskRequest{ Name: t.Name() + " task " + taskSuffix, Description: nil, - PatientId: patientId, + PatientId: patientID, Public: hwutil.PtrTo(true), DueAt: nil, // behold: peak enginering: @@ -292,7 +292,7 @@ func TestGetTasksByPatient(t *testing.T) { hwtesting.WaitForProjectionsToSettle() - res, err := taskClient.GetTasksByPatient(ctx, &pb.GetTasksByPatientRequest{PatientId: patientId}) + res, err := taskClient.GetTasksByPatient(ctx, &pb.GetTasksByPatientRequest{PatientId: patientID}) require.NoError(t, err) assert.Len(t, res.Tasks, len(suffixMap)) @@ -313,7 +313,7 @@ func TestGetTasksByPatient(t *testing.T) { // GetTasksByPatientSortedByStatus resByStatus, err := taskClient.GetTasksByPatientSortedByStatus(ctx, &pb.GetTasksByPatientSortedByStatusRequest{ - PatientId: patientId, + PatientId: patientID, }) require.NoError(t, err) @@ -337,7 +337,7 @@ func TestGetAssignedTasks(t *testing.T) { taskClient := taskServiceClient() ctx := context.Background() - patientId := preparePatient(t, ctx, "") + patientID := preparePatient(t, ctx, "") suffixMap := [][]string{ {"1 A", "1 B", "1 C"}, // Task 1 @@ -370,7 +370,7 @@ func TestGetAssignedTasks(t *testing.T) { taskRes, err := taskClient.CreateTask(ctx, &pb.CreateTaskRequest{ Name: t.Name() + " task " + taskSuffix, Description: nil, - PatientId: patientId, + PatientId: patientID, Public: hwutil.PtrTo(true), DueAt: nil, // behold: peak enginering: diff --git a/services/tasks-svc/stories/TaskTemplateCRUD_test.go b/services/tasks-svc/stories/TaskTemplateCRUD_test.go index 083e27138..208951859 100644 --- a/services/tasks-svc/stories/TaskTemplateCRUD_test.go +++ b/services/tasks-svc/stories/TaskTemplateCRUD_test.go @@ -36,14 +36,14 @@ func TestCreateUpdateGetTaskTemplate(t *testing.T) { wardRes, err := wardServiceClient.CreateWard(ctx, createWardReq) require.NoError(t, err, "could not create ward") - // wardId will be used for scoping - wardId := wardRes.GetId() + // wardID will be used for scoping + wardID := wardRes.GetId() // // create new template // createReq := &pb.CreateTaskTemplateRequest{ - WardId: &wardId, + WardId: &wardID, Description: hwutil.PtrTo("Some Description"), Subtasks: make([]*pb.CreateTaskTemplateRequest_SubTask, 0), Name: t.Name() + " tt", @@ -52,7 +52,7 @@ func TestCreateUpdateGetTaskTemplate(t *testing.T) { require.NoError(t, err, "could not create task template") - templateId := createRes.GetId() + templateID := createRes.GetId() hwtesting.WaitForProjectionsToSettle() @@ -60,7 +60,7 @@ func TestCreateUpdateGetTaskTemplate(t *testing.T) { // get new template // - template := getTaskTemplate(t, ctx, templateId) + template := getTaskTemplate(t, ctx, templateID) assert.Equal(t, createReq.Name, template.Name) assert.Equal(t, *createReq.Description, template.Description) @@ -73,7 +73,7 @@ func TestCreateUpdateGetTaskTemplate(t *testing.T) { // updateReq := &pb.UpdateTaskTemplateRequest{ - Id: templateId, + Id: templateID, Name: hwutil.PtrTo("New Name"), Description: nil, Consistency: &createRes.Consistency, @@ -89,7 +89,7 @@ func TestCreateUpdateGetTaskTemplate(t *testing.T) { // get updated template // - template = getTaskTemplate(t, ctx, templateId) + template = getTaskTemplate(t, ctx, templateID) assert.Equal(t, *updateReq.Name, template.Name) assert.Equal(t, updateRes.Consistency, template.Consistency) @@ -99,7 +99,7 @@ func TestCreateUpdateGetTaskTemplate(t *testing.T) { // createStRes, err := taskTemplateClient.CreateTaskTemplateSubTask(ctx, &pb.CreateTaskTemplateSubTaskRequest{ - TaskTemplateId: templateId, + TaskTemplateId: templateID, Name: t.Name() + " ST 1", }) require.NoError(t, err) @@ -109,7 +109,7 @@ func TestCreateUpdateGetTaskTemplate(t *testing.T) { // get updated template // - template = getTaskTemplate(t, ctx, templateId) + template = getTaskTemplate(t, ctx, templateID) assert.Len(t, template.Subtasks, 1) assert.Equal(t, createStRes.Id, template.Subtasks[0].Id) @@ -130,7 +130,7 @@ func TestCreateUpdateGetTaskTemplate(t *testing.T) { // get updated template // - template = getTaskTemplate(t, ctx, templateId) + template = getTaskTemplate(t, ctx, templateID) assert.Len(t, template.Subtasks, 1) assert.Equal(t, createStRes.Id, template.Subtasks[0].Id) @@ -141,7 +141,7 @@ func TestCreateUpdateGetTaskTemplate(t *testing.T) { // create another template // createReq = &pb.CreateTaskTemplateRequest{ - WardId: &wardId, + WardId: &wardID, Description: hwutil.PtrTo("Some Description"), Subtasks: make([]*pb.CreateTaskTemplateRequest_SubTask, 0), Name: t.Name() + " tt", @@ -155,7 +155,7 @@ func TestCreateUpdateGetTaskTemplate(t *testing.T) { // templates, err := taskTemplateClient.GetAllTaskTemplates(ctx, &pb.GetAllTaskTemplatesRequest{ - WardId: &wardId, + WardId: &wardID, }) require.NoError(t, err) diff --git a/services/tasks-svc/stories/WardCRUD_test.go b/services/tasks-svc/stories/WardCRUD_test.go index 971e2f2ce..380b4c4ab 100644 --- a/services/tasks-svc/stories/WardCRUD_test.go +++ b/services/tasks-svc/stories/WardCRUD_test.go @@ -121,13 +121,13 @@ func TestGetRecentWards(t *testing.T) { } for i, bedSfxs := range suffixMatrix { roomSuffix := strconv.Itoa(i + 1) - roomId, _ := prepareRoom(t, ctx, taskCountWardID, roomSuffix) + roomID, _ := prepareRoom(t, ctx, taskCountWardID, roomSuffix) for j, bedSuffix := range bedSfxs { - bedId, _ := prepareBed(t, ctx, roomId, bedSuffix) + bedID, _ := prepareBed(t, ctx, roomID, bedSuffix) patientID := preparePatient(t, ctx, bedSuffix) _, err := patientClient.AssignBed(ctx, &pb.AssignBedRequest{ Id: patientID, - BedId: bedId, + BedId: bedID, }) require.NoError(t, err, "could not assign bed to patient") _, err = taskClient.CreateTask(ctx, &pb.CreateTaskRequest{ @@ -229,13 +229,13 @@ func TestGetWardOverviews(t *testing.T) { for i, bedSfxs := range suffixMatrix { roomSuffix := strconv.Itoa(i + 1) - roomId, _ := prepareRoom(t, ctx, wardID, roomSuffix) + roomID, _ := prepareRoom(t, ctx, wardID, roomSuffix) for j, bedSuffix := range bedSfxs { - bedId, _ := prepareBed(t, ctx, roomId, bedSuffix) + bedID, _ := prepareBed(t, ctx, roomID, bedSuffix) patientID := preparePatient(t, ctx, bedSuffix) _, err := patientClient.AssignBed(ctx, &pb.AssignBedRequest{ Id: patientID, - BedId: bedId, + BedId: bedID, }) require.NoError(t, err, "could not assign bed to patient") _, err = taskClient.CreateTask(ctx, &pb.CreateTaskRequest{ @@ -336,17 +336,17 @@ func TestGetWardDetails(t *testing.T) { rooms := make([]map[string]interface{}, 0) for i, bedSfxs := range suffixMatrix { roomSuffix := strconv.Itoa(i + 1) - roomId, roomConsistency := prepareRoom(t, ctx, wardID, roomSuffix) + roomID, roomConsistency := prepareRoom(t, ctx, wardID, roomSuffix) expectedRoom := map[string]interface{}{ - "id": roomId, + "id": roomID, "name": t.Name() + " room " + roomSuffix, "consistency": roomConsistency, } beds := make([]map[string]interface{}, 0) for _, bedSuffix := range bedSfxs { - bedId, bedConsistency := prepareBed(t, ctx, roomId, bedSuffix) + bedID, bedConsistency := prepareBed(t, ctx, roomID, bedSuffix) beds = append(beds, map[string]interface{}{ - "id": bedId, + "id": bedID, "name": t.Name() + " bed " + bedSuffix, "consistency": bedConsistency, }) diff --git a/services/tasks-svc/stories/setup_test.go b/services/tasks-svc/stories/setup_test.go index b9c2a570e..639a86cb5 100644 --- a/services/tasks-svc/stories/setup_test.go +++ b/services/tasks-svc/stories/setup_test.go @@ -115,11 +115,11 @@ func prepareRoom(t *testing.T, ctx context.Context, wardID, suffix string) (room return roomRes.Id, roomRes.Consistency } -func prepareBed(t *testing.T, ctx context.Context, roomId, suffix string) (bedID, consistency string) { +func prepareBed(t *testing.T, ctx context.Context, roomID, suffix string) (bedID, consistency string) { t.Helper() createRes, err := bedServiceClient().CreateBed(ctx, &pb.CreateBedRequest{ - RoomId: roomId, + RoomId: roomID, Name: t.Name() + " bed " + suffix, }) require.NoError(t, err, "prepareBed: could not create bed", suffix) diff --git a/services/user-svc/internal/hwkc/client.go b/services/user-svc/internal/hwkc/client.go index dabc62216..ff2c49f5c 100644 --- a/services/user-svc/internal/hwkc/client.go +++ b/services/user-svc/internal/hwkc/client.go @@ -17,8 +17,8 @@ import ( ) type IClient interface { - GetUserById(ctx context.Context, userID uuid.UUID) (*User, error) - GetOrganizationsOfUserById(ctx context.Context, userID uuid.UUID) ([]*Organization, error) + GetUserByID(ctx context.Context, userID uuid.UUID) (*User, error) + GetOrganizationsOfUserByID(ctx context.Context, userID uuid.UUID) ([]*Organization, error) CreateOrganization(ctx context.Context, name, displayName string, isPersonal bool) (*Organization, error) UpdateOrganization(ctx context.Context, organizationID uuid.UUID, organization Organization) error DeleteOrganization(ctx context.Context, organizationID uuid.UUID) error @@ -27,8 +27,8 @@ type IClient interface { } type Client struct { - adminApiBaseUrl *url.URL - realmBaseUrl *url.URL + adminAPIBaseURL *url.URL + realmBaseURL *url.URL http *http.Client } @@ -38,14 +38,14 @@ func NewClientFromEnv(ctx context.Context) (*Client, error) { return NewClient(ctx, realm, auth.GetOAuthIssuerURL(), auth.GetOAuthClientID(), clientSecret) } -func NewClient(ctx context.Context, realm, issuerUrl, clientId, clientSecret string) (*Client, error) { - provider, err := oidc.NewProvider(context.Background(), issuerUrl) +func NewClient(ctx context.Context, realm, issuerURL, clientID, clientSecret string) (*Client, error) { + provider, err := oidc.NewProvider(context.Background(), issuerURL) if err != nil { return nil, fmt.Errorf("cannot lookup oidc provider: %w", err) } config := clientcredentials.Config{ - ClientID: clientId, + ClientID: clientID, ClientSecret: clientSecret, TokenURL: provider.Endpoint().TokenURL, } @@ -54,28 +54,28 @@ func NewClient(ctx context.Context, realm, issuerUrl, clientId, clientSecret str return nil, fmt.Errorf("token exchange failed: %w", err) } - parsedIssuerUrl, err := url.Parse(issuerUrl) + parsedIssuerURL, err := url.Parse(issuerURL) if err != nil { - return nil, fmt.Errorf("cannot parse issuer url ('%s'): %w", issuerUrl, err) + return nil, fmt.Errorf("cannot parse issuer url ('%s'): %w", issuerURL, err) } - adminApiBaseUrl, err := url.Parse( - fmt.Sprintf("%s://%s/admin/realms/%s", parsedIssuerUrl.Scheme, parsedIssuerUrl.Host, realm)) + adminAPIBaseURL, err := url.Parse( + fmt.Sprintf("%s://%s/admin/realms/%s", parsedIssuerURL.Scheme, parsedIssuerURL.Host, realm)) if err != nil { return nil, fmt.Errorf( - "cannot parse newly created admin api base url from issuer url ('%s'): %w", issuerUrl, err) + "cannot parse newly created admin api base url from issuer url ('%s'): %w", issuerURL, err) } - realmBaseUrl, err := url.Parse( - fmt.Sprintf("%s://%s/realms/%s", parsedIssuerUrl.Scheme, parsedIssuerUrl.Host, realm)) + realmBaseURL, err := url.Parse( + fmt.Sprintf("%s://%s/realms/%s", parsedIssuerURL.Scheme, parsedIssuerURL.Host, realm)) if err != nil { return nil, fmt.Errorf( - "cannot parse newly created admin api base url from issuer url ('%s'): %w", issuerUrl, err) + "cannot parse newly created admin api base url from issuer url ('%s'): %w", issuerURL, err) } client := &Client{ - adminApiBaseUrl: adminApiBaseUrl, - realmBaseUrl: realmBaseUrl, + adminAPIBaseURL: adminAPIBaseURL, + realmBaseURL: realmBaseURL, http: config.Client(ctx), } @@ -92,9 +92,9 @@ func (c *Client) ensureSuccessfulResponse(res *http.Response) error { return BadResponseError{Res: res} } -func (c *Client) GetUserById(ctx context.Context, userID uuid.UUID) (*User, error) { +func (c *Client) GetUserByID(ctx context.Context, userID uuid.UUID) (*User, error) { // https://www.keycloak.org/docs-api/26.0.0/rest-api/index.html#_get_adminrealmsrealmusersuser_id - u := c.adminApiBaseUrl.JoinPath("users", userID.String()) + u := c.adminAPIBaseURL.JoinPath("users", userID.String()) req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil) if err != nil { @@ -119,9 +119,9 @@ func (c *Client) GetUserById(ctx context.Context, userID uuid.UUID) (*User, erro return user, nil } -func (c *Client) GetOrganizationsOfUserById(ctx context.Context, userID uuid.UUID) ([]*Organization, error) { +func (c *Client) GetOrganizationsOfUserByID(ctx context.Context, userID uuid.UUID) ([]*Organization, error) { // Users -> GET /{realm}/users/{userId}/orgs https://t.ly/cgwOO - u := c.realmBaseUrl.JoinPath("users", userID.String(), "orgs") + u := c.realmBaseURL.JoinPath("users", userID.String(), "orgs") req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil) if err != nil { @@ -153,7 +153,7 @@ func (c *Client) CreateOrganization( isPersonal bool, ) (*Organization, error) { // Organizations -> POST /{realm}/orgs https://t.ly/cgwOO - u := c.realmBaseUrl.JoinPath("orgs") + u := c.realmBaseURL.JoinPath("orgs") payload := Organization{ Name: hwutil.StrPtr(name), @@ -209,7 +209,7 @@ func (c *Client) CreateOrganization( func (c *Client) UpdateOrganization(ctx context.Context, organizationID uuid.UUID, organization Organization) error { // Organizations -> PUT /{realm}/orgs/{orgId} https://t.ly/cgwOO - u := c.realmBaseUrl.JoinPath("orgs", organizationID.String()) + u := c.realmBaseURL.JoinPath("orgs", organizationID.String()) jsonPayload, err := json.Marshal(organization) if err != nil { @@ -236,7 +236,7 @@ func (c *Client) UpdateOrganization(ctx context.Context, organizationID uuid.UUI func (c *Client) DeleteOrganization(ctx context.Context, organizationID uuid.UUID) error { // Organizations -> DELETE /{realm}/orgs/{orgId} https://t.ly/cgwOO - u := c.realmBaseUrl.JoinPath("orgs", organizationID.String()) + u := c.realmBaseURL.JoinPath("orgs", organizationID.String()) req, err := http.NewRequestWithContext(ctx, http.MethodDelete, u.String(), nil) if err != nil { @@ -258,7 +258,7 @@ func (c *Client) DeleteOrganization(ctx context.Context, organizationID uuid.UUI func (c *Client) AddUserToOrganization(ctx context.Context, userID, organizationID uuid.UUID) error { // Organization Memberships -> PUT /{realm}/orgs/{orgId}/members/{userId} https://t.ly/cgwOO - u := c.realmBaseUrl.JoinPath("orgs", organizationID.String(), "members", userID.String()) + u := c.realmBaseURL.JoinPath("orgs", organizationID.String(), "members", userID.String()) req, err := http.NewRequestWithContext(ctx, http.MethodPut, u.String(), nil) if err != nil { @@ -280,7 +280,7 @@ func (c *Client) AddUserToOrganization(ctx context.Context, userID, organization func (c *Client) RemoveUserFromOrganization(ctx context.Context, userID, organizationID uuid.UUID) error { // Organization Memberships -> DELETE /{realm}/orgs/{orgId}/members/{userId} https://t.ly/R0Suf - u := c.realmBaseUrl.JoinPath("orgs", organizationID.String(), "members", userID.String()) + u := c.realmBaseURL.JoinPath("orgs", organizationID.String(), "members", userID.String()) req, err := http.NewRequestWithContext(ctx, http.MethodDelete, u.String(), nil) if err != nil { diff --git a/services/user-svc/internal/hwkc/noop_client.go b/services/user-svc/internal/hwkc/noop_client.go index 6dff5701c..5e3bdb485 100644 --- a/services/user-svc/internal/hwkc/noop_client.go +++ b/services/user-svc/internal/hwkc/noop_client.go @@ -19,13 +19,13 @@ func NewNoOpClient() *NoOpClient { return &NoOpClient{} } -func (c *NoOpClient) GetUserById(_ context.Context, userID uuid.UUID) (*User, error) { +func (c *NoOpClient) GetUserByID(_ context.Context, userID uuid.UUID) (*User, error) { return &User{ ID: hwutil.PtrTo(userID.String()), }, nil } -func (c *NoOpClient) GetOrganizationsOfUserById(_ context.Context, userID uuid.UUID) ([]*Organization, error) { +func (c *NoOpClient) GetOrganizationsOfUserByID(_ context.Context, _ uuid.UUID) ([]*Organization, error) { return []*Organization{ { ID: hwutil.PtrTo(uuid.NewString()), diff --git a/services/user-svc/internal/organization/organization.go b/services/user-svc/internal/organization/organization.go index 28bbfa7c5..da0bcd905 100644 --- a/services/user-svc/internal/organization/organization.go +++ b/services/user-svc/internal/organization/organization.go @@ -132,7 +132,7 @@ func (s ServiceServer) GetOrganizationsByUser( ) (*pb.GetOrganizationsByUserResponse, error) { userID := uuid.MustParse(req.UserId) - organizations, err := GetOrganizationsByUserId(ctx, userID, s.authz) + organizations, err := GetOrganizationsByUserID(ctx, userID, s.authz) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } @@ -168,12 +168,12 @@ type OrganizationWithMembers struct { Members []organization_repo.User } -func GetOrganizationsByUserId( - ctx context.Context, userId uuid.UUID, authz hwauthz.AuthZ, +func GetOrganizationsByUserID( + ctx context.Context, userID uuid.UUID, authz hwauthz.AuthZ, ) ([]OrganizationWithMembers, error) { organizationRepo := organization_repo.New(hwdb.GetDB()) - rows, err := organizationRepo.GetOrganizationsWithMembersByUser(ctx, userId) + rows, err := organizationRepo.GetOrganizationsWithMembersByUser(ctx, userID) err = hwdb.Error(ctx, err) if err != nil { return nil, err @@ -238,7 +238,7 @@ func (s ServiceServer) GetOrganizationsForUser( ) (*pb.GetOrganizationsForUserResponse, error) { userID := auth.MustGetUserID(ctx) - organizations, err := GetOrganizationsByUserId(ctx, userID, s.authz) + organizations, err := GetOrganizationsByUserID(ctx, userID, s.authz) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } @@ -410,14 +410,14 @@ func (s ServiceServer) InviteMember( return nil, err } - organizationId, err := uuid.Parse(req.OrganizationId) + organizationID, err := uuid.Parse(req.OrganizationId) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } // sanity checks conditions, err := organizationRepo.GetInvitationConditions(ctx, organization_repo.GetInvitationConditionsParams{ - OrganizationID: organizationId, + OrganizationID: organizationID, Email: req.Email, States: []int32{ int32(pb.InvitationState_INVITATION_STATE_ACCEPTED.Number()), @@ -442,7 +442,7 @@ func (s ServiceServer) InviteMember( // do invite invitation, err := organizationRepo.InviteMember(ctx, organization_repo.InviteMemberParams{ Email: req.Email, - OrganizationID: organizationId, + OrganizationID: organizationID, State: int32(pb.InvitationState_INVITATION_STATE_PENDING.Number()), }) err = hwdb.Error(ctx, err) @@ -458,7 +458,7 @@ func (s ServiceServer) InviteMember( if invitation.UserID.Valid { subj = commonperm.User(invitation.UserID.UUID) } - org := commonperm.Organization(organizationId) + org := commonperm.Organization(organizationID) resc := perm.Invite(invitation.InvitationID) if _, err := s.authz. Create(hwauthz.NewRelationship(subj, perm.InviteInvitee, resc)). @@ -468,7 +468,7 @@ func (s ServiceServer) InviteMember( log.Info(). Str("email", req.Email). // TODO: privacy issues? - Str("organizationID", organizationId.String()). + Str("organizationID", organizationID.String()). Msg("user invited to organization") return &pb.InviteMemberResponse{ @@ -655,7 +655,7 @@ func (s ServiceServer) AcceptInvitation( ) (*pb.AcceptInvitationResponse, error) { organizationRepo := organization_repo.New(hwdb.GetDB()) - invitationId, err := uuid.Parse(req.InvitationId) + invitationID, err := uuid.Parse(req.InvitationId) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } @@ -668,7 +668,7 @@ func (s ServiceServer) AcceptInvitation( // check permissions user := commonperm.UserFromCtx(ctx) email := perm.Email(claims.Email) - invite := perm.Invite(invitationId) + invite := perm.Invite(invitationID) checks := []hwauthz.PermissionCheck{ hwauthz.NewPermissionCheck(user, perm.InviteCanUserAccept, invite), // either the user as access @@ -684,7 +684,7 @@ func (s ServiceServer) AcceptInvitation( // Check if invite exists rows, err := organizationRepo.GetInvitations(ctx, organization_repo.GetInvitationsParams{ - ID: uuid.NullUUID{UUID: invitationId, Valid: true}, + ID: uuid.NullUUID{UUID: invitationID, Valid: true}, Email: &claims.Email, }) err = hwdb.Error(ctx, err) @@ -703,7 +703,7 @@ func (s ServiceServer) AcceptInvitation( // Update Invitation State err = organizationRepo.UpdateInvitationState(ctx, organization_repo.UpdateInvitationStateParams{ - ID: invitationId, + ID: invitationID, State: int32(pb.InvitationState_INVITATION_STATE_ACCEPTED.Number()), }) err = hwdb.Error(ctx, err) @@ -734,7 +734,7 @@ func (s ServiceServer) DeclineInvitation( ) (*pb.DeclineInvitationResponse, error) { organizationRepo := organization_repo.New(hwdb.GetDB()) - invitationId, err := uuid.Parse(req.InvitationId) + invitationID, err := uuid.Parse(req.InvitationId) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } @@ -747,7 +747,7 @@ func (s ServiceServer) DeclineInvitation( // check permissions user := commonperm.UserFromCtx(ctx) email := perm.Email(claims.Email) - invite := perm.Invite(invitationId) + invite := perm.Invite(invitationID) checks := []hwauthz.PermissionCheck{ hwauthz.NewPermissionCheck(user, perm.InviteCanUserDeny, invite), // either the user as access @@ -763,7 +763,7 @@ func (s ServiceServer) DeclineInvitation( // Check if invite exists rows, err := organizationRepo.GetInvitations(ctx, organization_repo.GetInvitationsParams{ - ID: uuid.NullUUID{UUID: invitationId, Valid: true}, + ID: uuid.NullUUID{UUID: invitationID, Valid: true}, Email: &claims.Email, }) err = hwdb.Error(ctx, err) @@ -782,7 +782,7 @@ func (s ServiceServer) DeclineInvitation( // Update invitation state err = organizationRepo.UpdateInvitationState(ctx, organization_repo.UpdateInvitationStateParams{ - ID: invitationId, + ID: invitationID, State: int32(pb.InvitationState_INVITATION_STATE_REJECTED.Number()), }) err = hwdb.Error(ctx, err) @@ -801,14 +801,14 @@ func (s ServiceServer) RevokeInvitation( log := zlog.Ctx(ctx) - invitationId, err := uuid.Parse(req.InvitationId) + invitationID, err := uuid.Parse(req.InvitationId) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } // check permissions user := commonperm.UserFromCtx(ctx) - invite := perm.Invite(invitationId) + invite := perm.Invite(invitationID) check := hwauthz.NewPermissionCheck(user, perm.InviteCanUserCancel, invite) if err := s.authz.Must(ctx, check); err != nil { @@ -816,7 +816,7 @@ func (s ServiceServer) RevokeInvitation( } rows, err := organizationRepo.GetInvitations(ctx, organization_repo.GetInvitationsParams{ - ID: uuid.NullUUID{UUID: invitationId, Valid: true}, + ID: uuid.NullUUID{UUID: invitationID, Valid: true}, }) err = hwdb.Error(ctx, err) if err != nil { @@ -835,7 +835,7 @@ func (s ServiceServer) RevokeInvitation( // Update invitation state err = organizationRepo.UpdateInvitationState(ctx, organization_repo.UpdateInvitationStateParams{ - ID: invitationId, + ID: invitationID, State: int32(pb.InvitationState_INVITATION_STATE_REVOKED.Number()), }) err = hwdb.Error(ctx, err) @@ -973,7 +973,7 @@ func (s ServiceServer) CreatePersonalOrganization( return nil, err } - organisations, err := kc.GetOrganizationsOfUserById(ctx, userID) + organisations, err := kc.GetOrganizationsOfUserByID(ctx, userID) if err != nil { return nil, err } @@ -1006,7 +1006,7 @@ func (s ServiceServer) CreatePersonalOrganization( return nil, err } else if userResult == nil { hash := sha256.Sum256([]byte(userID.String())) - avatarUrl := fmt.Sprintf( + avatarURL := fmt.Sprintf( "%s%s", "https://source.boringavatars.com/marble/128/", hex.EncodeToString(hash[:]), @@ -1017,7 +1017,7 @@ func (s ServiceServer) CreatePersonalOrganization( Email: userClaims.Email, Nickname: userClaims.PreferredUsername, Name: userClaims.Name, - AvatarUrl: &avatarUrl, + AvatarUrl: &avatarURL, }) if err = hwdb.Error(ctx, err); err != nil { return nil, err diff --git a/services/user-svc/internal/user/user.go b/services/user-svc/internal/user/user.go index 56426a11f..bc6098b67 100644 --- a/services/user-svc/internal/user/user.go +++ b/services/user-svc/internal/user/user.go @@ -82,14 +82,14 @@ func HandleUserUpdatedEvent(ctx context.Context, evt *daprcmn.TopicEvent) (retry return true, err } - userId, err := uuid.Parse(payload.Id) + userID, err := uuid.Parse(payload.Id) if err != nil { log.Error().Err(err).Send() return true, err } err = userRepo.UpdateUser(ctx, user_repo.UpdateUserParams{ - ID: userId, + ID: userID, Email: payload.Email, Name: payload.Name, Nickname: payload.Nickname,