Initial commit - nettoyage et initialisation

This commit is contained in:
2026-05-19 22:01:18 +02:00
commit ee85d38c43
51 changed files with 2333 additions and 0 deletions
@@ -0,0 +1,15 @@
package com.astalange.web;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication(scanBasePackages = "com.astalange")
@EntityScan(basePackages = "com.astalange.core.entity")
@EnableJpaRepositories(basePackages = "com.astalange.core.repository")
public class AsTalangeApplication {
public static void main(String[] args) {
SpringApplication.run(AsTalangeApplication.class, args);
}
}
@@ -0,0 +1,55 @@
package com.astalange.web.config;
import com.astalange.core.security.UserDetailsServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.argon2.Argon2PasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
public class SecurityConfig {
private final UserDetailsServiceImpl userDetailsService;
public SecurityConfig(UserDetailsServiceImpl userDetailsService) {
this.userDetailsService = userDetailsService;
}
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(auth -> auth
.requestMatchers("/css/**", "/js/**", "/images/**").permitAll()
.anyRequest().authenticated()
)
.formLogin(form -> form
.loginPage("/login")
.defaultSuccessUrl("/", true)
.permitAll()
)
.logout(logout -> logout
.logoutSuccessUrl("/login?logout")
.permitAll()
);
return http.build();
}
@Bean
public PasswordEncoder passwordEncoder() {
return Argon2PasswordEncoder.defaultsForSpringSecurity_v5_8();
}
@Bean
public AuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService);
authProvider.setPasswordEncoder(passwordEncoder());
return authProvider;
}
}
@@ -0,0 +1,74 @@
package com.astalange.web.controller;
import com.astalange.core.entity.Adherent;
import com.astalange.core.repository.AdherentRepository;
import com.astalange.core.repository.CategorieRepository;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
@Controller
@RequestMapping("/adherents")
public class AdherentController {
private final AdherentRepository adherentRepository;
private final CategorieRepository categorieRepository;
private final com.astalange.core.repository.LicenceRepository licenceRepository;
private final com.astalange.core.repository.ModePaiementRepository modePaiementRepository;
public AdherentController(AdherentRepository adherentRepository, CategorieRepository categorieRepository, com.astalange.core.repository.LicenceRepository licenceRepository, com.astalange.core.repository.ModePaiementRepository modePaiementRepository) {
this.adherentRepository = adherentRepository;
this.categorieRepository = categorieRepository;
this.licenceRepository = licenceRepository;
this.modePaiementRepository = modePaiementRepository;
}
@GetMapping
public String listAdherents(Model model) {
List<Adherent> adherents = adherentRepository.findAll();
model.addAttribute("adherents", adherents);
return "adherents/list";
}
@GetMapping("/new")
public String showCreateForm(Model model) {
model.addAttribute("adherent", new Adherent());
return "adherents/form";
}
@org.springframework.web.bind.annotation.PostMapping
public String saveAdherent(
@jakarta.validation.Valid @org.springframework.web.bind.annotation.ModelAttribute("adherent") Adherent adherent,
org.springframework.validation.BindingResult result,
Model model) {
if (result.hasErrors()) {
return "adherents/form";
}
adherentRepository.save(adherent);
return "redirect:/adherents";
}
@GetMapping("/{id}/edit")
public String editAdherent(@org.springframework.web.bind.annotation.PathVariable Long id, Model model) {
Adherent adherent = adherentRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("Adhérent invalide : " + id));
model.addAttribute("adherent", adherent);
model.addAttribute("categories", categorieRepository.findAll());
model.addAttribute("licences", licenceRepository.findByAdherentId(id));
model.addAttribute("modesPaiement", modePaiementRepository.findAll());
return "adherents/form";
}
@org.springframework.web.bind.annotation.PostMapping("/{id}/delete")
public String deleteAdherent(@org.springframework.web.bind.annotation.PathVariable Long id) {
Adherent adherent = adherentRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("Adhérent invalide : " + id));
adherentRepository.delete(adherent);
return "redirect:/adherents";
}
}
@@ -0,0 +1,52 @@
package com.astalange.web.controller;
import com.astalange.core.entity.Categorie;
import com.astalange.core.repository.CategorieRepository;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
@Controller
@RequestMapping("/categories")
public class CategorieController {
private final CategorieRepository categorieRepository;
public CategorieController(CategorieRepository categorieRepository) {
this.categorieRepository = categorieRepository;
}
@GetMapping
public String listCategories(Model model) {
model.addAttribute("categories", categorieRepository.findAll());
return "parametrage/categories_list";
}
@GetMapping("/new")
public String showCreateForm(Model model) {
model.addAttribute("categorie", new Categorie());
return "parametrage/categories_form";
}
@GetMapping("/{id}/edit")
public String showEditForm(@PathVariable Long id, Model model) {
Categorie categorie = categorieRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("Invalid category ID: " + id));
model.addAttribute("categorie", categorie);
return "parametrage/categories_form";
}
@PostMapping
public String saveCategorie(@ModelAttribute("categorie") Categorie categorie) {
categorieRepository.save(categorie);
return "redirect:/categories";
}
@PostMapping("/{id}/delete")
public String deleteCategorie(@PathVariable Long id) {
Categorie categorie = categorieRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("Invalid category ID: " + id));
categorieRepository.delete(categorie);
return "redirect:/categories";
}
}
@@ -0,0 +1,71 @@
package com.astalange.web.controller;
import com.astalange.core.entity.Adherent;
import com.astalange.core.repository.AdherentRepository;
import com.astalange.core.repository.LicenceRepository;
import com.astalange.core.repository.PaiementRepository;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import java.math.BigDecimal;
import java.util.List;
@Controller
public class HomeController {
private final AdherentRepository adherentRepository;
private final LicenceRepository licenceRepository;
private final PaiementRepository paiementRepository;
public HomeController(AdherentRepository adherentRepository, LicenceRepository licenceRepository, PaiementRepository paiementRepository) {
this.adherentRepository = adherentRepository;
this.licenceRepository = licenceRepository;
this.paiementRepository = paiementRepository;
}
@GetMapping("/")
public String home(Model model, Authentication authentication) {
if (authentication != null) {
model.addAttribute("username", authentication.getName());
}
long totalAdherents = adherentRepository.count();
long licencesBrouillon = licenceRepository.countByEtat("Brouillon");
long licencesValidees = licenceRepository.countByEtat("Validée");
long licencesPayees = licenceRepository.countByEtat("Payée");
BigDecimal totalEncaisse = paiementRepository.sumMontant();
if (totalEncaisse == null) totalEncaisse = BigDecimal.ZERO;
List<com.astalange.core.entity.Licence> allLicences = licenceRepository.findAll();
BigDecimal totalAttendu = allLicences.stream()
.map(lic -> {
if (lic.getCategorie() == null) return BigDecimal.ZERO;
return (lic.getAdherent() != null && lic.getAdherent().isResidentTalange())
? lic.getCategorie().getTarifBase()
: lic.getCategorie().getTarifExterieur();
})
.reduce(BigDecimal.ZERO, BigDecimal::add);
BigDecimal resteARecouvrer = totalAttendu.subtract(totalEncaisse);
if (resteARecouvrer.compareTo(BigDecimal.ZERO) < 0) resteARecouvrer = BigDecimal.ZERO;
List<Adherent> derniersInscrits = adherentRepository.findTop5ByOrderByIdDesc();
model.addAttribute("totalAdherents", totalAdherents);
model.addAttribute("licencesBrouillon", licencesBrouillon);
model.addAttribute("licencesActives", licencesValidees + licencesPayees);
model.addAttribute("totalEncaisse", totalEncaisse);
model.addAttribute("resteARecouvrer", resteARecouvrer);
model.addAttribute("derniersInscrits", derniersInscrits);
return "index";
}
@GetMapping("/login")
public String login() {
return "login";
}
}
@@ -0,0 +1,49 @@
package com.astalange.web.controller;
import com.astalange.core.entity.Adherent;
import com.astalange.core.entity.Categorie;
import com.astalange.core.entity.Licence;
import com.astalange.core.repository.AdherentRepository;
import com.astalange.core.repository.CategorieRepository;
import com.astalange.core.repository.LicenceRepository;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class LicenceController {
private final AdherentRepository adherentRepository;
private final CategorieRepository categorieRepository;
private final LicenceRepository licenceRepository;
public LicenceController(AdherentRepository adherentRepository, CategorieRepository categorieRepository, LicenceRepository licenceRepository) {
this.adherentRepository = adherentRepository;
this.categorieRepository = categorieRepository;
this.licenceRepository = licenceRepository;
}
@PostMapping("/adherents/{id}/licences")
public String addLicence(
@PathVariable Long id,
@RequestParam Long categorieId,
@RequestParam String saison,
@RequestParam String etat) {
Adherent adherent = adherentRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("Invalid Adherent ID"));
Categorie categorie = categorieRepository.findById(categorieId)
.orElseThrow(() -> new IllegalArgumentException("Invalid Categorie ID"));
Licence licence = new Licence();
licence.setAdherent(adherent);
licence.setCategorie(categorie);
licence.setSaison(saison);
licence.setEtat(etat);
licenceRepository.save(licence);
return "redirect:/adherents/" + id + "/edit";
}
}
@@ -0,0 +1,52 @@
package com.astalange.web.controller;
import com.astalange.core.entity.ModePaiement;
import com.astalange.core.repository.ModePaiementRepository;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
@Controller
@RequestMapping("/modespaiement")
public class ModePaiementController {
private final ModePaiementRepository modePaiementRepository;
public ModePaiementController(ModePaiementRepository modePaiementRepository) {
this.modePaiementRepository = modePaiementRepository;
}
@GetMapping
public String listModes(Model model) {
model.addAttribute("modes", modePaiementRepository.findAll());
return "parametrage/modespaiement_list";
}
@GetMapping("/new")
public String showCreateForm(Model model) {
model.addAttribute("modePaiement", new ModePaiement());
return "parametrage/modespaiement_form";
}
@GetMapping("/{id}/edit")
public String showEditForm(@PathVariable Long id, Model model) {
ModePaiement mode = modePaiementRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("Invalid ID: " + id));
model.addAttribute("modePaiement", mode);
return "parametrage/modespaiement_form";
}
@PostMapping
public String saveMode(@ModelAttribute("modePaiement") ModePaiement modePaiement) {
modePaiementRepository.save(modePaiement);
return "redirect:/modespaiement";
}
@PostMapping("/{id}/delete")
public String deleteMode(@PathVariable Long id) {
ModePaiement mode = modePaiementRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("Invalid ID: " + id));
modePaiementRepository.delete(mode);
return "redirect:/modespaiement";
}
}
@@ -0,0 +1,60 @@
package com.astalange.web.controller;
import com.astalange.core.entity.Licence;
import com.astalange.core.entity.ModePaiement;
import com.astalange.core.entity.Paiement;
import com.astalange.core.repository.LicenceRepository;
import com.astalange.core.repository.ModePaiementRepository;
import com.astalange.core.repository.PaiementRepository;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.math.BigDecimal;
import java.time.LocalDate;
@Controller
public class PaiementController {
private final LicenceRepository licenceRepository;
private final ModePaiementRepository modePaiementRepository;
private final PaiementRepository paiementRepository;
public PaiementController(LicenceRepository licenceRepository, ModePaiementRepository modePaiementRepository, PaiementRepository paiementRepository) {
this.licenceRepository = licenceRepository;
this.modePaiementRepository = modePaiementRepository;
this.paiementRepository = paiementRepository;
}
@PostMapping("/licences/{id}/paiements")
public String addPaiement(
@PathVariable Long id,
@RequestParam Long adherentId,
@RequestParam BigDecimal montant,
@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate datePaiement,
@RequestParam Long modePaiementId) {
Licence licence = licenceRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("Invalid Licence ID"));
ModePaiement mode = modePaiementRepository.findById(modePaiementId)
.orElseThrow(() -> new IllegalArgumentException("Invalid ModePaiement ID"));
// Validation basique pour ne pas payer plus que le reste à payer
if (montant.compareTo(licence.getResteAPayer()) > 0) {
montant = licence.getResteAPayer();
}
if (montant.compareTo(BigDecimal.ZERO) > 0) {
Paiement paiement = new Paiement();
paiement.setLicence(licence);
paiement.setModePaiement(mode);
paiement.setMontant(montant);
paiement.setDatePaiement(datePaiement);
paiementRepository.save(paiement);
}
return "redirect:/adherents/" + adherentId + "/edit";
}
}