Compare commits
No commits in common. "8f04ac7ae884e4a195f67d246c209fd914e9e5b0" and "e3408d1566f03f53ffdd7ae8071f9682f70cda7c" have entirely different histories.
8f04ac7ae8
...
e3408d1566
@ -18,10 +18,16 @@ dependencies {
|
||||
runtimeOnly 'mysql:mysql-connector-java'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
|
||||
// Spring security
|
||||
//implementation 'org.springframework.boot:spring-boot-starter-security'
|
||||
//implementation 'org.springframework.security:spring-security-test'
|
||||
|
||||
// JSON web token
|
||||
implementation 'io.jsonwebtoken:jjwt-api:0.11.2'
|
||||
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2',
|
||||
'io.jsonwebtoken:jjwt-jackson:0.11.2'
|
||||
// Uncomment the next line if you want to use RSASSA-PSS (PS256, PS384, PS512) algorithms:
|
||||
//'org.bouncycastle:bcprov-jdk15on:1.60',
|
||||
'io.jsonwebtoken:jjwt-jackson:0.11.2' // or 'io.jsonwebtoken:jjwt-gson:0.11.2' for gson
|
||||
}
|
||||
|
||||
test {
|
||||
|
@ -15,6 +15,8 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.sql.Time;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@ -94,7 +96,7 @@ public class EventController {
|
||||
|
||||
List<Event> eventList = eventDAO.getAllEventsInTimespan(authUser.getId(), startDate, endDate);
|
||||
|
||||
return new ResponseEntity<>(JSONMapper.eventListToJSON(eventList), HttpStatus.OK);
|
||||
return new ResponseEntity<>(JSONMapper.ToJSON(eventList), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,9 +1,6 @@
|
||||
package com.vpr.server.controller;
|
||||
|
||||
import com.vpr.server.dao.interfaces.UserDAO;
|
||||
import com.vpr.server.data.Event;
|
||||
import com.vpr.server.data.User;
|
||||
import com.vpr.server.json.JSONMapper;
|
||||
import com.vpr.server.repository.UserRepository;
|
||||
import com.vpr.server.security.Hasher;
|
||||
import com.vpr.server.security.Token;
|
||||
@ -12,21 +9,19 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(path = "/user")
|
||||
public class UserController {
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
@Autowired
|
||||
private UserDAO userDAO;
|
||||
|
||||
private final AuthController authController;
|
||||
private AuthController authController;
|
||||
|
||||
public UserController() {
|
||||
this.authController = new AuthController();
|
||||
@ -151,9 +146,7 @@ public class UserController {
|
||||
|
||||
@GetMapping(path = "/all")
|
||||
public @ResponseBody
|
||||
ResponseEntity<String> getAllUser() {
|
||||
List<User> userList = userDAO.getAllUser();
|
||||
|
||||
return new ResponseEntity<>(JSONMapper.userListToJSON(userList), HttpStatus.OK);
|
||||
Object[] getAllUsers() {
|
||||
return userRepository.findAllUsernames();
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
package com.vpr.server.dao.implementation;
|
||||
|
||||
import com.vpr.server.dao.interfaces.UserDAO;
|
||||
import com.vpr.server.data.Event;
|
||||
import com.vpr.server.data.User;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.transaction.Transactional;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
@Transactional
|
||||
public class UserDAOImplementation implements UserDAO {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager manager;
|
||||
|
||||
@Override
|
||||
public List<User> getAllUser() {
|
||||
return manager.createNamedQuery("getAllUser", User.class).getResultList();
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.vpr.server.dao.interfaces;
|
||||
|
||||
import com.vpr.server.data.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserDAO {
|
||||
List<User> getAllUser();
|
||||
}
|
@ -4,15 +4,7 @@ import javax.persistence.*;
|
||||
import java.util.List;
|
||||
|
||||
// @Entity creates a table out of this class with Hibernate
|
||||
@Entity(name = "User")
|
||||
@Table(name = "user")
|
||||
@NamedNativeQueries({
|
||||
@NamedNativeQuery(
|
||||
name = "getAllUser",
|
||||
query = "SELECT * FROM user",
|
||||
resultClass = User.class
|
||||
)
|
||||
})
|
||||
@Entity
|
||||
public class User {
|
||||
// Generate the primary key
|
||||
@Id
|
||||
|
@ -1,38 +1,14 @@
|
||||
package com.vpr.server.json;
|
||||
|
||||
import com.vpr.server.data.Event;
|
||||
import com.vpr.server.data.User;
|
||||
import com.vpr.server.data.UserEvent;
|
||||
|
||||
import java.sql.Time;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JSONMapper {
|
||||
|
||||
public static String userToJSON(User user) {
|
||||
return "{" +
|
||||
"\"userId\": " + user.getId() + ", " +
|
||||
"\"forename\": \"" + user.getForename() + "\", " +
|
||||
"\"name\": \"" + user.getName() + "\", " +
|
||||
"\"login\": \"" + user.getLogin() + "\"," +
|
||||
"\"isAdmin\": " + user.isAdmin() +
|
||||
"}";
|
||||
}
|
||||
|
||||
public static String userListToJSON(List<User> userList) {
|
||||
StringBuilder userListJSON = new StringBuilder();
|
||||
for (User user : userList) {
|
||||
userListJSON.append(", ");
|
||||
userListJSON.append(userToJSON(user));
|
||||
}
|
||||
userListJSON.delete(0, 2);
|
||||
|
||||
return "[" + userListJSON + "]";
|
||||
}
|
||||
|
||||
public static List<String> eventToJSON(Event event) {
|
||||
public static List<String> ToJSON(Event event){
|
||||
List<String> eventListJSON = new ArrayList<>();
|
||||
|
||||
for (UserEvent userEvent : event.getUserEvent()) {
|
||||
@ -46,8 +22,8 @@ public class JSONMapper {
|
||||
"\"priority\": " + event.getPriority() + "," +
|
||||
"\"fullDay\": " + event.isFullDay() + "," +
|
||||
"\"private\": " + event.isPrivate() + "," +
|
||||
"\"start\": " + timeToJSON(event.getStart()) + "," +
|
||||
"\"end\": " + timeToJSON(event.getEnd()) +
|
||||
"\"start\": " + ToJSON(event.getStart()) + "," +
|
||||
"\"end\": " + ToJSON(event.getEnd()) +
|
||||
"}";
|
||||
|
||||
eventListJSON.add(eventJSON);
|
||||
@ -56,10 +32,10 @@ public class JSONMapper {
|
||||
return eventListJSON;
|
||||
}
|
||||
|
||||
public static String eventListToJSON(List<Event> eventList) {
|
||||
public static String ToJSON(List<Event> eventList){
|
||||
StringBuilder eventListJSON = new StringBuilder();
|
||||
for(Event event : eventList){
|
||||
List<String> eventsJSON = eventToJSON(event);
|
||||
List<String> eventsJSON = ToJSON(event);
|
||||
for(String eventJSON : eventsJSON){
|
||||
eventListJSON.append(", ");
|
||||
eventListJSON.append(eventJSON);
|
||||
@ -70,7 +46,7 @@ public class JSONMapper {
|
||||
return "[" + eventListJSON + "]";
|
||||
}
|
||||
|
||||
public static String timeToJSON(Time time) {
|
||||
public static String ToJSON(Time time){
|
||||
if(time == null){
|
||||
return "null";
|
||||
}
|
||||
|
@ -78,4 +78,7 @@ public interface EventRepository extends CrudRepository<Event, Integer> {
|
||||
nativeQuery = true
|
||||
)
|
||||
void deleteById(long id);
|
||||
|
||||
//@Query(nativeQuery = true)
|
||||
//List<Event> findEventsInDateRange(Long userId, String startDate, String endDate);
|
||||
}
|
Loading…
Reference in New Issue
Block a user