-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added REST-Endpoint for Contracts with support for HTTP-GET Req…
…uest to get all Contracts
- Loading branch information
1 parent
a62ed86
commit 549f074
Showing
12 changed files
with
280 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dev.urner.volodb.dao; | ||
|
||
import java.util.List; | ||
|
||
import dev.urner.volodb.entity.Contract; | ||
|
||
public interface ContractDAO { | ||
List<Contract> findAll(); | ||
|
||
Contract findById(int contractId); | ||
|
||
List<Contract> findByVolunteerId(int volunteerId); | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/dev/urner/volodb/dao/ContractDAOJpaImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package dev.urner.volodb.dao; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
import dev.urner.volodb.entity.Contract; | ||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.TypedQuery; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class ContractDAOJpaImpl implements ContractDAO { | ||
|
||
private final EntityManager entityManager; | ||
|
||
@Override | ||
public List<Contract> findAll() { | ||
TypedQuery<Contract> query = entityManager.createQuery("from Contract", Contract.class); | ||
return query.getResultList(); | ||
} | ||
|
||
@Override | ||
public Contract findById(int contractId) { | ||
return entityManager.find(Contract.class, contractId); | ||
} | ||
|
||
@Override | ||
public List<Contract> findByVolunteerId(int volunteerId) { | ||
TypedQuery<Contract> query = entityManager | ||
.createQuery( | ||
"SELECT c " + | ||
"FROM Contract c " + | ||
"WHERE c.volunteer.id = :volunteerId", | ||
Contract.class) | ||
.setParameter("volunteerId", volunteerId); | ||
return query.getResultList(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dev.urner.volodb.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Entity | ||
@Table(name = "contactPerson") | ||
@Getter | ||
@Setter | ||
@RequiredArgsConstructor | ||
public class ContactPerson { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id") | ||
private int id; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "person") | ||
private Person person; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "project") | ||
private Project project; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.