feat: add lombok
This commit is contained in:
parent
59b435b27b
commit
c28f6e464f
BIN
lib/lombok.jar
Normal file
BIN
lib/lombok.jar
Normal file
Binary file not shown.
@ -5,6 +5,7 @@ import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.charm.back.controller.filter.ErrorFilter;
|
||||
@ -23,10 +24,10 @@ import java.util.Optional;
|
||||
import static jakarta.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
||||
|
||||
@WebServlet("/email")
|
||||
@Slf4j
|
||||
public class EmailController extends HttpServlet {
|
||||
private final ProfileService service = ProfileService.getInstance();
|
||||
private final RequestToProfileUpdateDtoMapper requestToProfileUpdateDtoMapper = RequestToProfileUpdateDtoMapper.getInstance();
|
||||
public static final Logger logger = LoggerFactory.getLogger(EmailController.class);
|
||||
|
||||
@Override
|
||||
protected void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
@ -48,7 +49,7 @@ public class EmailController extends HttpServlet {
|
||||
ProfileUpdateDto dto = requestToProfileUpdateDtoMapper.map(req, new ProfileUpdateDto());
|
||||
try {
|
||||
service.update(dto);
|
||||
logger.info("Email {} was changed in profile with id = {}", dto.getEmail(), dto.getId());
|
||||
log.info("Email {} was changed in profile with id = {}", dto.getEmail(), dto.getId());
|
||||
resp.sendRedirect(String.format("/profile?id=%s", dto.getId()));
|
||||
} catch (DuplicateEmailException e) {
|
||||
resp.sendError(SC_BAD_REQUEST);
|
||||
|
||||
@ -5,9 +5,7 @@ import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.charm.back.dto.ProfileGetDto;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import ru.charm.back.dto.RegistrationDto;
|
||||
import ru.charm.back.mapper.RequestToRegistrationDtoMapper;
|
||||
import ru.charm.back.service.ProfileService;
|
||||
@ -15,12 +13,11 @@ import ru.charm.back.service.ProfileService;
|
||||
import java.io.IOException;
|
||||
|
||||
@WebServlet("/registration")
|
||||
@Slf4j
|
||||
public class RegistrationController extends HttpServlet {
|
||||
private final ProfileService service = ProfileService.getInstance();
|
||||
|
||||
private final RequestToRegistrationDtoMapper requestToRegistrationDtoMapper = RequestToRegistrationDtoMapper.getInstance();
|
||||
public static final Logger logger = LoggerFactory.getLogger(RegistrationController.class);
|
||||
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
@ -31,7 +28,7 @@ public class RegistrationController extends HttpServlet {
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
RegistrationDto dto = requestToRegistrationDtoMapper.map(req);
|
||||
Long id = service.save(dto);
|
||||
logger.info("Profile with the email address {} has been registered with id {}", dto.getEmail(), id);
|
||||
log.info("Profile with the email address {} has been registered with id {}", dto.getEmail(), id);
|
||||
resp.sendRedirect(String.format("/profile?id=%s", id));
|
||||
}
|
||||
|
||||
@ -44,7 +41,7 @@ public class RegistrationController extends HttpServlet {
|
||||
}
|
||||
resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
|
||||
if (success) {
|
||||
logger.info("Profile with id {} has been deleted", sId);
|
||||
log.info("Profile with id {} has been deleted", sId);
|
||||
}
|
||||
resp.sendRedirect("/registration");
|
||||
}
|
||||
|
||||
@ -4,28 +4,26 @@ import jakarta.servlet.*;
|
||||
import jakarta.servlet.annotation.WebFilter;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static jakarta.servlet.RequestDispatcher.ERROR_EXCEPTION;
|
||||
|
||||
@WebFilter(value = "/*", dispatcherTypes = DispatcherType.ERROR)
|
||||
@Slf4j
|
||||
public class ErrorFilter implements Filter {
|
||||
public static final Logger logger = LoggerFactory.getLogger(ErrorFilter.class);
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
HttpServletRequest req = (HttpServletRequest) servletRequest;
|
||||
HttpServletResponse res = (HttpServletResponse) servletResponse;
|
||||
|
||||
Throwable trowable = (Throwable) req.getAttribute(ERROR_EXCEPTION);
|
||||
Throwable throwable = (Throwable) req.getAttribute(ERROR_EXCEPTION);
|
||||
|
||||
if (res.getStatus() >= 500) {
|
||||
logger.error("Error 500", trowable);
|
||||
log.error("Error 500", throwable);
|
||||
} else {
|
||||
logger.warn("Exception code {}", res.getStatus());
|
||||
log.warn("Exception code {}", res.getStatus());
|
||||
}
|
||||
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
package ru.charm.back.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import ru.charm.back.model.Gender;
|
||||
import ru.charm.back.model.Status;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
public class ProfileGetDto {
|
||||
private Long id;
|
||||
private String email;
|
||||
@ -15,76 +17,4 @@ public class ProfileGetDto {
|
||||
private String about;
|
||||
private Gender gender;
|
||||
private Status status;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
}
|
||||
|
||||
public void setSurname(String surname) {
|
||||
this.surname = surname;
|
||||
}
|
||||
|
||||
public LocalDate getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
public void setBirthDate(LocalDate birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public Integer getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(Integer age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getAbout() {
|
||||
return about;
|
||||
}
|
||||
|
||||
public void setAbout(String about) {
|
||||
this.about = about;
|
||||
}
|
||||
|
||||
public Gender getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(Gender gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
package ru.charm.back.dto;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
import ru.charm.back.model.Gender;
|
||||
import ru.charm.back.model.Status;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
public class ProfileUpdateDto {
|
||||
private Long id;
|
||||
private String email;
|
||||
@ -16,76 +18,4 @@ public class ProfileUpdateDto {
|
||||
private String about;
|
||||
private Gender gender;
|
||||
private Status status;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
}
|
||||
|
||||
public void setSurname(String surname) {
|
||||
this.surname = surname;
|
||||
}
|
||||
|
||||
public LocalDate getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
public void setBirthDate(LocalDate birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public String getAbout() {
|
||||
return about;
|
||||
}
|
||||
|
||||
public void setAbout(String about) {
|
||||
this.about = about;
|
||||
}
|
||||
|
||||
public Gender getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(Gender gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,22 +1,9 @@
|
||||
package ru.charm.back.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RegistrationDto {
|
||||
private String email;
|
||||
private String password;
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package ru.charm.back.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
public class Profile {
|
||||
private Long id;
|
||||
private String email;
|
||||
@ -12,76 +15,4 @@ public class Profile {
|
||||
private String about;
|
||||
private Gender gender;
|
||||
private Status status;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
}
|
||||
|
||||
public void setSurname(String surname) {
|
||||
this.surname = surname;
|
||||
}
|
||||
|
||||
public LocalDate getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
public void setBirthDate(LocalDate birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public String getAbout() {
|
||||
return about;
|
||||
}
|
||||
|
||||
public void setAbout(String about) {
|
||||
this.about = about;
|
||||
}
|
||||
|
||||
public Gender getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(Gender gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,7 @@
|
||||
package ru.charm.back.service;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import ru.charm.back.dao.ProfileDao;
|
||||
import ru.charm.back.dto.ProfileGetDto;
|
||||
import ru.charm.back.dto.ProfileUpdateDto;
|
||||
@ -14,6 +16,7 @@ import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class ProfileService {
|
||||
|
||||
private static final ProfileService INSTANCE = new ProfileService();
|
||||
@ -26,9 +29,6 @@ public class ProfileService {
|
||||
|
||||
private final RegistrationDtoToProfileMapper registrationDtoToProfileMapper = RegistrationDtoToProfileMapper.getInstance();
|
||||
|
||||
private ProfileService() {
|
||||
}
|
||||
|
||||
public static ProfileService getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package ru.charm.back.utils;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@UtilityClass
|
||||
public class StringUtils {
|
||||
public static boolean isBlank(String str) {
|
||||
return str == null || str.isBlank();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user