Skip to content
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.example.spring_boot_a.api.review;
package com.example.spring_boot_a.controller;

import com.example.spring_boot_a.api.review.dto.MyReviewItemDto;
import com.example.spring_boot_a.domain.service.MyReviewQueryService;
import com.example.spring_boot_a.domain.entity.review.dto.MyReviewItemDto;
import com.example.spring_boot_a.service.MyReviewQueryService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.example.spring_boot_a.api.review;
package com.example.spring_boot_a.controller;

import com.example.spring_boot_a.api.review.dto.*;
import com.example.spring_boot_a.domain.entity.review.dto.ReviewCreateRequest;
import com.example.spring_boot_a.domain.entity.review.dto.ReviewResponse;
import com.example.spring_boot_a.domain.entity.review.dto.StarSummaryResponse;
import com.example.spring_boot_a.service.ReviewService;
import jakarta.validation.Valid;
import org.springframework.data.domain.*;
import org.springframework.web.bind.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.example.spring_boot_a.controller;

import com.example.spring_boot_a.domain.entity.user.converter.UserConverter;
import com.example.spring_boot_a.domain.entity.user.dto.UserRequestDto;
import com.example.spring_boot_a.domain.entity.user.dto.UserResponseDto;
import com.example.spring_boot_a.domain.entity.user.User;
import com.example.spring_boot_a.global.apiPayload.code.ApiResponse;
import com.example.spring_boot_a.global.apiPayload.code.GeneralSuccessCode;
import com.example.spring_boot_a.service.UserService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/users")
public class UserController {

private final UserService userService;
private final UserConverter userConverter;


@PostMapping
public ResponseEntity<ApiResponse<UserResponseDto.CreateResult>> createUser(
@Valid @RequestBody UserRequestDto.Create request
) {
User user = userConverter.toUser(request);

User saved = userService.createUser(user);

UserResponseDto.CreateResult responseDTO = userConverter.toCreateResult(saved);

return ResponseEntity
.status(GeneralSuccessCode.CREATED.getStatus())
.body(ApiResponse.onSuccess(GeneralSuccessCode.CREATED, responseDTO));
}


@GetMapping("/{userId}")
public ResponseEntity<ApiResponse<UserResponseDto.Detail>> getUser(
@PathVariable Long userId
) {
User user = userService.getUser(userId);

UserResponseDto.Detail dto = userConverter.toDetail(user);

return ResponseEntity
.status(GeneralSuccessCode.OK.getStatus())
.body(ApiResponse.onSuccess(GeneralSuccessCode.OK, dto));
}


@GetMapping
public ResponseEntity<ApiResponse<List<UserResponseDto.Summary>>> getUsers() {
List<User> users = userService.getUsers();

List<UserResponseDto.Summary> dtos = userConverter.toSummaryList(users);

return ResponseEntity
.status(GeneralSuccessCode.OK.getStatus())
.body(ApiResponse.onSuccess(GeneralSuccessCode.OK, dtos));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.example.spring_boot_a.domain.entity;

import com.example.spring_boot_a.domain.entity.etc.Location;
import com.example.spring_boot_a.domain.entity.etc.Mission;
import com.example.spring_boot_a.domain.entity.review.Review;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.spring_boot_a.domain.entity;

import com.example.spring_boot_a.domain.entity.enums.TermType;
import com.example.spring_boot_a.domain.entity.user.UserTerm;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.spring_boot_a.domain.entity;
package com.example.spring_boot_a.domain.entity.etc;

import com.example.spring_boot_a.domain.entity.user.UserFood;
import com.example.spring_boot_a.domain.entity.enums.FoodType;
import jakarta.persistence.*;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.spring_boot_a.domain.entity;
package com.example.spring_boot_a.domain.entity.etc;

import com.example.spring_boot_a.domain.entity.Store;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.spring_boot_a.domain.entity;
package com.example.spring_boot_a.domain.entity.etc;

import com.example.spring_boot_a.domain.entity.Store;
import com.example.spring_boot_a.domain.entity.user.UserMission;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.spring_boot_a.domain.entity;
package com.example.spring_boot_a.domain.entity.etc;

import com.example.spring_boot_a.domain.entity.review.Review;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.spring_boot_a.domain.entity;
package com.example.spring_boot_a.domain.entity.etc;

import com.example.spring_boot_a.domain.entity.review.Review;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.example.spring_boot_a.domain.entity;
package com.example.spring_boot_a.domain.entity.review;

import com.example.spring_boot_a.domain.entity.etc.ReviewPhoto;
import com.example.spring_boot_a.domain.entity.Store;
import com.example.spring_boot_a.domain.entity.etc.Reply;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -25,9 +28,7 @@ public class Review {
@ManyToOne(optional = false) @JoinColumn(name = "store_id")
private Store store;

@ManyToOne(optional = false) @JoinColumn(name = "user_id")
private User user;

@JoinColumn(name = "user_id")
@OneToMany(mappedBy = "review", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<ReviewPhoto> photos = new HashSet<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.spring_boot_a.api.review.dto;
package com.example.spring_boot_a.domain.entity.review.dto;

import java.time.Instant;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.spring_boot_a.api.review.dto;
package com.example.spring_boot_a.domain.entity.review.dto;

import jakarta.validation.constraints.*;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.spring_boot_a.api.review.dto;
package com.example.spring_boot_a.domain.entity.review.dto;

import java.time.Instant;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.spring_boot_a.api.review.dto;
package com.example.spring_boot_a.domain.entity.review.dto;

public record StarSummaryResponse(
long s5,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.spring_boot_a.domain.entity;
package com.example.spring_boot_a.domain.entity.user;

import com.example.spring_boot_a.domain.entity.review.Review;
import com.example.spring_boot_a.domain.entity.enums.AddressGu;
import com.example.spring_boot_a.domain.entity.enums.Gender;
import com.example.spring_boot_a.domain.entity.enums.SocialLoginType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.spring_boot_a.domain.entity;
package com.example.spring_boot_a.domain.entity.user;

import com.example.spring_boot_a.domain.entity.etc.Food;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.spring_boot_a.domain.entity;
package com.example.spring_boot_a.domain.entity.user;

import com.example.spring_boot_a.domain.entity.etc.Mission;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.spring_boot_a.domain.entity;
package com.example.spring_boot_a.domain.entity.user;

import com.example.spring_boot_a.domain.entity.Term;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.example.spring_boot_a.domain.entity.user.converter;

import com.example.spring_boot_a.domain.entity.user.dto.UserRequestDto;
import com.example.spring_boot_a.domain.entity.user.dto.UserResponseDto;
import com.example.spring_boot_a.domain.entity.user.User;
import org.springframework.stereotype.Component;

import java.time.Instant;
import java.util.List;

@Component
public class UserConverter {

public User toUser(UserRequestDto.Create request) {
User user = new User();
user.setName(request.getName());
user.setGender(request.getGender());
user.setBirth(request.getBirth());
user.setAddress(request.getAddress());
user.setEmail(request.getEmail());
user.setPhoneNumber(request.getPhoneNumber());
user.setSocialType(request.getSocialType());
user.setPoint(0);
user.setUpdatedAt(Instant.now());
return user;
}

public UserResponseDto.CreateResult toCreateResult(User user) {
return UserResponseDto.CreateResult.builder()
.userId(user.getUserId())
.name(user.getName())
.email(user.getEmail())
.build();
}

public UserResponseDto.Detail toDetail(User user) {
return UserResponseDto.Detail.builder()
.userId(user.getUserId())
.name(user.getName())
.gender(user.getGender())
.birth(user.getBirth())
.address(user.getAddress())
.email(user.getEmail())
.phoneNumber(user.getPhoneNumber())
.point(user.getPoint())
.socialType(user.getSocialType())
.updatedAt(user.getUpdatedAt())
.build();
}

public UserResponseDto.Summary toSummary(User user) {
return UserResponseDto.Summary.builder()
.userId(user.getUserId())
.name(user.getName())
.address(user.getAddress())
.point(user.getPoint())
.build();
}

public List<UserResponseDto.Summary> toSummaryList(List<User> users) {
return users.stream()
.map(this::toSummary)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.example.spring_boot_a.domain.entity.user.dto;

import com.example.spring_boot_a.domain.entity.enums.AddressGu;
import com.example.spring_boot_a.domain.entity.enums.Gender;
import com.example.spring_boot_a.domain.entity.enums.SocialLoginType;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

public class UserRequestDto {

@Getter
@NoArgsConstructor
public static class Create {

@NotBlank(message = "이름은 필수값입니다.")
private String name;

@NotNull(message = "성별은 필수값입니다.")
private Gender gender;

private LocalDate birth;

@NotNull(message = "주소(구)는 필수값입니다.")
private AddressGu address;

@NotBlank(message = "이메일은 필수값입니다.")
@Email(message = "이메일 형식이 올바르지 않습니다.")
private String email;

@NotBlank(message = "전화번호는 필수값입니다.")
@Size(max = 20, message = "전화번호는 최대 20자입니다.")
private String phoneNumber;

@NotNull(message = "소셜 타입은 필수값입니다.")
private SocialLoginType socialType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.example.spring_boot_a.domain.entity.user.dto;

import com.example.spring_boot_a.domain.entity.enums.AddressGu;
import com.example.spring_boot_a.domain.entity.enums.Gender;
import com.example.spring_boot_a.domain.entity.enums.SocialLoginType;
import lombok.Builder;
import lombok.Getter;

import java.time.Instant;
import java.time.LocalDate;

public class UserResponseDto {

@Getter
@Builder
public static class CreateResult {
private Long userId;
private String name;
private String email;
}

@Getter
@Builder
public static class Detail {
private Long userId;
private String name;
private Gender gender;
private LocalDate birth;
private AddressGu address;
private String email;
private String phoneNumber;
private Integer point;
private SocialLoginType socialType;
private Instant updatedAt;
}

@Getter
@Builder
public static class Summary {
private Long userId;
private String name;
private AddressGu address;
private Integer point;
}
}
Loading