Skip to content

Commit

Permalink
Refactoring #20 #17 #6
Browse files Browse the repository at this point in the history
  • Loading branch information
SMore-Napi committed Oct 5, 2021
1 parent 84cab4e commit 8b94fa8
Show file tree
Hide file tree
Showing 30 changed files with 752 additions and 317 deletions.
15 changes: 4 additions & 11 deletions src/main/java/innotutor/innotutor_backend/DTO/UserDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,10 @@ of this software and associated documentation files (the "Software"), to deal
*/
package innotutor.innotutor_backend.DTO;

import innotutor.innotutor_backend.DTO.card.CardDTO;
import innotutor.innotutor_backend.DTO.enrollment.AssignedCardsDTO;
import innotutor.innotutor_backend.DTO.enrollment.RequestedStudentsListDTO;
import innotutor.innotutor_backend.DTO.enrollment.RespondedTutorsListDTO;
import innotutor.innotutor_backend.DTO.session.SessionsListDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -45,15 +38,15 @@ public class UserDTO {
private String contacts;
private String description;
// Upcoming events
private SessionsListDTO sessionsList;
//private SessionsListDTO sessionsList;
// You provide help via creating own CV cards
//private List<CardDTO> servicesList;
// Students who requested to your CV cards
//private RequestedStudentsListDTO myStudentsList;
// You ask for help via creating own Request Card
private List<CardDTO> requestsList;
//private List<CardDTO> requestsList;
// Tutors who responded to your Request cards
private RespondedTutorsListDTO myTutorsList;
//private RespondedTutorsListDTO myTutorsList;
// Cards to which you assigned or asked to be
private AssignedCardsDTO assignedCardsList;
//private AssignedCardsDTO assignedCardsList;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ public class StudentRequestDTO implements UserCard {
private String subject;
private List<String> sessionFormat;
private List<String> sessionType;

@Override
public Long getCreatorId() {
return studentId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public class TutorCvDTO implements UserCard {
private String subject;
private List<String> sessionFormat;
private List<String> sessionType;

@Override
public Long getCreatorId() {
return tutorId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.List;

public interface UserCard {
Long getCreatorId();

String getSubject();

List<String> getSessionFormat();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ of this software and associated documentation files (the "Software"), to deal
SOFTWARE.
*/
package innotutor.innotutor_backend;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;

import java.io.FileInputStream;
import java.io.IOException;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

import java.io.FileInputStream;
import java.io.IOException;

@SpringBootApplication
public class InnotutorBackendApplication {

Expand Down Expand Up @@ -71,8 +71,6 @@ public void firebaseInitialization() throws IOException {
@Bean
@Primary
public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
ObjectMapper objectMapper = builder.build();
return objectMapper;
return builder.build();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,51 @@ of this software and associated documentation files (the "Software"), to deal
package innotutor.innotutor_backend.controller;

import innotutor.innotutor_backend.DTO.card.CardDTO;
import innotutor.innotutor_backend.DTO.enrollment.EnrollmentDTO;
import innotutor.innotutor_backend.security.CustomPrincipal;
import innotutor.innotutor_backend.service.CardEnrollService;
import innotutor.innotutor_backend.service.CardService;
import innotutor.innotutor_backend.service.UserService;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/card", produces = MediaType.APPLICATION_JSON_VALUE)
@CrossOrigin(origins = "*", allowedHeaders = "*", methods = {RequestMethod.POST})
@RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@CrossOrigin(origins = "*", allowedHeaders = "*", methods = {RequestMethod.GET, RequestMethod.POST})
public class CardController {

private final UserService userService;
private final CardService cardService;
private final CardEnrollService cardEnrollService;

public CardController(CardService cardService) {
public CardController(UserService userService, CardService cardService, CardEnrollService cardEnrollService) {
this.userService = userService;
this.cardService = cardService;
this.cardEnrollService = cardEnrollService;
}

@GetMapping(value = "/card/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<CardDTO> getCard(@PathVariable Long id, @AuthenticationPrincipal CustomPrincipal user) {
if (id == null){
new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
CardDTO card = cardService.getCardById(id, userService.getUserId(user));
return card == null
? new ResponseEntity<>(HttpStatus.NOT_FOUND)
: new ResponseEntity<>(card, HttpStatus.OK);
}

@PostMapping(value = "/request-card", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<CardDTO> postRequestCard(@RequestBody CardDTO cardDTO) {
if (cardDTO == null) {
@PostMapping(value = "/enroll", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<EnrollmentDTO> postTutorCardEnroll(@RequestBody EnrollmentDTO enrollmentDTO,
@AuthenticationPrincipal CustomPrincipal user) {
if (enrollmentDTO == null) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
CardDTO result = cardService.postRequestCard(cardDTO);
enrollmentDTO.setEnrollerId(userService.getUserId(user));
EnrollmentDTO result = cardEnrollService.postCardEnroll(enrollmentDTO);
return result == null
? new ResponseEntity<>(HttpStatus.BAD_REQUEST)
: new ResponseEntity<>(result, HttpStatus.CREATED);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
/*
MIT License
Copyright (c) 2021 InnoTutor
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package innotutor.innotutor_backend.controller;

import innotutor.innotutor_backend.DTO.UserDTO;
import innotutor.innotutor_backend.DTO.enrollment.RequestedStudentsListDTO;
import innotutor.innotutor_backend.security.CustomPrincipal;
import innotutor.innotutor_backend.service.CardEnrollService;
Expand All @@ -14,21 +36,21 @@

@RestController
@RequestMapping(value = "/my-students", produces = MediaType.APPLICATION_JSON_VALUE)
@CrossOrigin(origins = "*", allowedHeaders = "*", methods = {RequestMethod.POST, RequestMethod.GET})
public class UserStudentsController {
@CrossOrigin(origins = "*", allowedHeaders = "*", methods = {RequestMethod.GET, RequestMethod.PUT, RequestMethod.DELETE})
public class MyStudentsController {
private final StudentsService studentsService;
private final CardEnrollService cardEnrollService;
private final UserService userService;
public UserStudentsController(StudentsService studentsService, CardEnrollService cardEnrollService, UserService userService) {

public MyStudentsController(StudentsService studentsService, CardEnrollService cardEnrollService, UserService userService) {
this.studentsService = studentsService;
this.cardEnrollService = cardEnrollService;
this.userService = userService;
}

@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RequestedStudentsListDTO> getUserStudentsList(@AuthenticationPrincipal CustomPrincipal user) {
Long userId = userService.getUserId(user);
RequestedStudentsListDTO students = studentsService.getUserStudentsList(userId);
RequestedStudentsListDTO students = studentsService.getUserStudentsList(userService.getUserId(user));
return students == null
? new ResponseEntity<>(HttpStatus.NOT_FOUND)
: new ResponseEntity<>(students, HttpStatus.OK);
Expand All @@ -39,8 +61,7 @@ public ResponseEntity<?> acceptStudent(@PathVariable Long id, @AuthenticationPri
if (id == null) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
Long userId = userService.getUserId(user);
return cardEnrollService.acceptStudent(userId, id)
return cardEnrollService.acceptStudent(userService.getUserId(user), id)
? new ResponseEntity<>(HttpStatus.OK)
: new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
Expand All @@ -50,8 +71,7 @@ public ResponseEntity<?> removeStudent(@PathVariable Long id, @AuthenticationPri
if (id == null) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
Long userId = userService.getUserId(user);
return cardEnrollService.removeStudent(userId, id)
return cardEnrollService.removeStudent(userService.getUserId(user), id)
? new ResponseEntity<>(HttpStatus.OK)
: new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
Expand Down

This file was deleted.

0 comments on commit 8b94fa8

Please sign in to comment.