Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
mertycom committed Feb 2, 2023
1 parent e6eec73 commit c97c3ba
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 14 deletions.
Binary file modified .gradle/7.5.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/7.5.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.5.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.5.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/file-system.probe
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public LoginResponseDto login(LoginRequestDto dto) {
return loginResponseDto;
}

@Transactional

public RegisterResponseDto save(RegisterRequestDto dto){
if(!dto.getPassword().equals(dto.getRePassword()))
throw new AuthMicroserviceException(ErrorType.REGISTER_REPASSWORD_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.bilgeadam.dto.request.CreateProfileRequestDto;
import com.bilgeadam.dto.request.UpdateRequestDto;
import com.bilgeadam.dto.response.DetailResponseDto;
import com.bilgeadam.dto.response.SummaryResponseDto;
import com.bilgeadam.repository.entity.UserProfile;
import com.bilgeadam.service.UserProfileService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -32,7 +34,20 @@ public ResponseEntity<Boolean> createProfile(@RequestBody @Valid CreateProfileRe
}

@PutMapping("/update")
@Operation(summary = "update sayfası")
public ResponseEntity<Boolean> updateRequest(UpdateRequestDto request){
return ResponseEntity.ok(userProfileService.updateRequest(request));
}

@GetMapping("/detail/{id}")
@Operation(summary = "detay sayfası")
public ResponseEntity<DetailResponseDto> detailRequest(@PathVariable("id") Long id){
return ResponseEntity.ok(userProfileService.detailRequest(id));
}

@GetMapping("/summary/{id}")
@Operation(summary = "özet sayfası")
public ResponseEntity<SummaryResponseDto> summaryRequest(@PathVariable("id") Long id){
return ResponseEntity.ok(userProfileService.summaryRequest(id));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,26 @@ public ResponseEntity<ErrorMessage> handlerAuthMicroseviceException(UserProfileE
@ResponseBody
public final ResponseEntity<ErrorMessage> handleMessageNotReadableException(
HttpMessageNotReadableException exception) {
ErrorType errorType = BAD_REQUEST_ERROR;
ErrorType errorType = BAD_REQUEST;
return new ResponseEntity<>(createErrorMessage(exception,errorType), errorType.getHttpStatus());
}

@ExceptionHandler(InvalidFormatException.class)
@ResponseBody
public final ResponseEntity<ErrorMessage> handleInvalidFormatException(
InvalidFormatException exception) {
ErrorType errorType = BAD_REQUEST_ERROR;
ErrorType errorType = BAD_REQUEST;
return new ResponseEntity<>(createErrorMessage(exception,errorType), errorType.getHttpStatus());
}

@ExceptionHandler(DataIntegrityViolationException.class)
@ResponseBody
public final ResponseEntity<ErrorMessage> handlePSQLException(
DataIntegrityViolationException exception) {
ErrorType errorType = REGISTER_KULLANICIADI_KAYITLI;
return new ResponseEntity<>(createErrorMessage(exception,errorType), errorType.getHttpStatus());
}


@ExceptionHandler(MethodArgumentTypeMismatchException.class)
@ResponseBody
public final ResponseEntity<ErrorMessage> handleMethodArgumentMisMatchException(
MethodArgumentTypeMismatchException exception) {

ErrorType errorType = BAD_REQUEST_ERROR;
ErrorType errorType = BAD_REQUEST;
return new ResponseEntity<>(createErrorMessage(exception,errorType), errorType.getHttpStatus());
}

Expand All @@ -73,7 +66,7 @@ public final ResponseEntity<ErrorMessage> handleMethodArgumentMisMatchException(
public final ResponseEntity<ErrorMessage> handleMethodArgumentMisMatchException(
MissingPathVariableException exception) {

ErrorType errorType = BAD_REQUEST_ERROR;
ErrorType errorType = BAD_REQUEST;
return new ResponseEntity<>(createErrorMessage(exception,errorType), errorType.getHttpStatus());
}

Expand All @@ -83,7 +76,7 @@ public final ResponseEntity<ErrorMessage> handleMethodArgumentMisMatchException(
public final ResponseEntity<ErrorMessage> handleMethodArgumentNotValidException(
MethodArgumentNotValidException exception) {

ErrorType errorType = BAD_REQUEST_ERROR;
ErrorType errorType = BAD_REQUEST;
List<String> fields = new ArrayList<>();
exception
.getBindingResult()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package com.bilgeadam.mapper;

import com.bilgeadam.dto.response.DetailResponseDto;
import com.bilgeadam.dto.response.SummaryResponseDto;
import com.bilgeadam.repository.entity.UserProfile;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

import java.util.Optional;


@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE,componentModel = "spring")
public interface UserProfileMapper {

UserProfileMapper INSTANCE = Mappers.getMapper(UserProfileMapper.class);

DetailResponseDto fromUserProfileToDetailResponseDto(final UserProfile profile);

SummaryResponseDto fromUserProfileToSummaryResponseDto(final UserProfile userProfile);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.bilgeadam.service;

import com.bilgeadam.dto.request.UpdateRequestDto;
import com.bilgeadam.dto.response.DetailResponseDto;
import com.bilgeadam.dto.response.SummaryResponseDto;
import com.bilgeadam.exception.ErrorType;
import com.bilgeadam.exception.UserProfileException;
import com.bilgeadam.mapper.UserProfileMapper;
import com.bilgeadam.repository.UserProfileRepository;
import com.bilgeadam.repository.entity.UserProfile;
import com.bilgeadam.utility.ServiceManager;
Expand All @@ -15,10 +17,12 @@
public class UserProfileService extends ServiceManager<UserProfile,String> {

private final UserProfileRepository userProfileRepository;
private final UserProfileMapper userProfileMapper;

public UserProfileService(UserProfileRepository userProfileRepository) {
public UserProfileService(UserProfileRepository userProfileRepository, UserProfileMapper userProfileMapper) {
super(userProfileRepository);
this.userProfileRepository = userProfileRepository;
this.userProfileMapper = userProfileMapper;
}

public boolean updateRequest(UpdateRequestDto request) {
Expand All @@ -31,4 +35,20 @@ public boolean updateRequest(UpdateRequestDto request) {
profile.get().setTelephone(request.getTelephone());
return true;
}

public DetailResponseDto detailRequest(Long id) {
Optional<UserProfile> profile = userProfileRepository.findOptionalById(id);
if(!profile.isPresent()){
throw new UserProfileException(ErrorType.USER_NOT_FOUND);
}
return userProfileMapper.INSTANCE.fromUserProfileToDetailResponseDto(profile.get());
}

public SummaryResponseDto summaryRequest(Long id) {
Optional<UserProfile> profile = userProfileRepository.findOptionalById(id);
if(!profile.isPresent()){
throw new UserProfileException(ErrorType.USER_NOT_FOUND);
}
return userProfileMapper.INSTANCE.fromUserProfileToSummaryResponseDto(profile.get());
}
}

0 comments on commit c97c3ba

Please sign in to comment.