diff --git a/lib/lombok.jar b/lib/lombok.jar new file mode 100644 index 0000000..b6b4f02 Binary files /dev/null and b/lib/lombok.jar differ diff --git a/src/ru/charm/back/controller/EmailController.java b/src/ru/charm/back/controller/EmailController.java index b27dc3d..7857c18 100644 --- a/src/ru/charm/back/controller/EmailController.java +++ b/src/ru/charm/back/controller/EmailController.java @@ -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); diff --git a/src/ru/charm/back/controller/RegistrationController.java b/src/ru/charm/back/controller/RegistrationController.java index b014977..2f413a6 100644 --- a/src/ru/charm/back/controller/RegistrationController.java +++ b/src/ru/charm/back/controller/RegistrationController.java @@ -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"); } diff --git a/src/ru/charm/back/controller/filter/ErrorFilter.java b/src/ru/charm/back/controller/filter/ErrorFilter.java index a4547b2..98af12a 100644 --- a/src/ru/charm/back/controller/filter/ErrorFilter.java +++ b/src/ru/charm/back/controller/filter/ErrorFilter.java @@ -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); diff --git a/src/ru/charm/back/dto/ProfileGetDto.java b/src/ru/charm/back/dto/ProfileGetDto.java index 9b572af..fecabcf 100644 --- a/src/ru/charm/back/dto/ProfileGetDto.java +++ b/src/ru/charm/back/dto/ProfileGetDto.java @@ -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; - } } diff --git a/src/ru/charm/back/dto/ProfileUpdateDto.java b/src/ru/charm/back/dto/ProfileUpdateDto.java index 7f51187..2f2099f 100644 --- a/src/ru/charm/back/dto/ProfileUpdateDto.java +++ b/src/ru/charm/back/dto/ProfileUpdateDto.java @@ -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; - } } diff --git a/src/ru/charm/back/dto/RegistrationDto.java b/src/ru/charm/back/dto/RegistrationDto.java index ffeac3f..013ff95 100644 --- a/src/ru/charm/back/dto/RegistrationDto.java +++ b/src/ru/charm/back/dto/RegistrationDto.java @@ -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; - } } diff --git a/src/ru/charm/back/model/Profile.java b/src/ru/charm/back/model/Profile.java index 588bfe3..1273eba 100644 --- a/src/ru/charm/back/model/Profile.java +++ b/src/ru/charm/back/model/Profile.java @@ -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; - } } \ No newline at end of file diff --git a/src/ru/charm/back/service/ProfileService.java b/src/ru/charm/back/service/ProfileService.java index 389bdfd..3d95643 100644 --- a/src/ru/charm/back/service/ProfileService.java +++ b/src/ru/charm/back/service/ProfileService.java @@ -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; } diff --git a/src/ru/charm/back/utils/StringUtils.java b/src/ru/charm/back/utils/StringUtils.java index 13713ae..6b9da5e 100644 --- a/src/ru/charm/back/utils/StringUtils.java +++ b/src/ru/charm/back/utils/StringUtils.java @@ -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();