Skip to content
Snippets Groups Projects
Commit 1277c778 authored by Theo Vienne's avatar Theo Vienne
Browse files
parents 662adbc3 d3222a45
Branches
No related tags found
No related merge requests found
......@@ -19,7 +19,7 @@ create table requete(
description text
);
create table demande(
create table rendezvous(
email text not null,
rno int not null,
date date not null,
......@@ -34,4 +34,4 @@ create table demande(
insert into calendrier values(TO_DATE('20/09/2024','DD/MM/YYYY'));
insert into utilisateur values ('theo.vienne.etu@univ-lille.fr', 'Theo', 'Vienne', 0619515793, TO_DATE('31/08/2000','DD/MM/YYYY'), 'theovienne');
insert into requete(motif, description) values ('Rhume', 'Douleur au crane');
insert into demande values('theo.vienne.etu@univ-lille.fr',1,TO_DATE('20/09/2024','DD/MM/YYYY'));
\ No newline at end of file
insert into rendezvous values('theo.vienne.etu@univ-lille.fr',1,TO_DATE('20/09/2024','DD/MM/YYYY'));
\ No newline at end of file
package sae.doctolib.dao;
import java.util.List;
import sae.doctolib.dto.Meeting;
public interface DaoMeeting {
public List<Meeting> findAll();
public Meeting findByEmailAndRno(String email, int rno);
public void save(Meeting meeting);
public void removeByEmail(String email);
public void removeByRno(int rno);
public void removeByEmailAndRno(String email, int rno);
public void update(Meeting meeting);
}
package sae.doctolib.dao.implementation;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import sae.doctolib.connection.DS;
import sae.doctolib.dao.DaoMeeting;
import sae.doctolib.dto.Meeting;
public class MeetingService implements DaoMeeting{
private Connection con;
public MeetingService() {
this.con = DS.getConnection();
}
@Override
public List<Meeting> findAll() {
List<Meeting> res = new ArrayList<>();
String request = "SELECT * FROM rendezvous";
try {
Statement stmt = this.con.createStatement();
ResultSet rs = stmt.executeQuery(request);
while(rs.next()){
Date sqlDate = rs.getDate("date");
LocalDate date = sqlDate.toLocalDate();
Meeting meeting = new Meeting(rs.getString("email"), rs.getInt("rno"), date);
res.add(meeting);
}
} catch (SQLException e) {
e.printStackTrace();
}
return res;
}
@Override
public Meeting findByEmailAndRno(String email, int rno) {
Meeting res = null;
String request = "SELECT * FROM rendezvous WHERE email = ? AND rno = ?";
try {
PreparedStatement ps = this.con.prepareStatement(request);
ps.setString(1, email);
ps.setInt(2, rno);
ResultSet rs = ps.executeQuery();
if(rs.next()){
res = new Meeting(rs.getString("email"), rs.getInt("rno"), rs.getDate("date").toLocalDate());
}
} catch (SQLException e) {
e.printStackTrace();
}
return res;
}
@Override
public void save(Meeting meeting) {
String email = meeting.getEmail();
int rno = meeting.getRno();
LocalDate date = meeting.getDate();
String request = "INSERT INTO rendezvous VALUES(" + email + "," + rno + "," + Date.valueOf(date) + ")";
try {
Statement stmt = this.con.createStatement();
stmt.executeUpdate(request);
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
public void removeByEmail(String email) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'removeByEmail'");
}
@Override
public void removeByRno(int rno) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'removeByRno'");
}
@Override
public void removeByEmailAndRno(String email, int rno) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'removeByEmailAndRno'");
}
@Override
public void update(Meeting meeting) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'update'");
}
}
......@@ -2,13 +2,13 @@ package sae.doctolib.dto;
import java.time.LocalDate;
public class Demand {
public class Meeting {
private String email;
private int rno;
private LocalDate date;
public Demand(String email, int rno, LocalDate date) {
public Meeting(String email, int rno, LocalDate date) {
this.email = email;
this.rno = rno;
this.date = date;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment