Skip to content

Commit

Permalink
Update: 포인트 내역 테이블 및 정산 테이블 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
BYEONGRYEOL committed May 19, 2024
1 parent 5b8f67a commit b14f5ed
Show file tree
Hide file tree
Showing 43 changed files with 634 additions and 160 deletions.
57 changes: 40 additions & 17 deletions sql/setup-dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ insert ignore into creator (id, user_id, workable, created_at, modified_at)
values (:creatorId, :creatorUserId, true, localtime, localtime),
(2, :emptyCreatorId, false, localtime, localtime);

insert ignore into picture_pose (id, created_at, modified_at, url)
values (1, LOCALTIME, LOCALTIME, 'pose_picture_url1'),
(2, LOCALTIME, LOCALTIME, 'pose_picture_url2'),
(3, LOCALTIME, LOCALTIME, 'pose_picture_url3'),
(4, LOCALTIME, LOCALTIME, 'pose_picture_url4');
insert ignore into picture_pose (id, created_at, modified_at, url, uploaded_by)
values (1, LOCALTIME, LOCALTIME, 'pose_picture_url1', :userId),
(2, LOCALTIME, LOCALTIME, 'pose_picture_url2', :userId),
(3, LOCALTIME, LOCALTIME, 'pose_picture_url3', :userId),
(4, LOCALTIME, LOCALTIME, 'pose_picture_url4', :userId);

insert ignore into picture_user_face (id, created_at, modified_at, url, user_id)
insert ignore into picture_user_face (id, created_at, modified_at, url, uploaded_by)
values (1, LOCALTIME, LOCALTIME, 'user_face_picture_url1', :userId),
(2, LOCALTIME, LOCALTIME, 'user_face_picture_url2', :userId),
(3, LOCALTIME, LOCALTIME, 'user_face_picture_url3', :userId),
Expand Down Expand Up @@ -116,17 +116,40 @@ insert ignore into report (id, created_at, modified_at, content, report_status,
values (1, localtime, localtime, '변태자식이 본인 발가락 사진을 보낸 것 같습니다.', 'NOT_RESOLVED', 4),
(2, localtime, localtime, '모르는 사람 얼굴이에요', 'RESOLVED', 6);

insert ignore into picture_created_by_creator (id, created_at, modified_at, url, picture_generate_response_id)
values (1, localtime, localtime, '얼굴 완성 전 url 1', 2),
(2, localtime, localtime, '얼굴 완성 전 url 2', 3),
(3, localtime, localtime, '얼굴 완성 전 url 3', 4);

insert ignore into picture_completed (id, created_at, modified_at, url, picture_generate_response_id, user_id)
values (1, localtime, localtime, '얼굴 완성 사진 url 1', 3, :userId),
(2, localtime, localtime, '얼굴 완성 사진 url 2', 4, :userId),
(3, localtime, localtime, '얼굴 완성 사진 url 3', 5, :userId),
(4, localtime, localtime, '얼굴 완성 사진 url 4', 6, :userId);

insert ignore into picture_created_by_creator (id, created_at, modified_at, url, picture_generate_response_id,
uploaded_by)
values (1, localtime, localtime, '얼굴 완성 전 url 1', 2, :creatorUserId),
(2, localtime, localtime, '얼굴 완성 전 url 2', 3, :creatorUserId),
(3, localtime, localtime, '얼굴 완성 전 url 3', 4, :creatorUserId);

insert ignore into picture_completed (id, created_at, modified_at, url, picture_generate_response_id, user_id,
uploaded_by)
values (1, localtime, localtime, '얼굴 완성 사진 url 1', 3, :userId, :adminId),
(2, localtime, localtime, '얼굴 완성 사진 url 2', 4, :userId, :adminId),
(3, localtime, localtime, '얼굴 완성 사진 url 3', 5, :userId, :adminId),
(4, localtime, localtime, '얼굴 완성 사진 url 4', 6, :userId, :adminId);

insert ignore into response_example (id, created_at, modified_at, example_picture_url, example_prompt, prompt_only,
uploaded_by)
values (1, localtime, localtime, '/EXAMPLE/벚꽃벤치여자.png', '벚꽃 벤치 여자', false, :adminId),
(2, localtime, localtime, '/EXAMPLE/한강잠수부.png', '한강잠수부', false, :adminId),
(3, localtime, localtime, null, '프롬프트만있음 사진은 없고', true, :adminId);


insert ignore into settlement (id, created_at, modified_at, elapsed_minutes, reward, picture_generate_response_id)
values (1, localtime, localtime, 80, 2000, 2),
(2, localtime, localtime, 50, 2500, 3),
(3, localtime, localtime, 230, 1000, 5);

insert ignore into deposit (id, created_at, modified_at, deposit_amount, user_id)
values (1, localtime, localtime, 0, :adminId),
(2, localtime, localtime, 1000, :userId),
(3, localtime, localtime, 0, :emptyUserId),
(4, localtime, localtime, 0, :creatorUserId),
(5, localtime, localtime, 0, :emptyCreatorId),
(6, localtime, localtime, 0, :oauthFirstJoinUserId),
(7, localtime, localtime, 0, :deactivatedUserId),
(8, localtime, localtime, 0, :deactivatedCreatorId);

# insert ignore into post (id, user_id, main_picture_id, content, likes, post_status, created_at)
# values (1, 3, 1, 'post content 테스트', 1001, 'POSTED', '20010101')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ResponseEntity<ApiResult<Boolean>> updatePicture(
CreatePictureCompletedCommand command = CreatePictureCompletedCommand.builder()
.pictureGenerateResponse(foundPictureGenerateResponse)
.url(requestDto.getUrl())
.uploadedBy(userDetails.getId()).build();
.userId(userDetails.getId()).build();
pictureService.updatePicture(command);
return success(true);
}
Expand Down
19 changes: 9 additions & 10 deletions src/main/java/com/gt/genti/adapter/in/web/AdminUserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@

import static com.gt.genti.other.util.ApiUtils.*;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gt.genti.application.service.ReportService;
import com.gt.genti.application.service.UserService;
import com.gt.genti.dto.ChangeUserStatusRequestDto;
import com.gt.genti.dto.ReportResponseDto;
import com.gt.genti.dto.ReportUpdateDto;
import com.gt.genti.dto.ChangeUserRoleDto;
import com.gt.genti.dto.ChangeUserStatusDto;

import lombok.RequiredArgsConstructor;

Expand All @@ -25,10 +20,14 @@
@RequiredArgsConstructor
public class AdminUserController {
UserService userService;
@PostMapping("/users/{userId}")
public ResponseEntity<ApiResult<Boolean>> changeUserStatus(@PathVariable Long userId, @RequestBody ChangeUserStatusRequestDto changeUserStatusRequestDto){
return success(userService.updateUserStatus(userId, changeUserStatusRequestDto));
@PostMapping("/users/{userId}/status")
public ResponseEntity<ApiResult<Boolean>> changeUserStatus(@PathVariable Long userId, @RequestBody ChangeUserStatusDto changeUserStatusDto){
return success(userService.updateUserStatus(userId, changeUserStatusDto));
}

@PostMapping("/users/{userId}/role")
public ResponseEntity<ApiResult<Boolean>> changeUserRole(@PathVariable Long userId, @RequestBody ChangeUserRoleDto changeUserRoleDto){
return success(userService.updateUserRole(userId, changeUserRoleDto));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ public ResponseEntity<ApiResult<UpdateCreatorStatusResponseDto>> updateCreatorSt
@RequestBody UpdateCreatorStatusRequestDto updateCreatorStatusRequestDto) {
return success(creatorService.updateCreatorStatus(userDetails.getId(), updateCreatorStatusRequestDto));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,29 @@
import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gt.genti.application.service.PostService;
import com.gt.genti.application.service.UploadUrlService;
import com.gt.genti.dto.PostBriefResponseDto;
import com.gt.genti.dto.PostDetailResponseDto;
import com.gt.genti.external.aws.dto.PreSignedUrlRequestDto;
import com.gt.genti.external.aws.dto.PreSignedUrlResponseDto;
import com.gt.genti.other.annotation.ToBeUpdated;
import com.gt.genti.other.aop.annotation.CheckUserIsQuit;
import com.gt.genti.other.auth.UserDetailsImpl;

import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class UploadUrlController {
public class PictureController {
private final UploadUrlService uploadUrlService;

@PostMapping("/presigned-url")
public ResponseEntity<ApiResult<PreSignedUrlResponseDto>> getUploadUrl(@RequestBody PreSignedUrlRequestDto preSignedUrlRequestDto){
return success(uploadUrlService.getUploadUrl(preSignedUrlRequestDto));
}

@PostMapping("/presigned-urls")
@PostMapping("/presigned-url/many")
public ResponseEntity<ApiResult<List<PreSignedUrlResponseDto>>> getUploadUrls(@RequestBody List<PreSignedUrlRequestDto> requestDtoList){
return success(uploadUrlService.getUploadUrls(requestDtoList));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import com.gt.genti.domain.enums.PictureGenerateRequestStatus;
import com.gt.genti.dto.PictureGenerateRequestBriefResponseDto;
import com.gt.genti.dto.PictureGenerateRequestDetailResponseDto;
import com.gt.genti.dto.PictureGenerateResponseSubmitDto;
import com.gt.genti.dto.UpdateMemoRequestDto;
import com.gt.genti.dto.UpdatePictureUrlRequestDto;
import com.gt.genti.other.auth.UserDetailsImpl;

import jakarta.websocket.server.PathParam;
import lombok.RequiredArgsConstructor;

@RestController
Expand All @@ -38,6 +38,20 @@ public ResponseEntity<ApiResult<PictureGenerateRequestBriefResponseDto>> getAssi
userDetails.getId(), PictureGenerateRequestStatus.ASSIGNING));
}

@PostMapping("/picture-generate-requests/{pictureGenerateRequestId}/accept")
public ResponseEntity<ApiResult<Boolean>> acceptPictureGenerateRequest(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@PathVariable Long pictureGenerateRequestId) {
return success(pictureGenerateWorkService.acceptPictureGenerateRequest(userDetails.getId(), pictureGenerateRequestId));
}

@PostMapping("/picture-generate-requests/{pictureGenerateRequestId}/reject")
public ResponseEntity<ApiResult<Boolean>> rejectPictureGenerateRequest(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@PathVariable Long pictureGenerateRequestId) {
return success(pictureGenerateWorkService.rejectPictureGenerateRequest(userDetails.getId(), pictureGenerateRequestId));
}

@GetMapping("/picture-generate-requests/{pictureGenerateRequestId}")
public ResponseEntity<ApiResult<PictureGenerateRequestDetailResponseDto>> getPictureGenerateRequestDetail(
@AuthenticationPrincipal UserDetailsImpl userDetails,
Expand All @@ -61,13 +75,15 @@ public ResponseEntity<ApiResult<Boolean>> updatePictureUrl(
@RequestBody List<UpdatePictureUrlRequestDto> updatePictureUrlRequestDtoList
) {
return success(
pictureGenerateWorkService.updatePictureCreatedByCreatorList(pictureGenerateResponseId, updatePictureUrlRequestDtoList, userDetails.getId()));
pictureGenerateWorkService.updatePictureCreatedByCreatorList(pictureGenerateResponseId,
updatePictureUrlRequestDtoList, userDetails.getId()));
}

@PostMapping("/picture-generate-responses/{pictureGenerateResponseId}/submit")
public ResponseEntity<ApiResult<Boolean>> submitPictureGenerateResponse(
public ResponseEntity<ApiResult<PictureGenerateResponseSubmitDto>> submitPictureGenerateResponse(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@PathVariable Long pictureGenerateResponseId) {
return success(pictureGenerateWorkService.submit(pictureGenerateResponseId));
return success(pictureGenerateWorkService.submit(userDetails.getId(), pictureGenerateResponseId));
}

@PostMapping("/picture-generate-responses/{pictureGenerateResponseId}/memo")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.gt.genti.adapter.in.web;

import static com.gt.genti.other.util.ApiUtils.*;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gt.genti.application.service.PictureGenerateWorkService;
import com.gt.genti.domain.enums.PictureGenerateRequestStatus;
import com.gt.genti.dto.PictureGenerateRequestBriefResponseDto;
import com.gt.genti.dto.PictureGenerateRequestDetailResponseDto;
import com.gt.genti.dto.PictureGenerateResponseSubmitDto;
import com.gt.genti.dto.SettlementResponseDto;
import com.gt.genti.dto.UpdateMemoRequestDto;
import com.gt.genti.dto.UpdatePictureUrlRequestDto;
import com.gt.genti.other.auth.UserDetailsImpl;
import com.gt.genti.service.SettlementService;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping("/api/creators")
@RequiredArgsConstructor
public class SettlementController {
private final SettlementService settlementService;
@GetMapping("/settlements")
public ResponseEntity<ApiResult<List<SettlementResponseDto>>> getMySettlements(
@AuthenticationPrincipal UserDetailsImpl userDetails) {
//TODO 출금내역또한 나와야한다.
// edited at 2024-05-19
// author 서병렬

return success(settlementService.getAllSettlements(userDetails.getId()));
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/gt/genti/application/service/DepositService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.gt.genti.application.service;

import org.springframework.stereotype.Service;

import com.gt.genti.domain.Deposit;
import com.gt.genti.domain.User;
import com.gt.genti.repository.DepositRepository;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class DepositService {
private final DepositRepository depositRepository;

public Deposit createDeposit(User user) {
Deposit newDeposit = new Deposit(user);
return depositRepository.save(newDeposit);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.gt.genti.application.service;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.stereotype.Component;

@Component
public class MatchingRegistry {
private final ConcurrentHashMap<Long, List<Long>> matchRecord = new ConcurrentHashMap<>();

public void add(Long requestId, Long creatorId) {
if (matchRecord.containsKey(requestId)) {
matchRecord.get(requestId).add(creatorId);
} else {
List<Long> newCreatorList = new ArrayList<>();
newCreatorList.add(creatorId);
matchRecord.put(requestId, newCreatorList);
}
}

public List<Long> getMatchedCreatorBefore(Long requestId) {
if (matchRecord.containsKey(requestId)) {
return matchRecord.get(requestId);
}
return new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.gt.genti.adapter.usecase.PictureGenerateRequestUseCase;
import com.gt.genti.application.port.in.PictureGenerateRequestPort;
import com.gt.genti.command.CreatePicturePoseCommand;
import com.gt.genti.domain.Creator;
import com.gt.genti.domain.PictureGenerateRequest;
import com.gt.genti.domain.PicturePose;
import com.gt.genti.domain.PictureUserFace;
Expand All @@ -21,7 +20,6 @@
import com.gt.genti.error.ExpectedException;
import com.gt.genti.external.openai.dto.PromptAdvancementRequestDto;
import com.gt.genti.external.openai.service.OpenAIService;
import com.gt.genti.other.util.RandomUtils;
import com.gt.genti.repository.CreatorRepository;
import com.gt.genti.repository.UserRepository;
import com.gt.genti.service.PictureService;
Expand All @@ -38,6 +36,7 @@ public class PictureGenerateRequestService implements PictureGenerateRequestUseC
private final UserRepository userRepository;
private final OpenAIService openAIService;
private final PictureService pictureService;
private final RequestMatchService requestMatchService;

@Override
public List<PictureGenerateRequestDetailResponseDto> getPictureGenerateRequest(Long userId,
Expand Down Expand Up @@ -96,7 +95,7 @@ public Boolean createPictureGenerateRequest(Long requesterId,

PicturePose foundPicturePose = pictureService.findByUrlPicturePose(posePictureUrl)
.orElseGet(() -> pictureService.updatePicture(
CreatePicturePoseCommand.builder().url(posePictureUrl).uploadedBy(requesterId).build()));
CreatePicturePoseCommand.builder().url(posePictureUrl).userId(requesterId).build()));

List<String> facePictureUrl = pictureGenerateRequestRequestDto.getFacePictureUrlList();

Expand All @@ -115,7 +114,11 @@ public Boolean createPictureGenerateRequest(Long requesterId,
.userFacePictureList(uploadedFacePictureList)
.build();

matchCreatorIfAvailable(pgr);
Boolean result = requestMatchService.matchPictureGenerateRequest(pgr);
//TODO result 결과로 현재 공급자와 매칭 시도인지 알 수 있으나, 도메인 로직상 사용하지 않음
// edited at 2024-05-19
// author 서병렬

pictureGenerateRequestPort.save(pgr);

return true;
Expand Down Expand Up @@ -148,19 +151,4 @@ public Boolean modifyPictureGenerateRequest(Long userId,
return true;
}

private void matchCreatorIfAvailable(PictureGenerateRequest pgr) {
List<Creator> creatorList = creatorRepository.findAllAvailableCreator();
if (!creatorList.isEmpty()) {
Creator randomSelectedCreator = RandomUtils.getRandomElement(creatorList);
pgr.assign(randomSelectedCreator);
sendNotification(randomSelectedCreator);
}
}

private void sendNotification(Creator creator) {
//TODO 공급자 앱에 푸시알림
// edited at 2024-05-04
// author
}

}
Loading

0 comments on commit b14f5ed

Please sign in to comment.