Skip to content

Commit

Permalink
Merge pull request #563 from ita-social-projects/develop
Browse files Browse the repository at this point in the history
fields for user, response statuses
  • Loading branch information
fortamt authored Aug 12, 2022
2 parents fd1d97c + 3cccb44 commit 20966d0
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ public ResponseEntity<UserDTO> getExpertById(@PathVariable("userId") Integer use
@ApiOperation(value = "Get current user",
authorizations = {@Authorization(value = "Authorization")})
public ResponseEntity<UserDTO> getCurrentUser(@AuthenticationPrincipal UserPrincipal userPrincipal) {
if (userPrincipal == null) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
UserDTO userDTO = userService.findExpertById(userPrincipal.getId());
return ResponseEntity
.status((userDTO != null) ? HttpStatus.OK : HttpStatus.NOT_FOUND)
Expand Down Expand Up @@ -247,6 +250,6 @@ public ResponseEntity<Collection<? extends GrantedAuthority>> getAuthorities(
authorities = userPrincipal.getAuthorities();
}
return ResponseEntity.status(authorities != null
? HttpStatus.OK : HttpStatus.NOT_FOUND).body(authorities);
? HttpStatus.OK : HttpStatus.FORBIDDEN).body(authorities);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class PostDTO {
private PostTypeDTO type;
private String status;
private Set<OriginDTO> origins;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd.MM.yyyy")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm dd.MM.yyyy")
private Timestamp createdAt;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd.MM.yyyy")
private Timestamp modifiedAt;
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/softserveinc/dokazovi/dto/user/UserDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Builder;
import lombok.Data;

import java.sql.Timestamp;
import java.util.Set;

/**
Expand All @@ -30,7 +31,11 @@ public class UserDTO {

private String bio;

private String socialNetwork;
private String region;

private String city;

private Set<String> socialNetworks;

private Set<DirectionDTO> directions;

Expand All @@ -40,4 +45,7 @@ public class UserDTO {

private LatestUserPostDTO lastAddedPost;

private Timestamp createdAt;

private Timestamp editedAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ public class DoctorEntity {
@Column(columnDefinition = "TEXT")
private String bio;

@Column(columnDefinition = "TEXT")
private String socialNetwork;

@ColumnDefault("1.0")
private Double promotionScale;

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/softserveinc/dokazovi/entity/UserEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import org.hibernate.annotations.CreationTimestamp;

import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
Expand Down Expand Up @@ -70,6 +72,21 @@ public class UserEntity {
@CreationTimestamp
private Timestamp createdAt;

private Timestamp editedAt;

private String region;

private String city;

@ElementCollection
@CollectionTable(
name = "users_social_networks",
joinColumns = @JoinColumn(name = "user_id"))
@Column(name = "link")
@EqualsAndHashCode.Exclude
@ToString.Exclude
private Set<String> socialNetworks;

@OneToMany(fetch = FetchType.EAGER, mappedBy = "user", cascade = CascadeType.ALL)
@EqualsAndHashCode.Exclude
@ToString.Exclude
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ public interface UserRepository extends JpaRepository<UserEntity, Integer> {
* @return the resulting user entity page
*/
@Query(nativeQuery = true,
value = " SELECT U.* FROM DOCTORS D "
value = " SELECT U.*, SN.LINK FROM DOCTORS D "
+ " JOIN USERS U ON U.USER_ID = D.USER_ID "
+ " JOIN USERS_SOCIAL_NETWORKS SN ON D.USER_ID = SN.USER_ID"
+ " ORDER BY D.PROMOTION_LEVEL DESC, D.RATING DESC, "
+ " U.LAST_NAME, U.FIRST_NAME ")
Page<UserEntity> findDoctorsProfiles(Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.util.CollectionUtils;

import javax.transaction.Transactional;
import java.sql.Timestamp;
import java.util.Set;
import java.util.UUID;

Expand Down Expand Up @@ -232,6 +233,7 @@ public UserEntity update(UserEntity user) {
if (user != null) {
UserEntity oldUser = getById(user.getId());
if (oldUser != null) {
user.setEditedAt(new Timestamp(System.currentTimeMillis()));
return userRepository.save(user);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
alter table public.users
add column EDITED_AT timestamp;

create table if not exists USERS_SOCIAL_NETWORKS(
user_id integer not null
constraint social_networks_user_id_fkey
references users,
link varchar
);

insert into USERS_SOCIAL_NETWORKS (user_id, link)
select user_id, social_network from DOCTORS;

alter table public.doctors
drop column social_network;

alter table public.users
add column REGION varchar;

alter table public.users
add column CITY varchar;
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void checkTokenTest() throws Exception {
void getAuthoritiesTestNotFound() throws Exception {
String uri = USER + USER_GET_AUTHORITIES;
when(userPrincipal.getAuthorities()).thenReturn(null);
mockMvc.perform(get(uri)).andExpect(status().isNotFound());
mockMvc.perform(get(uri)).andExpect(status().isForbidden());
Collection<? extends GrantedAuthority> actual = userPrincipal.getAuthorities();
Assertions.assertNull(actual);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,10 @@ void updateUserEntityTest() {
UserEntity userEntity = userService.getById(1);
userEntity.setEmail(expectedEmail);
when(userRepository.save(any(UserEntity.class))).thenReturn(expected);
Assertions.assertNull(expected.getEditedAt());
UserEntity actual = userService.update(userEntity);
Assertions.assertEquals(expectedEmail, actual.getEmail());
Assertions.assertNotNull(actual.getEditedAt());
}

@Test
Expand Down

0 comments on commit 20966d0

Please sign in to comment.