Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
32b7f1e
Add problem-extractor package
hicks8989 Sep 18, 2022
4d74ba6
Add tests
hicks8989 Sep 18, 2022
d1d8bcf
Merge pull request #1 from leetcode-roulette/feature/add-problem-extr…
hicks8989 Sep 18, 2022
83bb4c6
Create test.yml
hicks8989 Sep 18, 2022
40e4663
Merge pull request #2 from leetcode-roulette/hicks8989-patch-1
hicks8989 Sep 18, 2022
35cec89
Export app and run server in `index.ts`
hicks8989 Sep 24, 2022
388ff51
Add submission information to db
hicks8989 Sep 24, 2022
aea78d6
Merge pull request #4 from leetcode-roulette/feature/get-submission-i…
hicks8989 Sep 24, 2022
4392a6c
Added logger to app
hicks8989 Sep 24, 2022
760ef6d
Merge pull request #5 from leetcode-roulette/feature/add-logger
hicks8989 Sep 24, 2022
9d51d88
Add Cron Job to continuously populate values
hicks8989 Sep 24, 2022
c74d574
Update `cronExpression` to run once an hour
hicks8989 Sep 24, 2022
ae940bb
Add `CRON_EXPRESSION` to `process.env`
hicks8989 Sep 24, 2022
39bc405
Merge pull request #6 from leetcode-roulette/feature/setup-cron-job
hicks8989 Sep 24, 2022
e81fc8d
Update cron job
hicks8989 Sep 24, 2022
c7796bb
Merge pull request #7 from leetcode-roulette/feature/setup-cron-job
hicks8989 Sep 24, 2022
4b2a90b
Create `README.md`
hicks8989 Sep 24, 2022
019a375
Merge pull request #8 from leetcode-roulette/docs/add-readme
hicks8989 Sep 24, 2022
bae7ad9
Fxed update bug
hicks8989 Sep 26, 2022
d616da1
Merge pull request #9 from leetcode-roulette/fix/remove-axios-cache
hicks8989 Sep 26, 2022
8e0b5b2
Add promise resolution code to `PopulateProblems`
hicks8989 Sep 29, 2022
fed2ecd
Merge pull request #10 from leetcode-roulette/fix/add-promise-resolution
hicks8989 Sep 29, 2022
5bcd290
Changed connect function to be async
jaredaivory Oct 7, 2022
75b3213
Changed from Promise<void> to Promise<boolean>
jaredaivory Oct 7, 2022
5b155ec
Add `try catch` block to `Database.connect`
hicks8989 Oct 7, 2022
34c3437
Remove redundant log call in DB
hicks8989 Oct 8, 2022
c3badc1
Merge pull request #11 from leetcode-roulette/fix/NOTICKET/database-c…
hicks8989 Oct 8, 2022
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
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Build and Test

on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
145 changes: 143 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,143 @@
# problem-extractor
Problem extractor service to populate the database
# Problem Extractor
[Leetcode Roulette](https://leetcoderoulette.com) service that runs scheduled jobs to get [Leetcode](https://leetcode.com) problem data from the [Leetcode APIs](https://leetcode.com/api/problems/all).

![ci](https://github.com/conventional-changelog/standard-version/workflows/ci/badge.svg)
[![NPM version](https://img.shields.io/npm/v/standard-version.svg)](https://www.npmjs.com/package/standard-version)

## Getting Started
To get started running the Problem Extractor service locally, clone the repository to your local machine and change to the project root directory. Next, make sure to make the needed configurations and run `npm install` to get the needed packages for the project. Next, build and run the project with `npm run build` followed by `npm start` respectively.

```
git clone https://github.com/leetcode-roulette/problem-extractor.git
cd problem-extractor
```

This will add the project to a new `problem-extractor` directory and change into the directory.

```
npm install
npm run build
npm start
```

This will install the required dependencies on your local machine followed by building the source code to a `dist` folder and running the server code in the `dist/index.js` file.

### Prerequisites
Before running the Problem Extractor service locally, the following steps will need to be taken to ensure the needed software will be installed or set up.

* Install [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) and [NodeJS](https://nodejs.dev/en/learn/how-to-install-nodejs/)
* Install [MongoDB](https://www.mongodb.com/docs/manual/installation/) or [MongoDB Atlas](https://www.mongodb.com/cloud/atlas/lp/try4) and setup using the provided [instructions](https://www.mongodb.com/docs/atlas/getting-started/)

### Initial Configuration
Before starting, you'll need to configure the mongoose database connection string. This can be done by creating a `.env` file in the root directory of the project. In the `.env` file, be sure to specify a connection string named `MONGO_CONNECTION_STRING`.

#### Examples:
* ***MONGO_CONNECTION_STRING***: "mongodb://localhost:27017/myDB"

## Developing
To begin development on this project, clone the repository to your local machine and change to the project root directory. Next, make sure to make the needed configurations and run `npm install` to get the needed packages for the project. Finally, run the `npm run dev` command to deploy a local development environment on your local machine.

```
git clone https://github.com/leetcode-roulette/problem-extractor.git
cd problem-extractor
npm install
npm run dev
```

This will spin up a nodemon server using the server code in the `src/index.ts` file.

### Building
To build the project, run the `npm run build` command.

```
npm run build
```

This will compile the typescript in the `src` folder and create a new `dist` folder consisting of built Javascript code.

### Testing
To test the project, run the `npm run test` command.

```
npm run test
```

This will run the tests in any file in the `src` directory following the specified formats.

* `"**/tests/**/*.spec.ts"`
* `"**/tests/**/*.test.ts"`

## Features
This project sets up a cron job to receieve and populate a database with problems from [leetcode](https://leetcode.com).

## Configuration
The following configurations can be specified in a `.env` file.

##### MONGO_CONNECTION_STRING
Type: `String`
Default: None

Specifies mongodb database uri for mongoose to connect to.

```Javascript
mongoose.connect(MONGO_CONNECTION_STRING); // Connects to the provided uri
```

##### CRON_EXPRESSION
Type: `String`
Default: `'0 * * * *'`

Specifies how often the `cronjob` should run.

```javascript
new CronJob(process.env.CRON_EXPRESSION || "0 * * * *"); // Runs at the start of every hour by default
```

##### TIMEZONE
Type: `String`
Default: `'UTC'`

Specifies the timezone that the `cronjob` should use.

```javascript
cron.schedule(cronExpression, this.job, {
timezone: process.env.TIMEZONE || "UTC",
});
```

##### PORT
Type: `Integer`
Default: 3000

Specifies which port the server will run on.

```javascript
app.listen(PORT, () => {
logger.info(`Server is listening on port ${PORT}`); // Log the port the application is being run on
});
```

##### VERSION
Type: `String`
Default: `'1.0.0'`

Specifies the current version of the project.

##### ENVIRONMENT
Type: `String`
Default: `'dev'`

Specifies the environment that is being used.

```javascript
res.status(200).json({
version: VERSION,
environment: ENVIRONMENT,
status: "Live"
});
```

## Built With
* [NodeJS](https://nodejs.org) - Node.js is an open-source, cross-platform, JavaScript runtime environment that executes JavaScript code outside a web browser.
* [MongoDB](https://mongodb.com) - MongoDB is a source-available cross-platform document-oriented database program.
* [Typescript](https://typescriptlang.org) - TypeScript is a free and open source programming language developed and maintained by Microsoft.
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
],
};
Loading