Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import com.formssafe.domain.content.question.repository.DescriptiveQuestionRepository;
import com.formssafe.global.error.ErrorCode;
import com.formssafe.global.error.type.BadRequestException;
import java.time.LocalDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
Expand All @@ -20,7 +21,7 @@ public class DescriptiveQuestionService {

public DescriptiveQuestion getDescriptiveQuestionByUuid(String id, Long formId) {
DescriptiveQuestion descriptiveQuestion = descriptiveQuestionRepository.findByUuidAndFormId(id, formId)
.orElseThrow(() -> new BadRequestException(ErrorCode.SYSTEM_ERROR, "설문에 존재하지 않는 문항입니다.")
.orElseThrow(() -> new BadRequestException(ErrorCode.DESCRIPTIVE_QUESTION_NOT_EXIST, "설문에 존재하지 않는 문항입니다.")
);
return descriptiveQuestion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import com.formssafe.domain.content.question.repository.ObjectiveQuestionRepository;
import com.formssafe.global.error.ErrorCode;
import com.formssafe.global.error.type.BadRequestException;
import java.time.LocalDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
Expand All @@ -20,7 +21,7 @@ public class ObjectiveQuestionService {

public ObjectiveQuestion getObjectiveQuestionByUuid(String id, Long formId) {
ObjectiveQuestion objectiveQuestion = objectiveQuestionRepository.findByUuidAndFormId(id, formId).orElseThrow(
() -> new BadRequestException(ErrorCode.SYSTEM_ERROR, "설문에 존재하지 않는 문항입니다.")
() -> new BadRequestException(ErrorCode.OBJECTIVE_QUESTION_NOT_EXIST, "설문에 존재하지 않는 문항입니다.")
);
return objectiveQuestion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
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.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@Tag(name = "files", description = "s3 presigned-url 받아오기")
@RestController
Expand All @@ -36,6 +32,6 @@ public class FileController {
@GetMapping("/upload/{fileName}")
@ResponseStatus(HttpStatus.OK)
FileResponseDto createPresignedUrl(@PathVariable String fileName, @AuthenticationPrincipal LoginUserDto loginUser) {
Copy link
Collaborator

@minnim1010 minnim1010 May 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용하지 않는 파라미터는 삭제 부탁드립니다!

return fileService.createPresignedUrl("image", fileName, loginUser);
return fileService.createPresignedUrl("image", fileName);
}
}
10 changes: 5 additions & 5 deletions src/main/java/com/formssafe/domain/file/service/FileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
import com.formssafe.domain.file.dto.FileResponseDto;
import com.formssafe.domain.user.dto.UserRequest.LoginUserDto;
import java.net.URL;
import java.util.Date;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.net.URL;
import java.util.Date;
import java.util.UUID;

@Service
@RequiredArgsConstructor
public class FileService {
Expand All @@ -23,7 +23,7 @@ public class FileService {

private final AmazonS3 amazonS3;

public FileResponseDto createPresignedUrl(String prefix, String fileName, LoginUserDto loginUser) {
public FileResponseDto createPresignedUrl(String prefix, String fileName) {
if (!prefix.isEmpty()) {
fileName = createPath(prefix, fileName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@
import org.springframework.http.HttpStatus;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/forms")
Expand Down Expand Up @@ -78,9 +71,9 @@ public void modifySubmission(@PathVariable long formId, @RequestBody SubmissionC
schema = @Schema(implementation = ErrorResponse.class),
examples = @ExampleObject(value = "{\"error\": \"세션이 존재하지 않습니다.\"}")))
@GetMapping("/{formId}/submission")
public ResponseEntity<SubmissionResponseDto> getSumbission(@PathVariable long formId,
@AuthenticationPrincipal LoginUserDto loginUser) {
SubmissionResponseDto submissionResponseDto = submissionService.getSubmission(formId, loginUser);
public ResponseEntity<SubmissionResponseDto> getTempSumbission(@PathVariable long formId,
@AuthenticationPrincipal LoginUserDto loginUser) {
SubmissionResponseDto submissionResponseDto = submissionService.getTempSubmission(formId, loginUser);
if (submissionResponseDto == null) {
return ResponseEntity.noContent().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@
import com.formssafe.global.error.ErrorCode;
import com.formssafe.global.error.type.BadRequestException;
import com.formssafe.global.util.DateTimeUtil;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
Expand Down Expand Up @@ -105,7 +106,7 @@ public void modify(long formId, SubmissionCreateDto request, LoginUserDto loginU
}
}

public SubmissionResponseDto getSubmission(long formId, LoginUserDto loginUser) {
public SubmissionResponseDto getTempSubmission(long formId, LoginUserDto loginUser) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null을 반환할 수 있다면 Optional로 감싸면 어떨까요? nullable한 값을 반환할 수 있다는 걸 명시할 수 있으니 좋을 것 같습니다.

User user = userService.getUserById(loginUser.id());

Submission submission = submissionRepository.findSubmissionByFormIDAndUserId(formId, loginUser.id())
Expand All @@ -119,6 +120,10 @@ public SubmissionResponseDto getSubmission(long formId, LoginUserDto loginUser)
return SubmissionResponseDto.from(formId, submissionDetailResponseDtos, submission.isTemp());
}

public Submission getSubmission(long formId, LoginUserDto loginUser) {
return submissionRepository.findSubmissionByFormIDAndUserId(formId, loginUser.id()).orElse(null);
}

public List<SubmissionDetailResponseDto> getSubmissionDetailDto(Submission submission) {
List<Object> submissions = new ArrayList<>();
submissions.addAll(getDescriptiveSubmissionFromSubmission(submission));
Expand Down Expand Up @@ -200,6 +205,10 @@ private void createDetailSubmission(List<SubmissionDetailDto> submissionDetailDt
}
descriptiveSubmissionRepository.saveAll(descriptiveSubmissions);
objectiveSubmissionRepository.saveAll(objectiveSubmissions);

//TODO : 확인 필요
submission.getDescriptiveSubmissionList().addAll(descriptiveSubmissions);
submission.getObjectiveSubmissionList().addAll(objectiveSubmissions);
}

private void validate(User user, Form form) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public class SubmissionValidateService {
public void validDescriptiveSubmission(DescriptiveSubmission descriptiveSubmission,
DescriptiveQuestionType descriptiveQuestionType) {
if (descriptiveQuestionType.displayName().equals("short")) {
if (descriptiveSubmission.getContent().length() > 500) {
if (descriptiveSubmission.getContent().length() > 500 || descriptiveSubmission.getContent().isEmpty()) {
throw new BadRequestException(ErrorCode.SHORT_QUESTION_SUBMISSION_CONTENT_OVER_LIMIT,
"short형 질문의 응답은 500자 이내여야 합니다. : " + descriptiveSubmission.getContent());
"short형 질문의 응답은 1자 이상 500자 이내여야 합니다. : " + descriptiveSubmission.getContent());
}
} else if (descriptiveQuestionType.displayName().equals("long")) {
if (descriptiveSubmission.getContent().length() > 5000) {
if (descriptiveSubmission.getContent().length() > 5000 || descriptiveSubmission.getContent().isEmpty()) {
throw new BadRequestException(ErrorCode.LONG_QUESTION_SUBMISSION_CONTENT_OVER_LIMIT,
"long형 질문의 응답은 5000자 이내여야 합니다. : " + descriptiveSubmission.getContent());
"long형 질문의 응답은 1자 이상 5000자 이내여야 합니다. : " + descriptiveSubmission.getContent());
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/com/formssafe/domain/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ public class UserService {
private final UserValidateService userValidateService;

public User getUserById(Long id) {
User user = userRepository.findById(id)
return userRepository.findById(id)
.orElseThrow(() -> new UserNotFoundException(ErrorCode.USER_NOT_FOUND, "존재하지 않는 userId 입니다 : " + id));

return user;
}

@Transactional
Expand All @@ -43,6 +41,7 @@ public void join(JoinDto request, LoginUserDto loginUser) {
if (user.isActive()) {
throw new BadRequestException(ErrorCode.USER_ALREADY_JOIN, "이미 회원가입하셨습니다.");
}
verifyNickname(request.nickname());

user.updateNickname(request.nickname());
user.activate();
Expand All @@ -57,15 +56,18 @@ public UserProfileDto getProfile(LoginUserDto loginUser) {
@Transactional
public void updateNickname(NicknameUpdateDto request, LoginUserDto loginUser) {
String nickname = request.nickname();
userValidateService.validUserNickname(nickname);
verifyNickname(nickname);

User user = getUserById(loginUser.id());
user.updateNickname(request.nickname());
}

if (user.getNickname().equals(nickname) || userRepository.existsByNickname(nickname)) {
private void verifyNickname(String nickname) {
userValidateService.validUserNickname(nickname);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

내부에서 닉네임 길이 유효성 검사만 하고 있으니 validUserNicknameLength()로 구체화하면 어떨까요? 메서드명만 봤을 때 verifyNickname()과 무엇이 다른지 구분이 어렵습니다.


if (userRepository.existsByNickname(nickname)) {
throw new BadRequestException(ErrorCode.USER_NICKNAME_DUPLICATE, "중복된 닉네임이 존재합니다.");
}

user.updateNickname(request.nickname());
}

@Transactional
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/formssafe/global/error/ErrorCode.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.formssafe.global.error;

import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.FORBIDDEN;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import static org.springframework.http.HttpStatus.UNAUTHORIZED;

import lombok.Getter;
import org.springframework.http.HttpStatus;

import static org.springframework.http.HttpStatus.*;

@Getter
public enum ErrorCode {
/**
Expand Down Expand Up @@ -107,7 +104,9 @@ public enum ErrorCode {
QUESTION_DTO_CONVERT_ERROR(BAD_REQUEST, "CONTENT002", "Question 엔티티를 DTO로 변환할 수 없습니다."),
UNEXPECTED_CONTENT_TYPE(BAD_REQUEST, "CONTENT003", "올바르지 않은 Content type입니다."),
INVALID_CONTENT_TITLE_LENGTH(BAD_REQUEST, "CONTENT004", "설문 문항 제목은 1자 이상 100자 이하여야 합니다."),
INVALID_CONTENT_DESCRIPTION_LENGTH(BAD_REQUEST, "CONTENT005", "설문 문항 설명은 1000자 이하여야 합니다.");
INVALID_CONTENT_DESCRIPTION_LENGTH(BAD_REQUEST, "CONTENT005", "설문 문항 설명은 1000자 이하여야 합니다."),
OBJECTIVE_QUESTION_NOT_EXIST(BAD_REQUEST, "CONTENT006", "객관식 설문 문항이 존재하지 않습니다."),
DESCRIPTIVE_QUESTION_NOT_EXIST(BAD_REQUEST, "CONTENT007", "주관식 설문 문항이 존재하지 않습니다.");


private final HttpStatus httpStatus;
Expand Down
Loading