diff --git a/carrotMarket/src/main/java/org/sopt/carrotMarket/controller/ItemController.java b/carrotMarket/src/main/java/org/sopt/carrotMarket/controller/ItemController.java index de43ed7..e8ce5fc 100644 --- a/carrotMarket/src/main/java/org/sopt/carrotMarket/controller/ItemController.java +++ b/carrotMarket/src/main/java/org/sopt/carrotMarket/controller/ItemController.java @@ -7,6 +7,7 @@ import org.sopt.carrotMarket.service.ItemService; import org.sopt.carrotMarket.service.dto.GetAllItemsInfoResponseDTO; import org.sopt.carrotMarket.service.dto.RegisterItemDTO; +import org.sopt.carrotMarket.service.dto.RegisterItemResponseDTO; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -22,8 +23,9 @@ public class ItemController { @PostMapping("/item") public ResponseEntity> registerItem(@RequestHeader final Long memberId, @ModelAttribute final RegisterItemDTO registerItemDTO) { - itemService.registerItem(memberId, registerItemDTO); - return ApiResponseUtil.success(SuccessMessage.ITEM_REGISTER_SUCCESS); + RegisterItemResponseDTO registerItemResponseDTO = itemService.registerItem(memberId, registerItemDTO); + + return ApiResponseUtil.success(SuccessMessage.ITEM_REGISTER_SUCCESS, registerItemResponseDTO); } //memberID에 해당되는 모든 물건 GET diff --git a/carrotMarket/src/main/java/org/sopt/carrotMarket/controller/MemberController.java b/carrotMarket/src/main/java/org/sopt/carrotMarket/controller/MemberController.java index 0b42f8f..0c1f3b2 100644 --- a/carrotMarket/src/main/java/org/sopt/carrotMarket/controller/MemberController.java +++ b/carrotMarket/src/main/java/org/sopt/carrotMarket/controller/MemberController.java @@ -9,6 +9,7 @@ import org.sopt.carrotMarket.domain.Member; import org.sopt.carrotMarket.service.MemberService; import org.sopt.carrotMarket.service.dto.RegisterMemberRequestDTO; +import org.sopt.carrotMarket.service.dto.RegisterMemberResponseDTO; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -24,7 +25,7 @@ public class MemberController { @PostMapping("/member") public ResponseEntity> createMember(@RequestBody RegisterMemberRequestDTO member) { - memberService.registerMember(member); - return ApiResponseUtil.success(SuccessMessage.MEMBER_REGISTER_SUCCESS); + RegisterMemberResponseDTO registerMemberResponseDTO = memberService.registerMember(member); + return ApiResponseUtil.success(SuccessMessage.MEMBER_REGISTER_SUCCESS, registerMemberResponseDTO); } } diff --git a/carrotMarket/src/main/java/org/sopt/carrotMarket/service/ItemService.java b/carrotMarket/src/main/java/org/sopt/carrotMarket/service/ItemService.java index 99f8b66..fe4febb 100644 --- a/carrotMarket/src/main/java/org/sopt/carrotMarket/service/ItemService.java +++ b/carrotMarket/src/main/java/org/sopt/carrotMarket/service/ItemService.java @@ -13,6 +13,7 @@ import org.sopt.carrotMarket.repository.MemberRepository; import org.sopt.carrotMarket.service.dto.GetAllItemsInfoResponseDTO; import org.sopt.carrotMarket.service.dto.RegisterItemDTO; +import org.sopt.carrotMarket.service.dto.RegisterItemResponseDTO; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -33,7 +34,7 @@ public class ItemService { private static final String BLOG_S3_UPLOAD_FOLER = "blog/"; @Transactional - public void registerItem(final Long memberId, final RegisterItemDTO registerItemDTO) { + public RegisterItemResponseDTO registerItem(final Long memberId, final RegisterItemDTO registerItemDTO) { Member member = findMemberById(memberId); @@ -49,6 +50,7 @@ public void registerItem(final Long memberId, final RegisterItemDTO registerItem registerItemDTO.detailInfo(), Location.valueOf(registerItemDTO.hopeTradeSpot())); itemRepository.save(item); + return RegisterItemResponseDTO.of(item.getId()); } catch (RuntimeException | IOException e) { throw new RuntimeException(e.getMessage()); diff --git a/carrotMarket/src/main/java/org/sopt/carrotMarket/service/MemberService.java b/carrotMarket/src/main/java/org/sopt/carrotMarket/service/MemberService.java index c7b2383..23b8b2a 100644 --- a/carrotMarket/src/main/java/org/sopt/carrotMarket/service/MemberService.java +++ b/carrotMarket/src/main/java/org/sopt/carrotMarket/service/MemberService.java @@ -5,6 +5,7 @@ import org.sopt.carrotMarket.domain.Member; import org.sopt.carrotMarket.repository.MemberRepository; import org.sopt.carrotMarket.service.dto.RegisterMemberRequestDTO; +import org.sopt.carrotMarket.service.dto.RegisterMemberResponseDTO; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,8 +17,9 @@ public class MemberService { private final MemberRepository memberRepository; @Transactional - public void registerMember(RegisterMemberRequestDTO member) { + public RegisterMemberResponseDTO registerMember(RegisterMemberRequestDTO member) { Member newMember = Member.register(member.name()); memberRepository.save(newMember); + return RegisterMemberResponseDTO.of(newMember.getId()); } } diff --git a/carrotMarket/src/main/java/org/sopt/carrotMarket/service/dto/RegisterItemResponseDTO.java b/carrotMarket/src/main/java/org/sopt/carrotMarket/service/dto/RegisterItemResponseDTO.java new file mode 100644 index 0000000..129287f --- /dev/null +++ b/carrotMarket/src/main/java/org/sopt/carrotMarket/service/dto/RegisterItemResponseDTO.java @@ -0,0 +1,15 @@ +package org.sopt.carrotMarket.service.dto; + +import lombok.Builder; +import org.sopt.carrotMarket.domain.Item; + +@Builder +public record RegisterItemResponseDTO( + Long itemId +) { + public static RegisterItemResponseDTO of(Long itemId) { + return RegisterItemResponseDTO.builder() + .itemId(itemId) + .build(); + } +} diff --git a/carrotMarket/src/main/java/org/sopt/carrotMarket/service/dto/RegisterMemberResponseDTO.java b/carrotMarket/src/main/java/org/sopt/carrotMarket/service/dto/RegisterMemberResponseDTO.java new file mode 100644 index 0000000..13c4c10 --- /dev/null +++ b/carrotMarket/src/main/java/org/sopt/carrotMarket/service/dto/RegisterMemberResponseDTO.java @@ -0,0 +1,15 @@ +package org.sopt.carrotMarket.service.dto; + +import lombok.Builder; +import org.springframework.http.ResponseEntity; + +@Builder +public record RegisterMemberResponseDTO( + Long memberId +) { + public static RegisterMemberResponseDTO of(Long memberId) { + return RegisterMemberResponseDTO.builder() + .memberId(memberId) + .build(); + } +}