Skip to content

Commit

Permalink
fix seed data
Browse files Browse the repository at this point in the history
  • Loading branch information
mSulimenko committed Dec 19, 2024
1 parent 5951a7d commit 8429faf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 47 deletions.
7 changes: 5 additions & 2 deletions server/db/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package db

import (
"context"
"encoding/json"
"fmt"
"github.com/moevm/nosql2h24-transcribtion/config"
"github.com/moevm/nosql2h24-transcribtion/models"
Expand All @@ -12,6 +11,10 @@ import (
"os"
)

import (
"go.mongodb.org/mongo-driver/bson"
)

func loadDataFromFile(filePath string, result interface{}) error {
file, err := os.Open(filePath)
if err != nil {
Expand All @@ -24,7 +27,7 @@ func loadDataFromFile(filePath string, result interface{}) error {
return err
}

err = json.Unmarshal(data, &result)
err = bson.UnmarshalExtJSON(data, true, result)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions server/db/seed_data/jobs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"_id": { "$oid": "650e7c3f5f1e4e0001a0bdf3" },
"user_id": { "$oid": "650e802f5f1e4e0001a0be00" },
"user_id": { "$oid": "650e812f5f1e4e0001a0be01" },
"title": "Transcription Task 1",
"status": "in_progress",
"source_language": "English",
Expand All @@ -11,12 +11,12 @@
"output_file": "transcription1.txt",
"created_at": "2023-10-15T09:00:00Z",
"updated_at": "2023-10-15T09:00:00Z",
"host_id": { "$oid": "650e822f5f1e4e0001a0be01" },
"host_id": { "$oid": "650e822f5f1e4e0001a0be11" },
"estimated_finish_datetime": "2023-10-15T11:00:00Z"
},
{
"_id": { "$oid": "650e7c3f5f1e4e0001a0bdf4" },
"user_id": { "$oid": "650e802f5f1e4e0001a0be01" },
"user_id": { "$oid": "650e812f5f1e4e0001a0be02" },
"title": "Translation Task 1",
"status": "completed",
"source_language": "Spanish",
Expand All @@ -26,12 +26,12 @@
"output_file": "translated1.pdf",
"created_at": "2023-11-12T11:30:00Z",
"updated_at": "2023-11-12T11:30:00Z",
"host_id": { "$oid": "650e832f5f1e4e0001a0be02" },
"host_id": { "$oid": "650e832f5f1e4e0001a0be12" },
"estimated_finish_datetime": "2023-11-12T14:30:00Z"
},
{
"_id": { "$oid": "650e7c3f5f1e4e0001a0bdf5" },
"user_id": { "$oid": "650e802f5f1e4e0001a0be02" },
"user_id": { "$oid": "650e812f5f1e4e0001a0be03" },
"title": "Data Processing Task 1",
"status": "pending",
"source_language": "French",
Expand All @@ -41,7 +41,7 @@
"output_file": "processed1.csv",
"created_at": "2023-11-18T15:00:00Z",
"updated_at": "2023-11-18T15:00:00Z",
"host_id": { "$oid": "650e842f5f1e4e0001a0be03" },
"host_id": { "$oid": "650e842f5f1e4e0001a0be13" },
"estimated_finish_datetime": "2023-11-18T18:00:00Z"
}
]
16 changes: 8 additions & 8 deletions server/db/seed_data/servers.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"_id": { "$oid": "650e822f5f1e4e0001a0be01" },
"_id": { "$oid": "650e822f5f1e4e0001a0be11" },
"hostname": "server_1",
"address": "192.168.1.1",
"description": "Main processing server for jobs.",
Expand All @@ -10,37 +10,37 @@
"current_jobs": [
{ "$oid": "650e7c3f5f1e4e0001a0bdf3" }
],
"completed_jobs": [
{ "$oid": "650e7c3f5f1e4e0001a0bdf7" }
],
"completed_jobs": [],
"cpu_info": "Intel Xeon E5-2680 v4",
"gpu_info": "NVIDIA Tesla V100",
"ram_size_gb": 256
},
{
"_id": { "$oid": "650e832f5f1e4e0001a0be02" },
"_id": { "$oid": "650e832f5f1e4e0001a0be12" },
"hostname": "server_2",
"address": "192.168.1.2",
"description": "Backup server for job processing.",
"status": "inactive",
"created_at": "2023-11-05T14:30:00Z",
"updated_at": "2023-11-05T14:30:00Z",
"current_jobs": [],
"completed_jobs": [],
"completed_jobs": [
{ "$oid": "650e7c3f5f1e4e0001a0bdf4" }
],
"cpu_info": "AMD EPYC 7742",
"gpu_info": "NVIDIA A100",
"ram_size_gb": 512
},
{
"_id": { "$oid": "650e842f5f1e4e0001a0be03" },
"_id": { "$oid": "650e842f5f1e4e0001a0be13" },
"hostname": "server_3",
"address": "192.168.1.3",
"description": "Test server for job simulation.",
"status": "active",
"created_at": "2023-11-20T09:00:00Z",
"updated_at": "2023-11-20T09:00:00Z",
"current_jobs": [
{ "$oid": "650e7c3f5f1e4e0001a0bdf4" }
{ "$oid": "650e7c3f5f1e4e0001a0bdf5" }
],
"completed_jobs": [],
"cpu_info": "Intel Xeon Platinum 8280",
Expand Down
40 changes: 9 additions & 31 deletions server/db/seed_data/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"jobs": []
},
{
"_id": { "$oid": "650e7c2f5f1e4e0001a0bdf1" },
"_id": { "$oid": "650e812f5f1e4e0001a0be01" },
"username": "john_doe",
"email": "[email protected]",
"password_hash": "hashed_password_123",
Expand All @@ -34,7 +34,7 @@
"jobs": [{ "$oid": "650e7c3f5f1e4e0001a0bdf3" }]
},
{
"_id": { "$oid": "650e7d2f5f1e4e0001a0bdf5" },
"_id": { "$oid": "650e812f5f1e4e0001a0be02" },
"username": "jane_smith",
"email": "[email protected]",
"password_hash": "hashed_password_456",
Expand All @@ -50,13 +50,13 @@
"payment_status": "pending",
"created_at": "2023-11-19T08:00:00Z",
"updated_at": "2023-11-19T09:00:00Z",
"job_id": { "$oid": "650e7d4f5f1e4e0001a0bdf7" }
"job_id": { "$oid": "650e7c3f5f1e4e0001a0bdf4" }
}
],
"jobs": [{ "$oid": "650e7d4f5f1e4e0001a0bdf7" }]
"jobs": [{ "$oid": "650e7c3f5f1e4e0001a0bdf4" }]
},
{
"_id": { "$oid": "650e7e2f5f1e4e0001a0bdf8" },
"_id": { "$oid": "650e812f5f1e4e0001a0be03" },
"username": "alice_wonder",
"email": "[email protected]",
"password_hash": "hashed_password_789",
Expand All @@ -72,13 +72,13 @@
"payment_status": "completed",
"created_at": "2023-11-15T10:30:00Z",
"updated_at": "2023-11-15T11:00:00Z",
"job_id": { "$oid": "650e7e4f5f1e4e0001a0bdfa" }
"job_id": { "$oid": "650e7c3f5f1e4e0001a0bdf5" }
}
],
"jobs": [{ "$oid": "650e7e4f5f1e4e0001a0bdfa" }]
"jobs": [{ "$oid": "650e7c3f5f1e4e0001a0bdf5" }]
},
{
"_id": { "$oid": "650e7f2f5f1e4e0001a0bdfb" },
"_id": { "$oid": "650e812f5f1e4e0001a0be04" },
"username": "bob_builder",
"email": "[email protected]",
"password_hash": "hashed_password_987",
Expand All @@ -87,28 +87,6 @@
"updated_at": "2023-09-20T08:00:00Z",
"last_login_at": "2023-11-18T07:00:00Z",
"payments": [],
"jobs": [{ "$oid": "650e7f4f5f1e4e0001a0bdfc" }]
},
{
"_id": { "$oid": "650e802f5f1e4e0001a0bdfd" },
"username": "charlie_chaplin",
"email": "[email protected]",
"password_hash": "hashed_password_654",
"permissions": "moderator",
"created_at": "2023-10-01T15:00:00Z",
"updated_at": "2023-10-01T15:00:00Z",
"last_login_at": "2023-11-22T18:00:00Z",
"payments": [
{
"_id": { "$oid": "650e803e5f1e4e0001a0bdfe" },
"price": "120.00",
"payment_method": "credit_card",
"payment_status": "completed",
"created_at": "2023-10-15T12:00:00Z",
"updated_at": "2023-10-15T12:30:00Z",
"job_id": { "$oid": "650e804f5f1e4e0001a0bdff" }
}
],
"jobs": [{ "$oid": "650e804f5f1e4e0001a0bdff" }]
"jobs": []
}
]

0 comments on commit 8429faf

Please sign in to comment.