diff --git a/pom.xml b/pom.xml index 9850069..fa3244e 100644 --- a/pom.xml +++ b/pom.xml @@ -16,15 +16,18 @@ 21 + org.springframework.boot spring-boot-starter-data-jpa - - - - + + + org.springframework.boot + spring-boot-starter-security + + org.springframework.boot spring-boot-starter-web @@ -35,23 +38,39 @@ postgresql runtime + org.springframework.boot spring-boot-starter-test test + org.springframework.security spring-security-test test + org.jetbrains annotations RELEASE compile - + + + org.springframework.boot + spring-boot-devtools + true + + + + org.projectlombok + lombok + 1.18.30 + provided + + diff --git a/src/main/java/com/MeetMate/Main.java b/src/main/java/com/MeetMate/MeetMateApplication.java similarity index 82% rename from src/main/java/com/MeetMate/Main.java rename to src/main/java/com/MeetMate/MeetMateApplication.java index c99df0e..7e18f53 100644 --- a/src/main/java/com/MeetMate/Main.java +++ b/src/main/java/com/MeetMate/MeetMateApplication.java @@ -8,9 +8,9 @@ @SpringBootApplication //@EnableConfigurationProperties //@EntityScan(basePackages = {"com.MeetMate.user"}) //force scan the packages -public class Main { +public class MeetMateApplication { public static void main(String[] args) { - SpringApplication.run(Main.class, args); + SpringApplication.run(MeetMateApplication.class, args); } } diff --git a/src/main/java/com/MeetMate/roles/Role.java b/src/main/java/com/MeetMate/roles/Role.java new file mode 100644 index 0000000..b12cdb4 --- /dev/null +++ b/src/main/java/com/MeetMate/roles/Role.java @@ -0,0 +1,8 @@ +package com.MeetMate.roles; + +public enum Role { + + ADMIN, + COMPANY, + CLIENT; +} \ No newline at end of file diff --git a/src/main/java/com/MeetMate/roles/Roles.java b/src/main/java/com/MeetMate/roles/Roles.java deleted file mode 100644 index f91905f..0000000 --- a/src/main/java/com/MeetMate/roles/Roles.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.MeetMate.roles; - -public enum Roles { - - OWNER, - ADMIN, - CUSTOMER; -} diff --git a/src/main/java/com/MeetMate/user/User.java b/src/main/java/com/MeetMate/user/User.java index 066f085..8f7720f 100644 --- a/src/main/java/com/MeetMate/user/User.java +++ b/src/main/java/com/MeetMate/user/User.java @@ -1,6 +1,8 @@ package com.MeetMate.user; +import com.MeetMate.roles.Role; import jakarta.persistence.*; +import lombok.*; import java.time.LocalDate; import java.time.Month; @@ -8,6 +10,7 @@ @Entity @Table(name = "users") +@Data public class User { @Id @SequenceGenerator( @@ -22,16 +25,17 @@ public class User { private Long id; private String name; private LocalDate birthday; + @Setter(AccessLevel.NONE) private LocalDate createdAt; private String email; private String password; - //enum Rolle + private Role role; //Last login //(refresh token) //bool verified - - //No need for column in database @Transient + @Getter(AccessLevel.NONE) + @Setter(AccessLevel.NONE) private int age; public User() { @@ -62,66 +66,8 @@ public User(String email, String password) { this.password = password; } - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public LocalDate getBirthday() { - if (this.birthday == null) birthday = LocalDate.EPOCH; - return birthday; - } - - public void setBirthday(LocalDate birthday) { - this.birthday = birthday; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - public int getAge() { return Period.between(getBirthday(), LocalDate.now()).getYears(); } - public LocalDate getCreatedAt() { - return createdAt; - } - - @Override - public String toString() { - return "User{" + - "id=" + id + - ", name='" + name + '\'' + - ", birthday=" + birthday + - ", createdAt=" + createdAt + - ", email='" + email + '\'' + - ", password='" + password + '\'' + - ", age=" + age + - '}'; - } - } diff --git a/src/main/java/com/MeetMate/user/UserController.java b/src/main/java/com/MeetMate/user/UserController.java index c6216c7..839c3b9 100644 --- a/src/main/java/com/MeetMate/user/UserController.java +++ b/src/main/java/com/MeetMate/user/UserController.java @@ -1,11 +1,8 @@ package com.MeetMate.user; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.StreamingHttpOutputMessage; -import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.*; -import org.springframework.web.service.annotation.PutExchange; import java.util.List; @@ -21,22 +18,24 @@ public UserController(UserService userService) { } @GetMapping(path = "get") + @ResponseBody public User getUser(@RequestParam(name = "id") Long userId) { return userService.getUser(userId); } @GetMapping(path = "getAll") + @ResponseBody public List getAllUsers() { return userService.getAllUsers(); } @PostMapping(path = "post") - public void registerNewUser(@RequestBody MultiValueMap formData) { + public void registerNewUser(@RequestParam MultiValueMap formData) { userService.addNewUser(formData); } - @PostMapping(path = "put") - public void updateUser(@RequestBody MultiValueMap formData) { + @PutMapping(path = "put") + public void updateUser(@RequestParam MultiValueMap formData) { System.out.println(formData); userService.updateUser(formData); } diff --git a/src/main/java/com/MeetMate/user/UserService.java b/src/main/java/com/MeetMate/user/UserService.java index 02af93f..6453a27 100644 --- a/src/main/java/com/MeetMate/user/UserService.java +++ b/src/main/java/com/MeetMate/user/UserService.java @@ -1,7 +1,6 @@ package com.MeetMate.user; import jakarta.transaction.Transactional; -import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.MultiValueMap; @@ -21,6 +20,7 @@ public UserService(UserRepository userRepository) { public User getUser(Long userId) { Optional userOptional = userRepository.findUserById(userId); + // ??? userRepository.findUserById(userId); if (userOptional.isPresent()) { return userOptional.get(); @@ -70,7 +70,7 @@ public void updateUser(MultiValueMap data) { if (userRepository.findUserByEmail(email).isEmpty()) { user.setEmail(email); - } + } // throw error user.setPassword(password); } diff --git a/src/test/java/com/MeetMate/MeetMateApplicationTests.java b/src/test/java/com/MeetMate/MeetMateApplicationTests.java index c77f80d..71a4ff7 100644 --- a/src/test/java/com/MeetMate/MeetMateApplicationTests.java +++ b/src/test/java/com/MeetMate/MeetMateApplicationTests.java @@ -1,13 +1,24 @@ package com.MeetMate; +import com.MeetMate.user.User; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import java.time.LocalDate; +import java.time.Month; + @SpringBootTest class MeetMateApplicationTests { - @Test - void contextLoads() { - } + @Test + void contextLoads() { + User test = new User( + "Carl A", + LocalDate.of(2000, Month.JANUARY, 21), + "carl.A@gmail.com", + "carl123"); + System.out.println(test.getAge()); + System.out.println(test.getName()); + } }