Skip to content

Commit

Permalink
[Feat] 멤버, 아이템 등록시 responseDTO 변경(#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjk4618 committed May 30, 2024
1 parent 4809b8a commit e85325a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -22,8 +23,9 @@ public class ItemController {
@PostMapping("/item")
public ResponseEntity<BaseResponse<?>> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +25,7 @@ public class MemberController {

@PostMapping("/member")
public ResponseEntity<BaseResponse<?>> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit e85325a

Please sign in to comment.