Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/docs/asciidoc/_auth.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
=== 회원 로그인
Comment thread
willjsw marked this conversation as resolved.
Outdated
`POST /auth/login`

요청 본문:
include::{snippets}/member-login/request-fields.adoc[]

응답 본문:
include::{snippets}/member-login/response-fields.adoc[]

응답 헤더 (쿠키):
include::{snippets}/member-login/response-headers.adoc[]

응답:
include::{snippets}/member-login/http-response.adoc[]
105 changes: 105 additions & 0 deletions src/docs/asciidoc/_delivery_address.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
== 배송지 주소 (Delivery Address) API

=== 1. 배송지 주소 등록
`POST /address`

요청 본문:
include::{snippets}/delivery-address-register/request-fields.adoc[]

응답:
include::{snippets}/delivery-address-register/http-response.adoc[]

==== 배송지 주소 등록 실패: 유효성 검사
* `우편번호 누락`
include::{snippets}/delivery-address-register-fail-postal-code-missing/http-response.adoc[]
include::{snippets}/delivery-address-register-fail-postal-code-missing/response-fields.adoc[]

---

=== 2. 배송지 주소 조회
`GET /address/{deliveryAddressId}/info`

경로 파라미터 (Path Parameters):
include::{snippets}/delivery-address-info-get/path-parameters.adoc[]

응답 본문:
include::{snippets}/delivery-address-info-get/response-fields.adoc[]

응답:
include::{snippets}/delivery-address-info-get/http-response.adoc[]

==== 배송지 주소 조회 실패: 존재하지 않는 주소 ID
include::{snippets}/delivery-address-info-get-fail-not-found/http-response.adoc[]
include::{snippets}/delivery-address-info-get-fail-not-found/response-fields.adoc[]

---

=== 3. 배송지 주소 목록 조회
`GET /address`

쿼리 파라미터 (Query Parameters):
include::{snippets}/delivery-address-info-list-get/query-parameters.adoc[]

응답 본문:
include::{snippets}/delivery-address-info-list-get/response-fields.adoc[]

응답:
include::{snippets}/delivery-address-info-list-get/http-response.adoc[]

---

=== 4. 수취인 정보 수정
`PATCH /address/{deliveryAddressId}/recipient`

경로 파라미터 (Path Parameters):
include::{snippets}/delivery-address-recipient-update/path-parameters.adoc[]

요청 본문:
include::{snippets}/delivery-address-recipient-update/request-fields.adoc[]

응답:
include::{snippets}/delivery-address-recipient-update/http-response.adoc[]

==== 수취인 정보 수정 실패: 존재하지 않는 주소 ID
include::{snippets}/delivery-address-recipient-update-fail-not-found/http-response.adoc[]
include::{snippets}/delivery-address-recipient-update-fail-not-found/response-fields.adoc[]

---

=== 5. 상세 주소 수정
`PATCH /address/{deliveryAddressId}/detail`

경로 파라미터 (Path Parameters):
include::{snippets}/delivery-address-detail-update/path-parameters.adoc[]

요청 본문:
include::{snippets}/delivery-address-detail-update/request-fields.adoc[]

응답:
include::{snippets}/delivery-address-detail-update/http-response.adoc[]

---

=== 6. 기본 배송지 설정
`PATCH /address/{deliveryAddressId}/default`

경로 파라미터 (Path Parameters):
include::{snippets}/delivery-address-default-set/path-parameters.adoc[]

응답:
include::{snippets}/delivery-address-default-set/http-response.adoc[]

---

=== 7. 배송지 주소 삭제
`DELETE /address/{deliveryAddressId}`

경로 파라미터 (Path Parameters):
include::{snippets}/delivery-address-delete/path-parameters.adoc[]

응답:
include::{snippets}/delivery-address-delete/http-response.adoc[]

==== 배송지 주소 삭제 실패: 권한 없음 (다른 회원의 주소 삭제 시도)
include::{snippets}/delivery-address-delete-fail-no-permission/http-response.adoc[]
include::{snippets}/delivery-address-delete-fail-no-permission/response-fields.adoc[]
4 changes: 2 additions & 2 deletions src/docs/asciidoc/_manager.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ include::{snippets}/manager-delete/path-parameters.adoc[]
include::{snippets}/manager-delete/http-response.adoc[]

==== 매니저 삭제 실패: 권한 없음
include::{snippets}/manager-delete-fail-not-manager/http-response.adoc[]
include::{snippets}/manager-delete-fail-not-manager/response-fields.adoc[]
include::{snippets}/manager-delete-fail-self-delete/http-response.adoc[]
include::{snippets}/manager-delete-fail-self-delete/response-fields.adoc[]
2 changes: 2 additions & 0 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

include::_member.adoc[]
include::_manager.adoc[]
include::_auth.adoc
include::_delivery_address.adoc

// include::_product.adoc[]

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.irum.come2us.domain.auth.application.service.AuthService;
import com.irum.come2us.domain.auth.presentation.dto.request.MemberLoginRequest;
import com.irum.come2us.domain.auth.presentation.dto.response.MemberLoginResponse;
import com.irum.come2us.global.util.CookieUtil;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -16,11 +18,18 @@
@Slf4j
public class AuthController {
private final AuthService authService;
private final CookieUtil cookieUtil;

@PostMapping("/login")
public MemberLoginResponse login(@RequestBody MemberLoginRequest request) {
public ResponseEntity<MemberLoginResponse> login(@RequestBody MemberLoginRequest request) {
log.info("회원 로그인 요청: {}", request);
return authService.processMemberLogin(request);
MemberLoginResponse responseBody = authService.processMemberLogin(request);
HttpHeaders cookieHeaders =
cookieUtil.generateRefreshTokenCookie(responseBody.refreshToken());
log.info("로그인 성공-토큰 발급 완료: {}", request.email());
log.trace("access token issued: {}", responseBody.accessToken());
log.trace("refresh token issued: {}", responseBody.refreshToken());
return ResponseEntity.status(HttpStatus.OK).headers(cookieHeaders).body(responseBody);
}

@PostMapping("/logout")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@
import com.irum.come2us.domain.deliveryaddress.presentation.dto.request.RecipientUpdateRequest;
import com.irum.come2us.domain.deliveryaddress.presentation.dto.response.DeliveryAddressInfoListResponse;
import com.irum.come2us.domain.deliveryaddress.presentation.dto.response.DeliveryAddressInfoResponse;
import com.irum.come2us.domain.member.application.util.MemberValidator;
import com.irum.come2us.domain.member.domain.entity.Member;
import com.irum.come2us.global.presentation.advice.exception.CommonException;
import com.irum.come2us.global.presentation.advice.exception.errorcode.DeliveryAddressErrorCode;
import com.irum.come2us.global.presentation.advice.exception.errorcode.GlobalErrorCode;
import com.irum.come2us.global.util.MemberUtil;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

@Service
@RequiredArgsConstructor
@Transactional
@Slf4j
public class DeliveryAddressService {
private final MemberValidator memberValidator;
private final MemberUtil memberUtil;
private final DeliveryAddressRepository deliveryAddressRepository;

Expand Down Expand Up @@ -52,30 +54,34 @@ public DeliveryAddressInfoResponse findDeliveryAddress(UUID deliveryAddressId) {
}

@Transactional(readOnly = true)
public DeliveryAddressInfoListResponse findDeliveryAddressList(UUID cursor, int pageSize) {
int limit = pageSize + 1;
public DeliveryAddressInfoListResponse findDeliveryAddressList(UUID cursor, Integer size) {
if (size == null || (size != 10 && size != 30 && size != 50)) {
log.warn("허용되지 않은 size 요청: {} -> 기본값 10으로 대체", size);
size = 10;
}
int limit = size + 1;
List<DeliveryAddressInfoResponse> addressList =
deliveryAddressRepository.findDeliveryAddressByCursor(
memberUtil.getCurrentMember().getMemberId(), cursor, limit);
boolean hasNext = addressList.size() > pageSize;
boolean hasNext = addressList.size() > size;
List<DeliveryAddressInfoResponse> resultList =
hasNext ? addressList.subList(0, pageSize) : addressList;
hasNext ? addressList.subList(0, size) : addressList;
UUID nextCursor = null;
if (hasNext) {
DeliveryAddressInfoResponse lastItem = resultList.get(resultList.size() - 1);
nextCursor = lastItem.id();
nextCursor = lastItem.deliveryAddressId();
}
return new DeliveryAddressInfoListResponse(resultList, nextCursor, hasNext);
}

public void changeRecipientInfo(RecipientUpdateRequest request) {
DeliveryAddress deliveryAddress = validDeliveryAddress(request.deliveryAddressId());
deliveryAddress.updateRecipientName(request.newRecipientName());
deliveryAddress.updateRecipientContact(request.newRecipientContact());
public void changeRecipientInfo(UUID deliveryAddressId, RecipientUpdateRequest request) {
DeliveryAddress deliveryAddress = validDeliveryAddress(deliveryAddressId);
applyValidUpdate(
deliveryAddress, request.newRecipientName(), request.newRecipientContact());
}

public void changeAddressDetail(AddressDetailUpdateRequest request) {
DeliveryAddress deliveryAddress = validDeliveryAddress(request.deliveryAddressId());
public void changeAddressDetail(UUID deliveryAddressId, AddressDetailUpdateRequest request) {
DeliveryAddress deliveryAddress = validDeliveryAddress(deliveryAddressId);
deliveryAddress.updateAddressDetail(request.newAddressDetail());
}

Expand Down Expand Up @@ -119,4 +125,11 @@ private DeliveryAddress getCurrentDefaultAddress() {
new CommonException(
DeliveryAddressErrorCode.DELIVERY_ADDRESS_NOT_FOUND));
}

public void applyValidUpdate(DeliveryAddress address, String newName, String newContact) {
if (!StringUtils.hasText(newName) && !StringUtils.hasText(newContact))
throw new CommonException(GlobalErrorCode.EMPTY_REQUEST);
if (StringUtils.hasText(newName)) address.updateRecipientName(newName);
if (StringUtils.hasText(newContact)) address.updateAddressDetail(newContact);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.irum.come2us.domain.deliveryaddress.presentation.dto.response.DeliveryAddressInfoListResponse;
import com.irum.come2us.domain.deliveryaddress.presentation.dto.response.DeliveryAddressInfoResponse;
import jakarta.annotation.Nullable;
import jakarta.validation.Valid;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand All @@ -21,44 +22,46 @@ public class DeliveryAddressController {

@PostMapping
public ResponseEntity<Void> registerDeliveryAddress(
@RequestBody DeliveryAddressRegisterRequest request) {
@Valid @RequestBody DeliveryAddressRegisterRequest request) {
deliveryAddressService.createDeliveryAddress(request);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@GetMapping("/info")
@GetMapping("/{deliveryAddressId}/info")
public DeliveryAddressInfoResponse getDeliveryAddressInfo(
@RequestParam UUID deliveryAddressId) {
@PathVariable UUID deliveryAddressId) {
return deliveryAddressService.findDeliveryAddress(deliveryAddressId);
}

@GetMapping
public DeliveryAddressInfoListResponse getDeliveryAddressInfoList(
@Nullable @RequestParam UUID cursor, @RequestParam int pageSize) {
return deliveryAddressService.findDeliveryAddressList(cursor, pageSize);
@Nullable @RequestParam UUID cursor, @RequestParam Integer size) {
return deliveryAddressService.findDeliveryAddressList(cursor, size);
}

@PatchMapping("/recipient")
public ResponseEntity<Void> updateRecipientInfo(@RequestBody RecipientUpdateRequest request) {
deliveryAddressService.changeRecipientInfo(request);
@PatchMapping("/{deliveryAddressId}/recipient")
public ResponseEntity<Void> updateRecipientInfo(
@PathVariable UUID deliveryAddressId, @RequestBody RecipientUpdateRequest request) {
deliveryAddressService.changeRecipientInfo(deliveryAddressId, request);
return ResponseEntity.noContent().build();
}

@PatchMapping("/detail")
@PatchMapping("/{deliveryAddressId}/detail")
public ResponseEntity<Void> updateAddressDetail(
@RequestBody AddressDetailUpdateRequest request) {
deliveryAddressService.changeAddressDetail(request);
@PathVariable UUID deliveryAddressId,
@Valid @RequestBody AddressDetailUpdateRequest request) {
deliveryAddressService.changeAddressDetail(deliveryAddressId, request);
return ResponseEntity.noContent().build();
}

@PatchMapping("/default")
public ResponseEntity<Void> setDefaultDeliveryAddress(@RequestParam UUID deliveryAddressId) {
@PatchMapping("/{deliveryAddressId}/default")
public ResponseEntity<Void> setDefaultDeliveryAddress(@PathVariable UUID deliveryAddressId) {
deliveryAddressService.changeDefaultDeliveryAddress(deliveryAddressId);
return ResponseEntity.noContent().build();
}

@DeleteMapping
public ResponseEntity<Void> deleteDeliveryAddress(@RequestParam UUID deliveryAddressId) {
@DeleteMapping("/{deliveryAddressId}")
public ResponseEntity<Void> deleteDeliveryAddress(@PathVariable UUID deliveryAddressId) {
deliveryAddressService.removeDeliveryAddress(deliveryAddressId);
return ResponseEntity.noContent().build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
package com.irum.come2us.domain.deliveryaddress.presentation.dto.request;

import java.util.UUID;

public record AddressDetailUpdateRequest(UUID deliveryAddressId, String newAddressDetail) {}
public record AddressDetailUpdateRequest(String newAddressDetail) {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
package com.irum.come2us.domain.deliveryaddress.presentation.dto.request;

import java.util.UUID;

public record RecipientUpdateRequest(
UUID deliveryAddressId, String newRecipientName, String newRecipientContact) {}
public record RecipientUpdateRequest(String newRecipientName, String newRecipientContact) {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
import java.util.UUID;

public record DeliveryAddressInfoResponse(
UUID id,
UUID deliveryAddressId,
Address address,
String recipientName,
String recipientContact,
Boolean isDefault) {
public static DeliveryAddressInfoResponse of(
UUID id,
UUID deliveryAddressId,
Address address,
String recipientName,
String recipientContact,
Boolean isDefault) {
return new DeliveryAddressInfoResponse(
id, address, recipientName, recipientContact, isDefault);
deliveryAddressId, address, recipientName, recipientContact, isDefault);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.irum.come2us.domain.member.domain.repository.MemberRepository;
import com.irum.come2us.global.presentation.advice.exception.CommonException;
import com.irum.come2us.global.presentation.advice.exception.errorcode.AuthErrorCode;
import com.irum.come2us.global.presentation.advice.exception.errorcode.GlobalErrorCode;
import com.irum.come2us.global.presentation.advice.exception.errorcode.MemberErrorCode;
import com.irum.come2us.global.security.MemberDetails;
import java.util.Optional;
Expand Down Expand Up @@ -108,7 +109,7 @@ public void assertMemberIsManager(Member member) {

public void applyValidUpdate(Member member, String newName, String newContact) {
if (!StringUtils.hasText(newName) && !StringUtils.hasText(newContact))
throw new CommonException(MemberErrorCode.EMPTY_REQUEST);
throw new CommonException(GlobalErrorCode.EMPTY_REQUEST);
if (StringUtils.hasText(newName)) member.updateName(newName);
if (StringUtils.hasText(newContact)) member.updateContact(newContact);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
@AllArgsConstructor
public enum GlobalErrorCode implements BaseErrorCode {
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "서버 오류입니다. 관리자에게 문의해주세요."),
INVALID_CURSOR(HttpStatus.BAD_REQUEST, "리소스를 조회할 수 없습니다.");
;
INVALID_CURSOR(HttpStatus.BAD_REQUEST, "리소스를 조회할 수 없습니다."),
EMPTY_REQUEST(HttpStatus.BAD_REQUEST, "비어있는 요청입니다.");

private final HttpStatus httpStatus;
private final String message;
Expand Down
Loading