-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: user controller method, dto classes
- Loading branch information
Showing
19 changed files
with
274 additions
and
333 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/main/java/com/shulpov/spots_app/authentication_management/validators/UserValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/com/shulpov/spots_app/comments/utils/CommentDtoConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.shulpov.spots_app.comments.utils; | ||
|
||
import com.shulpov.spots_app.comments.Comment; | ||
import com.shulpov.spots_app.comments.CommentDto; | ||
import com.shulpov.spots_app.users.dto.MainUserInfoDto; | ||
import com.shulpov.spots_app.users.utils.UserDtoConverter; | ||
import org.modelmapper.ModelMapper; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class CommentDtoConverter { | ||
private final ModelMapper modelMapper; | ||
private final UserDtoConverter userDtoConverter; | ||
|
||
public CommentDtoConverter(ModelMapper modelMapper, UserDtoConverter userDtoConverter) { | ||
this.modelMapper = modelMapper; | ||
this.userDtoConverter = userDtoConverter; | ||
} | ||
|
||
public CommentDto commentToDto(Comment comment) { | ||
CommentDto dto = modelMapper.map(comment, CommentDto.class); | ||
MainUserInfoDto mainUserInfoDto = userDtoConverter.userToUserMainInfoDto(comment.getCommentator()); | ||
dto.setCommentatorDto(mainUserInfoDto); | ||
return dto; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/java/com/shulpov/spots_app/image_infos/dto/ImageInfoDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/com/shulpov/spots_app/image_infos/utils/ImageInfoDtoConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.shulpov.spots_app.image_infos.utils; | ||
|
||
import com.shulpov.spots_app.image_infos.dto.ImageInfoDto; | ||
import com.shulpov.spots_app.image_infos.models.ImageInfo; | ||
import com.shulpov.spots_app.utils.ImageUtil; | ||
import org.modelmapper.ModelMapper; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ImageInfoDtoConverter { | ||
private final ModelMapper modelMapper; | ||
|
||
public ImageInfoDtoConverter(ModelMapper modelMapper) { | ||
this.modelMapper = modelMapper; | ||
} | ||
|
||
/** | ||
* Конвертор класса ImageInfo в класс ImageInfoDto | ||
*/ | ||
public ImageInfoDto imageInfoToDto(ImageInfo imageInfo) throws NullPointerException { | ||
ImageInfoDto dto = modelMapper.map(imageInfo, ImageInfoDto.class); | ||
|
||
if(imageInfo.getPhotographedUser() != null) { | ||
String url = ImageUtil.getUserImageDownloadUrl(imageInfo.getId()); | ||
dto.setUrl(url); | ||
} else if(imageInfo.getPhotographedSpot() != null) { | ||
String url = ImageUtil.getSpotImageDownloadUrl(imageInfo.getId()); | ||
dto.setUrl(url); | ||
} else { | ||
throw new NullPointerException("Invalid image info object (user and spot are null)"); | ||
} | ||
return dto; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/com/shulpov/spots_app/users/dto/MainUserInfoDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.shulpov.spots_app.users.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.shulpov.spots_app.image_infos.dto.ImageInfoDto; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.*; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Setter | ||
@Getter | ||
public class MainUserInfoDto { | ||
@Schema(description = "Имя пользователя", example = "Alex") | ||
private String name; | ||
|
||
@Schema(description = "Почта пользователя", example = "alex_green@gmail.com") | ||
private String email; | ||
|
||
@Schema(description = "Номер телефона пользователя", example = "89005553535") | ||
private String phoneNumber; | ||
|
||
@Schema(description = "Дата рождения пользователя", example = "2000-07-15") | ||
private Date birthday; | ||
|
||
@Schema(description = "Дата регистрации пользователя", example = "2022-07-15") | ||
private Date regDate; | ||
|
||
@JsonProperty("imageInfoList") | ||
private List<ImageInfoDto> imageInfoDtoList; | ||
} |
Oops, something went wrong.