Skip to content

Commit 81ca87d

Browse files
Merge pull request #23 from qnib/dyndb_listitems
Dyndb listitems
2 parents 4170127 + b5780db commit 81ca87d

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.1.0
2+
current_version = 0.2.0
33
commit = True
44
tag = True
55

cmd/boltdb/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func Log(handler http.Handler) http.Handler {
2929
func main() {
3030
flag.Parse()
3131
if *version {
32-
fmt.Println(`v0.1.0`)
32+
fmt.Println(`v0.2.0`)
3333
os.Exit(0)
3434
}
3535
port := os.Getenv("PORT")

pkg/storage/dynamodb/machinetype_service.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ func (s *machineTypeService) GetByUsername(username string) (mt *storage.Machine
3838
if err != nil {
3939
return
4040
}
41-
log.Println("Found item:")
42-
log.Println("Login: ", user.Login)
43-
log.Println("Password: ", user.Password)
4441
mt = &storage.MachineType{
4542
Login: user.Login,
4643
Password: user.Password,
@@ -50,9 +47,6 @@ func (s *machineTypeService) GetByUsername(username string) (mt *storage.Machine
5047
if err != nil {
5148
return
5249
}
53-
log.Println("Found item:")
54-
log.Println("Type: ", typ.Type)
55-
log.Println("Featuresd: ", typ.Features)
5650
mt.Features = strings.Split(typ.Features, ",")
5751
mt.DisplayName = typ.Type
5852
log.Printf("Return MT: %v", mt)
@@ -67,8 +61,19 @@ func (s *machineTypeService) Delete(accountName string, id int64) error {
6761
return nil
6862
}
6963

70-
func (s *machineTypeService) List(accountName string) (mt []storage.MachineType, err error) {
64+
func (s *machineTypeService) List(accountName string) (mts []storage.MachineType, err error) {
7165
log.Printf("mt.List(accountName=%s)", accountName)
66+
typeItems, err := mhTableTypeList(svc, fmt.Sprintf("%s_types", mhDbTablePrefix))
67+
if err != nil {
68+
return
69+
}
70+
for _, tItem := range typeItems {
71+
mt := storage.MachineType{
72+
DisplayName: tItem.Type,
73+
Features: strings.Split(tItem.Features, ","),
74+
}
75+
mts = append(mts, mt)
76+
}
7277
return
7378
}
7479

pkg/storage/dynamodb/service.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,20 @@ func mhTableUserScan(db *dynamodb.DynamoDB, tableName, usern string) (user Users
202202
return
203203
}
204204

205+
func mhTableTypeList(db *dynamodb.DynamoDB, tableName string) (typeItems []TypeItem, err error) {
206+
log.Printf("List machine types in '%s'", tableName)
207+
params := &dynamodb.ScanInput{
208+
TableName: aws.String(tableName),
209+
}
210+
result, err := svc.Scan(params)
211+
if err != nil {
212+
fmt.Println(err.Error())
213+
return
214+
}
215+
err = dynamodbattribute.UnmarshalListOfMaps(result.Items, &typeItems)
216+
return
217+
}
218+
205219
func mhTableTypeScan(db *dynamodb.DynamoDB, tableName, typen string) (typeItem TypeItem, err error) {
206220
log.Printf("Search for type '%s' in '%s'", typen, tableName)
207221
var queryInput = &dynamodb.QueryInput{

0 commit comments

Comments
 (0)