Unverified Commit 2192b59f authored by RoxaneCarraux's avatar RoxaneCarraux Committed by GitHub
Browse files

Merge pull request #14 from Zegorax/add_model_helpProposition

Add model help proposition
parents 7178233e cccad036
Loading
Loading
Loading
Loading
+104 −0
Original line number Diff line number Diff line
package com.example.demo;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import com.example.demo.Mentor;

import org.springframework.format.annotation.DateTimeFormat;


@Entity
@Table(name = "helpproposition")
public class HelpProposition {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column
	private Integer id;

	@Column
	private String matiere;
	
	@Column
	@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")
	private Date dateBegin;

	@Column
	@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")
	private Date dateEnd;
	
	@Column
	private String comment;
	
	@ManyToOne
	private Mentor mentor;

	@ManyToOne
	private Poulain poulain;

	public HelpProposition() {

	}

	public Integer getId() {
		return id;
	}

	public String getMatiere() {
		return matiere;
	}

	public Date getDateBegin() {
		return dateBegin;
	}
	
	public Date getDateEnd() {
		return dateEnd;
	}
	
	public String getComment() {
		return comment;
	}

	public Mentor getMentor(){
		return mentor;
	}

	public Poulain getPoulain(){
		return poulain;
	}
	
	public void setId(Integer id) {
		this.id = id;
	}

	public void setMatiere(String matiere) {
		this.matiere = matiere;
	}

	public void setDateBegin(Date date) {
		this.dateBegin = date;
	}

	public void setDateEnd(Date date) {
		this.dateEnd = date;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public void setMentor(Mentor mentor) {
		this.mentor = mentor;
	}
	
	public void setPoulain(Poulain poulain) {
		this.poulain = poulain;
	}
}
+58 −0
Original line number Diff line number Diff line
package com.example.demo;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import com.example.demo.HelpPropositionRepository;


@Controller
public class HelpPropositionController {
	@Autowired 
	HelpPropositionRepository helpPropositionRepository;
	
    @GetMapping("/allHelpProposition")
	public String getAll(Map<String, Object> model) {
		model.put("helpPropositions", helpPropositionRepository.findAll());
		return "allHelpProposition";
	}

	@GetMapping("/allOpenProposition")
	public String getOpen(Map<String, Object> model) {
		model.put("helpPropositions", helpPropositionRepository.fi());
		return "allHelpProposition";
	}

	@GetMapping("/formHelpProposition")
	public String helpPropositionForm(Model model) {
		model.addAttribute("helpProposition", new HelpProposition());
		return "formHelpProposition";
	}
	
	@PostMapping("/insertHelpProposition")
	public String insertHelpProposition(@ModelAttribute HelpProposition helpProposition, Model model) {
		//TODO : recup le mentor loggé
		Mentor mentor= new Mentor();
		mentor.setId(1);
		helpProposition.setMentor(mentor);

		helpPropositionRepository.save(helpProposition);
		return "formHelpProposition";
	}

	
	@GetMapping("/allPropositionByMentor")
	public String getallPropositionByMentor(Map<String, Object> model) {

		//TODO : recup le mentor loggé
		Mentor mentor = new Mentor();
		mentor.setId(1);
		model.put("helpPropositions", helpPropositionRepository.findByMentor(mentor));
		return "allHelpProposition";
	}

}
+11 −0
Original line number Diff line number Diff line
package com.example.demo;

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

import com.example.demo.HelpProposition;

public interface HelpPropositionRepository extends JpaRepository <HelpProposition, Long>  {
    List<HelpProposition> findByMentor(Mentor mentor);
}
+29 −6
Original line number Diff line number Diff line
@@ -26,8 +26,12 @@ public class HelpRequest {
	private String matiere;
	
	@Column
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	private Date date;
	@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")
	private Date dateBegin;

	@Column
	@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")
	private Date dateEnd;
	
	@Column
	private String comment;
@@ -35,6 +39,10 @@ public class HelpRequest {
	@ManyToOne
	private Poulain poulain;

	@ManyToOne
	private Mentor mentor;


	public HelpRequest() {

	}
@@ -47,8 +55,11 @@ public class HelpRequest {
		return matiere;
	}

	public Date getDate() {
		return date;
	public Date getDateBegin() {
		return dateBegin;
	}
	public Date getDateEnd() {
		return dateEnd;
	}
	
	public String getComment() {
@@ -59,6 +70,10 @@ public class HelpRequest {
		return poulain;
	}

	public Mentor getMentor(){
		return mentor;
	}
	
	public void setId(Integer id) {
		this.id = id;
	}
@@ -67,8 +82,12 @@ public class HelpRequest {
		this.matiere = matiere;
	}

	public void setDate(Date date) {
		this.date = date;
	public void setDateBegin(Date date) {
		this.dateBegin = date;
	}
	
	public void setDateEnd(Date date) {
		this.dateEnd = date;
	}

	public void setComment(String comment) {
@@ -78,4 +97,8 @@ public class HelpRequest {
	public void setPoulain(Poulain poulain) {
		this.poulain = poulain;
	}

	public void setMentor(Poulain poulain) {
		this.poulain = poulain;
	}
}
+5 −0
Original line number Diff line number Diff line
package com.example.demo;

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

import com.example.demo.HelpRequest;

public interface HelpRequestRepository extends JpaRepository <HelpRequest, Long>  {
    List<HelpRequest> findByPoulain(Poulain poulain);

}
Loading