Skip to content

Commit

Permalink
sqlc: beds, rooms, and patients (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
FoseFx committed Dec 10, 2023
1 parent 548dda3 commit 9bbbdd5
Show file tree
Hide file tree
Showing 48 changed files with 4,025 additions and 2,926 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ gen/**/helpers.go linguist-generated=false
services/impulse_svc/gen/** linguist-generated=true
services/**/schema.sql linguist-generated=true
**/*.expected linguist-generated=true

1 change: 1 addition & 0 deletions .github/workflows/cicd-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
with:
# Can this be a bug in golangci-lint? We already defined the working-directory for this step.
working-directory: services/${{ inputs.service }}
args: "--out-format=line-number"

test:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ You can either run `<script>` in the shell (`devenv shell`) or outside the shell
- `proto-lint`: Lint protos
- `nix-lint`: Lint .nix
- `migratesh`: [migrate.sh](#migratesh---running-migratemigrate-inside-docker)
- `models`

## Fake token

Expand Down
24 changes: 14 additions & 10 deletions gen/dart/lib/proto/services/task_svc/v1/patient_svc.pbjson.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

300 changes: 151 additions & 149 deletions gen/go/proto/services/task_svc/v1/patient_svc.pb.go

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions gen/python/proto/services/task_svc/v1/patient_svc_pb2.py

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion gen/ts/proto/services/task_svc/v1/patient_svc_pb.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 21 additions & 3 deletions gen/ts/proto/services/task_svc/v1/patient_svc_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions libs/hwdb/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package hwdb

import (
"context"
"errors"
"github.com/jackc/pgx/v5"
)

// Optional wraps a database query function and returns (nil, nil) in case of ErrNoRows
//
// hwdb.Optional(repo.GetOptionalElement)(ctx, param)
func Optional[P any, R any](fn func(ctx context.Context, param P) (R, error)) func(ctx context.Context, param P) (*R, error) {
return func(ctx context.Context, param P) (*R, error) {
res, err := fn(ctx, param)
if err != nil && errors.Is(err, pgx.ErrNoRows) {
return nil, nil
} else {
return &res, err
}
}
}
16 changes: 16 additions & 0 deletions libs/hwutil/arrays.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ func Filter[K any](array []K, condition func(value K) bool) []K {
return result
}

// Partition returns the subarrays, for which the condition is (true, false)
func Partition[K any](array []K, condition func(value K) bool) ([]K, []K) {
var in []K
var out []K

for _, value := range array {
if condition(value) {
in = append(in, value)
} else {
out = append(out, value)
}
}

return in, out
}

func Map[K any, V any](vs []K, f func(K) V) []V {
vsm := make([]V, len(vs))
for i, v := range vs {
Expand Down
10 changes: 10 additions & 0 deletions libs/hwutil/optionals.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ func MapNillable[I, O any](ptr *I, f func(I) O) *O {
return &res
}
}

// MapIf maps if cond true, else to nil
func MapIf[I, O any](cond bool, val I, f func(I) O) *O {
if !cond {
return nil
} else {
res := f(val)
return &res
}
}
31 changes: 28 additions & 3 deletions libs/hwutil/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,19 @@ func StringsToUUIDs(strings []string) ([]uuid.UUID, error) {
}

func UUIDToStringPtr(u *uuid.UUID) *string {
var s string
if u != nil {
s = u.String()
s := u.String()
return &s
}
return &s
return nil
}

func NullUUIDToStringPtr(u uuid.NullUUID) *string {
if u.Valid {
s := u.UUID.String()
return &s
}
return nil
}

func StringToUUIDPtr(s *string) (*uuid.UUID, error) {
Expand All @@ -72,6 +80,23 @@ func MustParseInt(s string) int {
return int(i)
}

// ParseNullUUID maps
// - valid uuids to their parsed counterparts (valid = true),
// - invalid uuids to invalid NullUUIDs and returns the parsing error
// - nil-pointers to invalid NullUUIDs without returning an error
//
// Great for parsing optional uuid
func ParseNullUUID(ptr *string) (uuid.NullUUID, error) {
id := uuid.NullUUID{} // invalid uuid
if ptr == nil {
return id, nil
}
parsedID, err := uuid.Parse(*ptr)
id.UUID = parsedID
id.Valid = err == nil
return id, err
}

// PtrTo returns the pointer to the passed value
func PtrTo[T any](v T) *T {
return &v
Expand Down
38 changes: 0 additions & 38 deletions libs/proto_helpers/task_svc/v1/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,6 @@ func UpdatesMapForUpdateTaskTemplateSubTaskRequest(r *pb.UpdateTaskTemplateSubTa
return m
}

func UpdatesMapForUpdatePatientRequest(r *pb.UpdatePatientRequest) map[string]interface{} {
m := make(map[string]interface{})

if r.HumanReadableIdentifier != nil {
m["human_readable_identifier"] = r.HumanReadableIdentifier
}

if r.Notes != nil {
m["notes"] = r.Notes
}

return m
}

func UpdatesMapForUpdateWardRequest(r *pb.UpdateWardRequest) map[string]interface{} {
m := make(map[string]interface{})

Expand All @@ -83,27 +69,3 @@ func UpdatesMapForUpdateWardRequest(r *pb.UpdateWardRequest) map[string]interfac

return m
}

func UpdatesMapForUpdateRoomRequest(r *pb.UpdateRoomRequest) map[string]interface{} {
m := make(map[string]interface{})

if r.Name != nil {
m["name"] = r.Name
}

return m
}

func UpdatesMapForUpdateBedRequest(r *pb.UpdateBedRequest) map[string]interface{} {
m := make(map[string]interface{})

if r.Name != nil {
m["name"] = r.Name
}

if r.RoomId != nil {
m["room_id"] = r.RoomId
}

return m
}
2 changes: 1 addition & 1 deletion proto/services/task_svc/v1/patient_svc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ message GetPatientListResponse {
string name = 2;
string description = 3;
TaskStatus status = 4;
string assigned_user_id = 5;
optional string assigned_user_id = 5;
string patient_id = 6;
bool public = 7;
repeated SubTask subtasks = 8;
Expand Down

0 comments on commit 9bbbdd5

Please sign in to comment.