<file_sep>package com.sitevente.app.controllers;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sitevente.app.repositories.ShowsRepository;
import com.sitevente.app.store.Pages;
import com.sitevente.app.store.Shows;

@RestController
@RequestMapping("/pages")
@CrossOrigin(origins = "*")
public class PagesController {
	
	@Autowired
	private ShowsRepository pagesRepository;
	
	public String testRequest(){
		return "Page content";
	}
	
	@RequestMapping("/homepage")
	public Pages getHomePageContent(){
		List<Shows> featuredShows = pagesRepository.findByFeaturedTrue();
		List<String> carousselImages = new ArrayList<>();
		for(Shows show: featuredShows) {
			carousselImages.add(show.getImageUrl());
		}
			
		Pages page = new Pages(carousselImages, featuredShows);
		return page;
		
	}

}
<file_sep>package com.sitevente.app.repositories;

import org.springframework.data.mongodb.repository.MongoRepository;

import com.sitevente.app.store.Sessions;

public interface SessionsRepository  extends MongoRepository<Sessions, String> {
	
	public Sessions findBySessionId(String sessionId);

}
<file_sep>package com.sitevente.app.repositories;

import org.springframework.data.mongodb.repository.MongoRepository;

import com.sitevente.app.store.Orders;

public interface OrdersRepository extends MongoRepository<Orders, String>{

	
	public Orders findByConfirmationNumber(String confirmationNumber);
	
	public Orders findBySessionId(String sessionId);


}
<file_sep>package config;

import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{
	
	private final String GESTIONNAIRE_DE_SALLE = "gestionnairedesalle";
	private final String USERS = "users";
	
	

	@Override
	public void configure(WebSecurity web) throws Exception {
		web.ignoring().antMatchers("/pages/**");
	}

	@Override
	protected void configure(AuthenticationManagerBuilder auth) throws Exception {
		auth.inMemoryAuthentication()
		.withUser("gestionnairedesalle").password("<PASSWORD>").roles(GESTIONNAIRE_DE_SALLE)
		.and();
	}

	@Override
	protected void configure(HttpSecurity http) throws Exception {
		http.authorizeRequests()
			.antMatchers("/gestionnaire/**").hasRole(GESTIONNAIRE_DE_SALLE)
			.and()
			.formLogin();
			
	}

}
<file_sep>spring.data.mongodb.host=ds249818.mlab.com
spring.data.mongodb.port=49818
spring.data.mongodb.database=heroku_z6zwz4vq
spring.data.mongodb.username=labgtivente
spring.data.mongodb.password=<PASSWORD>
<file_sep>package com.sitevente.app.store;

import java.util.Date;

import org.springframework.data.annotation.Id;

public class Tickets {
	
	@Id
	private String id;
	private double price;
	private String artistName;
	private String title;
	private String salleId;
	private Date timeAdded;
	private String showDate;
	private boolean reserved;
	private String showId;
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public double getPrice() {
		return price;
	}
	public void setPrice(double price) {
		this.price = price;
	}
	public String getArtistName() {
		return artistName;
	}
	public void setArtistName(String artistName) {
		this.artistName = artistName;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getSalleId() {
		return salleId;
	}
	public void setSalleId(String salleId) {
		this.salleId = salleId;
	}
	public Date getTimeAdded() {
		return timeAdded;
	}
	public void setTimeAdded(Date timeAdded) {
		this.timeAdded = timeAdded;
	}
	public String getShowDate() {
		return showDate;
	}
	public void setShowDate(String showDate) {
		this.showDate = showDate;
	}
	public boolean isReserved() {
		return reserved;
	}
	public void setReserved(boolean reserved) {
		this.reserved = reserved;
	}
	public String getShowId() {
		return showId;
	}
	public void setShowId(String showId) {
		this.showId = showId;
	}
	

}
<file_sep><project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>


	<groupId>com.ventesbillets.app</groupId>
	<artifactId>rest-api</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>Site Ventes 1 api</name>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.3.RELEASE</version>
	</parent>


	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-mongodb</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.data</groupId>
			<artifactId>spring-data-mongodb</artifactId>
			<version>2.0.8.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
			<scope>provided</scope>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<executable>true</executable>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.7.0</version>
				<executions>
					<!-- Replacing default-compile as it is treated specially by maven -->
					<execution>
						<id>default-compile</id>
						<phase>none</phase>
					</execution>
					<!-- Replacing default-testCompile as it is treated specially by maven -->
					<execution>
						<id>default-testCompile</id>
						<phase>none</phase>
					</execution>
				</executions>
				<configuration>
					<release>1.8</release>
					<verbose>true</verbose>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>com.heroku.sdk</groupId>
				<artifactId>heroku-maven-plugin</artifactId>
				<version>2.0.3</version>
			</plugin>
		</plugins>
	</build>

	<properties>
		<start-class>com.sitevente.app.VentesApiApp</start-class>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
		<start-class>org.springframework.boot.sample.tomcat.SampleTomcatApplication</start-class>
	</properties>


	<repositories>
		<repository>
			<id>spring-releases</id>
			<name>Spring Releases</name>
			<url>https://repo.spring.io/libs-release</url>
		</repository>
	</repositories>
	<pluginRepositories>
		<pluginRepository>
			<id>spring-releases</id>
			<name>Spring Releases</name>
			<url>https://repo.spring.io/libs-release</url>
		</pluginRepository>
	</pluginRepositories>

</project>
<file_sep>package com.sitevente.app.controllers;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.sitevente.app.repositories.ShowsRepository;
import com.sitevente.app.store.Shows;
import com.sitevente.app.store.ShowsTicketsInfo;
import com.sitevente.app.store.Tickets;

@RestController
@RequestMapping("/gestionnaire")
//Devra etre changer pour permettre seulement au gestionnaire de salle d'utiliser ce controlleur
@CrossOrigin(origins = "*")
public class GestionnaireDeSalleController {

	@Autowired
	private ShowsRepository showsRepository;

	/**
	 * Trouver les informations concernant tous les billets
	 * @return
	 */
	@RequestMapping("/shows")
	public List<ShowsTicketsInfo> getShowsTicketsInfo(){
		List<ShowsTicketsInfo> showsInfoList = new ArrayList<>();
		for(Shows show: showsRepository.findAll()){
			ShowsTicketsInfo showTicketsInfo = new ShowsTicketsInfo();
			showTicketsInfo.setArtistName(show.getArtistName());
			showTicketsInfo.setShowId(show.getId());
			showTicketsInfo.setShowTitle(show.getTitle());
			showTicketsInfo.setTicketsAvailable(show.getQtyAvailable());
			showTicketsInfo.setTicketsSold(show.getQtySold());

			showsInfoList.add(showTicketsInfo);
		}
		return showsInfoList;
	}

	/**
	 * Trouver les informations concernant un seul billet
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/shows/{id}")
	public Shows getSingleShowTicketsInfo(@PathVariable String id){
		Shows show = showsRepository.findById(id).get();

		return show;
	}
	
	@RequestMapping(method=RequestMethod.POST, value="/shows")
	public void addShow(@RequestBody List<Shows>showsList){
		for(Shows show: showsList){
			show.setQtyAvailable();
		}
		showsRepository.saveAll(showsList);
		
	}
	

	@RequestMapping(method=RequestMethod.DELETE, value="/shows/{id}")
	public String deleteShow(@PathVariable String id){
		
		if(showsRepository.findById(id).isPresent()){
			showsRepository.deleteById(id);
			return "Spectacle suprime";
		}else{
			return "Le spectacle n'a pas ete trouve";
		}
	}

	@RequestMapping(method=RequestMethod.PATCH, value="/shows/{id}")
	public String editShow(@PathVariable String id, @RequestBody Shows show){
		if(showsRepository.findById(id).isPresent()){
			showsRepository.save(show);
			return "Le spectacle a ete mis a jour";
		}else{
			return "Le spectacle n'a pas pu etre trouve";
		}
	}

	@RequestMapping(value = "/shows/{id}/_terminate", method = RequestMethod.POST)
	public Shows terminateTicketSale(@PathVariable String id){
		if(showsRepository.findById(id).isPresent()){
			showsRepository.findById(id).get().setSaleDone(true);
			return showsRepository.findById(id).get();
		}else{
			return null;
		}
	}
	
	@RequestMapping(value = "/addTickets/{showId}", method = RequestMethod.PATCH)
	public String addTickets(@PathVariable String id, @RequestBody List<Tickets> ticketsList){
		if(showsRepository.findById(id).isPresent()){
			Shows show = showsRepository.findById(id).get();
			show.addTickets(ticketsList);
			showsRepository.save(show);
			return "Les billets ont ete ajoutes";
		}
		
		return "Le spectacle n'a pas ete trouver";
	}
}
<file_sep>package com.sitevente.app.store;

public class PaymentForm {
	
	private String firstName;
	private String lastName;
	private String email;
	private String address;
	private String address2;
	private String country;
	private String region;
	private String postalCode;
	//Ajouter Un Objet de paiement
	private String sessionId;
	
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getAddress2() {
		return address2;
	}
	public void setAddress2(String address2) {
		this.address2 = address2;
	}
	public String getCountry() {
		return country;
	}
	public void setCountry(String country) {
		this.country = country;
	}
	public String getRegion() {
		return region;
	}
	public void setRegion(String region) {
		this.region = region;
	}
	public String getPostalCode() {
		return postalCode;
	}
	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}
	public String getSessionId() {
		return sessionId;
	}
	public void setSessionId(String sessionId) {
		this.sessionId = sessionId;
	}

}
<file_sep># e18-vente1-backend