Skip to content

Commit

Permalink
feat : 유저 정보 조회 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
JiwonKKang committed Aug 14, 2024
1 parent babd2fc commit 5dab6b5
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
username: ${{ secrets.GHCR_ACTOR }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Setup Gradle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import core.startup.mealtoktok.domain.mealdelivery.DeliveryDateTime;
import core.startup.mealtoktok.domain.mealdelivery.DeliveryState;
import core.startup.mealtoktok.domain.mealdelivery.MealDelivery;
import core.startup.mealtoktok.domain.order.OrderedMeal;
import core.startup.mealtoktok.domain.mealdelivery.OrderedMeal;

import com.fasterxml.jackson.annotation.JsonInclude;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import java.util.List;

import core.startup.mealtoktok.domain.mealdelivery.OrderedMeal;
import core.startup.mealtoktok.domain.order.OrderContent;
import core.startup.mealtoktok.domain.order.OrderPrice;
import core.startup.mealtoktok.domain.order.OrderType;
import core.startup.mealtoktok.domain.order.OrderedMeal;

public record MealOrderRequest(
OrderType orderType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import core.startup.mealtoktok.api.auth.dto.SignUpRequest.AddressInfoRequest;
import core.startup.mealtoktok.api.user.dto.AvailabilityResponse;
import core.startup.mealtoktok.api.user.dto.DeliveryAddressResponse;
import core.startup.mealtoktok.api.user.dto.UserResponse;
import core.startup.mealtoktok.common.dto.Response;
import core.startup.mealtoktok.domain.user.TargetDeliveryAddress;
import core.startup.mealtoktok.domain.user.TargetUser;
Expand All @@ -28,6 +29,12 @@ public class UserApi implements UserApiDocs {

private final UserService userService;

@Override
@GetMapping("/{userId}")
public Response<UserResponse> getUser(@PathVariable Long userId) {
return Response.success(UserResponse.from(userService.getUser(TargetUser.from(userId))));
}

@GetMapping("/nickname/change-available")
public Response<AvailabilityResponse> checkNicknameDuplicate(String nickname) {
boolean isDuplicated = userService.checkNicknameDuplicate(nickname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import core.startup.mealtoktok.api.auth.dto.SignUpRequest.AddressInfoRequest;
import core.startup.mealtoktok.api.user.dto.AvailabilityResponse;
import core.startup.mealtoktok.api.user.dto.DeliveryAddressResponse;
import core.startup.mealtoktok.api.user.dto.UserResponse;
import core.startup.mealtoktok.common.dto.Response;
import core.startup.mealtoktok.domain.user.TargetUser;

Expand All @@ -14,6 +15,10 @@
@Tag(name = "회원 API")
public interface UserApiDocs {

@Operation(summary = "유저 정보 조회")
Response<UserResponse> getUser(Long userId);

@Operation(summary = "닉네임 중복 확인")
Response<AvailabilityResponse> checkNicknameDuplicate(String nickname);

@Operation(summary = "닉네임 변경")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package core.startup.mealtoktok.api.user.dto;

import java.time.LocalDate;

import core.startup.mealtoktok.domain.user.User;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

@JsonInclude(Include.NON_NULL)
public record UserResponse(
Long userId,
String username,
String nickname,
String email,
String phoneNumber,
String profileImageUrl,
LocalDate birth) {

public static UserResponse from(User user) {
return new UserResponse(
user.getUserId(),
user.getUserProfile().getUsername(),
user.getUserProfile().getNickname(),
user.getUserProfile().getEmail(),
user.getUserProfile().getPhoneNumber(),
user.getUserProfile().getProfileImageUrl(),
user.getUserProfile().getBirth());
}
}
4 changes: 2 additions & 2 deletions application/app-api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spring:
on-profile: local
jwt:
access-token:
expiration: 2592000 #3일
expiration: 25920000

---
spring:
Expand All @@ -39,4 +39,4 @@ spring:
on-profile: dev
jwt:
access-token:
expiration: 2592000 #3일
expiration: 25920000
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
import lombok.Builder;
import lombok.Getter;

import core.startup.mealtoktok.domain.order.OrderedMeal;
import core.startup.mealtoktok.domain.order.TargetOrder;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder
public class MealDelivery {

private Long mealDeliveryId;
private TargetOrder targetOrder;
private Long orderId;
private OrderedMeal orderedMeal;
private DeliveryState deliveryState;
private DeliveryDateTime deliveryDateTime;
Expand All @@ -32,9 +29,9 @@ public void completeDelivery(LocalDateTime completeDateTime) {
this.deliveryState = DeliveryState.DELIVERED;
}

public static MealDelivery create(TargetOrder targetOrder, OrderedMeal orderedMeal) {
public static MealDelivery create(Long orderId, OrderedMeal orderedMeal) {
return new MealDelivery(
null, targetOrder, orderedMeal, DeliveryState.PENDING, DeliveryDateTime.init());
null, orderId, orderedMeal, DeliveryState.PENDING, DeliveryDateTime.init());
}

public boolean hasFullDiningOption() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@

import lombok.RequiredArgsConstructor;

import core.startup.mealtoktok.domain.order.OrderedMeal;
import core.startup.mealtoktok.domain.order.TargetOrder;

@Component
@RequiredArgsConstructor
public class MealDeliveryReserver {

private final MealDeliveryRepository mealDeliveryRepository;

public List<MealDelivery> reserve(TargetOrder targetOrder, List<OrderedMeal> orderedMeals) {
List<MealDelivery> mealDeliveries =
orderedMeals.parallelStream()
.map(orderedMeal -> MealDelivery.create(targetOrder, orderedMeal))
.toList();
public List<MealDelivery> reserve(List<MealDelivery> mealDeliveries) {
return mealDeliveryRepository.saveAll(mealDeliveries);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package core.startup.mealtoktok.domain.order;
package core.startup.mealtoktok.domain.mealdelivery;

import java.time.LocalDate;

import core.startup.mealtoktok.domain.order.ReservedSchedule;
import core.startup.mealtoktok.domain.order.ReservedTime;

public record OrderedMeal(
Long mealId,
ReservedSchedule reservedSchedule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@

import java.util.List;

import core.startup.mealtoktok.domain.mealdelivery.MealDelivery;
import core.startup.mealtoktok.domain.mealdelivery.OrderedMeal;

public record OrderContent(
OrderType orderType,
List<OrderedMeal> orderedMeals,
String specialInstruction,
OrderPrice orderPrice) {}
OrderPrice orderPrice) {

public List<MealDelivery> toMealDeliveries(TargetOrder targetOrder) {
return orderedMeals.parallelStream()
.map(orderedMeal -> MealDelivery.create(targetOrder.orderId(), orderedMeal))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public TargetOrder orderMeals(Orderer orderer, OrderContent orderContent) {
orderValidator.validate(orderContent);
TargetOrder targetOrder = orderAppender.append(orderer, orderContent);
List<MealDelivery> mealDeliveries =
mealDeliveryReserver.reserve(targetOrder, orderContent.orderedMeals());
mealDeliveryReserver.reserve(orderContent.toMealDeliveries(targetOrder));
fullDiningManager.reserve(mealDeliveries);
return targetOrder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public class UserService {
private final userRemover userRemover;
private final UserValidator userValidator;

public User getUser(TargetUser targetUser) {
return userReader.read(targetUser);
}

public TargetUser addDeliveryAddress(
TargetUser targetUser, AddressWithCoordinate addressWithCoordinate) {
User user = userReader.read(targetUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import core.startup.mealtoktok.domain.mealdelivery.DeliveryDateTime;
import core.startup.mealtoktok.domain.mealdelivery.DeliveryState;
import core.startup.mealtoktok.domain.mealdelivery.MealDelivery;
import core.startup.mealtoktok.domain.order.OrderedMeal;
import core.startup.mealtoktok.domain.mealdelivery.OrderedMeal;
import core.startup.mealtoktok.domain.order.ReservedTime;
import core.startup.mealtoktok.domain.order.TargetOrder;

Expand Down
4 changes: 2 additions & 2 deletions infra/src/main/resources/application-infra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
ddl-auto: create
properties:
hibernate:
show-sql: true
Expand Down Expand Up @@ -44,7 +44,7 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: create-drop
ddl-auto: update
properties:
hibernate:
show-sql: true
Expand Down

0 comments on commit 5dab6b5

Please sign in to comment.