Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ cp.iml
CP.iml
bin/
.vscode/
.DS_Store
**/application-dev.properties
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.2.0</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/coderscampus/cp/config/NoOpSecurityConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.coderscampus.cp.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//This file completely disables any cors security, for dev only!
@Configuration
public class NoOpSecurityConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedMethods("*");
}
}
37 changes: 33 additions & 4 deletions src/main/java/com/coderscampus/cp/domain/Checkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jakarta.persistence.*;

import java.math.BigInteger;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;

Expand All @@ -22,6 +24,8 @@ public class Checkin {
private Instant endTime;
private CodingType codingType;
private Integer issueNumber;
private BigInteger timeInClassInSeconds;

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "student_id")
private Student student;
Expand Down Expand Up @@ -138,12 +142,28 @@ public void setStudent(Student student) {
this.student = student;
}

public Boolean getSetUp() {
return isSetUp;
}

public void setSetUp(Boolean setUp) {
isSetUp = setUp;
}

public BigInteger getTimeInClassInSeconds() {
return timeInClassInSeconds;
}

public void setTimeInClassInSeconds(BigInteger timeInClassInSeconds) {
this.timeInClassInSeconds = timeInClassInSeconds;
}

// ENUMS
public enum CodingType{
FOUNDATIONS, CRUD, CODE_REVIEW, DESIGN, DOCUMENTATION
}
public enum Role{
FOUNDATIONS, OBSERVER, CODER, GUIDE, SCRUM_MASTER, PRODUCT_OWNER
FOUNDATIONS, OBSERVER, CODER, GUIDE, SCRUM_MASTER, PRODUCT_OWNER
}

@Override
Expand All @@ -152,17 +172,26 @@ public String toString() {
"id=" + id +
", uid='" + uid + '\'' +
", date=" + date +
", assignment=" + nextAssignment +
", nextAssignment=" + nextAssignment +
", blockers=" + blockers +
", blockerDescription='" + blockerDescription + '\'' +
", isSetUp=" + isSetUp +
", available=" + available +
", role=" + role +
", startTime=" + startTime +
", endTime=" + endTime +
", issueNumber=" + issueNumber +
", codingType=" + codingType +
", student=" + student +
", issueNumber=" + issueNumber +
", timeInClassInSeconds=" + timeInClassInSeconds +
'}';
}

public void calculateTimeInClass() {
if (startTime != null && endTime != null) {
long seconds = Duration.between(startTime, endTime).getSeconds();
setTimeInClassInSeconds(BigInteger.valueOf(seconds));
} else {
setTimeInClassInSeconds(BigInteger.ZERO);
}
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/coderscampus/cp/domain/CheckinListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.coderscampus.cp.domain;

import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate;

public class CheckinListener {
@PrePersist
@PreUpdate
public void beforeSave(Checkin checkin) {
checkin.calculateTimeInClass();
}
}
26 changes: 17 additions & 9 deletions src/main/java/com/coderscampus/cp/domain/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
import java.util.ArrayList;
import java.util.List;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;

@Entity
public class Student {
Expand All @@ -21,6 +16,9 @@ public class Student {
private String name;
private Integer assignmentNum;
private String ide;
@Lob
@Column(name = "student_photo", columnDefinition="MEDIUMBLOB")
private byte[] studentPhoto;
// @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
// private GitHub githubHandle;
// @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
Expand All @@ -37,7 +35,8 @@ public class Student {
// private Networking networking;
// @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
// private Website website;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@OneToMany(mappedBy = "student", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JsonIgnore
private List<Checkin> checkin = new ArrayList<Checkin>();


Expand Down Expand Up @@ -89,7 +88,15 @@ public String getIde() {
public void setIde(String ide) {
this.ide = ide;
}
// public GitHub getGithubHandle() {

public byte[] getStudentPhoto() {
return studentPhoto;
}

public void setStudentPhoto(byte[] studentPhoto) {
this.studentPhoto = studentPhoto;
}
// public GitHub getGithubHandle() {
// return githubHandle;
// }
//
Expand Down Expand Up @@ -158,6 +165,7 @@ public List<Checkin> getCheckin() {
return checkin;
}


public void setCheckin(List<Checkin> checkin) {
this.checkin = checkin;
}
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/coderscampus/cp/react/CheckinRestController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.coderscampus.cp.react;

import com.coderscampus.cp.domain.Checkin;
import com.coderscampus.cp.service.CheckinService;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@ComponentScan
@RestController
@RequestMapping("/api/check-in")

public class CheckinRestController {
private final CheckinService checkinService;

public CheckinRestController(CheckinService checkinService) {
this.checkinService = checkinService;
}
@PostMapping("/start-check-in")
public ResponseEntity<Checkin> createAndStartStudentCheckin(
@RequestParam Long studentId) {
Checkin newCheckin = checkinService.createStudentCheckin(studentId);
return ResponseEntity.ok(newCheckin);
}
@PostMapping("/finish-check-in")
public ResponseEntity<Checkin> finishStudentCheckin(
@RequestParam Long studentId) {
Checkin finishedCheckin = checkinService.endStudentCheckin(studentId);
System.out.println("Controller: Finished Checkin with ID: " + finishedCheckin.getId());
return ResponseEntity.ok(finishedCheckin);
}
}
56 changes: 56 additions & 0 deletions src/main/java/com/coderscampus/cp/react/StudentRestController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.coderscampus.cp.react;

import com.coderscampus.cp.domain.Student;
import com.coderscampus.cp.service.StudentService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@ComponentScan
@RestController
@RequestMapping("/api/student")
public class StudentRestController {
private final ObjectMapper objectMapper;
private final StudentService studentService;

public StudentRestController(ObjectMapper objectMapper, StudentService studentService) {
this.objectMapper = objectMapper;
this.studentService = studentService;
}
@GetMapping("/get-one-student")
public ResponseEntity<Student> getOneStudentById(
@RequestParam Long studentId) {
Student requestedStudent = studentService.findById(studentId);
System.out.println("Returning get-one-student: " + requestedStudent);
return ResponseEntity.ok(requestedStudent);
}
@GetMapping("/get-featured-students")
public ResponseEntity<List<Student>> getFeaturedStudentList() {
// List<Student> featuredStudentList = studentService.getFeaturedStudents();
// return ResponseEntity.ok(featuredStudentList);
return null;
}
@PostMapping("/create-student")
public ResponseEntity<Student> createStudent(@RequestBody String rawJson) throws JsonProcessingException {
System.out.println("Received JSON: " + rawJson);
// Convert rawJson back to Student object manually for debugging purposes
Student createStudentRequest = objectMapper.readValue(rawJson, Student.class);
System.out.println("Create student request name: " + createStudentRequest.getName());
Student newStudent = studentService.save(createStudentRequest);
return ResponseEntity.ok(newStudent);
}
@PostMapping("/update-student-photo")
public ResponseEntity<Student> updatePhoto(
@RequestParam("studentId") Long studentId,
@RequestParam("studentImage") MultipartFile studentImage) throws IOException {
System.out.println("Create student request id: " + studentId);
Student updatedStudent = studentService.updateStudentPhoto(studentId, studentImage.getBytes());
return ResponseEntity.ok(updatedStudent);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.coderscampus.cp.repository;
import com.coderscampus.cp.domain.Checkin;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface CheckinRepository extends JpaRepository<Checkin, Long> {
@Query("SELECT c FROM Checkin c WHERE c.student.id = :studentId AND c.endTime IS NULL")
Optional<Checkin> findByStudentIdAndCheckoutTimeIsNull(Long studentId);
}


Loading