Compare commits
2 commits
d9917ab8b0
...
97ed0cd797
Author | SHA1 | Date | |
---|---|---|---|
97ed0cd797 | |||
a8c39d066b |
5 changed files with 65 additions and 0 deletions
1
.dockerignore
Normal file
1
.dockerignore
Normal file
|
@ -0,0 +1 @@
|
|||
.git
|
17
Dockerfile
Normal file
17
Dockerfile
Normal file
|
@ -0,0 +1,17 @@
|
|||
FROM golang:1.16-alpine AS builder
|
||||
|
||||
COPY . /meditime
|
||||
|
||||
WORKDIR /meditime
|
||||
|
||||
RUN go build
|
||||
|
||||
FROM alpine:3.13
|
||||
|
||||
RUN apk add --no-cache \
|
||||
ca-certificates \
|
||||
tzdata
|
||||
|
||||
COPY --from=builder /meditime/meditime /usr/local/bin/meditime
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/meditime"]
|
10
Makefile
Normal file
10
Makefile
Normal file
|
@ -0,0 +1,10 @@
|
|||
IMAGE_REGISTRY = registry.0xdad.com/meditime
|
||||
IMAGE_TAG = latest
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
docker build -t "${IMAGE_REGISTRY}:${IMAGE_TAG}" .
|
||||
|
||||
.PHONY: deploy
|
||||
deploy: build
|
||||
docker push "${IMAGE_REGISTRY}:${IMAGE_TAG}"
|
|
@ -148,6 +148,13 @@ func (b *Badger) AddMedication(medication *Medication) error {
|
|||
})
|
||||
}
|
||||
|
||||
// RemoveMedication from the database
|
||||
func (b *Badger) RemoveMedication(medication *Medication) error {
|
||||
return b.db.Update(func(tx *badger.Txn) error {
|
||||
return tx.Delete(medication.badgerKey())
|
||||
})
|
||||
}
|
||||
|
||||
// ListMedicationsForUser from the database
|
||||
func (b *Badger) ListMedicationsForUser(user *User) (medications []*Medication, err error) {
|
||||
err = b.db.View(func(tx *badger.Txn) error {
|
||||
|
|
30
main.go
30
main.go
|
@ -270,6 +270,36 @@ func main() {
|
|||
|
||||
log(medication)
|
||||
|
||||
case "remove":
|
||||
fmt.Print("username: ")
|
||||
inputScanner.Scan()
|
||||
|
||||
username := string(bytes.TrimSpace(inputScanner.Bytes()))
|
||||
if username == "" {
|
||||
return fmt.Errorf("failed to get username from STDIN prompt: %w", inputScanner.Err())
|
||||
}
|
||||
|
||||
user, err := b.GetUser(username)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to lookup username %s: %w", username, err)
|
||||
}
|
||||
|
||||
if user == nil {
|
||||
return fmt.Errorf("username %s doesn't exist", username)
|
||||
}
|
||||
|
||||
fmt.Print("medication id: ")
|
||||
inputScanner.Scan()
|
||||
|
||||
medicationID := uuid.MustParse(string(bytes.TrimSpace(inputScanner.Bytes())))
|
||||
err = b.RemoveMedication(&db.Medication{
|
||||
IDUser: user.ID,
|
||||
ID: medicationID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case "list":
|
||||
fmt.Print("username: ")
|
||||
inputScanner.Scan()
|
||||
|
|
Loading…
Reference in a new issue