Skip to content

Commit

Permalink
Refactor: 클린아키텍쳐 구조잡기
Browse files Browse the repository at this point in the history
  • Loading branch information
BYEONGRYEOL committed May 4, 2024
1 parent d80850e commit 49d9286
Show file tree
Hide file tree
Showing 30 changed files with 178 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,27 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gt.genti.other.aop.annotation.CheckUserIsQuit;
import com.gt.genti.other.config.auth.UserDetailsImpl;
import com.gt.genti.dto.PictureGenerateRequestDetailResponseDto;
import com.gt.genti.dto.PictureGenerateRequestModifyDto;
import com.gt.genti.dto.PictureGenerateRequestRequestDto;
import com.gt.genti.dto.PictureGenerateRequestResponseDto;
import com.gt.genti.application.service.PictureGenerateRequestService;
import com.gt.genti.other.aop.annotation.CheckUserIsQuit;
import com.gt.genti.other.config.auth.UserDetailsImpl;

import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping("/api/requests")
@RequiredArgsConstructor
public class PictureGenerateRequestController {
private final PictureGenerateRequestService pictureGenerateRequestService;
private final PictureGenerateRequestUseCase pictureGenerateRequestUseCase;

@CheckUserIsQuit
@GetMapping("/active")
public ResponseEntity<ApiResult<List<PictureGenerateRequestDetailResponseDto>>> getMyActivePictureGenerateRequest(
@AuthenticationPrincipal UserDetailsImpl userDetails) {
return success(
pictureGenerateRequestService.getMyActivePictureGenerateRequest(userDetails.getId()));
pictureGenerateRequestUseCase.getMyActivePictureGenerateRequest(userDetails.getId()));
}

@CheckUserIsQuit
Expand All @@ -44,7 +43,7 @@ public ResponseEntity<ApiResult<PictureGenerateRequestResponseDto>> createPictur
@RequestBody PictureGenerateRequestRequestDto pictureGenerateRequestRequestDto) {

return success(
pictureGenerateRequestService.createPictureGenerateRequest(userDetails.getId(),
pictureGenerateRequestUseCase.createPictureGenerateRequest(userDetails.getId(),
pictureGenerateRequestRequestDto));
}

Expand All @@ -54,7 +53,7 @@ public ResponseEntity<ApiResult<Boolean>> modifyPictureGenerateRequest(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestBody PictureGenerateRequestModifyDto pictureGenerateRequestModifyDto) {
return success(
pictureGenerateRequestService.modifyPictureGenerateRequest(userDetails.getId(),
pictureGenerateRequestUseCase.modifyPictureGenerateRequest(userDetails.getId(),
pictureGenerateRequestModifyDto));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.gt.genti.adapter.in.web;

import java.util.List;
import java.util.Optional;

import org.springframework.stereotype.Component;

import com.gt.genti.domain.PictureGenerateRequest;
import com.gt.genti.domain.User;
import com.gt.genti.repository.PictureGenerateRequestRepository;

import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
public class PictureGenerateRequestPersistenceAdapter implements PictureGenerateRequestPort {
private final PictureGenerateRequestRepository pictureGenerateRequestRepository;

@Override
public List<PictureGenerateRequest> findByRequestStatusIsActiveAndUserId_JPQL(Long userId) {
return pictureGenerateRequestRepository.findByRequestStatusIsActiveAndUserId_JPQL(userId);
}

@Override
public List<PictureGenerateRequest> findAllByRequester(User requester) {
return pictureGenerateRequestRepository.findAllByRequester(requester);
}

@Override
public Optional<PictureGenerateRequest> findByCreatorAndRequestStatusIsBeforeWorkOrderByCreatedAtAsc(Long userId) {
return pictureGenerateRequestRepository.findByCreatorAndRequestStatusIsBeforeWorkOrderByCreatedAtAsc(userId);
}

@Override
public List<PictureGenerateRequest> findPendingRequests() {
return pictureGenerateRequestRepository.findPendingRequests();
}
@Override
public Optional<PictureGenerateRequest> findById(Long id){
return pictureGenerateRequestRepository.findById(id);
}

@Override
public PictureGenerateRequest save(PictureGenerateRequest pictureGenerateRequest){
return pictureGenerateRequestRepository.save(pictureGenerateRequest);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.gt.genti.adapter.in.web;

import java.util.List;
import java.util.Optional;

import org.springframework.data.repository.query.Param;

import com.gt.genti.domain.PictureGenerateRequest;
import com.gt.genti.domain.User;

public interface PictureGenerateRequestPort {

List<PictureGenerateRequest> findByRequestStatusIsActiveAndUserId_JPQL(Long userId);

List<PictureGenerateRequest> findAllByRequester(User requester);

Optional<PictureGenerateRequest> findByCreatorAndRequestStatusIsBeforeWorkOrderByCreatedAtAsc(Long userId);

List<PictureGenerateRequest> findPendingRequests();

Optional<PictureGenerateRequest> findById(Long id);

PictureGenerateRequest save(PictureGenerateRequest pictureGenerateRequest);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.gt.genti.adapter.in.web;

import java.util.List;

import com.gt.genti.domain.User;
import com.gt.genti.dto.PictureGenerateRequestDetailResponseDto;
import com.gt.genti.dto.PictureGenerateRequestModifyDto;
import com.gt.genti.dto.PictureGenerateRequestRequestDto;
import com.gt.genti.dto.PictureGenerateRequestResponseDto;
import com.gt.genti.dto.PictureGenerateRequestSimplifiedResponseDto;

public interface PictureGenerateRequestUseCase {
public List<PictureGenerateRequestDetailResponseDto> getMyActivePictureGenerateRequest(Long userId);

public PictureGenerateRequestDetailResponseDto getPictureGenerateRequestById(Long id);

public List<PictureGenerateRequestSimplifiedResponseDto> getAllMyPictureGenerateRequests(User requester);

public PictureGenerateRequestResponseDto createPictureGenerateRequest(Long requesterId,
PictureGenerateRequestRequestDto pictureGenerateRequestRequestDto);

public Boolean modifyPictureGenerateRequest(Long userId,
PictureGenerateRequestModifyDto pictureGenerateRequestModifyDto);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.gt.genti.adapter.in.web;

import java.util.Optional;

import org.springframework.stereotype.Component;

import com.gt.genti.domain.PosePicture;
import com.gt.genti.repository.PosePictureRepository;

import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
public class PosePicturePersistenceAdapter implements PosePicturePort {
private final PosePictureRepository posePictureRepository;

@Override
public Optional<PosePicture> findByUrl(String url) {
return posePictureRepository.findByUrl(url);
}

@Override
public PosePicture save(PosePicture posePicture) {
return posePictureRepository.save(posePicture);
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/gt/genti/adapter/in/web/PosePicturePort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.gt.genti.adapter.in.web;

import java.util.Optional;

import com.gt.genti.domain.PosePicture;

public interface PosePicturePort {

Optional<PosePicture> findByUrl(String url);
PosePicture save(PosePicture posePicture);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gt.genti.adapter.in.web.PictureGenerateRequestPort;
import com.gt.genti.adapter.in.web.PictureGenerateRequestUseCase;
import com.gt.genti.adapter.in.web.PosePicturePort;
import com.gt.genti.domain.Creator;
import com.gt.genti.domain.PictureGenerateRequest;
import com.gt.genti.domain.PosePicture;
Expand All @@ -16,30 +19,31 @@
import com.gt.genti.dto.PictureGenerateRequestModifyDto;
import com.gt.genti.dto.PictureGenerateRequestRequestDto;
import com.gt.genti.dto.PictureGenerateRequestResponseDto;
import com.gt.genti.dto.PictureGenerateRequestSimplifiedResponseDto;
import com.gt.genti.other.util.RandomUtils;
import com.gt.genti.repository.CreatorRepository;
import com.gt.genti.repository.PictureGenerateRequestRepository;
import com.gt.genti.repository.PosePictureRepository;
import com.gt.genti.repository.UserRepository;
import com.gt.genti.other.util.RandomUtils;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class PictureGenerateRequestService {
private final PictureGenerateRequestRepository pictureGenerateRequestRepository;
private final PosePictureRepository posePictureRepository;
public class PictureGenerateRequestService implements PictureGenerateRequestUseCase {
private final PictureGenerateRequestPort pictureGenerateRequestPort;
private final PosePicturePort posePicturePort;
private final CreatorRepository creatorRepository;
private final UserRepository userRepository;

@Override
public List<PictureGenerateRequestDetailResponseDto> getMyActivePictureGenerateRequest(Long userId) {
return pictureGenerateRequestRepository.findByRequestStatusIsActiveAndUserId_JPQL(userId).stream().map(
return pictureGenerateRequestPort.findByRequestStatusIsActiveAndUserId_JPQL(userId).stream().map(
PictureGenerateRequestDetailResponseDto::new
).toList();
}

@Override
public PictureGenerateRequestDetailResponseDto getPictureGenerateRequestById(Long id) {
PictureGenerateRequest findPictureGenerateRequest = pictureGenerateRequestRepository.findById(id).orElseThrow();
PictureGenerateRequest findPictureGenerateRequest = pictureGenerateRequestPort.findById(id).orElseThrow();
return PictureGenerateRequestDetailResponseDto.builder()
.pictureGenerateRequest(findPictureGenerateRequest)
.build();
Expand All @@ -48,19 +52,21 @@ public PictureGenerateRequestDetailResponseDto getPictureGenerateRequestById(Lon
//TODO 내가 생성한 요청 리스트 보기
// edited at 2024-04-13
// author 서병렬
@Override
public List<PictureGenerateRequestSimplifiedResponseDto> getAllMyPictureGenerateRequests(User requester) {
// return pictureGenerateRequestPersistenceAdapter.findAllByRequester(requester).stream().map(entity -> );
return null;
}

// public List<PictureGenerateRequestSimplifiedResponseDto> getAllMyPictureGenerateRequests(User requester){
// return pictureGenerateRequestRepository.findAllByRequester(requester).stream().map(entity -> );
// }

@Override
public PictureGenerateRequestResponseDto createPictureGenerateRequest(Long requesterId,
PictureGenerateRequestRequestDto pictureGenerateRequestRequestDto) {

User findRequester = userRepository.findById(requesterId).orElseThrow();
String posePictureUrl = pictureGenerateRequestRequestDto.getPosePictureUrl();
PosePicture findPosePicture = posePictureRepository.findByUrl(
PosePicture findPosePicture = posePicturePort.findByUrl(
posePictureUrl)
.or(() -> Optional.of(posePictureRepository.save(PosePicture.builder().url(
.or(() -> Optional.of(posePicturePort.save(PosePicture.builder().url(
posePictureUrl).build()))).orElseThrow();

PictureGenerateRequest pgr = new PictureGenerateRequest(findRequester, pictureGenerateRequestRequestDto,
Expand All @@ -76,7 +82,7 @@ public PictureGenerateRequestResponseDto createPictureGenerateRequest(Long reque
requestIsAssigned.set(true);
}

pictureGenerateRequestRepository.save(
pictureGenerateRequestPort.save(
new PictureGenerateRequest(findRequester, pictureGenerateRequestRequestDto, findPosePicture));

if (requestIsAssigned.get()) {
Expand All @@ -88,10 +94,11 @@ public PictureGenerateRequestResponseDto createPictureGenerateRequest(Long reque
//TODO 공급자 앱에 푸시알림
}

@Override
@Transactional
public Boolean modifyPictureGenerateRequest(Long userId,
PictureGenerateRequestModifyDto pictureGenerateRequestModifyDto) {
PictureGenerateRequest findPictureGenerateRequest = pictureGenerateRequestRepository.findById(
PictureGenerateRequest findPictureGenerateRequest = pictureGenerateRequestPort.findById(
pictureGenerateRequestModifyDto.getPictureGenerateRequestId()).orElseThrow();

if (!Objects.equals(userId, findPictureGenerateRequest.getRequester().getId())) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/gt/genti/domain/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import java.util.List;

import com.gt.genti.domain.common.BaseTimeEntity;
import com.gt.genti.domain.enums.PostStatus;
import com.gt.genti.domain.enums.converter.PostStatusConverter;
import com.gt.genti.domain.common.BaseTimeEntity;

import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/gt/genti/domain/ProfilePicture.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gt.genti.domain;


import com.gt.genti.domain.common.BaseTimeEntity;

import jakarta.persistence.Entity;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/gt/genti/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.time.Period;
import java.util.List;

import com.gt.genti.other.config.auth.OAuthAttributes;
import com.gt.genti.domain.common.BaseTimeEntity;
import com.gt.genti.other.config.auth.OAuthAttributes;
import com.gt.genti.domain.enums.OauthType;
import com.gt.genti.domain.enums.UserRole;
import com.gt.genti.domain.enums.UserStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gt.genti.domain_old.common;
package com.gt.genti.domain.common;

import java.time.LocalDateTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@Getter
@RequiredArgsConstructor
public enum CameraAngle implements ConvertableEnum{
public enum CameraAngle implements com.gt.genti.domain.enums.ConvertableEnum {
ABOVE("위에서 촬영"),
EYE_LEVEL("같은 높이에서 촬영"),
BELOW("아래에서 촬영");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@Getter
@RequiredArgsConstructor
public enum OauthType implements ConvertableEnum {
public enum OauthType implements com.gt.genti.domain.enums.ConvertableEnum {
GOOGLE("GOOGLE"),
KAKAO("KAKAO"),
APPLE("APPLE"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// package com.gt.genti.dto;
//
// import com.gt.genti.domain.enums.RequestStatus;
//
// public class PictureGenerateRequestSimplifiedResponseDto {
// Long id;
// String prompt;
// String url;
// RequestStatus requestStatus;
// }
package com.gt.genti.dto;

import com.gt.genti.domain.enums.RequestStatus;

public class PictureGenerateRequestSimplifiedResponseDto {
Long id;
String prompt;
String url;
RequestStatus requestStatus;
}

0 comments on commit 49d9286

Please sign in to comment.