Skip to content

Commit

Permalink
Merge pull request #22 from M2JT/code-clean-up-m2jt
Browse files Browse the repository at this point in the history
front & back-end code cleanup + features update
  • Loading branch information
hackrmann authored Dec 20, 2023
2 parents fc4b2d8 + 6492d9f commit 9ddb9a4
Show file tree
Hide file tree
Showing 19 changed files with 480 additions and 524 deletions.
169 changes: 88 additions & 81 deletions back-end/pom.xml
Original file line number Diff line number Diff line change
@@ -1,96 +1,103 @@
<?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>3.1.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.open-source-dev</groupId>
<artifactId>back-end</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>back-end</name>
<description>Charge Finder Java Project</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
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>3.1.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.open-source-dev</groupId>
<artifactId>back-end</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>back-end</name>
<description>Charge Finder Java Project</description>
<properties>
<java.version>17</java.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-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.2</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.1</version>
</dependency>

<dependency>
<groupId>software.aws.rds</groupId>
<artifactId>aws-mysql-jdbc</artifactId>
<version>1.1.11</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
</dependency>
<dependency>
<groupId>software.aws.rds</groupId>
<artifactId>aws-mysql-jdbc</artifactId>
<version>1.1.11</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.2</version>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.2</version>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.11.2</version>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.2</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.2</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.11.2</version>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
</dependency>
</dependencies>
</dependencies>

<repositories>
<repository>
<id>Maven Central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<repositories>
<repository>
<id>Maven Central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>

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

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.opensourcedev.backend.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class SecurityConfig {

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.opensourcedev.backend.controller;

import com.opensourcedev.backend.dto.LoginResponse;
import com.opensourcedev.backend.dto.MessageResponse;
import com.opensourcedev.backend.dto.RentalDetail;
import com.opensourcedev.backend.model.ChargingStation;
import com.opensourcedev.backend.model.Rental;
import com.opensourcedev.backend.model.User;
import com.opensourcedev.backend.service.MainService;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -16,40 +17,40 @@
@RequestMapping(value = "/", produces = "application/json")
public class MainController {

@Autowired
MainService mainService;

@GetMapping("/getAllStations")
public List<ChargingStation> getAllStations() {
return mainService.getAllStationsInfo();
}

@PostMapping("/rent")
public String rentPowerBank(@RequestBody RentalDetail rentalDetail) {
return mainService.rentPowerBank(rentalDetail)
? "rent successful!"
: "rent failed!";
}

@GetMapping("/getRentalHistory/{username}")
public List<Rental> getRentalHistory(@PathVariable String username) {
return mainService.getRentalHistory(username);
}

@PostMapping("/return/{rentalId}")
public String returnCharger(@PathVariable Integer rentalId) {
return (mainService.returnPowerBank(rentalId))
? "Rental returned successfully"
: "Error, rental couldn't be returned.";
}

@PostMapping("/register")
public ResponseEntity<LoginResponse> registerUser(@RequestBody User user) {
return mainService.registerUser(user);
}

@PostMapping("/login")
public ResponseEntity<LoginResponse> loginUser(@RequestBody User user) {
return mainService.loginUser(user);
}
@Autowired
MainService mainService;

@GetMapping("/getAllStations")
public List<ChargingStation> getAllStations() {
return mainService.getAllStationsInfo();
}

@PostMapping("/rent")
public String rentPowerBank(@RequestBody RentalDetail rentalDetail) {
return mainService.rentPowerBank(rentalDetail)
? "rent successful!"
: "rent failed!";
}

@GetMapping("/getRentalHistory/{username}")
public List<Rental> getRentalHistory(@PathVariable String username) {
return mainService.getRentalHistory(username);
}

@PostMapping("/return/{rentalId}")
public String returnCharger(@PathVariable Integer rentalId) {
return (mainService.returnPowerBank(rentalId))
? "Rental returned successfully"
: "Error, rental couldn't be returned.";
}

@PostMapping("/register")
public ResponseEntity<LoginResponse> registerUser(@RequestBody User user) {
return mainService.registerUser(user);
}

@PostMapping("/login")
public ResponseEntity<LoginResponse> loginUser(@RequestBody User user) {
return mainService.loginUser(user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@
import com.opensourcedev.backend.model.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
Integer getUserIDByName(String username);

@Insert("INSERT INTO user (username, email, user_password, join_date) VALUES (#{user.username}, #{user.email}, #{user.userPassword}, #{user.joinDate})")
void addUser(@Param("user") User user);
List<User> checkDuplicateRegistration(String newUsername, String newUserEmail);

void addNewUser(User newUser);

@Select("SELECT id, username, email, user_password, join_date FROM user WHERE email = #{email}")
@Results({
@Result(property = "userId", column = "id"),
@Result(property = "username", column = "username"),
@Result(property = "email", column = "email"),
@Result(property = "userPassword", column = "user_password"), // Explicit mapping for user_password
@Result(property = "joinDate", column = "join_date")
})
User getUserByEmail(@Param("email") String email);
User getUserByEmail(String email);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Rental {
private Integer charges;
private String rentalStatus;
private Integer chargingStationId;

private Date updateTime;

public Rental(Integer rentalId, Integer userId, Integer transactionId, Date rentalDate,
Integer duration, Integer charges, String rentalStatus, Integer chargingStationId) {
Expand All @@ -27,4 +27,5 @@ public Rental(Integer rentalId, Integer userId, Integer transactionId, Date rent
this.rentalStatus = rentalStatus;
this.chargingStationId = chargingStationId;
}

}
Loading

0 comments on commit 9ddb9a4

Please sign in to comment.