Skip to content

Commit

Permalink
refactor: 스웨거 url 애노테이션 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yooooonshine committed Dec 13, 2024
1 parent 433e813 commit 360e59a
Show file tree
Hide file tree
Showing 21 changed files with 227 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,29 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import aimo.backend.common.dto.DataResponse;
import aimo.backend.common.security.filter.jwtFilter.JwtTokenProvider;
import aimo.backend.common.util.memberLoader.MemberLoader;
import aimo.backend.domains.member.dto.parameter.DeleteProfileImageParameter;
import aimo.backend.domains.member.dto.parameter.SignUpParameter;
import aimo.backend.domains.member.dto.parameter.UpdateNicknameParameter;
import aimo.backend.domains.member.dto.parameter.DeleteMemberParameter;
import aimo.backend.domains.member.dto.parameter.DeleteProfileImageParameter;
import aimo.backend.domains.member.dto.parameter.FindMyInfoParameter;
import aimo.backend.domains.member.dto.parameter.SaveFileMetaDataParameter;
import aimo.backend.domains.member.dto.parameter.SignUpParameter;
import aimo.backend.domains.member.dto.parameter.UpdateNicknameParameter;
import aimo.backend.domains.member.dto.parameter.UpdatePasswordParameter;
import aimo.backend.domains.member.dto.request.CheckNicknameExistsRequest;
import aimo.backend.domains.member.dto.request.DeleteMemberRequest;
import aimo.backend.domains.member.dto.request.LogoutRequest;
import aimo.backend.domains.member.dto.response.FindMyInfoResponse;
import aimo.backend.domains.member.dto.response.NicknameExistsResponse;
import aimo.backend.domains.member.dto.request.SendTemporaryPasswordRequest;
import aimo.backend.common.dto.DataResponse;
import aimo.backend.common.security.filter.jwtFilter.JwtTokenProvider;
import aimo.backend.domains.member.dto.request.UpdateNicknameRequest;
import aimo.backend.domains.member.dto.request.UpdatePasswordRequest;
import aimo.backend.domains.member.dto.response.FindMyInfoResponse;
import aimo.backend.domains.member.dto.response.NicknameExistsResponse;
import aimo.backend.domains.member.service.MemberService;
import aimo.backend.infrastructure.s3.S3Service;
import aimo.backend.infrastructure.s3.dto.request.CreatePresignedUrlRequest;
import aimo.backend.infrastructure.s3.dto.response.CreatePresignedUrlResponse;
import aimo.backend.infrastructure.s3.dto.request.SaveFileMetaDataRequest;

import aimo.backend.domains.member.service.MemberService;
import aimo.backend.infrastructure.s3.dto.response.CreatePreSignedUrlResponse;
import aimo.backend.infrastructure.s3.model.PresignedUrlPrefix;
import jakarta.mail.MessagingException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
Expand Down Expand Up @@ -82,13 +81,11 @@ public ResponseEntity<DataResponse<Void>> deleteMember(@RequestBody @Valid Delet
}

@GetMapping("/profile/presigned/{filename}")
public ResponseEntity<DataResponse<CreatePresignedUrlResponse>> createProfileImagePreSignedUrl(
public ResponseEntity<DataResponse<CreatePreSignedUrlResponse>> createProfileImagePreSignedUrl(
@PathVariable("filename") String filename
) {
CreatePresignedUrlRequest createPresignedUrlRequest = CreatePresignedUrlRequest.of(filename);

return ResponseEntity.status(HttpStatus.CREATED)
.body(DataResponse.created(s3Service.createProfilePresignedUrl(createPresignedUrlRequest)));
.body(DataResponse.created(s3Service.createPreSignedUrl(filename, PresignedUrlPrefix.IMAGE)));
}

@PostMapping("/profile/success")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,22 @@
import org.springframework.web.bind.annotation.RestController;

import aimo.backend.common.dto.DataResponse;

import aimo.backend.common.util.memberLoader.MemberLoader;
import aimo.backend.domains.privatePost.dto.parameter.DeletePrivatePostParameter;
import aimo.backend.domains.privatePost.dto.parameter.FindPrivatePostParameter;
import aimo.backend.domains.privatePost.dto.parameter.FindPrivatePostPreviewParameter;
import aimo.backend.domains.privatePost.dto.parameter.SpeechToTextParameter;
import aimo.backend.domains.privatePost.dto.parameter.JudgementToAiParameter;
import aimo.backend.domains.privatePost.dto.request.UpdateContentToPrivatePostRequest;
import aimo.backend.domains.privatePost.dto.request.UploadTextRecordAndRequestJudgementRequest;
import aimo.backend.domains.privatePost.dto.response.PrivatePostPreviewResponse;
import aimo.backend.domains.privatePost.dto.response.PrivatePostResponse;
import aimo.backend.domains.privatePost.dto.request.SaveAudioSuccessRequest;
import aimo.backend.domains.privatePost.dto.response.SaveAudioSuccessResponse;
import aimo.backend.domains.privatePost.dto.request.SpeechToTextRequest;
import aimo.backend.domains.privatePost.dto.response.SpeechToTextResponse;

import aimo.backend.domains.privatePost.dto.request.UploadTextRecordAndRequestJudgementRequest;
import aimo.backend.domains.privatePost.model.OriginType;
import aimo.backend.domains.privatePost.service.AudioRecordService;
import aimo.backend.domains.privatePost.service.PrivatePostService;

import aimo.backend.domains.privatePost.dto.parameter.SaveAudioSuccessParameter;
import aimo.backend.domains.upload.dto.parameter.SpeechToTextParameter;
import aimo.backend.domains.upload.dto.request.SpeechToTextRequest;
import aimo.backend.domains.upload.service.AudioRecordService;
import aimo.backend.infrastructure.s3.S3Service;
import aimo.backend.infrastructure.s3.dto.request.CreatePresignedUrlRequest;
import aimo.backend.infrastructure.s3.dto.response.CreatePresignedUrlResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -100,26 +92,6 @@ public ResponseEntity<DataResponse<SpeechToTextResponse>> speechToText(
.body(DataResponse.created(audioRecordService.speechToText(parameter)));
}

@GetMapping("/audio/presigned/{filename}")
public ResponseEntity<DataResponse<CreatePresignedUrlResponse>> getPresignedUrlTo(
@Valid @PathVariable("filename") String filename
) {
CreatePresignedUrlRequest createPresignedUrlRequest = CreatePresignedUrlRequest.of(filename);

return ResponseEntity.status(HttpStatus.CREATED)
.body(DataResponse.created(s3Service.createAudioPreSignedUrl(createPresignedUrlRequest)));
}

@PostMapping("/audio/success")
public ResponseEntity<DataResponse<SaveAudioSuccessResponse>> saveAudioRecord(
@Valid @RequestBody SaveAudioSuccessRequest saveAudioSuccessRequest
) {
SaveAudioSuccessParameter parameter = SaveAudioSuccessParameter.from(saveAudioSuccessRequest);

return ResponseEntity.status(HttpStatus.CREATED)
.body(DataResponse.created(audioRecordService.save(parameter)));
}

// 개인글 조회
@GetMapping("/{privatePostId}")
public ResponseEntity<DataResponse<PrivatePostResponse>> findPrivatePost(
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static lombok.AccessLevel.*;

import aimo.backend.common.entity.BaseEntity;
import aimo.backend.domains.privatePost.dto.parameter.SaveAudioSuccessParameter;
import aimo.backend.domains.upload.dto.parameter.SaveAudioMetaDataParameter;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand Down Expand Up @@ -49,7 +49,7 @@ private AudioRecord(String filename, String extension, String url, Long size) {
this.extension = extension;
}

public static AudioRecord from(SaveAudioSuccessParameter parameter) {
public static AudioRecord from(SaveAudioMetaDataParameter parameter) {
return AudioRecord.builder()
.filename(parameter.filename())
.extension(parameter.extension())
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package aimo.backend.domains.upload.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
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 aimo.backend.common.dto.DataResponse;
import aimo.backend.domains.upload.dto.parameter.CreateAudioPreSignedUrlParameter;
import aimo.backend.domains.upload.dto.parameter.SaveAudioMetaDataParameter;
import aimo.backend.domains.upload.dto.request.SaveAudioMetaDataRequest;
import aimo.backend.domains.upload.dto.response.SaveAudioMetaDataResponse;
import aimo.backend.domains.upload.service.AudioRecordService;
import aimo.backend.infrastructure.s3.dto.request.CreatePreSignedUrlRequest;
import aimo.backend.infrastructure.s3.dto.response.CreatePreSignedUrlResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/audio")
public class AudioController {

private final AudioRecordService audioRecordService;

@PostMapping
public ResponseEntity<DataResponse<SaveAudioMetaDataResponse>> saveAudioMetaData(
@Valid @RequestBody SaveAudioMetaDataRequest request
) {
SaveAudioMetaDataParameter parameter = SaveAudioMetaDataParameter.from(request);

return ResponseEntity.status(HttpStatus.CREATED)
.body(DataResponse.created(audioRecordService.save(parameter)));
}

@GetMapping("/presigned/{filename}")
public ResponseEntity<DataResponse<CreatePreSignedUrlResponse>> createAudioPreSignedUrl(
@Valid @RequestBody CreatePreSignedUrlRequest request
) {
CreateAudioPreSignedUrlParameter parameter = CreateAudioPreSignedUrlParameter.of(request.filename());

CreatePreSignedUrlResponse response = audioRecordService.createAudioPreSignedUrl(parameter);

return ResponseEntity.status(HttpStatus.CREATED)
.body(DataResponse.created(response));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package aimo.backend.domains.upload.dto.parameter;

public record CreateAudioPreSignedUrlParameter(String filename, String extension) {

public static CreateAudioPreSignedUrlParameter of(String filename) {
String extension = filename.substring(filename.lastIndexOf(".") + 1);

return new CreateAudioPreSignedUrlParameter(filename, extension);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package aimo.backend.domains.upload.dto.parameter;

import aimo.backend.domains.upload.dto.request.SaveAudioMetaDataRequest;

public record SaveAudioMetaDataParameter(
String url,
Long size,
String filename,
String extension
) {

public static SaveAudioMetaDataParameter from(SaveAudioMetaDataRequest request) {
return new SaveAudioMetaDataParameter(
request.url(),
request.size(),
request.filename(),
request.extension()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package aimo.backend.domains.privatePost.dto.parameter;
package aimo.backend.domains.upload.dto.parameter;

import aimo.backend.domains.privatePost.dto.request.SpeechToTextRequest;
import aimo.backend.domains.upload.dto.request.SpeechToTextRequest;

public record SpeechToTextParameter(String url) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package aimo.backend.domains.privatePost.dto.request;
package aimo.backend.domains.upload.dto.request;

import jakarta.validation.constraints.NotNull;

public record SaveAudioSuccessRequest(
public record SaveAudioMetaDataRequest(
@NotNull(message = "URL이 필요합니다.")
String url,
@NotNull(message = "파일 사이즈가 필요합니다.")
Expand All @@ -13,7 +13,7 @@ public record SaveAudioSuccessRequest(
String extension
) {

public static SaveAudioSuccessRequest of(String url, Long size, String filename, String extension) {
return new SaveAudioSuccessRequest(url, size, filename, extension);
public static SaveAudioMetaDataRequest of(String url, Long size, String filename, String extension) {
return new SaveAudioMetaDataRequest(url, size, filename, extension);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package aimo.backend.domains.privatePost.dto.request;
package aimo.backend.domains.upload.dto.request;

import jakarta.validation.constraints.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package aimo.backend.domains.upload.dto.response;

import aimo.backend.domains.privatePost.entity.AudioRecord;

public record SaveAudioMetaDataResponse(
String url,
Long size,
String filename
) {

public static SaveAudioMetaDataResponse of(String url, Long size, String filename) {
return new SaveAudioMetaDataResponse(url, size, filename);
}

public static SaveAudioMetaDataResponse from(AudioRecord audioRecord) {
return new SaveAudioMetaDataResponse(
audioRecord.getUrl(),
audioRecord.getSize(),
audioRecord.getFilename()
);
}
}
Loading

0 comments on commit 360e59a

Please sign in to comment.