Skip to content

Commit

Permalink
Merge pull request #81 from NimsHub/development
Browse files Browse the repository at this point in the history
♻️ code refactor
  • Loading branch information
NimsHub authored Oct 14, 2023
2 parents e4d76f3 + bcf2fc7 commit 2a07f9d
Show file tree
Hide file tree
Showing 26 changed files with 114 additions and 82 deletions.
44 changes: 17 additions & 27 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>org.tensorflow</groupId>
<artifactId>tensorflow-core-platform</artifactId>
<version>0.5.0</version>
</dependency>

</dependencies>

Expand All @@ -130,23 +120,23 @@
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>prepare</id>
<phase>package</phase>
<configuration>
<tasks>
<copy todir="${project.build.directory}/${project.build.finalName}/" overwrite="false">
<fileset dir="./" includes=".platform/**"/>
<fileset dir="${project.build.directory}" includes="*.jar"/>
</copy>
<zip destfile="${project.build.directory}/${project.build.finalName}.zip"
basedir="${project.build.directory}/${project.build.finalName}"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<!-- <execution>-->
<!-- <id>prepare</id>-->
<!-- <phase>package</phase>-->
<!-- <configuration>-->
<!-- <tasks>-->
<!-- <copy todir="${project.build.directory}/${project.build.finalName}/" overwrite="false">-->
<!-- <fileset dir="./" includes=".platform/**"/>-->
<!-- <fileset dir="${project.build.directory}" includes="*.jar"/>-->
<!-- </copy>-->
<!-- <zip destfile="${project.build.directory}/${project.build.finalName}.zip"-->
<!-- basedir="${project.build.directory}/${project.build.finalName}"/>-->
<!-- </tasks>-->
<!-- </configuration>-->
<!-- <goals>-->
<!-- <goal>run</goal>-->
<!-- </goals>-->
<!-- </execution>-->
</executions>
</plugin>
</plugins>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/nimshub/biobeacon/BioBeaconApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
@SpringBootApplication
public class BioBeaconApplication {

@Value("${server.port}")
String port;

public static void main(String[] args) {
SpringApplication.run(BioBeaconApplication.class, args);
}

@Value("${server.port}")
String port;

@RestController
public class helloController {
public class HelloController {
@GetMapping("/")
public String hello() {
return String.format("Up and Running on Port %s ...", port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

Expand All @@ -16,8 +19,9 @@
@RequestMapping("/api/v1/activities")
public class ActivityController {
private final ActivityService activityService;

@GetMapping("/activity/{id}")
public ResponseEntity<ActivityTimeResponse> getActivityTimes(@PathVariable UUID id){
public ResponseEntity<ActivityTimeResponse> getActivityTimes(@PathVariable UUID id) {
return new ResponseEntity<>(activityService.getActivityTime(id), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ActivityTime {
@SequenceGenerator(name = "ActivityTime_SEQ", sequenceName = "ActivityTime_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ActivityTime_SEQ")
private Integer id;
@OneToOne(cascade = CascadeType.DETACH,fetch = FetchType.EAGER)
@OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.EAGER)
@JoinColumn(name = "session", referencedColumnName = "id", foreignKey =
@ForeignKey(name = "fk_session_id")
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.nimshub.biobeacon.activities;

import com.nimshub.biobeacon.activities.ActivityTime;
import com.nimshub.biobeacon.session.Session;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
Expand All @@ -13,6 +12,6 @@
*/

@Repository
public interface ActivityTimeRepository extends JpaRepository<ActivityTime,Integer> {
public interface ActivityTimeRepository extends JpaRepository<ActivityTime, Integer> {
Optional<ActivityTime> findBySession(Session session);
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public List<AthleteResponse> getAthletesByCoach(String authHeader) {

/**
* This method get athlete details by athlete ID
*
* @param athleteId : UUID
* @return : AthleteDetailsResponse
*/
Expand All @@ -170,7 +171,8 @@ public AthleteDetailsResponse getAthleteDetailsByAthleteId(UUID athleteId) {

/**
* This method updates the athlete
* @param request : CreateAthleteRequest
*
* @param request : CreateAthleteRequest
* @param authHeader : String
* @return : AuthenticationResponse
*/
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/nimshub/biobeacon/auth/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.nimshub.biobeacon.config.JwtService;
import com.nimshub.biobeacon.exceptions.UserAlreadyExistsException;
import com.nimshub.biobeacon.user.Role;
import com.nimshub.biobeacon.user.User;
import com.nimshub.biobeacon.user.UserRepository;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -78,9 +77,9 @@ public AuthenticationResponse authenticate(AuthenticationRequest request) {
.formatted(request.getEmail()));
}
Map<String, Object> extraClaims = new HashMap<>();
extraClaims.put("role",user.getRole());
extraClaims.put("role", user.getRole());

var jwtToken = jwtService.generateToken(extraClaims,user);
var jwtToken = jwtService.generateToken(extraClaims, user);
logger.info("User authentication success");

return AuthenticationResponse.builder()
Expand All @@ -89,7 +88,8 @@ public AuthenticationResponse authenticate(AuthenticationRequest request) {
}

/**
* This method updates user
* This method updates user
*
* @param user : User
* @return AuthenticationResponse
*/
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/nimshub/biobeacon/coach/CoachService.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public CoachDetailsResponse getCoach(String authHeader) {

/**
* This method updates the coach
* @param request : CreateCoachRequest
*
* @param request : CreateCoachRequest
* @param authHeader : String
* @return : AuthenticationResponse
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/nimshub/biobeacon/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public PasswordEncoder passwordEncoder() {
}

@Bean
public CorsConfigurationSource corsConfigurationSource(){
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(Arrays.asList(
"http://localhost:4200",
"http://192.248.50.238",
"https://d3bljg8pxxqty4.cloudfront.net",
"http://d3bljg8pxxqty4.cloudfront.net")); // Replace with the allowed origins for your application
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); // Configure the allowed HTTP methods
configuration.setAllowedHeaders(Arrays.asList("Content-Type", "Authorization","X-Device-Id","X-Api-Key")); // Configure the allowed headers
configuration.setAllowedHeaders(Arrays.asList("Content-Type", "Authorization", "X-Device-Id", "X-Api-Key")); // Configure the allowed headers
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/nimshub/biobeacon/config/JwtService.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private Key getSignInKey() {

/**
* This method generates Jwt token with User details
*
* @param userDetails : UserDetails
* @return : String
*/
Expand All @@ -75,6 +76,7 @@ public String generateToken(UserDetails userDetails) {

/**
* This method generates Jwt token with User details and extraClaims
*
* @param extraClaims : Map<String, Object>
* @param userDetails : UserDetails
* @return : String
Expand All @@ -97,6 +99,7 @@ public boolean isTokenValid(String token, UserDetails userDetails) {

/**
* This method checks if the token is expired or not
*
* @param token : String
* @return boolean
*/
Expand All @@ -106,6 +109,7 @@ private boolean isTokenExpired(String token) {

/**
* This method extract the expiration time out of token
*
* @param token : String
* @return Date
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.authorizeHttpRequests()
.requestMatchers("/actuator/**")
.hasAuthority("ADMIN")
.requestMatchers("/api/v1/auth/**", "/","/message/**",
.requestMatchers("/api/v1/auth/**", "/", "/message/**",
"/api/v1/sessions/update-session",
"/api/v1/coaches/get-all",
"/api/v1/coaches/create-coach",
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/com/nimshub/biobeacon/constants/Constants.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.nimshub.biobeacon.constants;

public class Constants {
// creating a private constructor to hide the public implicit one
private Constants() {
throw new IllegalStateException("Constants class");
}
public class Constants {
public static final String NO_DATA = "*";
public static final String BASH = "bash";
public static final String SCRIPT = "python3 ";
public static final String COMMAND = "-c";
public static final String COMMA = ",";
public static final Integer CHUNK_SIZE = 4;
public static final String CYCLING = "0";
public static final String PUSH_UP = "1";
public static final String RUNNING = "2";
public static final String SQUAT = "3";
public static final String TABLE_TENNIS = "4";
public static final String WALKING = "5";
public static final Integer SAMPLING_SIZE = 10;
// creating a private constructor to hide the public implicit one
private Constants() {
throw new IllegalStateException("Constants class");
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/nimshub/biobeacon/email/EmailSender.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.nimshub.biobeacon.email;

public interface EmailSender {
void send(String receiver,String subject,String body);
void send(String receiver, String subject, String body);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.nimshub.biobeacon.email;

import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class SMTPGmailService implements EmailSender{
public class SMTPGmailService implements EmailSender {

private final JavaMailSender mailSender;
Logger logger = LoggerFactory.getLogger(SMTPGmailService.class);

@Override
public void send(String receiver, String subject, String body) {
SimpleMailMessage email = new SimpleMailMessage();
Expand All @@ -19,6 +23,6 @@ public void send(String receiver, String subject, String body) {
email.setText(body);

mailSender.send(email);
System.out.println("Mail has been sent...");
logger.info("Mail has been sent...");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(HttpStatus.BAD_REQUEST)
public class ByteCodeException extends RuntimeException{
public class ByteCodeException extends RuntimeException {
public ByteCodeException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.nimshub.biobeacon.exceptions;

public class MqttConnectionException extends RuntimeException{
public MqttConnectionException(String message) {
super(message);
}
public class MqttConnectionException extends RuntimeException {
public MqttConnectionException(String message) {
super(message);
}
}
Loading

0 comments on commit 2a07f9d

Please sign in to comment.