-
Notifications
You must be signed in to change notification settings - Fork 0
트레이너 프로필 단일 조회 #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
트레이너 프로필 단일 조회 #46
Changes from all commits
2a5c138
0dc4e00
1f6c218
611b759
4f9841d
838af1e
4d5e808
53db3b1
33472d7
0e789ea
b9bee1d
2754bf6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,17 @@ | ||
| package com.demo.pteam.global.config; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.SerializationFeature; | ||
| import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| @Configuration | ||
| public class ApplicationConfig { | ||
| @Bean | ||
| public ObjectMapper objectMapper() { | ||
| return new ObjectMapper(); | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
| mapper.registerModule(new JavaTimeModule()); | ||
| return mapper; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,18 +2,37 @@ | |
|
|
||
| import com.demo.pteam.trainer.address.domain.Coordinates; | ||
| import com.demo.pteam.trainer.address.domain.TrainerAddress; | ||
| import com.demo.pteam.trainer.address.repository.entity.TrainerAddressEntity; | ||
| import com.demo.pteam.trainer.profile.controller.dto.TrainerProfileRequest; | ||
|
|
||
| public class TrainerAddressMapper { | ||
|
|
||
| // 요청 DTO -> 도메인 변환 | ||
| public static TrainerAddress toDomain(TrainerProfileRequest.Address dto) { | ||
| Coordinates coordinates = new Coordinates(dto.getLatitude(), dto.getLongitude()); | ||
| return TrainerAddress.from( | ||
|
|
||
| return new TrainerAddress( | ||
| null, | ||
| null, | ||
| dto.getRoadAddress(), | ||
| dto.getDetailAddress(), | ||
| null, | ||
| coordinates | ||
| ); | ||
|
Comment on lines
+14
to
21
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| // 도메인 -> 엔티티 변환 | ||
| public static TrainerAddressEntity toEntity(TrainerAddress address) { | ||
| Coordinates coordinates = address.getCoordinates(); | ||
|
|
||
| return TrainerAddressEntity.builder() | ||
| .numberAddress(address.getNumberAddress()) | ||
| .roadAddress(address.getRoadAddress()) | ||
| .detailAddress(address.getDetailAddress()) | ||
| .postalCode(address.getPostalCode()) | ||
| .latitude(coordinates.getLatitude()) | ||
| .longitude(coordinates.getLongitude()) | ||
| .build(); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,10 +2,13 @@ | |
|
|
||
| import com.demo.pteam.trainer.address.domain.Coordinates; | ||
| import com.demo.pteam.trainer.address.domain.TrainerAddress; | ||
| import com.demo.pteam.trainer.address.mapper.TrainerAddressMapper; | ||
| import com.demo.pteam.trainer.address.repository.entity.TrainerAddressEntity; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class TrainerAddressRepositoryImpl implements TrainerAddressRepository { | ||
|
|
@@ -14,15 +17,7 @@ public class TrainerAddressRepositoryImpl implements TrainerAddressRepository { | |
|
|
||
| @Override | ||
| public TrainerAddress save(TrainerAddress address) { | ||
| TrainerAddressEntity entity = TrainerAddressEntity.builder() | ||
| .numberAddress(address.getNumberAddress()) | ||
| .roadAddress(address.getRoadAddress()) | ||
| .detailAddress(address.getDetailAddress()) | ||
| .postalCode(address.getPostalCode()) | ||
| .latitude(address.getCoordinates().getLatitude()) | ||
| .longitude(address.getCoordinates().getLongitude()) | ||
| .build(); | ||
|
|
||
| TrainerAddressEntity entity = TrainerAddressMapper.toEntity(address); | ||
| TrainerAddressEntity saved = jpaRepository.save(entity); | ||
|
|
||
| Coordinates coordinates = new Coordinates( | ||
|
|
@@ -40,4 +35,17 @@ public TrainerAddress save(TrainerAddress address) { | |
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<TrainerAddress> findById(Long addressId) { | ||
| return jpaRepository.findById(addressId) | ||
| .map(entity -> new TrainerAddress( | ||
| entity.getId(), | ||
| entity.getNumberAddress(), | ||
| entity.getRoadAddress(), | ||
| entity.getDetailAddress(), | ||
| entity.getPostalCode(), | ||
| new Coordinates(entity.getLatitude(), entity.getLongitude()) | ||
| )); | ||
| } | ||
|
Comment on lines
+38
to
+49
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 매핑을 레포지토리보단 서비스에서 하는게 좋을 것 같다고 생각해요
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
생각해보니 그렇네요! 수정해보도록 하겠습니다!! |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,29 +2,45 @@ | |
|
|
||
| import com.demo.pteam.global.response.ApiResponse; | ||
| import com.demo.pteam.trainer.profile.controller.dto.TrainerProfileRequest; | ||
| import com.demo.pteam.trainer.profile.controller.dto.TrainerProfileResponse; | ||
| import com.demo.pteam.trainer.profile.service.TrainerProfileService; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/trainers/me/profile") | ||
| public class TrainerProfileController { | ||
|
|
||
| private final TrainerProfileService trainerProfileService; | ||
| private final TrainerProfileService trainerProfileService; | ||
|
|
||
| @PostMapping | ||
| public ResponseEntity<ApiResponse<Void>> createProfile( | ||
| @RequestBody @Valid TrainerProfileRequest request | ||
| ) { | ||
| Long userId = 4L; // TODO: 로그인 사용자 임시 | ||
| /** | ||
| * 트레이너 프로필 등록 API | ||
| * @param request 트레이너 프로필 요청 DTO | ||
| * @return 등록 성공 여부 | ||
| */ | ||
| @PostMapping | ||
| public ResponseEntity<ApiResponse<Void>> createProfile( | ||
| @RequestBody @Valid TrainerProfileRequest request | ||
| ) { | ||
| Long userId = 4L; // TODO: 로그인 사용자 임시 | ||
|
|
||
| trainerProfileService.createProfile(request, userId); | ||
| return ResponseEntity.status(201).body(ApiResponse.created("트레이너 프로필이 성공적으로 등록되었습니다.")); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. response에 |
||
| } | ||
|
|
||
| /** | ||
| * 트레이너 프로필 조회 API (사용자 본인) | ||
| * @return 트레이너 프로필 응답 DTO | ||
| */ | ||
| @GetMapping | ||
| public ResponseEntity<ApiResponse<TrainerProfileResponse>> getProfile() { | ||
| Long userId = 4L; // TODO: 로그인 사용자 임시 | ||
|
|
||
| TrainerProfileResponse response = trainerProfileService.getProfile(userId); | ||
| return ResponseEntity.ok(ApiResponse.success(response)); | ||
| } | ||
|
|
||
| trainerProfileService.createProfile(request, userId); | ||
| return ResponseEntity.status(201).body(ApiResponse.created("트레이너 프로필이 성공적으로 등록되었습니다.")); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,48 @@ | ||
| package com.demo.pteam.trainer.profile.controller.dto; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonFormat; | ||
| import lombok.*; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import java.time.LocalDateTime; | ||
| import java.time.LocalTime; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class TrainerProfileResponse { | ||
| private Long profileId; | ||
| private String displayName; | ||
| private String intro; | ||
| private Integer credit; | ||
|
|
||
| @JsonFormat(pattern = "HH:mm") | ||
| private LocalTime contactStartTime; | ||
|
|
||
| @JsonFormat(pattern = "HH:mm") | ||
| private LocalTime contactEndTime; | ||
| private String profileImg; | ||
|
|
||
| @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") | ||
| private LocalDateTime createdAt; | ||
|
|
||
| @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") | ||
| private LocalDateTime updatedAt; | ||
|
|
||
| private Address address; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public static class Address { | ||
| private String roadAddress; | ||
| private String detailAddress; | ||
| private String postalCode; | ||
| private BigDecimal latitude; | ||
| private BigDecimal longitude; | ||
| } | ||
|
|
||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spring-boot-starter-web를 추가하면jsr310이 자동으로 추가되기 때문에 의존성을 추가하지 않아도 괜찮습니다!