Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ services:
environment:
- PORT=$QUESTION_SVC_PORT
- DB_URI=$QUESTION_SVC_DB_URI
depends_on:
- mongodb-question

user-service:
build:
Expand All @@ -28,3 +30,26 @@ services:
- JWT_SECRET=$JWT_SECRET
- EMAIL_ADDRESS=$EMAIL_ADDRESS
- EMAIL_PASSWORD=$EMAIL_PASSWORD
depends_on:
- mongodb-user

mongodb-question:
image: mongo:latest
ports:
- 27017:27017
volumes:
- mongodb_question_data:/data/db
- ./init-mongo-scripts/init-mongo-questions.sh:/docker-entrypoint-initdb.d/init-mongo-questions.sh:ro


mongodb-user:
image: mongo:latest
ports:
- 27018:27017
volumes:
- mongodb_user_data:/data/db
- ./init-mongo-scripts/init-mongo-user.sh:/docker-entrypoint-initdb.d/init-mongo-user.sh:ro

volumes:
mongodb_question_data:
mongodb_user_data:
129 changes: 129 additions & 0 deletions init-mongo-scripts/init-mongo-questions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/bin/bash
mongosh <<EOF
use question_service

db.questions.insertMany([
{
title: "Reverse a String",
description: "Write a function that reverses a string. The input string is given as an array of characters s. You must do this by modifying the input array in-place with O(1) extra memory.",
category: "Strings, Algorithms",
complexity: "easy"
},
{
title: "Linked List Cycle Detection",
description: "Implement a function to detect if a linked list contains a cycle.",
category: "Data Structures, Algorithms",
complexity: "easy"
},
{
title: "Roman to Integer",
description: "Given a roman numeral, convert it to an integer.",
category: "Algorithms",
complexity: "easy"
},
{
title: "Add Binary",
description: "Given two binary strings a and b, return their sum as a binary string.",
category: "Bit Manipulation, Algorithms",
complexity: "easy"
},
{
title: "Fibonacci Number",
description: "Given n, calculate F(n) which is the Fibonacci number.",
category: "Recursion, Algorithms",
complexity: "easy"
},
{
title: "Implement Stack using Queues",
description: "Implement a last-in-first-out (LIFO) stack using only two queues.",
category: "Data Structures",
complexity: "easy"
},
{
title: "Combine Two Tables",
description: "Write a SQL solution to combine two tables, reporting the first name, last name, city, and state of each person.",
category: "Databases",
complexity: "easy"
},
{
title: "Repeated DNA Sequences",
description: "Given a string s that represents a DNA sequence, return all the 10-letter-long sequences that occur more than once.",
category: "Algorithms, Bit Manipulation",
complexity: "medium"
},
{
title: "Course Schedule",
description: "You are given an array prerequisites, return true if you can finish all courses.",
category: "Data Structures, Algorithms",
complexity: "medium"
},
{
title: "LRU Cache Design",
description: "Design and implement an LRU (Least Recently Used) cache.",
category: "Data Structures",
complexity: "medium"
},
{
title: "Longest Common Subsequence",
description: "Given two strings, return the length of their longest common subsequence.",
category: "Strings, Algorithms",
complexity: "medium"
},
{
title: "Rotate Image",
description: "You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).",
category: "Arrays, Algorithms",
complexity: "medium"
},
{
title: "Airplane Seat Assignment Probability",
description: "Return the probability that the nth person gets his own seat on a plane.",
category: "Brainteaser",
complexity: "medium"
},
{
title: "Validate Binary Search Tree",
description: "Given the root of a binary tree, determine if it is a valid binary search tree (BST).",
category: "Data Structures, Algorithms",
complexity: "medium"
},
{
title: "Sliding Window Maximum",
description: "You are given an array of integers, return the maximum sliding window for each window of size k.",
category: "Arrays, Algorithms",
complexity: "hard"
},
{
title: "N-Queen Problem",
description: "Given an integer n, return all distinct solutions to the n-queens puzzle.",
category: "Algorithms",
complexity: "hard"
},
{
title: "Serialize and Deserialize a Binary Tree",
description: "Design an algorithm to serialize and deserialize a binary tree.",
category: "Data Structures, Algorithms",
complexity: "hard"
},
{
title: "Wildcard Matching",
description: "Given an input string and a pattern, implement wildcard pattern matching with support for '?' and '*'.",
category: "Strings, Algorithms",
complexity: "hard"
},
{
title: "Chalkboard XOR Game",
description: "Alice and Bob take turns erasing exactly one number from a chalkboard, the bitwise XOR of the elements decides the winner.",
category: "Brainteaser",
complexity: "hard"
},
{
title: "Trips and Users",
description: "Write a SQL solution to compute the cancellation rate of requests with unbanned users for a given date range.",
category: "Databases",
complexity: "hard"
}
]);

print("20 questions inserted.");
EOF
21 changes: 21 additions & 0 deletions init-mongo-scripts/init-mongo-user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
mongosh <<EOF
use user_service
// password: admin
db.usermodels.insertOne({
username: "admin",
email: "[email protected]",
password: "\$2b\$10\$Znbj5qwkQymg2Yk1asb2zO3kyhS.2UP6Vv/oJE1DsBmyLnZhqG90.",
isAdmin: true
});
print("Admin user created.");

// password: notadmin
db.usermodels.insertOne({
username: "notadmin",
email: "[email protected]",
password: "\$2b\$10\$LgHKho0/lAJz.qQUHFyXEu/39v86mhu3ILaeWFIIk7He90CMQZvYu",
isAdmin: false
});
print("Notadmin user created.");
EOF