Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoApp committed Jan 16, 2024
1 parent f749aa5 commit b47a4c5
Show file tree
Hide file tree
Showing 171 changed files with 7,323 additions and 6,624 deletions.
36 changes: 28 additions & 8 deletions .github/workflows/wilco-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,46 @@ jobs:
timeout-minutes: 10
name: Pr checks

services:
postgres:
image: postgres:13
env:
POSTGRES_PASSWORD: postgres
SECRET_KEY: secret
POSTGRES_DB: anythink-market
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Check out project
uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v3
- name: Use Java
uses: actions/setup-java@v4
with:
node-version: "16"

- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.6.0
with:
mongodb-version: "4.4"
distribution: "adopt"
java-version: "11"

- uses: oNaiPs/secrets-to-env-action@v1
with:
secrets: ${{ toJSON(secrets) }}

- name: Setup Node for Wilco Checks
uses: actions/setup-node@v3
with:
node-version: "16"

- name: Wilco checks
id: Wilco
uses: trywilco/actions@main
with:
engine: ${{ secrets.WILCO_ENGINE_URL }}

- name: Print server logs on failure
if: ${{ failure() }}
run: |
cat /tmp/output.log
61 changes: 25 additions & 36 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
# Logs
logs
*.log
.DS_Store

npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
node_modules

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

.gradle/
/build/
!gradle/wrapper/gradle-wrapper.jar
*.db

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
3 changes: 2 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
FROM public.ecr.aws/v0a2l7y2/wilco/anythink-backend-node:latest
FROM public.ecr.aws/v0a2l7y2/wilco/anythink-backend-java:latest

10 changes: 0 additions & 10 deletions backend/Dockerfile.aws

This file was deleted.

21 changes: 21 additions & 0 deletions backend/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Aisensiy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 27 additions & 14 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
# Anythink Market Backend

The Anythink Market backend is Node web app written with [Express](https://expressjs.com/)
# How it works

## Dependencies
The application uses Spring Boot (Web, Mybatis).

- [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken) - For generating JWTs used by authentication
- [mongoose](https://github.com/Automattic/mongoose) - For modeling and mapping MongoDB data to javascript
- [mongoose-unique-validator](https://github.com/blakehaswell/mongoose-unique-validator) - For handling unique validation errors in Mongoose. Mongoose only handles validation at the document level, so a unique index across a collection will throw an exception at the driver level. The `mongoose-unique-validator` plugin helps us by formatting the error like a normal mongoose `ValidationError`.
- [passport](https://github.com/jaredhanson/passport) - For handling user authentication
- [slug](https://github.com/dodo/node-slug) - For encoding titles into a URL-friendly format
And the code is organized as this:

## Application Structure
1. `api` is the web layer implemented by Spring MVC
2. `core` is the business model including entities and services
3. `application` is the high-level services for querying the data transfer objects
4. `infrastructure` contains all the implementation classes as the technique details

- `app.js` - The entry point to our application. This file defines our express server and connects it to MongoDB using mongoose. It also requires the routes and models we'll be using in the application.
- `config/` - This folder contains configuration for passport as well as a central location for configuration/environment variables.
- `routes/` - This folder contains the route definitions for our API.
- `models/` - This folder contains the schema definitions for our Mongoose models.
# Getting started

## Error Handling
You'll need Java 11 installed.

In `routes/api/index.js`, we define a error-handling middleware for handling Mongoose's `ValidationError`. This middleware will respond with a 422 status code and format the response to have [error messages the clients can understand](https://github.com/gothinkster/realworld/blob/master/API.md#errors-and-status-codes)
./gradlew bootRun

To test that it works, open a browser tab at http://localhost:3000/api/tags
Alternatively, you can run:

curl http://localhost:3000/api/tags

# Run test

The repository contains a lot of test cases to cover both api test and repository test.

./gradlew test

# Code format

Use spotless for code format.

./gradlew spotlessJavaApply
89 changes: 0 additions & 89 deletions backend/app.js

This file was deleted.

77 changes: 77 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
plugins {
id 'org.springframework.boot' version '2.6.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id "com.netflix.dgs.codegen" version "5.0.6"
id "com.diffplug.spotless" version "6.2.1"
}

version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
targetCompatibility = '11'

spotless {
java {
target project.fileTree(project.rootDir) {
include '**/*.java'
exclude 'build/generated/**/*.*', 'build/generated-examples/**/*.*'
}
googleJavaFormat()
}
}

repositories {
mavenCentral()
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'com.squareup.okhttp3:okhttp:4.9.1'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.2'
implementation 'com.netflix.graphql.dgs:graphql-dgs-spring-boot-starter:4.9.21'
implementation 'org.flywaydb:flyway-core'
implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2',
'io.jsonwebtoken:jjwt-jackson:0.11.2'
implementation 'joda-time:joda-time:2.10.13'
implementation 'org.xerial:sqlite-jdbc:3.36.0.3'
implementation 'org.postgresql:postgresql:42.2.24'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'

compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

testImplementation 'io.rest-assured:rest-assured:4.5.1'
testImplementation 'io.rest-assured:json-path:4.5.1'
testImplementation 'io.rest-assured:xml-path:4.5.1'
testImplementation 'io.rest-assured:spring-mock-mvc:4.5.1'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:2.2.2'
testImplementation 'com.h2database:h2:1.4.200'
}

tasks.named('test') {
useJUnitPlatform()
}

tasks.named('clean') {
doFirst {
delete './dev.db'
}
}

tasks.named('generateJava') {
schemaPaths = ["${projectDir}/src/main/resources/schema"] // List of directories containing schema files
packageName = 'io.spring.graphql' // The package name to use to generate sources
}
3 changes: 0 additions & 3 deletions backend/config/index.js

This file was deleted.

18 changes: 0 additions & 18 deletions backend/config/passport.js

This file was deleted.

Binary file added backend/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Loading

0 comments on commit b47a4c5

Please sign in to comment.