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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Back-end: Spring Boot Controller Modification

Let's assume we need to modify a controller to handle a new endpoint or adjust existing logic.

FILE_OPERATION: MODIFY spring-backend/src/main/java/com/example/application/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
java
package com.example.application.service;

import com.example.application.model.User;
import com.example.application.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

@Autowired
private UserRepository userRepository;

public List<User> findAllUsers() {
return userRepository.findAll();
}

public User findUserById(Long id) {
return userRepository.findById(id).orElse(null);
}

public User updateUserBio(Long id, String bio) {
User user = userRepository.findById(id).orElse(null);
if (user != null) {
user.setBio(bio);
userRepository.save(user);
}
return user;
}
}