slaba baterija

master
dizda13 2017-04-01 16:04:20 +02:00
parent 88975de6e9
commit e5a7e4e01f
6 changed files with 80 additions and 6 deletions

View File

@ -0,0 +1,7 @@
package ba.steleks;
/**
* Created by admin on 01/04/2017.
*/
public class EventController {
}

View File

@ -37,7 +37,7 @@ class MessageRestController {
// return "temp " + Long.toString(id);
//}
@RequestMapping(value = "/whoami/{user}", method = RequestMethod.GET)
@RequestMapping(value = "/whoami/{username}", method = RequestMethod.GET)
public String whoami(@PathVariable("username") String username) {
return String.format("Hello! You're %s and you'll become a(n) root, " +
"but only if your password is '%s'!\n",

View File

@ -3,7 +3,7 @@ spring.datasource.url = jdbc:mysql://localhost:3306/events
spring.datasource.username = root
spring.datasource.password = skorpion
spring.jpa.generate-ddl=true
user.password=dizda
#
#spring.datasource.url = jdbc:mysql://localhost:3306/events
#spring.datasource.username = root

View File

@ -28,4 +28,5 @@ dependencies {
runtime('com.h2database:h2')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile('mysql:mysql-connector-java')
compile('org.hibernate:hibernate-validator')
}

View File

@ -0,0 +1,47 @@
package ba.steleks.repository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.data.rest.webmvc.support.RepositoryConstraintViolationExceptionMessage;
import org.springframework.http.HttpStatus;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import java.util.List;
import java.util.Locale;
/**
* Created by admin on 01/04/2017.
*/
@ControllerAdvice
public class GlobalExceptionController {
@ExceptionHandler(CustomGenericException.class)
public ModelAndView handleCustomException(CustomGenericException ex) {
ModelAndView model = new ModelAndView("error/generic_error");
model.addObject("errCode", ex.getErrCode());
model.addObject("errMsg", ex.getErrMsg());
return model;
}
@ExceptionHandler(Exception.class)
public ModelAndView handleAllException(Exception ex) {
ModelAndView model = new ModelAndView("error/generic_error");
model.addObject("errMsg", "this is Exception.class");
return model;
}
}

View File

@ -2,7 +2,13 @@ package ba.steleks.repository.model;/**
* Created by ensar on 22/03/17.
*/
import org.hibernate.validator.constraints.NotBlank;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Set;
import java.util.logging.Logger;
@ -15,14 +21,22 @@ public class User {
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@NotNull
private int cardNumber;
@NotNull
private String firstName;
@NotNull
private String lastName;
private String registrationDate;
@NotNull
@Column(updatable = false, insertable = false)
private Timestamp registrationDate;
@NotNull
private String email;
@NotNull
private String contactNumber;
@NotNull
private String passwordHash;
@NotNull
private String username;
private String profilePictureUrl;
@ -71,11 +85,11 @@ public class User {
this.lastName = lastName;
}
public String getRegistrationDate() {
public Timestamp getRegistrationDate() {
return registrationDate;
}
public void setRegistrationDate(String registrationDate) {
public void setRegistrationDate(Timestamp registrationDate) {
this.registrationDate = registrationDate;
}
@ -142,4 +156,9 @@ public class User {
public void setUserRoles(Set<UserRole> userRoles) {
this.userRoles = userRoles;
}
@PrePersist
protected void onCreate() {
this.registrationDate = new Timestamp(new Date().getTime());
}
}