Commit d0a3beca authored by Michal Čížek's avatar Michal Čížek
Browse files

Merge branch 'main' of gitlab.fi.muni.cz:xcizek3/flea-market-manager into main

parents 1fd0fb47 1b19d0d4
......@@ -2,9 +2,6 @@ package cz.fi.muni.pa165.flea.market.manager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.argon2.Argon2PasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
/**
* @author Norbert Kominak
......@@ -15,9 +12,4 @@ public class FleaMarketManagerInitializer {
public static void main(String[] args) {
SpringApplication.run(FleaMarketManagerInitializer.class, args);
}
@Bean
public PasswordEncoder passwordEncoder() {
return new Argon2PasswordEncoder();
}
}
......@@ -17,23 +17,24 @@ import cz.fi.muni.pa165.flea.market.manager.dto.user.LoginDTO;
import cz.fi.muni.pa165.flea.market.manager.dto.user.UserCreateDTO;
import cz.fi.muni.pa165.flea.market.manager.dto.user.UserDTO;
import cz.fi.muni.pa165.flea.market.manager.dto.user.UserUpdateDTO;
import cz.fi.muni.pa165.flea.market.manager.entity.MarketEvent;
import cz.fi.muni.pa165.flea.market.manager.entity.MarketLocation;
import cz.fi.muni.pa165.flea.market.manager.entity.Stand;
import cz.fi.muni.pa165.flea.market.manager.entity.StandType;
import cz.fi.muni.pa165.flea.market.manager.entity.User;
import cz.fi.muni.pa165.flea.market.manager.entity.*;
import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;
import org.dozer.loader.api.BeanMappingBuilder;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import java.util.Collections;
/**
* Configuration of dozer mapping
*
* @author Lucia Lopuchova
*/
@Import(PersistenceConfig.class)
@SpringBootConfiguration
public class ControllerConfig {
@Configuration
public class DozerMappingConfig {
@Bean
public Mapper dozer(){
......@@ -43,7 +44,7 @@ public class ControllerConfig {
return dozer;
}
public class DozerCustomConfig extends BeanMappingBuilder {
public static class DozerCustomConfig extends BeanMappingBuilder {
@Override
protected void configure() {
mapping(User.class, UserDTO.class);
......
package cz.fi.muni.pa165.flea.market.manager.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.argon2.Argon2PasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
/**
* Configuration of password encoder used to encode stored passwords
*
* @author Norbert Kominak
*/
@Configuration
public class PasswordEncoderConfig {
@Bean
public PasswordEncoder passwordEncoder() {
return new Argon2PasswordEncoder();
}
}
package cz.fi.muni.pa165.flea.market.manager.config;
/**
* Configuration of Rest API paths
*
* @author Norbert Kominak
*/
public class PathsConfig {
public final static String ROOT = "/pa165";
public final static String REST_ROOT = ROOT + "/rest";
......
......@@ -10,7 +10,6 @@ import org.springframework.security.authentication.AuthenticationCredentialsNotF
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
......
package cz.fi.muni.pa165.flea.market.manager.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* Configuration of View Controllers
*
* @author Michal Cizek
*/
@Configuration
public class ViewControllerConfig implements WebMvcConfigurer {
@Override
......
......@@ -2,6 +2,7 @@ package cz.fi.muni.pa165.flea.market.manager.dao;
import com.mysema.query.jpa.impl.JPAQuery;
import cz.fi.muni.pa165.flea.market.manager.dao.domain.DomainDaoImpl;
import cz.fi.muni.pa165.flea.market.manager.dao.exception.DaoException;
import cz.fi.muni.pa165.flea.market.manager.entity.MarketEvent;
import cz.fi.muni.pa165.flea.market.manager.entity.QMarketEvent;
import lombok.NonNull;
......@@ -22,10 +23,14 @@ public class MarketEventDao extends DomainDaoImpl<MarketEvent, QMarketEvent> {
}
public List<MarketEvent> findAllByMarketLocation(@NonNull String marketLocationId) {
try {
JPAQuery query = new JPAQuery(entityManager);
return query
.from(qEntity)
.where(qEntity.location.id.eq(marketLocationId))
.list(qEntity);
} catch (Exception e) {
throw new DaoException(e.getMessage(), e);
}
}
}
......@@ -2,13 +2,12 @@ package cz.fi.muni.pa165.flea.market.manager.dao;
import com.mysema.query.jpa.impl.JPAQuery;
import cz.fi.muni.pa165.flea.market.manager.dao.domain.DomainDaoImpl;
import cz.fi.muni.pa165.flea.market.manager.dao.exception.DaoException;
import cz.fi.muni.pa165.flea.market.manager.entity.MarketLocation;
import cz.fi.muni.pa165.flea.market.manager.entity.QMarketLocation;
import lombok.NonNull;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* DAO for entity {@link MarketLocation}
*
......@@ -22,10 +21,14 @@ public class MarketLocationDao extends DomainDaoImpl<MarketLocation, QMarketLoca
}
public MarketLocation findByAddress(@NonNull String address) {
try {
JPAQuery query = new JPAQuery(entityManager);
return query
.from(qEntity)
.where(qEntity.address.eq(address))
.singleResult(qEntity);
} catch (Exception e) {
throw new DaoException(e.getMessage(), e);
}
}
}
......@@ -2,15 +2,13 @@ package cz.fi.muni.pa165.flea.market.manager.dao;
import com.mysema.query.jpa.impl.JPAQuery;
import cz.fi.muni.pa165.flea.market.manager.dao.domain.DomainDaoImpl;
import cz.fi.muni.pa165.flea.market.manager.dao.exception.DaoException;
import cz.fi.muni.pa165.flea.market.manager.entity.QStand;
import cz.fi.muni.pa165.flea.market.manager.entity.Stand;
import cz.fi.muni.pa165.flea.market.manager.entity.StandType;
import cz.fi.muni.pa165.flea.market.manager.enums.ItemCategory;
import lombok.NonNull;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Objects;
/**
* Dao for {@link Stand} entity that provides basic CRUD operations.
......@@ -25,27 +23,39 @@ public class StandDao extends DomainDaoImpl<Stand, QStand> {
}
public List<Stand> findAllBySellerId(@NonNull String sellerId) {
try {
JPAQuery query = new JPAQuery(entityManager);
return query
.from(qEntity)
.where(qEntity.seller.id.eq(sellerId))
.list(qEntity);
} catch (Exception e) {
throw new DaoException(e.getMessage(), e);
}
}
public List<Stand> findAllByEventId(@NonNull String eventId) {
try {
JPAQuery query = new JPAQuery(entityManager);
return query
.from(qEntity)
.where(qEntity.event.id.eq(eventId))
.list(qEntity);
} catch (Exception e) {
throw new DaoException(e.getMessage(), e);
}
}
public List<Stand> findAllByStandType(@NonNull String standTypeId) {
try {
JPAQuery query = new JPAQuery(entityManager);
return query
.from(qEntity)
.where(qEntity.standType.id.eq(standTypeId))
.list(qEntity);
} catch (Exception e) {
throw new DaoException(e.getMessage(), e);
}
}
}
package cz.fi.muni.pa165.flea.market.manager.dao;
import com.mysema.query.jpa.impl.JPAQuery;
import cz.fi.muni.pa165.flea.market.manager.dao.domain.DomainDaoImpl;
import cz.fi.muni.pa165.flea.market.manager.entity.QStandType;
import cz.fi.muni.pa165.flea.market.manager.entity.StandType;
import lombok.NonNull;
import org.springframework.stereotype.Repository;
/**
......
package cz.fi.muni.pa165.flea.market.manager.dao;
import cz.fi.muni.pa165.flea.market.manager.dao.domain.DomainDaoImpl;
import com.mysema.query.jpa.impl.JPAQuery;
import cz.fi.muni.pa165.flea.market.manager.dao.domain.DomainDaoImpl;
import cz.fi.muni.pa165.flea.market.manager.dao.exception.DaoException;
import cz.fi.muni.pa165.flea.market.manager.entity.QUser;
import cz.fi.muni.pa165.flea.market.manager.entity.User;
import lombok.NonNull;
......@@ -19,10 +20,14 @@ public class UserDao extends DomainDaoImpl<User, QUser> {
}
public User findByEmail(@NonNull String email) {
try {
JPAQuery query = new JPAQuery(entityManager);
return query
.from(qEntity)
.where(qEntity.email.eq(email))
.singleResult(qEntity);
} catch (Exception e) {
throw new DaoException(e.getMessage(), e);
}
}
}
......@@ -2,6 +2,7 @@ package cz.fi.muni.pa165.flea.market.manager.dao.domain;
import com.mysema.query.jpa.impl.JPAQuery;
import com.mysema.query.types.path.EntityPathBase;
import cz.fi.muni.pa165.flea.market.manager.dao.exception.DaoException;
import cz.fi.muni.pa165.flea.market.manager.entity.domain.DomainEntity;
import lombok.NonNull;
import org.springframework.data.repository.NoRepositoryBean;
......@@ -30,28 +31,48 @@ public abstract class DomainDaoImpl<ENTITY extends DomainEntity, Q_ENTITY extend
@Override
public ENTITY create(@NonNull ENTITY object) {
entityManager.persist(object);
return object;
try {
entityManager.persist(object);
return object;
} catch (Exception e) {
throw new DaoException(e.getMessage(), e);
}
}
@Override
public ENTITY findById(@NonNull String id) {
return entityManager.find(entityClass, id);
try {
return entityManager.find(entityClass, id);
} catch (Exception e) {
throw new DaoException(e.getMessage(), e);
}
}
@Override
public List<ENTITY> findAll() {
JPAQuery query = new JPAQuery(entityManager);
return query.from(qEntity).list(qEntity);
try {
JPAQuery query = new JPAQuery(entityManager);
return query.from(qEntity).list(qEntity);
} catch (Exception e) {
throw new DaoException(e.getMessage(), e);
}
}
@Override
public ENTITY update(@NonNull ENTITY object) {
return entityManager.merge(object);
try {
return entityManager.merge(object);
} catch (Exception e) {
throw new DaoException(e.getMessage(), e);
}
}
@Override
public void delete(@NonNull ENTITY object) {
entityManager.remove(object);
try {
entityManager.remove(object);
} catch (Exception e) {
throw new DaoException(e.getMessage(), e);
}
}
}
......@@ -6,7 +6,6 @@ import cz.fi.muni.pa165.flea.market.manager.dto.marketlocation.MarketLocationCre
import cz.fi.muni.pa165.flea.market.manager.dto.marketlocation.MarketLocationUpdateDTO;
import cz.fi.muni.pa165.flea.market.manager.entity.MarketEvent;
import cz.fi.muni.pa165.flea.market.manager.entity.MarketLocation;
import cz.fi.muni.pa165.flea.market.manager.exception.DaoException;
import cz.fi.muni.pa165.flea.market.manager.service.domain.DomainServiceImpl;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -48,11 +47,7 @@ public class MarketLocationService extends DomainServiceImpl<MarketLocation> {
}
public MarketLocation findByAddress(@NonNull String address) {
try {
return locationDao.findByAddress(address);
} catch (Exception e){
throw new DaoException(e.getMessage(), e);
}
return locationDao.findByAddress(address);
}
public MarketLocation constructLocationFromDTO(@NonNull MarketLocationCreateDTO dto){
......
......@@ -7,14 +7,12 @@ import cz.fi.muni.pa165.flea.market.manager.dto.stand.StandDTO;
import cz.fi.muni.pa165.flea.market.manager.dto.stand.StandUpdateDTO;
import cz.fi.muni.pa165.flea.market.manager.entity.Stand;
import cz.fi.muni.pa165.flea.market.manager.enums.ItemCategory;
import cz.fi.muni.pa165.flea.market.manager.exception.DaoException;
import cz.fi.muni.pa165.flea.market.manager.service.domain.DomainServiceImpl;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
......@@ -44,19 +42,11 @@ public class StandService extends DomainServiceImpl<Stand> {
}
public List<Stand> findAllBySellerId(@NonNull String sellerId) {
try {
return dao.findAllBySellerId(sellerId);
} catch (Exception e) {
throw new DaoException(e.getMessage(), e);
}
return dao.findAllBySellerId(sellerId);
}
public List<Stand> findAllByEventId(@NonNull String eventId) {
try {
return dao.findAllByEventId(eventId);
} catch (Exception e) {
throw new DaoException(e.getMessage(), e);
}
return dao.findAllByEventId(eventId);
}
public Stand constructStandFromDTO(@NonNull StandCreateDTO standCreateDTO) {
......
......@@ -7,7 +7,6 @@ import cz.fi.muni.pa165.flea.market.manager.dto.standType.StandTypeDTO;
import cz.fi.muni.pa165.flea.market.manager.dto.standType.StandTypeUpdateDTO;
import cz.fi.muni.pa165.flea.market.manager.entity.Stand;
import cz.fi.muni.pa165.flea.market.manager.entity.StandType;
import cz.fi.muni.pa165.flea.market.manager.exception.DaoException;
import cz.fi.muni.pa165.flea.market.manager.service.domain.DomainServiceImpl;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
......
......@@ -6,7 +6,6 @@ import cz.fi.muni.pa165.flea.market.manager.dto.user.UserDTO;
import cz.fi.muni.pa165.flea.market.manager.dto.user.UserUpdateDTO;
import cz.fi.muni.pa165.flea.market.manager.entity.User;
import cz.fi.muni.pa165.flea.market.manager.enums.UserRole;
import cz.fi.muni.pa165.flea.market.manager.exception.DaoException;
import cz.fi.muni.pa165.flea.market.manager.service.domain.DomainServiceImpl;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -34,11 +33,7 @@ public class UserService extends DomainServiceImpl<User> {
}
public User findByEmail(@NonNull String email) {
try {
return dao.findByEmail(email);
} catch (Exception e) {
throw new DaoException(e.getMessage(), e);
}
return dao.findByEmail(email);
}
public String hashPassword(String password) {
......
......@@ -2,7 +2,6 @@ package cz.fi.muni.pa165.flea.market.manager.service.domain;
import cz.fi.muni.pa165.flea.market.manager.dao.domain.DomainDao;
import cz.fi.muni.pa165.flea.market.manager.entity.domain.DomainEntity;
import cz.fi.muni.pa165.flea.market.manager.exception.DaoException;
import lombok.NonNull;
import org.springframework.transaction.annotation.Transactional;
......@@ -26,46 +25,26 @@ public abstract class DomainServiceImpl<ENTITY extends DomainEntity> implements
@Override
public ENTITY create(@NonNull ENTITY object) {
try {
return dao.create(object);
} catch (Exception e){
throw new DaoException(e.getMessage(), e);
}
return dao.create(object);
}
@Override
public ENTITY findById(@NonNull String id) {
try {
return dao.findById(id);
} catch (Exception e){
throw new DaoException(e.getMessage(), e);
}
return dao.findById(id);
}
@Override
public List<ENTITY> findAll() {
try {
return dao.findAll();
} catch (Exception e){
throw new DaoException(e.getMessage(), e);
}
return dao.findAll();
}
@Override
public ENTITY update(@NonNull ENTITY object) {
try {
return dao.update(object);
} catch (Exception e){
throw new DaoException(e.getMessage(), e);
}
return dao.update(object);
}
@Override
public void delete(@NonNull ENTITY object) {
try {
dao.delete(object);
} catch (Exception e){
throw new DaoException(e.getMessage(), e);
}
dao.delete(object);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment