Skip to content
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# How to run
1 open using intellij idea <br />
2 run the following file src/main/java/com/example/slimfitbackend/SlimFitBackendApplication.java
21 changes: 12 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>1.18.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -44,14 +45,6 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.pmml4s</groupId>
<artifactId>pmml4s_3</artifactId>
Expand Down Expand Up @@ -132,6 +125,16 @@
<artifactId>mapstruct-processor</artifactId>
<version>1.5.5.Final</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,9 @@
@RequiredArgsConstructor
public class SecurityConfiguration {

private static final String[] WHITE_LIST_URL = {"/api/v1/auth/**",
"/v2/api-docs",
"/v3/api-docs",
"/v3/api-docs/**",
"/swagger-resources",
"/swagger-resources/**",
"/configuration/ui",
"/configuration/security",
"/swagger-ui/**",
"/webjars/**",
"/swagger-ui.html"};
@Autowired
private JwtAuthFilter jwtAuthFilter;

@Autowired
private AuthenticationProvider authenticationProvider;

Expand All @@ -53,7 +43,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.sessionCreationPolicy(STATELESS)
.and()
.authenticationProvider(authenticationProvider)
.addFilterBefore(jwtAuthFilter,UsernamePasswordAuthenticationFilter.class);
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);
return http.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.example.slimfitbackend.payload.AuthenticationResponse;
import com.example.slimfitbackend.payload.RegisterRequest;
import com.example.slimfitbackend.service.AuthenticationService;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -22,15 +20,12 @@ public class AuthenticationController {
private AuthenticationService service;

@PostMapping("/register")
public ResponseEntity<AuthenticationResponse> register(
@RequestBody RegisterRequest request
) {
public ResponseEntity<AuthenticationResponse> register(@RequestBody RegisterRequest request) {
return ResponseEntity.ok(service.register(request));
}

@PostMapping("/authenticate")
public ResponseEntity<AuthenticationResponse> authenticate(
@RequestBody AuthenticationRequest request
) {
public ResponseEntity<AuthenticationResponse> authenticate(@RequestBody AuthenticationRequest request) {
return ResponseEntity.ok(service.authenticate(request));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class IntakeRecordController {

@PostMapping("/newRecord")
public IntakeRecordResponse addNewRecord(@RequestBody IntakeRecordRequest intakeRecordRequest) throws Exception {
return intakeRecordService.saveNewIntakeRecord(intakeRecordRequest);
return intakeRecordService.saveNewIntakeRecord(intakeRecordRequest);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example.slimfitbackend.controller;

import com.example.slimfitbackend.payload.UserWeightResponse;
import com.example.slimfitbackend.service.ProgressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/progress")
public class ProgressController {

@Autowired
private ProgressService progressService;

@GetMapping("/actual")
private List<UserWeightResponse> getAllUserWeight() throws Exception {
return progressService.getActualWeightProgress();
}

@GetMapping("/goal")
private List<UserWeightResponse> getUserGoal() throws Exception {
return progressService.getUserGoal();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public class UserActivityController {
private UserActivityService userActivityService;

@PostMapping("/newActivity")
public NewActivityResponse addNewActivity(@RequestBody NewActivityRequest newActivityRequest) throws Exception {
public NewActivityResponse addNewActivity(@RequestBody NewActivityRequest newActivityRequest) {
return userActivityService.addNewActivity(newActivityRequest);
}

@GetMapping("/calorie")
public PredictCalorieResponse getPredictedCal(@Valid PredictCalorieRequest predictCalorieRequest) throws Exception {
public PredictCalorieResponse getPredictedCal(@Valid PredictCalorieRequest predictCalorieRequest) {
return userActivityService.getPredictedCalForAct(predictCalorieRequest);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.slimfitbackend.controller;

import com.example.slimfitbackend.payload.GetUserResponse;
import com.example.slimfitbackend.payload.SaveUserWeightRequest;
import com.example.slimfitbackend.payload.UserWeightResponse;
import com.example.slimfitbackend.payload.SaveUserRequest;
import com.example.slimfitbackend.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -20,8 +22,17 @@ public boolean createNewUser(@RequestBody SaveUserRequest saveUserRequest) {
}

@GetMapping("")
private GetUserResponse getUser() throws Exception {
private GetUserResponse getUser() {
return userService.getUser();
}

@GetMapping("/weight")
private UserWeightResponse getUserWeight() {
return userService.getUserWeightResponse();
}

@PostMapping("/weight")
private UserWeightResponse saveUserWeight(@RequestBody SaveUserWeightRequest saveUserWeightRequest) throws Exception {
return userService.saveUserWeight(saveUserWeightRequest);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.slimfitbackend.exceptions;

public class CustomException extends RuntimeException {

public CustomException() {
super();
}

public CustomException(String message) {
super(message);
}

public CustomException(String message, Throwable cause) {
super(message, cause);
}

public CustomException(Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.slimfitbackend.exceptions;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(CustomException.class)
public ResponseEntity<String> handleException(Exception e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
}
133 changes: 4 additions & 129 deletions src/main/java/com/example/slimfitbackend/model/DailyCalorie.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import jakarta.persistence.*;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Entity
@Data
@Getter
@Setter
@EnableAutoConfiguration
@Table(name = "daily_calorie")
public class DailyCalorie {
Expand Down Expand Up @@ -50,132 +53,4 @@ public class DailyCalorie {
private long dailyActivityActual;

private Date date;

public long getDailyActivityGoal() {
return dailyActivityGoal;
}

public void setDailyActivityGoal(long dailyActivityGoal) {
this.dailyActivityGoal = dailyActivityGoal;
}

public long getDailyActivityActual() {
return dailyActivityActual;
}

public void setDailyActivityActual(long dailyActivityActual) {
this.dailyActivityActual = dailyActivityActual;
}

public long getDailyCalorieId() {
return dailyCalorieId;
}

public void setDailyCalorieId(long dailyCalorieId) {
this.dailyCalorieId = dailyCalorieId;
}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public List<IntakeRecord> getIntakeRecords() {
return intakeRecords;
}

public void setIntakeRecords(List<IntakeRecord> intakeRecords) {
this.intakeRecords = intakeRecords;
}

public long getBreakfastGoal() {
return breakfastGoal;
}

public void setBreakfastGoal(long breakfastGoal) {
this.breakfastGoal = breakfastGoal;
}

public long getBreakfastActual() {
return breakfastActual;
}

public void setBreakfastActual(long breakfastActual) {
this.breakfastActual = breakfastActual;
}

public long getLunchGoal() {
return lunchGoal;
}

public void setLunchGoal(long lunchGoal) {
this.lunchGoal = lunchGoal;
}

public long getLunchActual() {
return lunchActual;
}

public void setLunchActual(long lunchActual) {
this.lunchActual = lunchActual;
}

public long getDinnerGoal() {
return dinnerGoal;
}

public void setDinnerGoal(long dinnerGoal) {
this.dinnerGoal = dinnerGoal;
}

public long getDinnerActual() {
return dinnerActual;
}

public void setDinnerActual(long dinnerActual) {
this.dinnerActual = dinnerActual;
}

public long getSnackGoal() {
return snackGoal;
}

public void setSnackGoal(long snackGoal) {
this.snackGoal = snackGoal;
}

public long getSnackActual() {
return snackActual;
}

public void setSnackActual(long snackActual) {
this.snackActual = snackActual;
}

public long getDailyGoal() {
return dailyGoal;
}

public void setDailyGoal(long dailyGoal) {
this.dailyGoal = dailyGoal;
}

public long getDailyActual() {
return dailyActual;
}

public void setDailyActual(long dailyActual) {
this.dailyActual = dailyActual;
}

public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}
}
Loading