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
5 changes: 1 addition & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userProfile")
public class UserController {
Expand Down Expand Up @@ -42,4 +44,10 @@ public ResponseEntity<String> deleteByUserId(@PathVariable String userId){
return new ResponseEntity<>("Success",HttpStatus.OK);

}

@RequestMapping(value = "getByUserName", method = RequestMethod.GET)
public List<User> getByUserName(@RequestParam String username){
List<User> user=userService.searchByUserName(username);
return user;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.scrapbook.UserProfileMicroservice.repository;/* Made by: mehtakaran9 */

import com.scrapbook.UserProfileMicroservice.entity.User;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface UserRepository extends CrudRepository<User, String> {


@Query(value = "SELECT * FROM user_profile WHERE username iLIKE %:username%",nativeQuery = true)
List<User> findByUsernameIgnoreCase(@Param("username") String username);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface UserService {
User updateUser(User user);

void deleteByUserId(String userId);

List<User> searchByUserName(String userName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {
Expand All @@ -28,6 +30,13 @@ public void deleteByUserId(String userId) {
userRepository.delete(userId);
}

@Override
@Transactional(readOnly = true)
public List<User> searchByUserName(String username) {
// System.out.println(userName);
return userRepository.findByUsernameIgnoreCase(username);
}

@Override
public User updateUser(User user) {
User user1 = userRepository.findOne(user.getUserId());
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
# ===============================
spring.datasource.url=jdbc:postgresql://localhost:5432/UserProfile
spring.datasource.username=postgres
spring.datasource.password=lakh
spring.datasource.password=haripooja1415
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.properties.hibernate.dialect =org.hibernate.dialect.PostgreSQLDialect

# ===============================
# = JPA / HIBERNATE
# ===============================
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = create-drop
spring.jpa.hibernate.ddl-auto = update

server.port=8081