diff --git a/src/main/java/com/example/howmuch/controller/EventController.java b/src/main/java/com/example/howmuch/controller/EventController.java index e279c29..a1c6cf2 100644 --- a/src/main/java/com/example/howmuch/controller/EventController.java +++ b/src/main/java/com/example/howmuch/controller/EventController.java @@ -109,6 +109,11 @@ public ResponseEntity getAllAcEvents() { ); } + @GetMapping("/acquaintance/name") + public ResponseEntity getAllAcName(){ + return new ResponseEntity<>(this.eventService.getAcName(), HttpStatus.OK); + } + // 지인 경조사 업데이트 @PatchMapping("/acquaintance/{id}") public ResponseEntity updateAcEvents( diff --git a/src/main/java/com/example/howmuch/domain/repository/AcEventRepository.java b/src/main/java/com/example/howmuch/domain/repository/AcEventRepository.java index d876557..673fe21 100644 --- a/src/main/java/com/example/howmuch/domain/repository/AcEventRepository.java +++ b/src/main/java/com/example/howmuch/domain/repository/AcEventRepository.java @@ -14,6 +14,8 @@ public interface AcEventRepository extends JpaRepository { List findAllByUserOrderByEventAtDesc(User user); + List findByUserOrderByAcquaintanceNicknameDesc(User user); + List findAllByAcquaintanceType(AcType type); List findAllByUserAndAcquaintanceTypeAndEventCategoryOrderByEventAtDesc(User user, AcType acType, EventCategory category); diff --git a/src/main/java/com/example/howmuch/dto/event/GetAllAcNicknameResponse.java b/src/main/java/com/example/howmuch/dto/event/GetAllAcNicknameResponse.java new file mode 100644 index 0000000..e90376c --- /dev/null +++ b/src/main/java/com/example/howmuch/dto/event/GetAllAcNicknameResponse.java @@ -0,0 +1,23 @@ +package com.example.howmuch.dto.event; + +import com.example.howmuch.domain.entity.AcEvent; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class GetAllAcNicknameResponse { + + String name; + + public static GetAllAcNicknameResponse from(AcEvent acEvent){ + return new GetAllAcNicknameResponse(acEvent.getAcquaintanceNickname()); + } + +} diff --git a/src/main/java/com/example/howmuch/dto/event/GetAllAcNicknameResponseDto.java b/src/main/java/com/example/howmuch/dto/event/GetAllAcNicknameResponseDto.java new file mode 100644 index 0000000..60e1692 --- /dev/null +++ b/src/main/java/com/example/howmuch/dto/event/GetAllAcNicknameResponseDto.java @@ -0,0 +1,25 @@ +package com.example.howmuch.dto.event; + +import com.example.howmuch.domain.entity.AcEvent; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class GetAllAcNicknameResponseDto { + + List names; + + + public static GetAllAcNicknameResponseDto from(List acEvents) { + return new GetAllAcNicknameResponseDto(acEvents.stream() + .map(GetAllAcNicknameResponse::from).toList()); + } +} diff --git a/src/main/java/com/example/howmuch/service/event/EventService.java b/src/main/java/com/example/howmuch/service/event/EventService.java index 7a7dcb9..f616f02 100644 --- a/src/main/java/com/example/howmuch/service/event/EventService.java +++ b/src/main/java/com/example/howmuch/service/event/EventService.java @@ -314,6 +314,13 @@ public GetAllAcEventsResponseDto getAcEventsByName(String acquaintanceName) { return new GetAllAcEventsResponseDto((long) totalCost, sortedAcEvents); } + // 지인 이름 조회 + @Transactional(readOnly = true) + public GetAllAcNicknameResponseDto getAcName(){ + User user = getUser(); + return GetAllAcNicknameResponseDto.from(acEventRepository.findByUserOrderByAcquaintanceNicknameDesc(user)); + } + private Map> getAllMyEvent(User user) { Map> allMyEvents = this.myEventRepository.findAllByUserOrderByEventAtDesc( user)