Ready to have fun?
20 |Find out the best activities for you in your area. Take our personalised test and help us help you discover your new passion.
21 |
28 |
29 |
30 |
33 |
34 |
35 | ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ ├── maven-wrapper.properties │ └── MavenWrapperDownloader.java ├── mysql-apt-config_0.8.16-1_all.deb ├── src ├── main │ ├── resources │ │ ├── static │ │ │ ├── img │ │ │ │ ├── blue.jpg │ │ │ │ ├── blueImg.png │ │ │ │ ├── coverImg.png │ │ │ │ ├── Grid-05.svg │ │ │ │ ├── cart.svg │ │ │ │ ├── paypal.svg │ │ │ │ └── logo.svg │ │ │ └── css │ │ │ │ └── reset-css.css │ │ ├── templates │ │ │ ├── handler.html │ │ │ ├── home │ │ │ │ ├── index.html │ │ │ │ ├── business_owner.html │ │ │ │ └── user_home.html │ │ │ ├── shopping │ │ │ │ ├── success.html │ │ │ │ └── shoppingCart.html │ │ │ ├── account │ │ │ │ ├── account-info.html │ │ │ │ ├── business-account-info.html │ │ │ │ ├── update-business.html │ │ │ │ └── update-user.html │ │ │ ├── abo │ │ │ │ ├── my-abos.html │ │ │ │ └── abo.html │ │ │ ├── login │ │ │ │ └── login.html │ │ │ ├── offer │ │ │ │ ├── offer-details.html │ │ │ │ ├── hobby-details.html │ │ │ │ ├── create_offer.html │ │ │ │ └── update-hobby.html │ │ │ ├── signup │ │ │ │ └── register-business.html │ │ │ └── fragments │ │ │ │ └── fragments.html │ │ ├── application.properties │ │ └── META-INF │ │ │ └── additional-spring-configuration-metadata.json │ └── java │ │ └── com │ │ └── example │ │ └── hobbie │ │ ├── model │ │ ├── entities │ │ │ ├── enums │ │ │ │ ├── GenderEnum.java │ │ │ │ ├── LocationEnum.java │ │ │ │ ├── UserRoleEnum.java │ │ │ │ └── CategoryNameEnum.java │ │ │ ├── BaseEntity.java │ │ │ ├── UserRoleEntity.java │ │ │ ├── Location.java │ │ │ ├── Category.java │ │ │ ├── Entry.java │ │ │ ├── BusinessOwner.java │ │ │ ├── UserEntity.java │ │ │ ├── Abo.java │ │ │ ├── Hobby.java │ │ │ ├── AppClient.java │ │ │ └── Test.java │ │ ├── repostiory │ │ │ ├── TestRepository.java │ │ │ ├── AppClientRepository.java │ │ │ ├── EntryRepository.java │ │ │ ├── UserRepository.java │ │ │ ├── LocationRepository.java │ │ │ ├── CategoryRepository.java │ │ │ ├── UserRoleRepository.java │ │ │ ├── BusinessOwnerRepository.java │ │ │ ├── HobbyRepository.java │ │ │ └── AboRepository.java │ │ ├── service │ │ │ ├── RegisterBusinessServiceModel.java │ │ │ ├── SignUpServiceModel.java │ │ │ ├── HobbyServiceModel.java │ │ │ ├── UpdateHobbyServiceModel.java │ │ │ └── TestServiceModel.java │ │ └── binding │ │ │ ├── SignUpBindingModel.java │ │ │ ├── UpdateClientBindingModel.java │ │ │ ├── RegisterBusinessBindingModel.java │ │ │ ├── UpdateBusinessBindingModel.java │ │ │ ├── HobbyBindingModel.java │ │ │ ├── UpdateHobbyBindingModel.java │ │ │ └── TestBindingModel.java │ │ ├── handler │ │ ├── NotFoundException.java │ │ ├── FailToDeleteException.java │ │ └── GlobalAdvice.java │ │ ├── service │ │ ├── TestService.java │ │ ├── CloudinaryService.java │ │ ├── NotificationService.java │ │ ├── CategoryService.java │ │ ├── LocationService.java │ │ ├── UserRoleService.java │ │ ├── ShoppingCartService.java │ │ ├── EntryService.java │ │ ├── AboService.java │ │ ├── impl │ │ │ ├── CloudinaryServiceImpl.java │ │ │ ├── UserRoleServiceImpl.java │ │ │ ├── NotificationServiceImpl.java │ │ │ ├── LocationServiceImpl.java │ │ │ ├── CategoryServiceImpl.java │ │ │ ├── TestServiceImpl.java │ │ │ ├── EntryServiceImpl.java │ │ │ ├── ShoppingCartServiceImpl.java │ │ │ └── AboServiceImpl.java │ │ ├── HobbyService.java │ │ └── UserService.java │ │ ├── HobbieApplication.java │ │ ├── config │ │ ├── ListenerConfig.java │ │ ├── MvcConfig.java │ │ ├── CloudConfig.java │ │ ├── HobbieConfigurationBeans.java │ │ ├── SecurityConfig.java │ │ ├── SessionTimerInterceptor.java │ │ └── UserInterceptor.java │ │ ├── view │ │ ├── EntryViewModel.java │ │ ├── AboViewModel.java │ │ ├── HobbyCardViewModel.java │ │ └── HobbyViewModel.java │ │ ├── init │ │ └── DBInit.java │ │ ├── security │ │ └── HobbieUserDetailsService.java │ │ └── web │ │ ├── ShoppingCartController.java │ │ ├── TestController.java │ │ ├── HomeController.java │ │ └── AboController.java └── test │ └── java │ └── com │ └── example │ └── hobbie │ ├── HobbieApplicationTests.java │ ├── service │ └── impl │ │ ├── TestServiceImplTest.java │ │ ├── CategoryServiceTest.java │ │ ├── LocationServiceImplTest.java │ │ └── UserRoleServiceImplTest.java │ └── web │ ├── AboControllerTest.java │ ├── TestControllerTest.java │ ├── HobbyControllerTest.java │ └── UserControllerTest.java ├── .gitignore └── README.md /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/purshink/Spring-Boot-Thymeleaf-App/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /mysql-apt-config_0.8.16-1_all.deb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/purshink/Spring-Boot-Thymeleaf-App/HEAD/mysql-apt-config_0.8.16-1_all.deb -------------------------------------------------------------------------------- /src/main/resources/static/img/blue.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/purshink/Spring-Boot-Thymeleaf-App/HEAD/src/main/resources/static/img/blue.jpg -------------------------------------------------------------------------------- /src/main/resources/static/img/blueImg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/purshink/Spring-Boot-Thymeleaf-App/HEAD/src/main/resources/static/img/blueImg.png -------------------------------------------------------------------------------- /src/main/resources/static/img/coverImg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/purshink/Spring-Boot-Thymeleaf-App/HEAD/src/main/resources/static/img/coverImg.png -------------------------------------------------------------------------------- /src/main/java/com/example/hobbie/model/entities/enums/GenderEnum.java: -------------------------------------------------------------------------------- 1 | package com.example.hobbie.model.entities.enums; 2 | 3 | public enum GenderEnum { 4 | MALE, FEMALE, OTHER; 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/example/hobbie/model/entities/enums/LocationEnum.java: -------------------------------------------------------------------------------- 1 | package com.example.hobbie.model.entities.enums; 2 | 3 | public enum LocationEnum { 4 | ZURICH, OTHER; 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/example/hobbie/model/entities/enums/UserRoleEnum.java: -------------------------------------------------------------------------------- 1 | package com.example.hobbie.model.entities.enums; 2 | 3 | public enum UserRoleEnum { 4 | ADMIN, USER, BUSINESS_USER; 5 | } 6 | -------------------------------------------------------------------------------- /src/main/resources/templates/handler.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |Find out the best activities for you in your area. Take our personalised test and help us help you discover your new passion.
21 |
28 |
29 |
30 |
33 |
34 |
35 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/src/main/java/com/example/hobbie/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.service;
2 |
3 | import com.example.hobbie.model.entities.AppClient;
4 | import com.example.hobbie.model.entities.BusinessOwner;
5 | import com.example.hobbie.model.entities.Hobby;
6 | import com.example.hobbie.model.entities.UserEntity;
7 | import com.example.hobbie.model.service.RegisterBusinessServiceModel;
8 | import com.example.hobbie.model.service.SignUpServiceModel;
9 |
10 | import java.util.List;
11 |
12 | public interface UserService {
13 | Listgit clone https://github.com/purshink/Spring-Boot-Thymeleaf-App32 | Navigate to the newly created folder: 33 | 34 |
cd Spring-Boot-Thymeleaf-App35 | 36 | Run the project with: 37 | 38 |
./mvnw clean spring-boot:run39 | 40 | Or on Windows: 41 | 42 |
mvnw.cmd clean spring-boot:run43 | 44 | Navigate to: 45 | 46 | http://localhost:8080 47 | 48 | Login with: 49 |
user or business, 50 | password:topsecret51 | 52 | * * * * * 53 | 54 | Spring Mail 55 | 56 | Make sure to specify a valid spring.mail.username and spring.mail.password in the application.properties file in order to be able to send an Email confirmation for updating user entries. 57 | 58 | IMPORTANT: if you decide not to specify mail credentials, you will get javax.mail.AuthenticationFailedException. The rest of the application should work normally despite this exception. 59 | 60 | 61 | -------------------------------------------------------------------------------- /src/main/java/com/example/hobbie/service/impl/CategoryServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.hobbie.service.impl; 2 | 3 | import com.example.hobbie.handler.NotFoundException; 4 | import com.example.hobbie.model.entities.Category; 5 | import com.example.hobbie.model.entities.enums.CategoryNameEnum; 6 | import com.example.hobbie.model.repostiory.CategoryRepository; 7 | import com.example.hobbie.service.CategoryService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.ArrayList; 12 | import java.util.Arrays; 13 | import java.util.List; 14 | import java.util.Optional; 15 | 16 | @Service 17 | public class CategoryServiceImpl implements CategoryService { 18 | private final CategoryRepository categoryRepository; 19 | 20 | @Autowired 21 | public CategoryServiceImpl(CategoryRepository categoryRepository) { 22 | this.categoryRepository = categoryRepository; 23 | } 24 | 25 | @Override 26 | public Category findByName(CategoryNameEnum category) { 27 | Optional
39 |
40 |
41 |
42 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/src/test/java/com/example/hobbie/service/impl/TestServiceImplTest.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.service.impl;
2 |
3 | import com.example.hobbie.model.entities.Hobby;
4 | import com.example.hobbie.model.entities.UserRoleEntity;
5 | import com.example.hobbie.model.entities.enums.CategoryNameEnum;
6 | import com.example.hobbie.model.entities.enums.LocationEnum;
7 | import com.example.hobbie.model.repostiory.TestRepository;
8 | import com.example.hobbie.model.service.TestServiceModel;
9 | import com.example.hobbie.service.TestService;
10 | import org.junit.jupiter.api.Test;
11 | import org.mockito.Mockito;
12 |
13 | import static org.junit.jupiter.api.Assertions.*;
14 | import static org.mockito.Mockito.times;
15 | import static org.mockito.Mockito.when;
16 |
17 | class TestServiceImplTest {
18 | private TestRepository mockTestRepository = Mockito.mock(TestRepository.class);
19 | private TestService mockTestService = Mockito.mock(TestService.class);
20 | @Test
21 | void saveTest() {
22 |
23 | TestServiceModel testServiceModel = new TestServiceModel();
24 | // testServiceModel.setCategoryFive(CategoryNameEnum.ACTIVE);
25 | // testServiceModel.setCategoryFour(CategoryNameEnum.OTHER);
26 | // testServiceModel.setCategorySeven(CategoryNameEnum.RELAX);
27 | // testServiceModel.setCategoryOne(CategoryNameEnum.FUN);
28 | // testServiceModel.setCategoryTwo(CategoryNameEnum.CREATIVE);
29 | // testServiceModel.setCategoryThree(CategoryNameEnum.INTELLECTUAL);
30 | // testServiceModel.setLocation(LocationEnum.ZURICH);
31 |
32 | when(mockTestRepository.save(Mockito.any( com.example.hobbie.model.entities.Test.class)))
33 | .thenAnswer(i -> i.getArguments()[0]);
34 | mockTestService.saveTest(testServiceModel);
35 |
36 | assertNotNull(mockTestRepository.findById(1L));
37 |
38 | }
39 | }
--------------------------------------------------------------------------------
/src/main/java/com/example/hobbie/security/HobbieUserDetailsService.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.security;
2 |
3 | import com.example.hobbie.model.entities.UserEntity;
4 | import com.example.hobbie.model.repostiory.UserRepository;
5 | import org.springframework.security.core.GrantedAuthority;
6 | import org.springframework.security.core.authority.SimpleGrantedAuthority;
7 | import org.springframework.security.core.userdetails.User;
8 | import org.springframework.security.core.userdetails.UserDetails;
9 | import org.springframework.security.core.userdetails.UserDetailsService;
10 | import org.springframework.security.core.userdetails.UsernameNotFoundException;
11 | import org.springframework.stereotype.Component;
12 |
13 | import java.util.List;
14 | import java.util.stream.Collectors;
15 |
16 | @Component
17 | public class HobbieUserDetailsService implements UserDetailsService {
18 | private final UserRepository userRepository;
19 |
20 | public HobbieUserDetailsService(UserRepository userRepository) {
21 | this.userRepository = userRepository;
22 | }
23 |
24 | @Override
25 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
26 | UserEntity userEntity = userRepository.findByUsername(username).orElseThrow(
27 | () -> new UsernameNotFoundException("User with username " + username + " was not found."));
28 |
29 | return mapToUserDetails(userEntity);
30 | }
31 |
32 | private UserDetails mapToUserDetails(UserEntity userEntity) {
33 |
34 | List
38 |
39 |
40 |
41 |
44 |
45 |
--------------------------------------------------------------------------------
/src/main/resources/templates/home/business_owner.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
34 |
35 |
36 |
37 |
40 |
41 |
--------------------------------------------------------------------------------
/src/main/resources/templates/abo/my-abos.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
42 |
43 |
44 |
45 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/src/main/java/com/example/hobbie/model/service/HobbyServiceModel.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.model.service;
2 |
3 | import com.example.hobbie.model.entities.Category;
4 | import com.example.hobbie.model.entities.enums.CategoryNameEnum;
5 | import com.example.hobbie.model.entities.enums.LocationEnum;
6 | import org.springframework.web.multipart.MultipartFile;
7 |
8 | import java.math.BigDecimal;
9 |
10 | public class HobbyServiceModel {
11 | private String name;
12 | private String description;
13 | private CategoryNameEnum category;
14 | private String photos;
15 | private BigDecimal price;
16 | private LocationEnum location;
17 | private MultipartFile img;
18 |
19 | public HobbyServiceModel() {
20 | }
21 |
22 |
23 | public String getName() {
24 | return name;
25 | }
26 |
27 | public void setName(String name) {
28 | this.name = name;
29 | }
30 |
31 | public String getDescription() {
32 | return description;
33 | }
34 |
35 | public void setDescription(String description) {
36 | this.description = description;
37 | }
38 |
39 | public CategoryNameEnum getCategory() {
40 | return category;
41 | }
42 |
43 | public void setCategory(CategoryNameEnum category) {
44 | this.category = category;
45 | }
46 |
47 | public BigDecimal getPrice() {
48 | return price;
49 | }
50 |
51 | public void setPrice(BigDecimal price) {
52 | this.price = price;
53 | }
54 |
55 | public String getPhotos() {
56 | return photos;
57 | }
58 |
59 | public void setPhotos(String photos) {
60 | this.photos = photos;
61 | }
62 |
63 | public LocationEnum getLocation() {
64 | return location;
65 | }
66 |
67 | public void setLocation(LocationEnum location) {
68 | this.location = location;
69 | }
70 |
71 | public MultipartFile getImg() {
72 | return img;
73 | }
74 |
75 | public void setImg(MultipartFile img) {
76 | this.img = img;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/test/java/com/example/hobbie/web/AboControllerTest.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.web;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
7 | import org.springframework.boot.test.context.SpringBootTest;
8 | import org.springframework.security.test.context.support.WithMockUser;
9 | import org.springframework.test.context.junit4.SpringRunner;
10 | import org.springframework.test.web.servlet.MockMvc;
11 |
12 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
13 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
14 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
15 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
16 |
17 | @RunWith(SpringRunner.class)
18 | @SpringBootTest
19 | @AutoConfigureMockMvc
20 | class AboControllerTest {
21 | private static final String ABO_CONTROLLER_PREFIX = "/my-abos";
22 |
23 | @Autowired
24 | private MockMvc mockMvc;
25 |
26 | @Test
27 | @WithMockUser(value = "user", roles = {"USER", "ADMIN"})
28 | public void testShowAllAbosOK() throws Exception {
29 | this.mockMvc.perform(get("/my-abos")).
30 | andExpect(view().name("abo/my-abos")).
31 | andExpect(status().isOk());
32 | }
33 |
34 | @Test
35 | @WithMockUser(value = "user", roles = {"USER", "ADMIN"})
36 | public void testShowAboOK() throws Exception {
37 | this.mockMvc.
38 | perform(get("/abo/{id}", 1L)).
39 | andExpect(status().isOk());
40 | }
41 |
42 | @Test
43 | @WithMockUser(value = "user", roles = {"USER", "ADMIN"})
44 | void deleteAboThrows() throws Exception {
45 | this.mockMvc.
46 | perform(post("/delete-abo/{id}", 1L)).
47 | andExpect(status().is(403));
48 | }
49 | }
--------------------------------------------------------------------------------
/src/main/resources/META-INF/additional-spring-configuration-metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "properties": [
3 | {
4 | "name": "paypal.mode",
5 | "type": "java.lang.String"
6 | },
7 | {
8 | "name": "paypal.client.id",
9 | "type": "java.lang.String",
10 | "description": "Description for paypal.client.id."
11 | },
12 | {
13 | "name": "paypal.client.secret",
14 | "type": "java.lang.String",
15 | "description": "Description for paypal.client.secret."
16 | },
17 | {
18 | "name": "spring.servlet.multipart.cloudinary.api-key",
19 | "type": "java.lang.String",
20 | "description": "Description for spring.servlet.multipart.cloudinary.api-key."
21 | },
22 | {
23 | "name": "spring.rsocket.server.error.include-message",
24 | "type": "java.lang.String",
25 | "description": "Description for spring.rsocket.server.error.include-message."
26 | },
27 | {
28 | "name": "spring.rsocket.server.error.include-stacktrace",
29 | "type": "java.lang.String",
30 | "description": "Description for spring.rsocket.server.error.include-stacktrace."
31 | },
32 | {
33 | "name": "spring.servlet.multipart.cloudinary.cloud-name",
34 | "type": "java.lang.String",
35 | "description": "Description for spring.servlet.multipart.cloudinary.cloud-name."
36 | },
37 | {
38 | "name": "spring.servlet.multipart.cloudinary.api-secret",
39 | "type": "java.lang.String",
40 | "description": "Description for spring.servlet.multipart.cloudinary.api-secret."
41 | },
42 | {
43 | "name": "cloudinary.cloud-name",
44 | "type": "java.lang.String",
45 | "description": "Description for cloudinary.cloud-name."
46 | },
47 | {
48 | "name": "cloudinary.api-key",
49 | "type": "java.lang.String",
50 | "description": "Description for cloudinary.api-key."
51 | },
52 | {
53 | "name": "cloudinary.api-secret",
54 | "type": "java.lang.String",
55 | "description": "Description for cloudinary.api-secret."
56 | }
57 | ]
58 | }
--------------------------------------------------------------------------------
/src/main/java/com/example/hobbie/model/entities/Abo.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.model.entities;
2 |
3 | import javax.persistence.*;
4 | import java.math.BigDecimal;
5 | import java.util.List;
6 |
7 | @Entity
8 | @Table(name = "abos")
9 | public class Abo extends BaseEntity {
10 | private Long clientId;
11 | private Long businessOwnerId;
12 | private Long hobbyId;
13 | private List
63 |
64 |
--------------------------------------------------------------------------------
/src/main/java/com/example/hobbie/model/binding/HobbyBindingModel.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.model.binding;
2 |
3 | import com.example.hobbie.model.entities.enums.CategoryNameEnum;
4 | import com.example.hobbie.model.entities.enums.LocationEnum;
5 | import org.springframework.web.multipart.MultipartFile;
6 |
7 | import javax.validation.constraints.NotNull;
8 | import javax.validation.constraints.Size;
9 | import java.math.BigDecimal;
10 |
11 | public class HobbyBindingModel {
12 | private String name;
13 | private String description;
14 | private CategoryNameEnum category;
15 | private BigDecimal price;
16 | private LocationEnum location;
17 | private MultipartFile img;
18 |
19 | public HobbyBindingModel() {
20 | }
21 |
22 | @Size(min = 3, max = 20, message = "Name must be between 3 and 20 symbols.")
23 | @NotNull(message = "Hobby name can not be empty.")
24 | public String getName() {
25 | return name;
26 | }
27 |
28 | public void setName(String name) {
29 | this.name = name;
30 | }
31 |
32 | @Size(min = 30, max = 1050, message = "Description must be between 30 and 1050 symbols")
33 | @NotNull(message = "You need to have a description")
34 | public String getDescription() {
35 | return description;
36 | }
37 |
38 | public void setDescription(String description) {
39 | this.description = description;
40 | }
41 |
42 | @NotNull(message = "You have to choose category")
43 | public CategoryNameEnum getCategory() {
44 | return category;
45 | }
46 |
47 | public void setCategory(CategoryNameEnum category) {
48 | this.category = category;
49 | }
50 |
51 | @NotNull(message = "You have to set price")
52 | public BigDecimal getPrice() {
53 | return price;
54 | }
55 |
56 | public void setPrice(BigDecimal price) {
57 | this.price = price;
58 | }
59 |
60 | @NotNull(message = "You have to choose a location")
61 | public LocationEnum getLocation() {
62 | return location;
63 | }
64 |
65 | public void setLocation(LocationEnum location) {
66 | this.location = location;
67 | }
68 |
69 | @NotNull(message = "You have to choose profile picture")
70 | public MultipartFile getImg() {
71 | return img;
72 | }
73 |
74 | public void setImg(MultipartFile img) {
75 | this.img = img;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/com/example/hobbie/web/TestController.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.web;
2 |
3 | import com.example.hobbie.config.UserInterceptor;
4 | import com.example.hobbie.model.binding.TestBindingModel;
5 | import com.example.hobbie.model.service.TestServiceModel;
6 | import com.example.hobbie.service.TestService;
7 | import org.modelmapper.ModelMapper;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Controller;
10 | import org.springframework.ui.Model;
11 | import org.springframework.validation.BindingResult;
12 | import org.springframework.web.bind.annotation.GetMapping;
13 | import org.springframework.web.bind.annotation.PostMapping;
14 | import org.springframework.web.servlet.mvc.support.RedirectAttributes;
15 |
16 | import javax.validation.Valid;
17 |
18 | @Controller
19 | public class TestController {
20 | private final TestService testService;
21 | private final ModelMapper modelMapper;
22 |
23 | @Autowired
24 | public TestController(TestService testService, ModelMapper modelMapper) {
25 | this.testService = testService;
26 | this.modelMapper = modelMapper;
27 | }
28 |
29 | @GetMapping("/test")
30 | public String showTest(Model model) {
31 | if (UserInterceptor.isUserLogged()) {
32 | if (!model.containsAttribute("testBindingModel")) {
33 | model.addAttribute("testBindingModel", new TestBindingModel());
34 | }
35 | return "test/test";
36 | } else {
37 | return "home/index";
38 | }
39 | }
40 |
41 | @PostMapping("/test")
42 | public String saveTestResults(@Valid TestBindingModel testBindingModel, BindingResult bindingResult, RedirectAttributes redirectAttributes) {
43 | if (UserInterceptor.isUserLogged()) {
44 | if (bindingResult.hasErrors()) {
45 | redirectAttributes.addFlashAttribute("testBindingModel", testBindingModel);
46 | redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.testBindingModel", bindingResult);
47 | return "redirect:/test";
48 | } else {
49 | this.testService.saveTest(this.modelMapper.map(testBindingModel, TestServiceModel.class));
50 |
51 | return "redirect:/";
52 | }
53 | } else {
54 | return "home/index";
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/example/hobbie/model/service/TestServiceModel.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.model.service;
2 |
3 | import com.example.hobbie.model.entities.enums.CategoryNameEnum;
4 | import com.example.hobbie.model.entities.enums.LocationEnum;
5 |
6 | public class TestServiceModel {
7 | private CategoryNameEnum categoryOne;
8 | private CategoryNameEnum categoryTwo;
9 | private CategoryNameEnum categoryThree;
10 | private CategoryNameEnum categoryFour;
11 | private CategoryNameEnum categoryFive;
12 | private CategoryNameEnum categorySix;
13 | private CategoryNameEnum categorySeven;
14 | private LocationEnum location;
15 |
16 | public TestServiceModel() {
17 | }
18 |
19 | public CategoryNameEnum getCategoryOne() {
20 | return categoryOne;
21 | }
22 |
23 | public void setCategoryOne(CategoryNameEnum categoryOne) {
24 | this.categoryOne = categoryOne;
25 | }
26 |
27 | public CategoryNameEnum getCategoryTwo() {
28 | return categoryTwo;
29 | }
30 |
31 | public void setCategoryTwo(CategoryNameEnum categoryTwo) {
32 | this.categoryTwo = categoryTwo;
33 | }
34 |
35 | public CategoryNameEnum getCategoryThree() {
36 | return categoryThree;
37 | }
38 |
39 | public void setCategoryThree(CategoryNameEnum categoryThree) {
40 | this.categoryThree = categoryThree;
41 | }
42 |
43 | public CategoryNameEnum getCategoryFour() {
44 | return categoryFour;
45 | }
46 |
47 | public void setCategoryFour(CategoryNameEnum categoryFour) {
48 | this.categoryFour = categoryFour;
49 | }
50 |
51 | public CategoryNameEnum getCategoryFive() {
52 | return categoryFive;
53 | }
54 |
55 | public void setCategoryFive(CategoryNameEnum categoryFive) {
56 | this.categoryFive = categoryFive;
57 | }
58 |
59 | public CategoryNameEnum getCategorySix() {
60 | return categorySix;
61 | }
62 |
63 | public void setCategorySix(CategoryNameEnum categorySix) {
64 | this.categorySix = categorySix;
65 | }
66 |
67 | public CategoryNameEnum getCategorySeven() {
68 | return categorySeven;
69 | }
70 |
71 | public void setCategorySeven(CategoryNameEnum categorySeven) {
72 | this.categorySeven = categorySeven;
73 | }
74 |
75 | public LocationEnum getLocation() {
76 | return location;
77 | }
78 |
79 | public void setLocation(LocationEnum location) {
80 | this.location = location;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/resources/templates/home/user_home.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 | 47 | Hiking 48 |
49 |Find out more...
51 |500 CHF
52 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/src/test/java/com/example/hobbie/web/TestControllerTest.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.web;
2 |
3 | import com.example.hobbie.model.entities.enums.CategoryNameEnum;
4 | import com.example.hobbie.model.entities.enums.LocationEnum;
5 | import org.junit.jupiter.api.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.security.test.context.support.WithMockUser;
11 | import org.springframework.test.context.junit4.SpringRunner;
12 | import org.springframework.test.web.servlet.MockMvc;
13 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
14 |
15 | import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
16 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
17 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
18 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
19 |
20 | @RunWith(SpringRunner.class)
21 | @SpringBootTest
22 | @AutoConfigureMockMvc
23 | class TestControllerTest {
24 | @Autowired
25 | private MockMvc mockMvc;
26 |
27 | @Test
28 | @WithMockUser(value = "user", roles = {"USER", "ADMIN"})
29 | void showTest_should_work() throws Exception {
30 | this.mockMvc.perform(get("/test")).
31 | andExpect(view().name("test/test")).
32 | andExpect(status().isOk());
33 | }
34 |
35 | @Test
36 | @WithMockUser(value = "user", roles = {"USER", "ADMIN"})
37 | void saveTestResults_should_work() throws Exception {
38 | mockMvc.perform(MockMvcRequestBuilders.post("/test")
39 | .param("categoryOne", CategoryNameEnum.CREATIVE.name())
40 | .param("categoryTwo", CategoryNameEnum.CREATIVE.name())
41 | .param("categoryThree", CategoryNameEnum.CREATIVE.name())
42 | .param("categoryFour", CategoryNameEnum.CREATIVE.name())
43 | .param("categoryFive", CategoryNameEnum.CREATIVE.name())
44 | .param("categorySix", CategoryNameEnum.CREATIVE.name())
45 | .param("categorySeven", CategoryNameEnum.CREATIVE.name())
46 | .param("location", LocationEnum.ZURICH.name())
47 | .with(csrf())).
48 | andExpect(status().is3xxRedirection());
49 | }
50 | }
--------------------------------------------------------------------------------
/src/main/java/com/example/hobbie/model/binding/UpdateHobbyBindingModel.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.model.binding;
2 |
3 | import com.example.hobbie.model.entities.enums.CategoryNameEnum;
4 | import com.example.hobbie.model.entities.enums.LocationEnum;
5 | import org.springframework.web.multipart.MultipartFile;
6 |
7 | import javax.validation.constraints.NotNull;
8 | import javax.validation.constraints.Size;
9 | import java.math.BigDecimal;
10 |
11 | public class UpdateHobbyBindingModel {
12 | private Long id;
13 | private String name;
14 | private String description;
15 | private CategoryNameEnum category;
16 | private BigDecimal price;
17 | private LocationEnum location;
18 | private MultipartFile img;
19 |
20 | public UpdateHobbyBindingModel() {
21 | }
22 |
23 | @Size(min = 3, max = 20, message = "Name must be between 3 and 20 symbols.")
24 | @NotNull(message = "Hobby name can not be empty.")
25 | public String getName() {
26 | return name;
27 | }
28 |
29 | public void setName(String name) {
30 | this.name = name;
31 | }
32 |
33 | @Size(min = 30, max = 1050, message = "Description must be between 30 and 1050 symbols")
34 | @NotNull(message = "You need to have a description")
35 | public String getDescription() {
36 | return description;
37 | }
38 |
39 | public void setDescription(String description) {
40 | this.description = description;
41 | }
42 |
43 |
44 | @NotNull(message = "You have to choose category")
45 | public CategoryNameEnum getCategory() {
46 | return category;
47 | }
48 |
49 | public void setCategory(CategoryNameEnum category) {
50 | this.category = category;
51 | }
52 |
53 | @NotNull(message = "You have to set price")
54 | public BigDecimal getPrice() {
55 | return price;
56 | }
57 |
58 | public void setPrice(BigDecimal price) {
59 | this.price = price;
60 | }
61 |
62 | @NotNull
63 | public Long getId() {
64 | return id;
65 | }
66 |
67 | public void setId(Long id) {
68 | this.id = id;
69 | }
70 |
71 | @NotNull(message = "You have to choose location")
72 | public LocationEnum getLocation() {
73 | return location;
74 | }
75 |
76 | public void setLocation(LocationEnum location) {
77 | this.location = location;
78 | }
79 |
80 | @NotNull(message = "You have to choose profile picture")
81 | public MultipartFile getImg() {
82 | return img;
83 | }
84 |
85 | public void setImg(MultipartFile img) {
86 | this.img = img;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/com/example/hobbie/config/SecurityConfig.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.config;
2 |
3 | import com.example.hobbie.security.HobbieUserDetailsService;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.context.annotation.Configuration;
6 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
7 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
8 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
9 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
10 | import org.springframework.security.crypto.password.PasswordEncoder;
11 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
12 |
13 | @Configuration
14 | @EnableWebSecurity
15 | public class SecurityConfig extends WebSecurityConfigurerAdapter {
16 | private final HobbieUserDetailsService hobbieUserDetailsService;
17 | private final PasswordEncoder passwordEncoder;
18 |
19 | @Autowired
20 | public SecurityConfig(HobbieUserDetailsService hobbieUserDetailsService, PasswordEncoder passwordEncoder) {
21 | this.hobbieUserDetailsService = hobbieUserDetailsService;
22 | this.passwordEncoder = passwordEncoder;
23 | }
24 |
25 | @Override
26 | protected void configure(AuthenticationManagerBuilder auth) throws Exception {
27 | auth.userDetailsService(hobbieUserDetailsService).passwordEncoder(passwordEncoder);
28 | }
29 |
30 | @Override
31 | protected void configure(HttpSecurity http) throws Exception {
32 |
33 | http.authorizeRequests().antMatchers("/css/**", "/img/**", "/js/**").permitAll()
34 | .antMatchers("/", "/users/login", "/users/signup", "/users/register-business").permitAll()
35 | .antMatchers("/**").authenticated()
36 | .and()
37 | .formLogin().loginPage("/users/login")
38 | .usernameParameter(UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY)
39 | .passwordParameter(UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY)
40 | .defaultSuccessUrl("/")
41 | .failureForwardUrl("/users/login-error")
42 | .and()
43 | .logout()
44 | .logoutSuccessUrl("/")
45 | // remove the session from the server
46 | .invalidateHttpSession(true).
47 | // delete the session cookie
48 | deleteCookies("JSESSIONID");
49 |
50 | }
51 |
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/com/example/hobbie/config/SessionTimerInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.config;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.security.core.context.SecurityContextHolder;
7 | import org.springframework.stereotype.Component;
8 | import org.springframework.web.servlet.HandlerInterceptor;
9 | import org.springframework.web.servlet.ModelAndView;
10 |
11 | import javax.servlet.http.HttpServletRequest;
12 | import javax.servlet.http.HttpServletResponse;
13 | import javax.servlet.http.HttpSession;
14 |
15 | @Component
16 | public class SessionTimerInterceptor implements HandlerInterceptor {
17 | private static final long MAX_INACTIVE_SESSION_TIME = 12 * 10000;
18 |
19 | private HttpSession session;
20 |
21 | Logger log = LoggerFactory.getLogger(SessionTimerInterceptor.class);
22 |
23 | @Autowired
24 | public SessionTimerInterceptor(HttpSession session) {
25 | this.session = session;
26 | }
27 |
28 | public SessionTimerInterceptor() {
29 | }
30 |
31 |
32 | @Override
33 | public boolean preHandle(
34 | HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
35 | log.info("Pre handle method - check handling start time");
36 | long startTime = System.currentTimeMillis();
37 | request.setAttribute("executionTime", startTime);
38 | if (UserInterceptor.isUserLogged()) {
39 | session = request.getSession();
40 | log.info(String.format("Time since last request in this session: %d ms",
41 | System.currentTimeMillis() - request.getSession().getLastAccessedTime()));
42 | if (System.currentTimeMillis() - session.getLastAccessedTime()
43 | > MAX_INACTIVE_SESSION_TIME) {
44 | log.warn("Logging out, due to inactive session");
45 | SecurityContextHolder.clearContext();
46 | request.logout();
47 | response.sendRedirect("/default");
48 |
49 | }
50 | }
51 | return true;
52 | }
53 |
54 | @Override
55 | public void postHandle(
56 | HttpServletRequest request,
57 | HttpServletResponse response,
58 | Object handler,
59 | ModelAndView model) throws Exception {
60 | log.info("Post handle method - check execution time of handling");
61 | long startTime = (Long) request.getAttribute("executionTime");
62 | log.info("Execution time for handling the request was: {} ms",
63 | System.currentTimeMillis() - startTime);
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/test/java/com/example/hobbie/service/impl/UserRoleServiceImplTest.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.service.impl;
2 |
3 | import com.example.hobbie.handler.NotFoundException;
4 | import com.example.hobbie.model.entities.UserRoleEntity;
5 | import com.example.hobbie.model.entities.enums.UserRoleEnum;
6 | import com.example.hobbie.model.repostiory.AppClientRepository;
7 | import com.example.hobbie.model.repostiory.BusinessOwnerRepository;
8 | import com.example.hobbie.model.repostiory.UserRepository;
9 | import com.example.hobbie.model.repostiory.UserRoleRepository;
10 | import com.example.hobbie.service.UserRoleService;
11 | import org.junit.Assert;
12 |
13 | import org.junit.jupiter.api.Assertions;
14 | import org.junit.jupiter.api.BeforeEach;
15 | import org.junit.jupiter.api.Test;
16 | import org.mockito.Mockito;
17 |
18 | import org.modelmapper.ModelMapper;
19 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
20 |
21 | import java.util.Optional;
22 |
23 | import static org.junit.jupiter.api.Assertions.*;
24 | import static org.mockito.ArgumentMatchers.any;
25 | import static org.mockito.Mockito.mock;
26 | import static org.mockito.Mockito.when;
27 |
28 | class UserRoleServiceImplTest {
29 | private UserRoleService mockUserRoleServiceToTest;
30 | private UserRoleEntity userRoleEntity;
31 | private UserRoleRepository mockUserRoleRepository;
32 |
33 | @BeforeEach
34 | public void setUp() {
35 | mockUserRoleRepository = mock(UserRoleRepository.class);
36 | mockUserRoleServiceToTest = new UserRoleServiceImpl(mockUserRoleRepository);
37 | userRoleEntity = new UserRoleEntity();
38 | userRoleEntity.setRole(UserRoleEnum.USER);
39 | when(mockUserRoleRepository.save(any(UserRoleEntity.class)))
40 | .thenAnswer(i -> i.getArguments()[0]);
41 |
42 | }
43 |
44 | @Test
45 | void getUserRoleByEnumName_Should_Work() {
46 |
47 | Mockito.when(mockUserRoleRepository.findByRole(UserRoleEnum.USER)).
48 | thenReturn(Optional.of(userRoleEntity));
49 | UserRoleEntity userRoleByEnumName = mockUserRoleServiceToTest.getUserRoleByEnumName(UserRoleEnum.USER);
50 |
51 | assertEquals(userRoleEntity.getRole(),userRoleByEnumName.getRole());
52 | }
53 |
54 | @Test
55 | void role_should_be_Saved() {
56 | Mockito.when(mockUserRoleRepository.save(any(UserRoleEntity.class))).
57 | thenReturn(userRoleEntity);
58 | UserRoleEntity userRole= mockUserRoleServiceToTest.saveRole(this.userRoleEntity);
59 |
60 | assertEquals(userRole.getId(), userRoleEntity.getId());
61 | }
62 |
63 | @Test
64 | void testUserNotFound() {
65 | Assertions.assertThrows(
66 | NotFoundException.class,
67 | () -> mockUserRoleServiceToTest.getUserRoleByEnumName(UserRoleEnum.USER));
68 | }
69 |
70 |
71 |
72 | }
--------------------------------------------------------------------------------
/src/test/java/com/example/hobbie/web/HobbyControllerTest.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.web;
2 |
3 | import com.example.hobbie.model.entities.enums.CategoryNameEnum;
4 | import com.example.hobbie.model.entities.enums.LocationEnum;
5 | import org.junit.jupiter.api.Test;
6 | import org.junit.runner.RunWith;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.security.test.context.support.WithMockUser;
11 | import org.springframework.test.context.junit4.SpringRunner;
12 | import org.springframework.test.web.servlet.MockMvc;
13 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
14 |
15 | import java.math.BigDecimal;
16 |
17 | import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
18 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
19 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
20 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
21 |
22 | @RunWith(SpringRunner.class)
23 | @SpringBootTest
24 | @AutoConfigureMockMvc
25 | class HobbyControllerTest {
26 |
27 | @Autowired
28 | private MockMvc mockMvc;
29 |
30 | @Test
31 | @WithMockUser(value = "user", roles = {"USER", "ADMIN"})
32 | void showOffer_should_work() throws Exception {
33 | this.mockMvc.perform(get("/hobbies/create-offer-page")).
34 | andExpect(view().name("offer/create_offer")).
35 | andExpect(status().isOk());
36 | }
37 |
38 | @Test
39 | void saveHobby_should_work() throws Exception {
40 | mockMvc.perform(MockMvcRequestBuilders.post("/hobbies/create_offer")
41 | .param("img", "file")
42 | .param("name", "Nikoleta").
43 | param("description", "bla").
44 | param("category", CategoryNameEnum.ACTIVE.name()).
45 | param("price", String.valueOf(new BigDecimal("100"))).
46 | param("location", LocationEnum.ZURICH.name()).
47 | with(csrf())).
48 | andExpect(status().is3xxRedirection());
49 | }
50 |
51 | @Test
52 | @WithMockUser(value = "user", roles = {"USER", "ADMIN"})
53 | void showHome_should_work() throws Exception {
54 | this.mockMvc.
55 | perform(get("/hobbies/save-hobby/{id}", 1L)).
56 | andExpect(status().isOk());
57 | }
58 |
59 | @Test
60 | @WithMockUser(value = "user", roles = {"USER", "ADMIN"})
61 | void removeHobby_should_work() throws Exception {
62 | this.mockMvc.
63 | perform(get("/hobbies/remove-hobby/{id}", 1L)).
64 | andExpect(status().isOk());
65 | }
66 | }
--------------------------------------------------------------------------------
/src/main/resources/templates/offer/offer-details.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 | 16 | Bouldering at an indoors bouldering centre in Pasila, Helsinki, Finland 17 | Climbing activities include: 18 | Bouldering: Ascending boulders or small outcrops, often with climbing shoes and a chalk bag or bucket. Usually, instead of using a safety rope from above, injury is avoided using a crash pad and a human spotter (to direct a falling climber on to the pad. They can also give beta, or advice)[2] 19 | Buildering: Ascending the exterior skeletons of buildings, typically without protective equipment. 20 | Canyoneering: Climbing along canyons for sport or recreation. 21 | Chalk climbing: Ascending chalk cliffs uses some of the same techniques as ice climbing. 22 | Competition climbing: A formal, competitive sport of recent origins, normally practiced on artificial walls that resemble natural formations. The International Federation of Sport Climbing (IFSC) is the official organization governing competition rock climbing worldwide and is recognized by the IOC and GAISF and is a member of the International World Games Association (IWGA). The UIAA is the official organization governing competition ice climbing worldwide. Competition climbing has three major disciplines: Lead, Bouldering and Speed. 23 | 24 | Pole climbing: Climbing poles and masts without equipment.
25 | 31 |
34 |
35 |
36 |
37 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/main/java/com/example/hobbie/service/impl/EntryServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.service.impl;
2 |
3 | import com.example.hobbie.handler.NotFoundException;
4 | import com.example.hobbie.model.entities.AppClient;
5 | import com.example.hobbie.service.NotificationService;
6 | import com.example.hobbie.view.EntryViewModel;
7 | import com.example.hobbie.model.entities.Entry;
8 | import com.example.hobbie.model.repostiory.EntryRepository;
9 | import com.example.hobbie.service.EntryService;
10 | import org.modelmapper.ModelMapper;
11 | import org.springframework.beans.factory.annotation.Autowired;
12 | import org.springframework.mail.MailException;
13 | import org.springframework.stereotype.Service;
14 |
15 | import java.text.SimpleDateFormat;
16 | import java.util.Calendar;
17 | import java.util.List;
18 | import java.util.Optional;
19 | import java.util.stream.Collectors;
20 |
21 | @Service
22 | public class EntryServiceImpl implements EntryService {
23 | private final EntryRepository entryRepository;
24 | private final ModelMapper modelMapper;
25 | private final NotificationService notificationService;
26 |
27 | @Autowired
28 | public EntryServiceImpl(EntryRepository entryRepository, ModelMapper modelMapper, NotificationService notificationService) {
29 | this.entryRepository = entryRepository;
30 | this.modelMapper = modelMapper;
31 | this.notificationService = notificationService;
32 | }
33 |
34 | @Override
35 | public List16 | Bouldering at an indoors bouldering centre in Pasila, Helsinki, Finland 17 | Climbing activities include: 18 | Bouldering: Ascending boulders or small outcrops, often with climbing shoes and a chalk bag or bucket. Usually, instead of using a safety rope from above, injury is avoided using a crash pad and a human spotter (to direct a falling climber on to the pad. They can also give beta, or advice)[2] 19 | Buildering: Ascending the exterior skeletons of buildings, typically without protective equipment. 20 | Canyoneering: Climbing along canyons for sport or recreation. 21 | Chalk climbing: Ascending chalk cliffs uses some of the same techniques as ice climbing. 22 | Competition climbing: A formal, competitive sport of recent origins, normally practiced on artificial walls that resemble natural formations. The International Federation of Sport Climbing (IFSC) is the official organization governing competition rock climbing worldwide and is recognized by the IOC and GAISF and is a member of the International World Games Association (IWGA). The UIAA is the official organization governing competition ice climbing worldwide. Competition climbing has three major disciplines: Lead, Bouldering and Speed. 23 | 24 | Pole climbing: Climbing poles and masts without equipment.
25 |
39 |
40 |
41 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/src/main/java/com/example/hobbie/config/UserInterceptor.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.config;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 | import org.springframework.security.core.context.SecurityContextHolder;
6 | import org.springframework.stereotype.Component;
7 | import org.springframework.web.servlet.HandlerInterceptor;
8 | import org.springframework.web.servlet.ModelAndView;
9 | import org.springframework.web.servlet.SmartView;
10 | import org.springframework.web.servlet.View;
11 |
12 | import javax.servlet.http.HttpServletRequest;
13 | import javax.servlet.http.HttpServletResponse;
14 | import javax.servlet.http.HttpSession;
15 |
16 | @Component
17 | public class UserInterceptor implements HandlerInterceptor {
18 |
19 | Logger log = LoggerFactory.getLogger(UserInterceptor.class);
20 |
21 | public static boolean isUserLogged() {
22 | try {
23 | return !SecurityContextHolder.getContext().getAuthentication()
24 | .getName().equals("anonymousUser");
25 | } catch (Exception e) {
26 | return false;
27 | }
28 | }
29 |
30 | @Override
31 | public boolean preHandle(HttpServletRequest request,
32 | HttpServletResponse response, Object object) throws Exception {
33 | if (isUserLogged()) {
34 | addToModelUserDetails(request.getSession());
35 | }
36 | return true;
37 | }
38 |
39 | private void addToModelUserDetails(HttpSession session) {
40 | log.info("=============== addToModelUserDetails =========================");
41 |
42 | String loggedUsername
43 | = SecurityContextHolder.getContext().getAuthentication().getName();
44 | session.setAttribute("username", loggedUsername);
45 |
46 | log.info("user(" + loggedUsername + ") session : " + session);
47 | log.info("=============== addToModelUserDetails =========================");
48 | }
49 |
50 | @Override
51 | public void postHandle(
52 | HttpServletRequest req,
53 | HttpServletResponse res,
54 | Object o,
55 | ModelAndView model) throws Exception {
56 |
57 | if (model != null && !isRedirectView(model)) {
58 | if (isUserLogged()) {
59 | addToModelUserDetails(model);
60 | }
61 | }
62 | }
63 |
64 | public static boolean isRedirectView(ModelAndView mv) {
65 | String viewName = mv.getViewName();
66 | if (viewName.startsWith("redirect:/")) {
67 | return true;
68 | }
69 | View view = mv.getView();
70 | return (view != null && view instanceof SmartView
71 | && ((SmartView) view).isRedirectView());
72 | }
73 |
74 | private void addToModelUserDetails(ModelAndView model) {
75 | log.info("=============== addToModelUserDetails =========================");
76 |
77 | String loggedUsername = SecurityContextHolder.getContext()
78 | .getAuthentication().getName();
79 | model.addObject("loggedUsername", loggedUsername);
80 |
81 | log.trace("session : " + model.getModel());
82 | log.info("=============== addToModelUserDetails =========================");
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/com/example/hobbie/model/entities/Test.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.model.entities;
2 |
3 | import com.example.hobbie.model.entities.enums.CategoryNameEnum;
4 | import com.example.hobbie.model.entities.enums.LocationEnum;
5 |
6 | import javax.persistence.*;
7 |
8 | @Entity
9 | @Table(name = "test_results")
10 | public class Test extends BaseEntity {
11 | private AppClient appClient;
12 | private CategoryNameEnum categoryOne;
13 | private CategoryNameEnum categoryTwo;
14 | private CategoryNameEnum categoryThree;
15 | private CategoryNameEnum categoryFour;
16 | private CategoryNameEnum categoryFive;
17 | private CategoryNameEnum categorySix;
18 | private CategoryNameEnum categorySeven;
19 | private LocationEnum location;
20 |
21 | public Test() {
22 | }
23 |
24 | @OneToOne
25 | public AppClient getAppClient() {
26 | return appClient;
27 | }
28 |
29 | public void setAppClient(AppClient appClient) {
30 | this.appClient = appClient;
31 | }
32 |
33 | @Enumerated(EnumType.STRING)
34 | @Column(name = "category_one")
35 | public CategoryNameEnum getCategoryOne() {
36 | return categoryOne;
37 | }
38 |
39 | public void setCategoryOne(CategoryNameEnum categoryOne) {
40 | this.categoryOne = categoryOne;
41 | }
42 |
43 | @Enumerated(EnumType.STRING)
44 | @Column(name = "category_two")
45 | public CategoryNameEnum getCategoryTwo() {
46 | return categoryTwo;
47 | }
48 |
49 | public void setCategoryTwo(CategoryNameEnum categoryTwo) {
50 | this.categoryTwo = categoryTwo;
51 | }
52 |
53 | @Enumerated(EnumType.STRING)
54 | @Column(name = "category_three")
55 | public CategoryNameEnum getCategoryThree() {
56 | return categoryThree;
57 | }
58 |
59 | public void setCategoryThree(CategoryNameEnum categoryThree) {
60 | this.categoryThree = categoryThree;
61 | }
62 |
63 | @Enumerated(EnumType.STRING)
64 | @Column(name = "category_four")
65 | public CategoryNameEnum getCategoryFour() {
66 | return categoryFour;
67 | }
68 |
69 | public void setCategoryFour(CategoryNameEnum categoryFour) {
70 | this.categoryFour = categoryFour;
71 | }
72 |
73 | @Enumerated(EnumType.STRING)
74 | @Column(name = "category_five")
75 | public CategoryNameEnum getCategoryFive() {
76 | return categoryFive;
77 | }
78 |
79 | public void setCategoryFive(CategoryNameEnum categoryFive) {
80 | this.categoryFive = categoryFive;
81 | }
82 |
83 | @Enumerated(EnumType.STRING)
84 | @Column(name = "category_six")
85 | public CategoryNameEnum getCategorySix() {
86 | return categorySix;
87 | }
88 |
89 | public void setCategorySix(CategoryNameEnum categorySix) {
90 | this.categorySix = categorySix;
91 | }
92 |
93 | @Enumerated(EnumType.STRING)
94 | @Column(name = "category_seven")
95 | public CategoryNameEnum getCategorySeven() {
96 | return categorySeven;
97 | }
98 |
99 | public void setCategorySeven(CategoryNameEnum categorySeven) {
100 | this.categorySeven = categorySeven;
101 | }
102 |
103 | @Enumerated(EnumType.STRING)
104 | public LocationEnum getLocation() {
105 | return location;
106 | }
107 |
108 | public void setLocation(LocationEnum location) {
109 | this.location = location;
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/src/main/java/com/example/hobbie/web/HomeController.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.web;
2 |
3 | import com.example.hobbie.config.UserInterceptor;
4 | import com.example.hobbie.model.entities.AppClient;
5 | import com.example.hobbie.service.AboService;
6 | import com.example.hobbie.service.HobbyService;
7 | import com.example.hobbie.service.UserService;
8 | import com.example.hobbie.view.HobbyCardViewModel;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 | import org.springframework.security.core.annotation.AuthenticationPrincipal;
11 | import org.springframework.security.core.userdetails.UserDetails;
12 | import org.springframework.stereotype.Controller;
13 | import org.springframework.web.bind.annotation.GetMapping;
14 | import org.springframework.web.bind.annotation.RequestMapping;
15 | import org.springframework.web.servlet.ModelAndView;
16 |
17 | import javax.servlet.http.HttpServletRequest;
18 | import java.util.List;
19 |
20 | @Controller
21 | @RequestMapping("/")
22 | public class HomeController {
23 | private final HobbyService hobbyService;
24 | private final UserService userService;
25 | private final AboService aboService;
26 |
27 | @Autowired
28 | public HomeController(HobbyService hobbyService, UserService userService, AboService aboService) {
29 | this.hobbyService = hobbyService;
30 | this.userService = userService;
31 | this.aboService = aboService;
32 | }
33 |
34 | @RequestMapping("/")
35 | public String showHome(HttpServletRequest request) {
36 | if (UserInterceptor.isUserLogged()) {
37 | if (request.isUserInRole("ROLE_BUSINESS_USER")) {
38 | return "redirect:/business_owner";
39 | } else if (request.isUserInRole("ROLE_USER")) {
40 | return "redirect:/user_home";
41 | }
42 | return "redirect:/";
43 | }
44 | return "home/index";
45 | }
46 |
47 | @GetMapping("/business_owner")
48 | public ModelAndView adminShow(@AuthenticationPrincipal UserDetails principal) {
49 | if (UserInterceptor.isUserLogged()) {
50 | ModelAndView mav = new ModelAndView("home/business_owner");
51 | mav.addObject("user", principal);
52 | mav.addObject("hobby_offers", hobbyService.getAllHobbyOffers());
53 | mav.addObject("abos", this.aboService.getAbosPerBusiness());
54 | return mav;
55 | } else {
56 | ModelAndView mav = new ModelAndView("home/index");
57 | return mav;
58 | }
59 | }
60 |
61 | @GetMapping("/user_home")
62 | public ModelAndView userHomeShow(@AuthenticationPrincipal UserDetails principal) {
63 | if (UserInterceptor.isUserLogged()) {
64 | boolean isEmpty = false;
65 | boolean hasNoResults = false;
66 | ModelAndView mav = new ModelAndView("home/user_home");
67 | mav.addObject("user", principal);
68 | AppClient currentUserAppClient = this.userService.findCurrentUserAppClient();
69 | List
60 |
61 |
62 |
63 |
66 |
67 |
--------------------------------------------------------------------------------
/src/main/java/com/example/hobbie/service/impl/ShoppingCartServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.service.impl;
2 |
3 | import com.example.hobbie.model.entities.Abo;
4 | import com.example.hobbie.model.entities.AppClient;
5 | import com.example.hobbie.model.entities.Entry;
6 | import com.example.hobbie.model.entities.Hobby;
7 | import com.example.hobbie.service.*;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.stereotype.Service;
10 | import org.springframework.transaction.annotation.Transactional;
11 |
12 | import java.math.BigDecimal;
13 | import java.math.RoundingMode;
14 | import java.util.ArrayList;
15 | import java.util.List;
16 |
17 | @Service
18 | @Transactional
19 | public class ShoppingCartServiceImpl implements ShoppingCartService {
20 | private final UserService userService;
21 | private final AboService aboService;
22 | private final EntryService entryService;
23 | private List
89 |
90 |
--------------------------------------------------------------------------------
/src/main/java/com/example/hobbie/web/AboController.java:
--------------------------------------------------------------------------------
1 | package com.example.hobbie.web;
2 |
3 | import com.example.hobbie.config.UserInterceptor;
4 | import com.example.hobbie.model.entities.Abo;
5 | import com.example.hobbie.model.entities.AppClient;
6 | import com.example.hobbie.view.AboViewModel;
7 | import com.example.hobbie.view.EntryViewModel;
8 | import com.example.hobbie.service.AboService;
9 | import com.example.hobbie.service.EntryService;
10 | import com.example.hobbie.service.HobbyService;
11 | import com.example.hobbie.service.UserService;
12 | import org.modelmapper.ModelMapper;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.stereotype.Controller;
15 | import org.springframework.ui.Model;
16 | import org.springframework.web.bind.annotation.*;
17 | import org.springframework.web.servlet.ModelAndView;
18 |
19 | import java.text.ParseException;
20 | import java.util.List;
21 |
22 | @Controller
23 | public class AboController {
24 | private final UserService userService;
25 | private final AboService aboService;
26 | private final HobbyService hobbyService;
27 | private final EntryService entryService;
28 | private final ModelMapper modelMapper;
29 |
30 | @Autowired
31 | public AboController(UserService userService, AboService aboService, HobbyService hobbyService, EntryService entryService, ModelMapper modelMapper) {
32 | this.userService = userService;
33 | this.aboService = aboService;
34 | this.hobbyService = hobbyService;
35 | this.entryService = entryService;
36 | this.modelMapper = modelMapper;
37 | }
38 |
39 | @GetMapping("/my-abos")
40 | public ModelAndView ShowAllAbos() {
41 | if (UserInterceptor.isUserLogged()) {
42 | ModelAndView mav = new ModelAndView("abo/my-abos");
43 | mav.addObject("liked", this.hobbyService.findSavedHobbies(this.userService.findCurrentUserAppClient()));
44 | mav.addObject("abos", this.aboService.getUserAbos(this.userService.findCurrentUserAppClient().getId()));
45 | return mav;
46 | } else {
47 | ModelAndView mav = new ModelAndView("home/index");
48 | return mav;
49 | }
50 | }
51 |
52 | @GetMapping("/abo/{id}")
53 | public String showAbo(@PathVariable Long id, Model model) {
54 | if (UserInterceptor.isUserLogged()) {
55 | model.addAttribute("clientDetails", this.aboService.getClientDetails(id));
56 | AboViewModel aboById = this.aboService.findAboById(id);
57 | model.addAttribute("aboDetails", aboById);
58 | List
99 |
100 |
--------------------------------------------------------------------------------
/src/main/resources/templates/fragments/fragments.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
98 |
99 |
108 |
109 |
--------------------------------------------------------------------------------
/src/main/resources/templates/offer/create_offer.html:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
111 |
112 |
111 |
112 |