Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the update for code test by zhangxiang #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

docker/data

target

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
83 changes: 13 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,16 @@
# Wiredcraft Back-end Developer Test

Make sure you read the whole document carefully and follow the guidelines in it.

## Context

Build a RESTful API that can `get/create/update/delete` user data from a persistence database

### User Model
## User Guide

##### 1. jump to target folder from project root, and build mysql container.
```
{
"id": "xxx", // user ID
"name": "test", // user name
"dob": "", // date of birth
"address": "", // user address
"description": "", // user description
"createdAt": "" // user created date
}
$: cd ./docker/mysql
$: docker-compose up -d
```

## Requirements

### Functionality

- The API should follow typical RESTful API design pattern.
- The data should be saved in the DB.
- Provide proper unit test.
- Provide proper API document.

### Tech stack

- Use Java and any framework.
- Use any DB.

### Bonus

- Write clear documentation on how it's designed and how to run the code.
- Write good in-code comments.
- Write good commit messages.
- An online demo is always welcome.

### Advanced requirements

*These are used for some further challenges. You can safely skip them if you are not asked to do any, but feel free to try out.*

- Provide a complete user auth (authentication/authorization/etc.) strategy, such as OAuth. This should provide a way to allow end users to securely login, autenticate requests and only access their own information.
- Provide a complete logging (when/how/etc.) strategy.
- Imagine we have a new requirement right now that the user instances need to link to each other, i.e., a list of "followers/following" or "friends". Can you find out how you would design the model structure and what API you would build for querying or modifying it?
- Related to the requirement above, suppose the address of user now includes a geographic coordinate(i.e., latitude and longitude), can you build an API that,
- given a user name
- return the nearby friends


## What We Care About

Feel free to use any open-source library as you see fit, but remember that we are evaluating your coding skills and problem solving skills.

Here's what you should aim for:

- Good use of current Java & API design best practices.
- Good testing approach.
- Extensible code.

## FAQ

> Where should I send back the result when I'm done?

Fork this repo and send us a pull request when you think it's ready for review. You don't have to finish everything prior and you can continue to work on it. We don't have a deadline for the task.

> What if I have a question?

Feel free to make your own assumptions about the scope of this task but try to document those. You can also reach to us for questions.
##### 2. jump to target folder from project root, and build redis container.
```
$: cd ./docker/redis
$: docker-compose up -d
```
##### 3. run project successfully. view all api list by swagger.
```
http://127.0.0.1/swagger-ui/index.html#/
```
3 changes: 3 additions & 0 deletions docker/mysql/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MYSQL_ROOT_PASSWORD=root
MYSQL_ROOT_HOST=%
MYSQL_DATABASE=wiredcraft
15 changes: 15 additions & 0 deletions docker/mysql/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3"
services:
mysql:
image: mysql:latest
container_name: mysql
restart: always
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_ROOT_HOST: ${MYSQL_ROOT_HOST}
MYSQL_DATABASE: ${MYSQL_DATABASE}
volumes:
- ./data/mysql:/var/lib/mysql
- ./data/conf/my.cnf:/etc/my.cnf
1 change: 1 addition & 0 deletions docker/redis/config/redis.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requirepass H3yuncom
12 changes: 12 additions & 0 deletions docker/redis/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3'
services:
redis:
image: redis:4.0.8-alpine
container_name: db-redis
restart: always
ports:
- 6379:6379
volumes:
- ./config:/docker/config
- ./data:/data
command: redis-server /docker/config/redis.conf
130 changes: 130 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0</version>
<relativePath/>
</parent>
<groupId>com.w.t</groupId>
<artifactId>test-backend-java</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
<java.version>1.8</java.version>
<mybatis-plus.version>3.4.1</mybatis-plus.version>
<alibaba.fastjson.version>1.2.68</alibaba.fastjson.version>
<flywaydb.flyway-core.version>5.2.4</flywaydb.flyway-core.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.7</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${alibaba.fastjson.version}</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>${flywaydb.flyway-core.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
</dependency>
<dependency>
<groupId>p6spy</groupId>
<artifactId>p6spy</artifactId>
<version>3.8.7</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
11 changes: 11 additions & 0 deletions src/main/java/com/w/t/WApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.w.t;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class WApplication {
public static void main(String[] args) {
SpringApplication.run(WApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.w.t.common.core.constant;

public class LocalStorageConstant {

public static String USER_SALT="RL7fWXO@yjGZqBl(G";

public static String USER_DETAIL="userDetail";

public static String TOKEN_KEY="userDetail";

public static String CURRENT_USER="currentUser";

}
45 changes: 45 additions & 0 deletions src/main/java/com/w/t/common/core/exception/BaseException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.w.t.common.core.exception;

import lombok.Data;

@Data
public class BaseException extends RuntimeException {

private static final long serialVersionUID = 1L;

private String module;

private String code;

private Object[] args;

private String defaultMessage;

public BaseException(String module, String code, Object[] args, String defaultMessage) {
this.module = module;
this.code = code;
this.args = args;
this.defaultMessage = defaultMessage;
}

public BaseException(String module, String code, Object[] args) {

this(module, code, args, null);

}

public BaseException(String module, String defaultMessage) {

this(module, null, null, defaultMessage);

}

public BaseException(String code, Object[] args) {
this(null, code, args, null);
}

public BaseException(String defaultMessage) {
this(null, null, null, defaultMessage);
}

}
Loading