From e6e147af263c67311ca3fc990f17989a98106b2e Mon Sep 17 00:00:00 2001 From: LeoMoulin Date: Mon, 8 Apr 2024 14:50:37 +0200 Subject: [PATCH] Implements the school fees gestion for a student and a payment table containing a history of all the financial transactions of the system --- .../Clyde/EndPoints/MinervalController.java | 11 +++ .../Clyde/EndPoints/MockController.java | 8 +- .../Clyde/EndPoints/PaymentController.java | 42 ++++++++++ .../Repositories/MinervalRepository.java | 2 + .../Clyde/Repositories/PaymentRepository.java | 10 +++ .../Clyde/Services/InscriptionService.java | 19 +++-- .../ovh/herisson/Clyde/Tables/Payment.java | 84 +++++++++++++++++++ frontend/src/Apps/Inscription.vue | 3 + frontend/src/Apps/Profil.vue | 59 +++++++++++-- frontend/src/rest/minerval.js | 9 ++ frontend/src/rest/payment.js | 6 ++ 11 files changed, 238 insertions(+), 15 deletions(-) create mode 100644 backend/src/main/java/ovh/herisson/Clyde/EndPoints/PaymentController.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Repositories/PaymentRepository.java create mode 100644 backend/src/main/java/ovh/herisson/Clyde/Tables/Payment.java create mode 100644 frontend/src/rest/minerval.js create mode 100644 frontend/src/rest/payment.js diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MinervalController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MinervalController.java index 7d93a04..27efc58 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MinervalController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MinervalController.java @@ -13,6 +13,7 @@ import ovh.herisson.Clyde.Tables.Role; import java.util.*; @RestController +@CrossOrigin(originPatterns = "*", allowCredentials = "true") public class MinervalController { private final AuthenticatorService authServ; private final MinervalRepository mr; @@ -42,4 +43,14 @@ public class MinervalController { Minerval m = mlist.get(0); return new ResponseEntity<>(m, HttpStatus.OK); } + + @PatchMapping("/minerval") + public ResponseEntity updateMinerval(@RequestBody Minerval updatedMinerval){ + Minerval minerval = mr.findById(updatedMinerval.getId()); + + minerval.setPaidAmount(updatedMinerval.getPaidAmount()); + minerval.setToPay(updatedMinerval.getToPay()); + mr.save(minerval); + return new ResponseEntity<>(HttpStatus.OK); + } } diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java index 3fda0d5..0a5d145 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/MockController.java @@ -2,6 +2,7 @@ package ovh.herisson.Clyde.EndPoints; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.web.bind.annotation.*; +import ovh.herisson.Clyde.Repositories.MinervalRepository; import ovh.herisson.Clyde.Repositories.TokenRepository; import ovh.herisson.Clyde.Repositories.UserCurriculumRepository; import ovh.herisson.Clyde.Repositories.UserRepository; @@ -29,7 +30,9 @@ public class MockController { public final UserCurriculumRepository ucr; - public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService, UserCurriculumRepository ucr){ + public final MinervalRepository minervalRepository; + + public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService, UserCurriculumRepository ucr, MinervalRepository minervalRepository){ this.tokenRepo = tokenRepo; this.userRepo = userRepo; this.tokenService = tokenService; @@ -38,6 +41,7 @@ public class MockController { this.courseService = courseService; this.inscriptionService = inscriptionService; this.ucr = ucr; + this.minervalRepository = minervalRepository; } /** Saves an example of each user type by : @@ -61,6 +65,8 @@ public class MockController { userRepo.saveAll(mockUsers); + Minerval minerval = new Minerval(joe.getRegNo(), 0, 852, 2023); + minervalRepository.save(minerval); // Course / Curriculum part Curriculum infoBab1 = new Curriculum(1,"info"); diff --git a/backend/src/main/java/ovh/herisson/Clyde/EndPoints/PaymentController.java b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/PaymentController.java new file mode 100644 index 0000000..b2bf755 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/EndPoints/PaymentController.java @@ -0,0 +1,42 @@ +package ovh.herisson.Clyde.EndPoints; + + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import ovh.herisson.Clyde.Repositories.PaymentRepository; +import ovh.herisson.Clyde.Responses.UnauthorizedResponse; +import ovh.herisson.Clyde.Tables.Minerval; +import ovh.herisson.Clyde.Tables.Payment; +import ovh.herisson.Clyde.Tables.Role; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.GregorianCalendar; + +@RestController +@CrossOrigin(originPatterns = "*", allowCredentials = "true") +public class PaymentController { + + private final PaymentRepository paymentRepository; + + public PaymentController(PaymentRepository paymentRepository){ + this.paymentRepository = paymentRepository; + } + + //Post a payment record + @PostMapping("/payment") + public ResponseEntity postPayment(@RequestBody Payment payment){ + paymentRepository.save(payment); + return new ResponseEntity<>(HttpStatus.OK); + } + + + //Get all payment records of a student + @GetMapping("/payment/{studentRegNo}") + public ResponseEntity> getPaymentsByUser(@PathVariable long studentRegNo){ + ArrayList toReturn = paymentRepository.getPaymentsByStudentRegNo(studentRegNo); + return new ResponseEntity<>(toReturn, HttpStatus.OK); + } + +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/MinervalRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/MinervalRepository.java index 37c46d7..5af1cab 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Repositories/MinervalRepository.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/MinervalRepository.java @@ -7,4 +7,6 @@ import java.util.ArrayList; public interface MinervalRepository extends CrudRepository { public ArrayList getMinervalsByStudentRegNoOrderByYearDesc(Long studentRegNo); + + public Minerval findById(long id); } diff --git a/backend/src/main/java/ovh/herisson/Clyde/Repositories/PaymentRepository.java b/backend/src/main/java/ovh/herisson/Clyde/Repositories/PaymentRepository.java new file mode 100644 index 0000000..2e196f4 --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Repositories/PaymentRepository.java @@ -0,0 +1,10 @@ +package ovh.herisson.Clyde.Repositories; + +import org.springframework.data.repository.CrudRepository; +import ovh.herisson.Clyde.Tables.Payment; + +import java.util.ArrayList; + +public interface PaymentRepository extends CrudRepository { + public ArrayList getPaymentsByStudentRegNo(long regNo); +} diff --git a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java index 48e2717..8e31b39 100644 --- a/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java +++ b/backend/src/main/java/ovh/herisson/Clyde/Services/InscriptionService.java @@ -2,14 +2,8 @@ package ovh.herisson.Clyde.Services; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; -import ovh.herisson.Clyde.Repositories.CurriculumRepository; -import ovh.herisson.Clyde.Repositories.InscriptionRepository; -import ovh.herisson.Clyde.Repositories.UserCurriculumRepository; -import ovh.herisson.Clyde.Repositories.UserRepository; -import ovh.herisson.Clyde.Tables.InscriptionRequest; -import ovh.herisson.Clyde.Tables.RequestState; -import ovh.herisson.Clyde.Tables.User; -import ovh.herisson.Clyde.Tables.UserCurriculum; +import ovh.herisson.Clyde.Repositories.*; +import ovh.herisson.Clyde.Tables.*; @Service public class InscriptionService { @@ -22,14 +16,16 @@ public class InscriptionService { private final CurriculumRepository curriculumRepo; + private final MinervalRepository minervalRepository; private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); - public InscriptionService(InscriptionRepository inscriptionRepo, UserRepository userRepo, UserCurriculumRepository userCurriculumRepo, CurriculumRepository curriculumRepo){ + public InscriptionService(InscriptionRepository inscriptionRepo, UserRepository userRepo, UserCurriculumRepository userCurriculumRepo, CurriculumRepository curriculumRepo, MinervalRepository minervalRepository){ this.inscriptionRepo = inscriptionRepo; this.userRepo = userRepo; this.userCurriculumRepo = userCurriculumRepo; this.curriculumRepo = curriculumRepo; + this.minervalRepository = minervalRepository; } public InscriptionRequest save(InscriptionRequest inscriptionRequest){ @@ -82,6 +78,11 @@ public class InscriptionService { userRepo.save(userFromRequest); userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId()),0)); + + //Create a minerval for the new student + Minerval minerval = new Minerval(userFromRequest.getRegNo(), 0, 852, 2023); + minervalRepository.save(minerval); + } inscrRequest.setState(requestState); save(inscrRequest); diff --git a/backend/src/main/java/ovh/herisson/Clyde/Tables/Payment.java b/backend/src/main/java/ovh/herisson/Clyde/Tables/Payment.java new file mode 100644 index 0000000..ae4189e --- /dev/null +++ b/backend/src/main/java/ovh/herisson/Clyde/Tables/Payment.java @@ -0,0 +1,84 @@ +package ovh.herisson.Clyde.Tables; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; + +import java.util.Date; + +@Entity +public class Payment { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + private long studentRegNo; + private String card; + private String client; + private Date expDate; + private int amount; + private Date date; + public Payment(){} + + public Payment(long studentRegNo, String card, String client, Date expDate, int amount, Date date){ + this.studentRegNo = studentRegNo; + this.card = card; + this.client = client; + this.expDate = expDate; + this.amount = amount; + this.date = date; + } + + public long getStudentRegNo() { + return studentRegNo; + } + + public void setStudentRegNo(long studentRegNo) { + this.studentRegNo = studentRegNo; + } + + public String getCard() { + return card; + } + + public void setCard(String card) { + this.card = card; + } + + public String getClient() { + return client; + } + + public void setClient(String client) { + this.client = client; + } + + public Date getExpDate() { + return expDate; + } + + public void setExpDate(Date expDate) { + this.expDate = expDate; + } + + public int getAmount() { + return amount; + } + + public void setAmount(int amount) { + this.amount = amount; + } + + public long getId() { + return id; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } +} diff --git a/frontend/src/Apps/Inscription.vue b/frontend/src/Apps/Inscription.vue index 2788cf5..7069c9e 100644 --- a/frontend/src/Apps/Inscription.vue +++ b/frontend/src/Apps/Inscription.vue @@ -12,6 +12,9 @@ async function upPage(id,review){ await validateRegister(id,review); + if (review == "Accepted"){ + + } requests.value = await getAllRegisters(); } diff --git a/frontend/src/Apps/Profil.vue b/frontend/src/Apps/Profil.vue index 2471429..4d6052f 100644 --- a/frontend/src/Apps/Profil.vue +++ b/frontend/src/Apps/Profil.vue @@ -6,12 +6,15 @@ import i18n from "@/i18n.js" import { uploadProfilePicture } from '@/rest/uploads.js' import CourseList from "@/Apps/CourseList.vue"; + import {editMinerval, getCurrentMinerval} from "@/rest/minerval.js"; + import {postPayment} from "@/rest/payment.js"; const user = ref(await getSelf()); const UserCurriculum = ref(""); const curricula = ref (await getAllCurriculums()); - + const minerv = ref({}); if(user.value.role === "Student"){ + minerv.value = ref(await getCurrentMinerval(user.value.regNo)); UserCurriculum.value = await getSomeonesCurriculumList(user.value.regNo); } @@ -22,7 +25,8 @@ const curric = ref(false); const reg = ref(false); const courseslist = ref(false); - + const minerval = ref(false); + const paymentPage = ref(false); const pattern = { profilPictureUrl:null, email:null, @@ -37,7 +41,16 @@ id:null, } - + //Used to modelize a payment + const paymentData={ + studentRegNo: user.value.regNo, + date:null, + card:null, + client:null, + expDate:null, + amount: null + } + const paymentAmount = ref(0); let toModify= Object.assign({}, pattern); let personnalInfos = Object.assign({}, patternInfos); @@ -117,7 +130,7 @@
-
+
{{user.firstName}} {{user.lastName}}
@@ -142,6 +155,42 @@
+ +
+
+
+
+ Payment : {{minerv.value.toPay}}€ left to pay +
+ +
+
+ +
+
+
+ Payment : School fees have already been paid this year +
+
+
+ Proceed to payment of {{paymentAmount}}€ +
+ Client: + +
+
+ Card: + +
+
+ ExpDate: + +
+
+ +
+
+
@@ -207,7 +256,7 @@
-
+
Anciens Cursus diff --git a/frontend/src/rest/minerval.js b/frontend/src/rest/minerval.js new file mode 100644 index 0000000..1606678 --- /dev/null +++ b/frontend/src/rest/minerval.js @@ -0,0 +1,9 @@ +import {restGet, restPatch, restPost} from "@/rest/restConsumer.js"; + +export async function getCurrentMinerval(userRegNo){ + return restGet("/minerval/"+userRegNo) +} + +export async function editMinerval(updatedMinerval){ + return restPatch("/minerval", updatedMinerval) +} diff --git a/frontend/src/rest/payment.js b/frontend/src/rest/payment.js new file mode 100644 index 0000000..a194457 --- /dev/null +++ b/frontend/src/rest/payment.js @@ -0,0 +1,6 @@ +import {restPost} from "@/rest/restConsumer.js"; + +export async function postPayment(payment){ + return restPost("/payment", payment) +} +