Skip to content

Commit

Permalink
Merge pull request #54 from canadmin/canadmin
Browse files Browse the repository at this point in the history
Canadmin
  • Loading branch information
canadmin authored May 26, 2020
2 parents 95a2566 b7e5334 commit 9ca2dde
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 26,11 @@ public class SearchController {
public ResponseEntity<List<UserResponseDTO>> searchUser(@RequestBody @Valid SearchRequest searchRequest){
return new ResponseEntity<>(searchService.getSearchUser(searchRequest), HttpStatus.OK);
}
@ApiOperation(value = "Sadece Web için kullanılacak")
@CrossOrigin
@PostMapping
public ResponseEntity<List<UserResponseDTO>> searchUserForWeb(@RequestBody @Valid SearchRequest searchRequest){
return new ResponseEntity<>(searchService.getSearchUser(searchRequest), HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 38,7 @@ public UserController(UserService userService, ModelMapper modelMapper) {
@ApiOperation(value = "Bunu kullanmayın test için yazılmıştı")
@CrossOrigin
@GetMapping("/users")
public ResponseEntity<List<UserResponseDTO>> getAllUser(){
public ResponseEntity<List<UserResponseDTO>> getAllUser(){
return new ResponseEntity<List<UserResponseDTO>>(userService.getAllUser(), HttpStatus.OK);
}
/*
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/impoort/impoortapi/domain/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 51,7 @@ public class User {
CascadeType.REFRESH,
CascadeType.MERGE,
CascadeType.PERSIST
}, orphanRemoval = true)
} )
@JsonIgnore
@JoinColumn(name = "watcher_user_id")
private List<Watcher> watcher;
Expand All @@ -60,7 60,7 @@ public class User {
CascadeType.REFRESH,
CascadeType.MERGE,
CascadeType.PERSIST
}, orphanRemoval = true)
})
@JsonIgnore
@JoinColumn(name = "watching_user_id")
private List<Watching> watching;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 14,7 @@
@Repository
public interface PostRepository extends JpaRepository<Post,Integer> {

@Query("select post from Post post where post.postType = 2 order by post.likeCount desc ")
@Query("select post from Post post where post.postType = 1 order by post.likeCount desc ")
List<Post> getPost(Pageable pageable);
List<Post> findAllByPostIdIn(List<Integer> postId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 4,7 @@
import com.impoort.impoortapi.api.v1.model.responsemodel.UserResponseDTO;
import com.impoort.impoortapi.domain.user.User;
import com.impoort.impoortapi.repository.UserRepository;
import com.impoort.impoortapi.repository.company.CompanyRepository;
import com.impoort.impoortapi.security.JwtUtil;
import com.impoort.impoortapi.security.authDto.UserAuthRequestDto;
import com.impoort.impoortapi.security.authDto.UserAuthResponseDto;
Expand All @@ -24,11 25,13 @@
public class AuthenticationServiceImpl implements AuthenticationService {
private final ModelMapper modelMapper;
private final UserRepository userRepository;
private final CompanyRepository companyRepository;

@Autowired
public AuthenticationServiceImpl(ModelMapper modelMapper, UserRepository userRepository) {
public AuthenticationServiceImpl(ModelMapper modelMapper, UserRepository userRepository, CompanyRepository companyRepository) {
this.modelMapper = modelMapper;
this.userRepository = userRepository;
this.companyRepository = companyRepository;
}

@Override
Expand All @@ -38,6 41,7 @@ public Object login(UserAuthRequestDto userAuthRequestDto) {
User user = userRepository.findByEmail(userAuthRequestDto.getEmail());
UserResponseDTO userResponseDTO = modelMapper.map(user, UserResponseDTO.class);
UserAuthRequestDto userAuthFound = modelMapper.map(user, UserAuthRequestDto.class);
userResponseDTO.setExperiences(companyRepository.findByWorkerId(userResponseDTO.getUserId()));
if (isValidPassword(userAuthRequestDto.getPassword(), userAuthFound.getPassword())) {
String jwt = JwtUtil.generateToken(userAuthRequestDto.getEmail());
userAuthResponseDto.setToken(jwt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 17,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -88,24 89,13 @@ public UserResponseDTO updateUser(UserResponseDTO userResponseDTO) {

//bu kullanıcının profil bilgilerinin güncellenmesi için yazıldı
@Override
@Transactional
public UserResponseDTO updateUser(UserUpdateDto userUpdateDto) {


User updatedUser = (modelMapper.map(userUpdateDto, User.class));
User oldUser = userRepository.getOne(userUpdateDto.getUserId());

User newUser = updatedUser;
newUser.setActiveGuide(oldUser.getActiveGuide());
newUser.setWatcherCount(oldUser.getWatcherCount());
newUser.setWatchingCount(oldUser.getWatchingCount());
newUser.setWatcher(oldUser.getWatcher());
newUser.setWatching(oldUser.getWatching());
newUser.setWatchingPostCount(oldUser.getWatchingPostCount());
newUser.setEmployeeCount(oldUser.getEmployeeCount());
newUser.setActive(oldUser.isActive());

userRepository.save(newUser);
UserResponseDTO userResponseDTO = modelMapper.map(newUser, UserResponseDTO.class);
userRepository.save(updatedUser);
UserResponseDTO userResponseDTO = modelMapper.map(updatedUser, UserResponseDTO.class);
userResponseDTO.setExperiences(companyRepository.findByWorkerId(userResponseDTO.getUserId()));
return userResponseDTO;
}
Expand Down
10 changes: 8 additions & 2 deletions src/main/resources/application-test.properties
Original file line number Diff line number Diff line change
@@ -1,5 1,11 @@
spring.h2.console.path=/h2
spring.h2.console.enabled=true
spring.datasource.platform=h2
spring.datasource.url=jdbc:h2:mem:test
spring.h2.console.settings.web-allow-others=true
spring.h2.console.settings.web-allow-others=true
spring.jpa.hibernate.ddl-auto = update

spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

0 comments on commit 9ca2dde

Please sign in to comment.