Skip to content

Commit

Permalink
feat: #353 사용자 정보 수정 기능 추가 (#361)
Browse files Browse the repository at this point in the history
* feat: 이미지 url을 만드는 util 클래스 추가

* feat: User의 이미지를 엔티티 객체로 수정

* feat: 사용자 정보 수정 기능 추가

* feat: 이미지 조회 서비스 추가

* refactor: 메시지의 이미지 url과 관련해 util을 사용하도록 수정

* refactor: 이미지를 반환하도록 수정

* feat: 사용자 프로필 이미지 조회 컨트롤러 추가

* refactor: 업데이트 메서드에 Transactional 설정

* test: userService 예외 테스트 추가

* feat: 누락된 dto 파일 추가

* refactor: 메서드명이 명확하도록 수정

* refactor: Embedded를 통한 중복 필드 제거

* rename: 이미지 url 생성 util 클래스 패키지 위치 및 네이밍 변경

* refactor: 메서드명을 명확하도록 수정

* refactor: 개행 수정

* refactor: 변수명을 컨벤션에 맞도록 수정

* refactor: 변수명 수정 및 중복 제거

* feat: 사용자 수정 컨트롤러 기능 추가

* refactor: 메서드 로직을 명확하게 분리

* ci: 충돌 문제 해결

* ci: flyway profileImage 연관관계 수정

* docs: 문서 최신화

* style: 해결된 todo 제거

* ci: flyway 문법 수정

* refactor: User profileImage의 fk 설정

---------

Co-authored-by: apptie <[email protected]>
  • Loading branch information
JJ503 and apptie committed Oct 7, 2023
1 parent 2c1055e commit 2539211
Show file tree
Hide file tree
Showing 87 changed files with 1,378 additions and 616 deletions.
23 changes: 23 additions & 0 deletions backend/ddang/src/docs/asciidoc/docs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ include::{snippets}/authentication-controller-test/access-token과_refresh-token

include::{snippets}/authentication-controller-test/access-token과_refresh-token을_전달하면_로그아웃한다/http-response.adoc[]

== 사용자 정보 API
=== 사용자 정보 조회

==== 요청

include::{snippets}/user-controller-test/사용자_정보를_조회한다/http-request.adoc[]

==== 응답

include::{snippets}/user-controller-test/사용자_정보를_조회한다/http-response.adoc[]
include::{snippets}/user-controller-test/사용자_정보를_조회한다/response-fields.adoc[]

=== 사용자 정보 수정

==== 요청

include::{snippets}/user-controller-test/사용자_정보를_수정한다/http-request.adoc[]

==== 응답

include::{snippets}/user-controller-test/사용자_정보를_수정한다/http-response.adoc[]
include::{snippets}/user-controller-test/사용자_정보를_수정한다/response-fields.adoc[]

== 카테고리 API

=== 메인 카테고리 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private List<AuctionRegion> convertAuctionRegions(final CreateAuctionDto dto) {
private List<AuctionImage> convertAuctionImages(final CreateAuctionDto dto) {
return imageProcessor.storeImageFiles(dto.auctionImages())
.stream()
.map(StoreImageDto::toEntity)
.map(StoreImageDto::toAuctionImageEntity)
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public record ReadAuctionDto(
String mainCategory,
String subCategory,
Long sellerId,
String sellerProfile,
Long sellerProfileId,
String sellerName,
double sellerReliability
) {
Expand All @@ -40,18 +40,18 @@ public static ReadAuctionDto from(final Auction auction) {
auction.getCreatedTime(),
auction.getClosingTime(),
convertReadRegionsDto(auction),
convertImageUrls(auction),
convertImageIds(auction),
auction.getAuctioneerCount(),
auction.getSubCategory().getMainCategory().getName(),
auction.getSubCategory().getName(),
auction.getSeller().getId(),
auction.getSeller().getProfileImage(),
auction.getSeller().getProfileImage().getId(),
auction.getSeller().getName(),
auction.getSeller().getReliability()
);
}

private static List<Long> convertImageUrls(final Auction auction) {
private static List<Long> convertImageIds(final Auction auction) {
return auction.getAuctionImages()
.stream()
.map(AuctionImage::getId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
@RequiredArgsConstructor
public class AuctionController {

private static final String AUCTIONS_IMAGE_BASE_URL = "/auctions/images/";

private final AuctionService auctionService;
private final ChatRoomService chatRoomService;

Expand All @@ -52,7 +50,7 @@ public ResponseEntity<CreateAuctionResponse> create(
images,
userInfo.userId()
));
final CreateAuctionResponse response = CreateAuctionResponse.of(createInfoAuctionDto, calculateBaseImageUrl());
final CreateAuctionResponse response = CreateAuctionResponse.from(createInfoAuctionDto);

return ResponseEntity.created(URI.create("/auctions/" + createInfoAuctionDto.id()))
.body(response);
Expand All @@ -67,7 +65,6 @@ public ResponseEntity<ReadAuctionDetailResponse> read(
final ReadChatRoomDto readChatRoomDto = chatRoomService.readChatInfoByAuctionId(auctionId, userInfo);
final ReadAuctionDetailResponse response = ReadAuctionDetailResponse.of(
readAuctionDto,
calculateBaseImageUrl(),
userInfo,
readChatRoomDto
);
Expand All @@ -85,7 +82,7 @@ public ResponseEntity<ReadAuctionsResponse> readAllByCondition(
pageable,
readAuctionSearchCondition
);
final ReadAuctionsResponse response = ReadAuctionsResponse.of(readAuctionsDto, calculateBaseImageUrl());
final ReadAuctionsResponse response = ReadAuctionsResponse.from(readAuctionsDto);

return ResponseEntity.ok(response);
}
Expand All @@ -99,9 +96,4 @@ public ResponseEntity<Void> delete(

return ResponseEntity.noContent().build();
}

private String calculateBaseImageUrl() {
return ServletUriComponentsBuilder.fromCurrentContextPath().build().toUriString()
.concat(AUCTIONS_IMAGE_BASE_URL);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.ddang.ddang.auction.presentation.dto.response;

import com.ddang.ddang.auction.application.dto.ReadAuctionDto;
import com.ddang.ddang.image.presentation.util.ImageBaseUrl;
import com.ddang.ddang.image.presentation.util.ImageUrlCalculator;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -36,10 +38,10 @@ public record AuctionDetailResponse(
int auctioneerCount
) {

public static AuctionDetailResponse of(final ReadAuctionDto dto, final String baseUrl) {
public static AuctionDetailResponse from(final ReadAuctionDto dto) {
return new AuctionDetailResponse(
dto.id(),
convertImageUrls(dto, baseUrl),
convertImageUrls(dto),
dto.title(),
new CategoryResponse(dto.mainCategory(), dto.subCategory()),
dto.description(),
Expand All @@ -54,10 +56,10 @@ public static AuctionDetailResponse of(final ReadAuctionDto dto, final String ba
);
}

private static List<String> convertImageUrls(final ReadAuctionDto dto, final String baseUrl) {
private static List<String> convertImageUrls(final ReadAuctionDto dto) {
return dto.auctionImageIds()
.stream()
.map(id -> baseUrl.concat(String.valueOf(id)))
.map(id -> ImageUrlCalculator.calculate(ImageBaseUrl.AUCTION, id))
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.ddang.ddang.auction.presentation.dto.response;

import com.ddang.ddang.auction.application.dto.CreateInfoAuctionDto;
import com.ddang.ddang.image.presentation.util.ImageBaseUrl;
import com.ddang.ddang.image.presentation.util.ImageUrlCalculator;

public record CreateAuctionResponse(
Long id,
Expand All @@ -11,15 +13,19 @@ public record CreateAuctionResponse(
int auctioneerCount
) {

public static CreateAuctionResponse of(final CreateInfoAuctionDto dto, final String baseUrl) {
public static CreateAuctionResponse from(final CreateInfoAuctionDto dto) {
return new CreateAuctionResponse(
dto.id(),
dto.title(),
baseUrl.concat(String.valueOf(dto.auctionImageId())),
convertAuctionImageUrl(dto.auctionImageId()),
dto.startPrice(),
// TODO 2차 데모데이 이후 enum으로 처리
"UNBIDDEN",
0
);
}

private static String convertAuctionImageUrl(final Long id) {
return ImageUrlCalculator.calculate(ImageBaseUrl.AUCTION, id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@ public record ReadAuctionDetailResponse(

public static ReadAuctionDetailResponse of(
final ReadAuctionDto auctionDto,
final String baseUrl,
final AuthenticationUserInfo userInfo,
final ReadChatRoomDto chatRoomDto
) {
final AuctionDetailResponse auctionDetailResponse = AuctionDetailResponse.of(auctionDto, baseUrl);
final SellerResponse sellerResponse = new SellerResponse(
auctionDto.sellerId(),
auctionDto.sellerProfile(),
auctionDto.sellerName(),
auctionDto.sellerReliability()
);
final AuctionDetailResponse auctionDetailResponse = AuctionDetailResponse.from(auctionDto);
final SellerResponse sellerResponse = SellerResponse.from(auctionDto);
final ChatRoomInAuctionResponse chatRoomResponse = ChatRoomInAuctionResponse.from(chatRoomDto);

return new ReadAuctionDetailResponse(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.ddang.ddang.auction.presentation.dto.response;

import com.ddang.ddang.auction.application.dto.ReadAuctionDto;
import com.ddang.ddang.image.presentation.util.ImageBaseUrl;
import com.ddang.ddang.image.presentation.util.ImageUrlCalculator;

import java.time.LocalDateTime;

Expand All @@ -13,19 +15,20 @@ public record ReadAuctionResponse(
int auctioneerCount
) {

public static ReadAuctionResponse of(final ReadAuctionDto dto, final String baseUrl) {
public static ReadAuctionResponse from(final ReadAuctionDto dto) {
return new ReadAuctionResponse(
dto.id(),
dto.title(),
convertImageUrl(dto, baseUrl),
convertImageUrl(dto.auctionImageIds().get(0)),
processAuctionPrice(dto.startPrice(), dto.lastBidPrice()),
processAuctionStatus(dto.closingTime(), dto.lastBidPrice()),
dto.auctioneerCount()
);
}

private static String convertImageUrl(final ReadAuctionDto dto, final String baseUrl) {
return baseUrl.concat(String.valueOf(dto.auctionImageIds().get(0)));

private static String convertImageUrl(final Long id) {
return ImageUrlCalculator.calculate(ImageBaseUrl.AUCTION, id);
}

private static int processAuctionPrice(final Integer startPrice, final Integer lastBidPrice) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.ddang.ddang.auction.presentation.dto.response;

import com.ddang.ddang.auction.application.dto.ReadAuctionsDto;

import java.util.List;

public record ReadAuctionsResponse(List<ReadAuctionResponse> auctions, boolean isLast) {

public static ReadAuctionsResponse of(final ReadAuctionsDto readAuctionsDto, final String baseUrl) {
public static ReadAuctionsResponse from(final ReadAuctionsDto readAuctionsDto) {
final List<ReadAuctionResponse> readAuctionResponses = readAuctionsDto.readAuctionDtos()
.stream()
.map(dto -> ReadAuctionResponse.of(
dto, baseUrl
))
.map(ReadAuctionResponse::from)
.toList();

return new ReadAuctionsResponse(readAuctionResponses, readAuctionsDto.isLast());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
package com.ddang.ddang.auction.presentation.dto.response;

import com.ddang.ddang.auction.application.dto.ReadAuctionDto;
import com.ddang.ddang.image.presentation.util.ImageBaseUrl;
import com.ddang.ddang.image.presentation.util.ImageUrlCalculator;

public record SellerResponse(
Long id,
String image,
String nickname,
double reliability
) {

public static SellerResponse from(final ReadAuctionDto auctionDto) {
return new SellerResponse(
auctionDto.sellerId(),
convertImageUrl(auctionDto.sellerProfileId()),
auctionDto.sellerName(),
auctionDto.sellerReliability()
);
}

private static String convertImageUrl(final Long id) {
return ImageUrlCalculator.calculate(ImageBaseUrl.USER, id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public record ReadBidDto(
String name,
String profileImage,
Long profileImageId,
int price,
LocalDateTime bidTime
) {
Expand All @@ -17,7 +17,7 @@ public static ReadBidDto from(final Bid bid) {

return new ReadBidDto(
bidder.getName(),
bidder.getProfileImage(),
bidder.getProfileImage().getId(),
bid.getPrice().getValue(),
bid.getCreatedTime()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.ddang.ddang.bid.application.exception;

// TODO: 2023/07/30 [고민] 상위 excpetion 클래스 위치는 어디가 좋은가?
public class InvalidBidException extends IllegalArgumentException {

public InvalidBidException(final String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.ddang.ddang.bid.presentation.dto.response;

import com.ddang.ddang.bid.application.dto.ReadBidDto;
import com.ddang.ddang.image.presentation.util.ImageBaseUrl;
import com.ddang.ddang.image.presentation.util.ImageUrlCalculator;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.time.LocalDateTime;
Expand All @@ -17,6 +19,10 @@ public record ReadBidResponse(
) {

public static ReadBidResponse from(final ReadBidDto dto) {
return new ReadBidResponse(dto.name(), dto.profileImage(), dto.price(), dto.bidTime());
return new ReadBidResponse(dto.name(), convertImageUrl(dto.profileImageId()), dto.price(), dto.bidTime());
}

private static String convertImageUrl(final Long id) {
return ImageUrlCalculator.calculate(ImageBaseUrl.USER, id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.ddang.ddang.chat.infrastructure.persistence.JpaChatRoomRepository;
import com.ddang.ddang.chat.infrastructure.persistence.JpaMessageRepository;
import com.ddang.ddang.chat.presentation.dto.request.ReadMessageRequest;
import com.ddang.ddang.image.application.ImageService;
import com.ddang.ddang.notification.application.NotificationService;
import com.ddang.ddang.notification.application.dto.CreateNotificationDto;
import com.ddang.ddang.notification.domain.NotificationType;
Expand All @@ -29,12 +30,13 @@
public class MessageService {

private final NotificationService notificationService;
private final ImageService imageService;
private final JpaMessageRepository messageRepository;
private final JpaChatRoomRepository chatRoomRepository;
private final JpaUserRepository userRepository;

@Transactional
public Long create(final CreateMessageDto dto) {
public Long create(final CreateMessageDto dto, final String baseUrl) {
final ChatRoom chatRoom = chatRoomRepository.findById(dto.chatRoomId())
.orElseThrow(() -> new ChatRoomNotFoundException(
"지정한 아이디에 대한 채팅방을 찾을 수 없습니다."));
Expand All @@ -53,19 +55,22 @@ public Long create(final CreateMessageDto dto) {

final Message persistMessage = messageRepository.save(message);

sendNotification(persistMessage);
sendNotification(persistMessage, baseUrl);

return persistMessage.getId();
}

private void sendNotification(final Message message) {
private void sendNotification(final Message message, final String baseUrl) {
final Long profileImageId = message.getWriter().getProfileImage().getId();
final String profileImageUrl = baseUrl.concat(String.valueOf(profileImageId));

final CreateNotificationDto dto = new CreateNotificationDto(
NotificationType.MESSAGE,
message.getReceiver().getId(),
message.getWriter().getName(),
message.getContents(),
calculateRedirectUrl(message.getChatRoom().getId()),
message.getWriter().getProfileImage()
profileImageUrl
);
notificationService.send(dto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

import com.ddang.ddang.user.domain.User;

public record ReadUserInChatRoomDto(Long id, String name, String profileImage, double reliability) {
public record ReadUserInChatRoomDto(Long id, String name, Long profileImageId, double reliability) {

public static ReadUserInChatRoomDto from(final User user) {
return new ReadUserInChatRoomDto(user.getId(), user.getName(), user.getProfileImage(), user.getReliability());
return new ReadUserInChatRoomDto(
user.getId(),
user.getName(),
user.getProfileImage().getId(),
user.getReliability()
);
}
}
Loading

0 comments on commit 2539211

Please sign in to comment.