I have a API in JavaSpring and i want to know how can i get All “Finances” by user id, relly got stuck on that and i want to send a body to the API that sends a UserId and get all Finance matching the user
@Entity
@Table(name = "finance")
public class Finance {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private User user;
@Column(nullable = false)
private String title;
private String description;
@Column(nullable = false)
private String date;
@Column(nullable = false)
private Integer value;
My code is like this now and i have no idea what i am doing, i try to create the repository just to find out that i dont know to do that
Service:
public ResponseEntity<Object> GetFinanceByUserId(Integer userId) {
List<Finance> userFinances = financeRepository.findByUserId(userId);
return new ResponseEntity<>(userFinances, HttpStatus.OK);
}
Repository:
public interface FinanceRepository extends JpaRepository<Finance, Integer> {
List<Finance> findByUserId(Integer userId);
}
New contributor
Dilker Winter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.