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

Feature/statusupdate #17

Open
wants to merge 18 commits into
base: temp/main1
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
14 changes: 12 additions & 2 deletions backend/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?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">
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>
Expand Down Expand Up @@ -92,10 +92,20 @@
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>4.2.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
).authorizeHttpRequests(t ->
t.requestMatchers("/api/**").permitAll()
.anyRequest().permitAll()
)
.oauth2Login(oauth2Login ->
oauth2Login
.loginPage("/login")
.defaultSuccessUrl("/home", true)
.failureUrl("/login?error=true")
);


return http.build();
}


@Bean
public CorsConfigurationSource corsConfigurationSource() {
final CorsConfiguration configuration = new CorsConfiguration();
Expand All @@ -51,7 +57,5 @@ public CorsConfigurationSource corsConfigurationSource() {
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}

}


}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@

package com.paf.socailfitnessapplication.controller;

import com.paf.socailfitnessapplication.entity.User;
import com.paf.socailfitnessapplication.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/users")
Expand All @@ -16,8 +19,47 @@ public class UserController {

private final UserService userService;

@GetMapping
public List<User> getAllUsers() {
return userService.getAllUsers();
}

@GetMapping("/{id}")
public User getUserById(@PathVariable String id) {
return userService.getUserById(id);
}

@GetMapping("/username/{username}") // New endpoint to get user by username
public User getUserByUsername(@PathVariable String username) {
return userService.getUserByUsername(username);
}

@PostMapping
public User createUser(@RequestBody User user) {
return userService.createUser(user);
}

@PutMapping("/{id}")
public User updateUser(@PathVariable String id, @RequestBody User user) {
return userService.updateUser(id, user);
}

@DeleteMapping("/{id}")
public void deleteUser(@PathVariable String id) {
userService.deleteUser(id);
}

@PostMapping("/authenticate")
public ResponseEntity<?> authenticateUser(@RequestBody Map<String, String> credentials) {
String username = credentials.get("username");
String password = credentials.get("password");
User authenticatedUser = userService.authenticateUser(username, password);

if (authenticatedUser != null) {
return ResponseEntity.ok(authenticatedUser);
} else {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Invalid username or password");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public ResponseEntity<WorkoutStatusUpdateResponseDTO> updateWorkoutStatusUpdate(
return updatedWorkoutStatusUpdate.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}



// Endpoint to delete an existing workout status update by its ID
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteWorkoutStatusUpdate(@PathVariable String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ public class User {
private String id;
private String username;
private String email;
private String password; // Add password field

}
// Add setter method for name
public void setName(String name) {
this.username = name;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface UserRepository extends MongoRepository<User, String> {
Optional<User> findByUsername(String username);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@

package com.paf.socailfitnessapplication.service;

import com.paf.socailfitnessapplication.entity.User;

import java.util.List;

public interface UserService {
List<User> getAllUsers();
User getUserById(String id);
User createUser(User user);
}
User updateUser(String id, User user);
void deleteUser(String id);
User getUserByUsername(String username);
User authenticateUser(String username, String password); // New method for user authentication

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,60 @@
import com.paf.socailfitnessapplication.repo.UserRepository;
import com.paf.socailfitnessapplication.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {

private final UserRepository userRepository;

@Override
public List<User> getAllUsers() {
return userRepository.findAll();
}

@Override
public User getUserById(String id) {
Optional<User> userOptional = userRepository.findById(id);
return userOptional.orElse(null);
}

@Override
public User createUser(User user) {
return userRepository.save(user);
}

@Override
public User updateUser(String id, User user) {
user.setId(id);
return userRepository.save(user);
}
}

@Override
public void deleteUser(String id) {
userRepository.deleteById(id);
}

@Override
public User getUserByUsername(String username) {
Optional<User> userOptional = userRepository.findByUsername(username);
return userOptional.orElse(null);
}

@Override
public User authenticateUser(String username, String password) {
Optional<User> userOptional = userRepository.findByUsername(username);
if (userOptional.isPresent()) {
User user = userOptional.get();
if (user.getPassword().equals(password)) {
return user;
}
}
return null; // Return null if authentication fails
}

}
14 changes: 11 additions & 3 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
spring.application.name=socailfitnessapplication

spring.application.name=socialfitnessapplication

# Cloud connection string
spring.data.mongodb.uri=mongodb+srv://sulakna:[email protected]/Gym_App?retryWrites=true&w=majority

# Server port local
# spring.data.mongodb.uri=mongodb://localhost:27017/mydatabase

spring.data.mongodb.uri=mongodb+srv://sulakna:[email protected]/Gym_App?retryWrites=true&w=majority
# OAuth2 Client Configuration for Google
spring.security.oauth2.client.registration.google.client-id=255847001730-p284moskphraui764jj1nh97asndp6ik.apps.googleusercontent.com
spring.security.oauth2.client.registration.google.client-secret=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

# Additional OAuth2 Configuration for Google
#spring.security.oauth2.client.registration.google.scope=openid,profile,email
#spring.security.oauth2.client.registration.google.redirect-uri={baseUrl}/login/oauth2/code/google
14 changes: 11 additions & 3 deletions backend/target/classes/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
spring.application.name=socailfitnessapplication

spring.application.name=socialfitnessapplication

# Cloud connection string
spring.data.mongodb.uri=mongodb+srv://sulakna:[email protected]/Gym_App?retryWrites=true&w=majority

# Server port local
# spring.data.mongodb.uri=mongodb://localhost:27017/mydatabase

spring.data.mongodb.uri=mongodb+srv://sulakna:[email protected]/Gym_App?retryWrites=true&w=majority
# OAuth2 Client Configuration for Google
spring.security.oauth2.client.registration.google.client-id=255847001730-p284moskphraui764jj1nh97asndp6ik.apps.googleusercontent.com
spring.security.oauth2.client.registration.google.client-secret=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

# Additional OAuth2 Configuration for Google
#spring.security.oauth2.client.registration.google.scope=openid,profile,email
#spring.security.oauth2.client.registration.google.redirect-uri={baseUrl}/login/oauth2/code/google
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading