Skip to content

Commit 01e3a5e

Browse files
committed
Merge branch 'main' into bug/courseInfoNotShowing
# Conflicts: # backend/src/main/java/com/youdemy/controller/CourseController.java # backend/src/main/java/com/youdemy/controller/HomeController.java # backend/src/main/java/com/youdemy/controller/OrderPController.java # backend/src/main/java/com/youdemy/controller/UserController.java # backend/src/main/java/com/youdemy/repository/OrderPRepository.java # backend/src/main/resources/templates/header.html
2 parents f8cd83e + 023619e commit 01e3a5e

18 files changed

+230
-164
lines changed

README.md

Lines changed: 63 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Youdemy
22

3+
Youdemy is a teching platform that empowers teachers to upload unlimited content divided by courses and lessos so that students across the world can access these resources.
4+
35
## Programmers
46

57
| Name | Email | Github |
@@ -9,93 +11,84 @@
911
| Fiorella Hernandez | [email protected] | fiorellaV |
1012
| Jose Manuel De Pablo Cobo | [email protected] | pablocjm |
1113

12-
## Description
13-
14-
Our web application will be a teaching platform where students will be able to acquire courses from teachers around the world.
14+
## PHASE 0: APLICATION FUNCTIONALITIES
1515

16-
## Users
16+
### ENTITIES
1717

18-
- Guest
19-
- Student
20-
- Teacher
21-
- Administrator
18+
Our application has 4 different entities
19+
* **USER** - The applications users. There are different types of users in our application:
20+
* Student
21+
* Teacher
22+
* Aministrator
23+
* **COURSE** - This entity represents a course that only a teacher has permission to create.
24+
* **LESSONS** - This entity represents the lessons that are within a course each with their own information and are created at the time of creating and editing a course.
25+
* **ORDER** - This entity represents the purchasing process of a user and it stores the information of what courses are owned by what users.
2226

27+
## Users
28+
Within the user entity there are different types of users;
2329

24-
### Guests
30+
* **GUEST** - is the type of user that doesnt sign up for an account and has only access to view the course catalog and the main description of courses.
31+
* **STUDENT** - is the type of user that signs up for a student account and has the additional option of purchasing courses and accessing the lessons within the course.
32+
* **TEACHER** - Teachers are the creators within the application. They can create courses and lessons and upload or enter the information. They can also delete and edit the courses they own.
33+
* **ADMINISTRATOR** - Administrators are able to edit or delete any course or lessons and they also have access to their dashboard where they can see all of the web application information.
2534

26-
- Search Content
2735

28-
### Students
36+
### USER PERMISSION
2937

38+
Students
3039
- Search Content
3140
- Buy courses
32-
- Review courses based on stars
33-
- Leave comments
34-
35-
### Teachers
3641

42+
Teachers
3743
- Create courses
38-
- Create different topics inside the course
39-
- Upload videos
40-
- Request video removal
41-
42-
### Administrators
44+
- Create different lessons inside the course
45+
- Upload video url
46+
- delete owned courses and lessons
47+
- edit owned courses and lessons
4348

49+
Administrators
4450
- Search Content
45-
- Approve course
46-
- Eliminate Course
47-
- Ban users
51+
- Delete any course
52+
- Edit any course
4853
- Visualize stastistics
49-
50-
## Tables
51-
52-
- User
53-
- Order
54-
- Course
55-
- Video
56-
57-
## User
58-
- userID or mail
59-
- name
60-
- lastname
61-
- age
62-
- role (student, teacher)
63-
64-
## Order
65-
- orderID
66-
- userID (FK)
67-
- courseID (FK)
68-
- paymentMethod
69-
- price
70-
- orderDate
71-
72-
## Course
73-
- CourseID
74-
- courseName
75-
- Category (tech, finance, law)
76-
- price
77-
- enrolledStudents
78-
79-
## Video
80-
- videoId
81-
- videoName
82-
- videoDataa
83-
- courseID (FK)
8454

8555

8656
## Additional Technology
87-
- PDF generator
88-
- Play Video
8957

90-
## Algorithm
91-
Search algorithm for courses (ajax)
58+
Generate a pdf with the order information so that user can download this information
59+
60+
![](/diagrams_and_images/additional_technology.png)
61+
62+
## Advanced Algorithm
63+
64+
Search algorithm for courses (ajax).
65+
66+
![](/diagrams_and_images/algorithm.png)
9267

9368
## Graphics
9469
Administrators will be able to check visual information about courses
9570

96-
# What every developer did
71+
## Screens
72+
73+
The application consists of the following screens:
74+
75+
## DIAGRAMS
76+
77+
### Navigation Diagram
78+
The following diagram shows how users can navigate through the different pages of the application according to their role.
79+
![Navigation Diagram](/diagrams_and_images/Navigation_Diagram.png)
9780

98-
## Emiliano Sloth
81+
### Class Diagram
82+
The following diagram shows the different classes in our web application.
83+
![Class Diagram](diagrams_and_images/Class_Diagram.png)
84+
85+
### Class Diagram
86+
The following diagram shows our database infrastructure/schema.
87+
![Database Diagram](/diagrams_and_images/database_schema.jpeg)
88+
89+
## CONTRIBUTIONS
90+
91+
### Emiliano Sloth
9992
- Restful Error Handling
10093
- User Authentication
10194
- CRF Handling
@@ -105,31 +98,28 @@ Administrators will be able to check visual information about courses
10598
- Delete Course and Lessons within Course
10699
- Teacher allowed to Modify their own content
107100

108-
## Fiorella Hernández
101+
### Fiorella Hernández
109102
- Video View
110103
- Video Player
111104

112-
## José Manuel de Pablo
105+
### José Manuel de Pablo
113106
- Order Handling (Create, Delete).
114107
- Checkout step from course page to finish order.
115108
- Order info to PDF file.
116109
- Listing Orders to PDF file.
117-
- Users only can see his/her orders.
110+
- Users only can see their own orders.
118111
- Admin dashboard listing entities.
119112
- Update database schema.
113+
- My account page
120114

121-
## Oscar Arranz Pato
115+
### Oscar Arranz Pato
122116
- Course creation
123117
- Lesson creation
124118
- AJAX course loading
125119
- Course search
126120

127-
# Diagrams
128-
![Class Diagram](./Class%20Diagram.png)
129-
![Database Diagram](./database%20schema%20updated.jpeg)
130-
131121

132-
# Start coding
122+
## Start coding
133123
Follow these steps to get working:
134124

135125
1. Clone the repo `git clone https://github.com/CodeURJC-DAW-2021-22/webapp10`.

backend/src/main/java/com/youdemy/controller/CourseController.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.youdemy.service.OrderPService;
1212
import com.youdemy.service.UserService;
1313

14-
import org.json.JSONObject;
1514
import org.springframework.beans.factory.annotation.Autowired;
1615
import org.springframework.data.domain.Page;
1716
import org.springframework.data.domain.PageRequest;
@@ -126,21 +125,21 @@ public Page<Course> getCurrentCourse(@RequestParam Optional<Integer> page,
126125
return courseService.findByTitle(search.orElse(""),
127126
PageRequest.of(page.orElse(0), 6));
128127
}
129-
130-
128+
129+
131130
@GetMapping("/{id}")
132131
public String showCourse(Model model, @PathVariable long id, HttpServletRequest request) {
133132
Optional<Course> course = courseService.findById(id);
134133
if (course.isPresent()) {
134+
model.addAttribute("course", course.get());
135135
Principal principal = request.getUserPrincipal();
136136
if(principal != null) {
137137
String userName = principal.getName();
138138
Optional<User> user = userRepository.findByFirstName(userName);
139139
long userId = user.get().getId();
140140
model.addAttribute("userId", userId);
141141

142-
if(course.get().getAuthor().getId() == userId
143-
|| model.getAttribute("admin") == Boolean.valueOf(true)) {
142+
if(course.get().getAuthor().getId() == userId) {
144143
model.addAttribute("owner", true);
145144
model.addAttribute("hasAccess", true);
146145
}

backend/src/main/java/com/youdemy/controller/OrderPController.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,16 @@ public void addAttributes(Model model, HttpServletRequest request) {
5959
"/",
6060
""
6161
})
62-
public String showOrders(Model model) {
63-
model.addAttribute("orders", orderService.findAll());
62+
public String showOrders(Model model, HttpServletRequest request) {
63+
64+
Principal principal = request.getUserPrincipal();
65+
66+
if (principal != null) { //checkin if user registered can is trying to access to other users orders
67+
String userName = principal.getName();
68+
Optional<User> pUser = userRepository.findByFirstName(userName);
69+
long userId = pUser.get().getId();
70+
model.addAttribute("orders", orderRepository.findByUser(userId));
71+
}
6472

6573
return "orders";
6674
}
@@ -101,11 +109,13 @@ public String showOrder(Model model, @PathVariable long id, HttpServletRequest r
101109

102110
@PostMapping("/new")
103111
public String createOrder(Model model, @RequestParam long userId ,
104-
@RequestParam int price, @RequestParam long courseId,
112+
@RequestParam int price, @RequestParam long courseId,
113+
@RequestParam String uname,
114+
@RequestParam String ctitle,
105115
@RequestParam String billingAddress,
106116
@RequestParam String paymentMethod,
107117
@RequestParam String country, @RequestParam String region,
108-
@RequestParam String expiration,
118+
@RequestParam String expiration,
109119
@RequestParam String cvv, @RequestParam String ccnumber) throws IOException {
110120

111121
Optional<OrderP> order = Optional.ofNullable(new OrderP());
@@ -124,6 +134,8 @@ public String createOrder(Model model, @RequestParam long userId ,
124134
dbOrder.setPaymentMethod(paymentMethod);
125135
dbOrder.setRegion(region);
126136
dbOrder.setDate();
137+
dbOrder.setUserName(uname);
138+
dbOrder.setCourseTitle(ctitle);
127139
dbOrder.setDataCard(ccnumber);
128140
orderRepository.save(dbOrder);
129141

backend/src/main/java/com/youdemy/controller/UserController.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
package com.youdemy.controller;
22

3+
import com.youdemy.service.OrderPService;
34
import com.youdemy.service.UserService;
45
import org.springframework.beans.factory.annotation.Autowired;
56
import org.springframework.security.crypto.password.PasswordEncoder;
67
import org.springframework.stereotype.Controller;
78
import org.springframework.ui.Model;
89
import org.springframework.web.bind.annotation.ModelAttribute;
10+
import org.springframework.web.bind.annotation.PathVariable;
911
import org.springframework.web.bind.annotation.PostMapping;
1012
import org.springframework.web.bind.annotation.RequestMapping;
1113
import org.springframework.web.bind.annotation.RequestParam;
1214

1315
import com.youdemy.model.User;
14-
import com.youdemy.repository.UserRepository;
1516

1617
import javax.servlet.http.HttpServletRequest;
1718
import java.security.Principal;
19+
import java.util.ArrayList;
1820
import java.util.Objects;
1921

20-
2122
@Controller
2223
public class UserController {
2324

2425
@Autowired
2526
private UserService userService;
27+
28+
@Autowired
29+
private OrderPService orderPService;
2630

2731
@Autowired
2832
private PasswordEncoder passwordEncoder;
@@ -81,4 +85,21 @@ public String registerUser(@RequestParam String userFirstName, @RequestParam Str
8185
return "signin";
8286
}
8387

88+
@RequestMapping("/myaccount/{id}")
89+
public String showUserInfo(Model model, @PathVariable long id, HttpServletRequest request) {
90+
Principal principal = request.getUserPrincipal();
91+
92+
if(principal != null) {
93+
String userName = principal.getName();
94+
User user = userService.findByFirstName(userName);
95+
long userId;
96+
userId = user.getId();
97+
if (userId != id) {
98+
return "accessDenied";
99+
}
100+
model.addAttribute("orders", (ArrayList) orderPService.findByUser(userId));
101+
model.addAttribute("user", user);
102+
}
103+
return "myAccount";
104+
}
84105
}

backend/src/main/java/com/youdemy/model/OrderP.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ public class OrderP {
2020
@GeneratedValue(strategy = GenerationType.IDENTITY)
2121
private long id;
2222
private int price;
23-
private long user;
23+
24+
private long user;
2425
private long course;
26+
private String courseTitle;
27+
private String userName;
2528
private String paymentMethod;
2629
private String billingAddress;
2730
private String country;
@@ -31,13 +34,15 @@ public class OrderP {
3134

3235
public OrderP() {}
3336

34-
public OrderP( long user, int price, long course, String paymentMethod,
37+
public OrderP( long user, int price, long course, String userName, String courseTitle, String paymentMethod,
3538
String billingAddress, String country, String region,
3639
String dataCard) {
3740
super();
3841
this.user = user;
3942
this.price = price;
4043
this.course = course;
44+
this.userName = userName;
45+
this.courseTitle = courseTitle;
4146
this.paymentMethod = paymentMethod;
4247
this.billingAddress = billingAddress;
4348
this.country = country;
@@ -118,6 +123,22 @@ public void setDataCard(String dataCard) {
118123
this.dataCard = dataCard;
119124
}
120125

126+
public String getUserName() {
127+
return userName;
128+
}
129+
130+
public void setUserName(String userName) {
131+
this.userName = userName;
132+
}
133+
134+
public String getCourseTitle() {
135+
return courseTitle;
136+
}
137+
138+
public void setCourseTitle(String courseTitle) {
139+
this.courseTitle = courseTitle;
140+
}
141+
121142
public void setDate() {
122143
DateFormat dateFormatter = new SimpleDateFormat("dd-MM-yyyy");
123144
String date = dateFormatter.format(new Date(System.currentTimeMillis()));

backend/src/main/java/com/youdemy/security/WebSecurityConfig.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ protected void configure(HttpSecurity http) throws Exception {
4444
http.authorizeRequests().antMatchers("/image/**").hasAnyRole("TEACHER", "ADMIN");
4545
http.authorizeRequests().antMatchers("/orders/**").hasAnyRole("USER");
4646
http.authorizeRequests().antMatchers("/admin").hasAnyRole("ADMIN");
47+
http.authorizeRequests().antMatchers("/myaccount/**").hasAnyRole("USER","ADMIN");
4748

4849
// H2 Console access without csrf
4950
http.csrf().ignoringAntMatchers("/h2-console/**");

0 commit comments

Comments
 (0)