feat(collab): add My Requests & Applications dashboard with Accept/Reject applicant workflow
Some checks failed
Deploy RIT Freshers Hub to VPS / Deploy to Live VPS (push) Has been cancelled
Some checks failed
Deploy RIT Freshers Hub to VPS / Deploy to Live VPS (push) Has been cancelled
This commit is contained in:
@@ -32,6 +32,16 @@ public class CollabController {
|
|||||||
return collabRequestRepository.findAllByOrderByCreatedAtDesc();
|
return collabRequestRepository.findAllByOrderByCreatedAtDesc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/my-requests")
|
||||||
|
public List<CollabRequest> getMyCollabRequests(@RequestParam String email) {
|
||||||
|
return collabRequestRepository.findByAuthorEmailOrderByCreatedAtDesc(email);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/my-applications")
|
||||||
|
public List<CollabApplication> getMyCollabApplications(@RequestParam String email) {
|
||||||
|
return collabApplicationRepository.findByApplicantEmailOrderByCreatedAtDesc(email);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public ResponseEntity<CollabRequest> getCollabRequestById(@PathVariable Integer id) {
|
public ResponseEntity<CollabRequest> getCollabRequestById(@PathVariable Integer id) {
|
||||||
return collabRequestRepository.findById(id)
|
return collabRequestRepository.findById(id)
|
||||||
@@ -39,6 +49,11 @@ public class CollabController {
|
|||||||
.orElse(ResponseEntity.notFound().build());
|
.orElse(ResponseEntity.notFound().build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}/applications")
|
||||||
|
public List<CollabApplication> getApplicationsForRequest(@PathVariable Integer id) {
|
||||||
|
return collabApplicationRepository.findByCollabRequestIdOrderByCreatedAtDesc(id);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public CollabRequest createCollabRequest(@RequestBody CollabRequest request) {
|
public CollabRequest createCollabRequest(@RequestBody CollabRequest request) {
|
||||||
if (request.getStatus() == null) request.setStatus("OPEN");
|
if (request.getStatus() == null) request.setStatus("OPEN");
|
||||||
@@ -51,6 +66,22 @@ public class CollabController {
|
|||||||
return collabRequestRepository.save(request);
|
return collabRequestRepository.save(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public ResponseEntity<CollabRequest> updateCollabRequest(
|
||||||
|
@PathVariable Integer id,
|
||||||
|
@RequestBody CollabRequest updated) {
|
||||||
|
return collabRequestRepository.findById(id).map(req -> {
|
||||||
|
if (updated.getProjectIdea() != null) req.setProjectIdea(updated.getProjectIdea());
|
||||||
|
if (updated.getTag() != null) req.setTag(updated.getTag());
|
||||||
|
if (updated.getDepartment() != null) req.setDepartment(updated.getDepartment());
|
||||||
|
if (updated.getYear() != null) req.setYear(updated.getYear());
|
||||||
|
if (updated.getGithubLink() != null) req.setGithubLink(updated.getGithubLink());
|
||||||
|
if (updated.getContactInfo() != null) req.setContactInfo(updated.getContactInfo());
|
||||||
|
if (updated.getCollaboratorsNeeded() != null) req.setCollaboratorsNeeded(updated.getCollaboratorsNeeded());
|
||||||
|
return ResponseEntity.ok(collabRequestRepository.save(req));
|
||||||
|
}).orElse(ResponseEntity.notFound().build());
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/{id}/apply")
|
@PostMapping("/{id}/apply")
|
||||||
public ResponseEntity<CollabApplication> applyToCollabRequest(
|
public ResponseEntity<CollabApplication> applyToCollabRequest(
|
||||||
@PathVariable Integer id,
|
@PathVariable Integer id,
|
||||||
@@ -66,7 +97,7 @@ public class CollabController {
|
|||||||
|
|
||||||
CollabApplication savedApp = collabApplicationRepository.save(application);
|
CollabApplication savedApp = collabApplicationRepository.save(application);
|
||||||
|
|
||||||
// Increment count on parent request
|
// Increment applications count on parent request
|
||||||
request.setApplicationsCount(request.getApplicationsCount() + 1);
|
request.setApplicationsCount(request.getApplicationsCount() + 1);
|
||||||
collabRequestRepository.save(request);
|
collabRequestRepository.save(request);
|
||||||
|
|
||||||
@@ -83,6 +114,7 @@ public class CollabController {
|
|||||||
payload.put("telegram_chat_id", request.getTelegramChatId());
|
payload.put("telegram_chat_id", request.getTelegramChatId());
|
||||||
payload.put("discord_user_id", request.getDiscordUserId());
|
payload.put("discord_user_id", request.getDiscordUserId());
|
||||||
payload.put("applicant_name", savedApp.getApplicantName());
|
payload.put("applicant_name", savedApp.getApplicantName());
|
||||||
|
payload.put("applicant_email", savedApp.getApplicantEmail());
|
||||||
payload.put("applicant_dept", savedApp.getApplicantDept());
|
payload.put("applicant_dept", savedApp.getApplicantDept());
|
||||||
payload.put("applicant_year", savedApp.getApplicantYear());
|
payload.put("applicant_year", savedApp.getApplicantYear());
|
||||||
payload.put("applicant_contact", savedApp.getApplicantContact());
|
payload.put("applicant_contact", savedApp.getApplicantContact());
|
||||||
@@ -108,18 +140,24 @@ public class CollabController {
|
|||||||
app.setStatus(newStatus);
|
app.setStatus(newStatus);
|
||||||
CollabApplication updated = collabApplicationRepository.save(app);
|
CollabApplication updated = collabApplicationRepository.save(app);
|
||||||
|
|
||||||
// Delete request entirely when accepted count meets requested collaborators count
|
// Manage parent request counts
|
||||||
if ("ACCEPTED".equals(newStatus) && !"ACCEPTED".equals(oldStatus)) {
|
CollabRequest parentReq = app.getCollabRequest();
|
||||||
CollabRequest parentReq = app.getCollabRequest();
|
if (parentReq != null) {
|
||||||
if (parentReq != null) {
|
if ("ACCEPTED".equals(newStatus) && !"ACCEPTED".equals(oldStatus)) {
|
||||||
int accepted = (parentReq.getAcceptedCount() == null ? 0 : parentReq.getAcceptedCount()) + 1;
|
int accepted = (parentReq.getAcceptedCount() == null ? 0 : parentReq.getAcceptedCount()) + 1;
|
||||||
parentReq.setAcceptedCount(accepted);
|
parentReq.setAcceptedCount(accepted);
|
||||||
int needed = parentReq.getCollaboratorsNeeded() == null ? 1 : parentReq.getCollaboratorsNeeded();
|
int needed = parentReq.getCollaboratorsNeeded() == null ? 1 : parentReq.getCollaboratorsNeeded();
|
||||||
if (accepted >= needed) {
|
if (accepted >= needed) {
|
||||||
collabRequestRepository.delete(parentReq);
|
parentReq.setStatus("CLOSED");
|
||||||
} else {
|
|
||||||
collabRequestRepository.save(parentReq);
|
|
||||||
}
|
}
|
||||||
|
collabRequestRepository.save(parentReq);
|
||||||
|
} else if (!"ACCEPTED".equals(newStatus) && "ACCEPTED".equals(oldStatus)) {
|
||||||
|
int accepted = Math.max(0, (parentReq.getAcceptedCount() == null ? 0 : parentReq.getAcceptedCount()) - 1);
|
||||||
|
parentReq.setAcceptedCount(accepted);
|
||||||
|
if ("CLOSED".equals(parentReq.getStatus())) {
|
||||||
|
parentReq.setStatus("OPEN");
|
||||||
|
}
|
||||||
|
collabRequestRepository.save(parentReq);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ResponseEntity.ok(updated);
|
return ResponseEntity.ok(updated);
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ public class CollabApplication {
|
|||||||
@Column(name = "applicant_name", nullable = false)
|
@Column(name = "applicant_name", nullable = false)
|
||||||
private String applicantName;
|
private String applicantName;
|
||||||
|
|
||||||
|
@Column(name = "applicant_email")
|
||||||
|
private String applicantEmail;
|
||||||
|
|
||||||
@Column(name = "applicant_dept", nullable = false)
|
@Column(name = "applicant_dept", nullable = false)
|
||||||
private String applicantDept;
|
private String applicantDept;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ import com.rit.portal.entity.CollabApplication;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface CollabApplicationRepository extends JpaRepository<CollabApplication, Integer> {
|
public interface CollabApplicationRepository extends JpaRepository<CollabApplication, Integer> {
|
||||||
|
List<CollabApplication> findByApplicantEmailOrderByCreatedAtDesc(String applicantEmail);
|
||||||
|
List<CollabApplication> findByCollabRequestIdOrderByCreatedAtDesc(Integer collabRequestId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.util.List;
|
|||||||
@Repository
|
@Repository
|
||||||
public interface CollabRequestRepository extends JpaRepository<CollabRequest, Integer> {
|
public interface CollabRequestRepository extends JpaRepository<CollabRequest, Integer> {
|
||||||
List<CollabRequest> findAllByOrderByCreatedAtDesc();
|
List<CollabRequest> findAllByOrderByCreatedAtDesc();
|
||||||
|
List<CollabRequest> findByAuthorEmailOrderByCreatedAtDesc(String authorEmail);
|
||||||
List<CollabRequest> findByTelegramChatIdAndStatusOrderByCreatedAtDesc(Long telegramChatId, String status);
|
List<CollabRequest> findByTelegramChatIdAndStatusOrderByCreatedAtDesc(Long telegramChatId, String status);
|
||||||
List<CollabRequest> findByDiscordUserIdAndStatusOrderByCreatedAtDesc(String discordUserId, String status);
|
List<CollabRequest> findByDiscordUserIdAndStatusOrderByCreatedAtDesc(String discordUserId, String status);
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user