perf(user): cambio readById por readMe para leer información propia

parent 6b7e0d57
package com.example.apprecetas.user.infrastructure.controller; package com.example.apprecetas.user.infrastructure.controller;
import com.example.apprecetas.user.application.ReadUserUseCase; import com.example.apprecetas.user.application.ReadUserUseCase;
import com.example.apprecetas.user.domain.entity.User;
import com.example.apprecetas.user.infrastructure.controller.dto.UserOutputDto; import com.example.apprecetas.user.infrastructure.controller.dto.UserOutputDto;
import com.example.apprecetas.user.infrastructure.mapper.UserMapper; import com.example.apprecetas.user.infrastructure.mapper.UserMapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -22,9 +23,11 @@ public class ReadUserController { ...@@ -22,9 +23,11 @@ public class ReadUserController {
private final UserMapper mapper = Mappers.getMapper(UserMapper.class); private final UserMapper mapper = Mappers.getMapper(UserMapper.class);
@GetMapping("/id/{id}") @GetMapping("/me")
public ResponseEntity<UserOutputDto> readById(@PathVariable String id) { public ResponseEntity<UserOutputDto> readMe() {
return ResponseEntity.ok().body(mapper.map(service.readById(id))); String email = SecurityContextHolder.getContext().getAuthentication().getName();
User user = service.readByEmail(email);
return ResponseEntity.ok().body(mapper.map(service.readById(user.getId())));
} }
@GetMapping @GetMapping
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment