Skip to content

Commit

Permalink
Merge pull request #92 from Na-o-man/feature/#87/sample-photo-api
Browse files Browse the repository at this point in the history
[FEAT] 샘플 이미지 업로드 API 구현, 이외 사진 도메인 리팩토링
  • Loading branch information
bflykky authored Aug 11, 2024
2 parents 67404ce + fb966c4 commit 1caa571
Show file tree
Hide file tree
Showing 19 changed files with 350 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
@Repository
public interface AgendaPhotoRepository extends JpaRepository<AgendaPhoto, Long> {
List<AgendaPhoto> findByAgendaId(Long agendaId);
List<AgendaPhoto> findByPhotoId(Long photoId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public interface AgendaPhotoService {

AgendaPhoto findAgendaPhoto(Long agendaPhotoId);
List<AgendaPhoto> findAgendaPhotoList(Long agendaId);
List<AgendaPhoto> findAgendaPhotoListByPhotoId(Long photoId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public AgendaPhoto findAgendaPhoto(Long agendaPhotoId) {
public List<AgendaPhoto> findAgendaPhotoList(Long agendaId) {
return agendaPhotoRepository.findByAgendaId(agendaId);
}

@Override
public List<AgendaPhoto> findAgendaPhotoListByPhotoId(Long photoId) {
return agendaPhotoRepository.findByPhotoId(photoId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import com.umc.naoman.domain.member.entity.Member;
import org.springframework.data.domain.Pageable;

import java.util.List;

public interface AgendaService {
Agenda createAgenda(Member member, AgendaRequest.CreateAgendaRequest request);
Agenda getAgendaDetailInfo(Long agendaId, Member member);
PagedAgendaDetailInfo getAgendaList(Long shareGroupId, Member member, Pageable pageable);
Agenda deleteAgenda(Long agendaId);

Agenda findAgenda(Long agendaId);
List<Agenda> findAgendaListByPhotoId(Long photoId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Transactional(readOnly = true)
Expand Down Expand Up @@ -76,4 +77,13 @@ public Agenda deleteAgenda(Long agendaId) {
agenda.delete();
return agenda;
}

// 특정 사진이 안건 후보로 담겨 있는 안건 목록을 조회하는 함수
@Override
public List<Agenda> findAgendaListByPhotoId(Long photoId) {
List<AgendaPhoto> agendaPhotoList = agendaPhotoService.findAgendaPhotoListByPhotoId(photoId);
return agendaPhotoList.stream()
.map(agendaPhoto -> agendaPhoto.getAgenda())
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
Expand All @@ -31,13 +32,11 @@ public class MemberController {
private final MemberConverter memberConverter;

@GetMapping("/{memberId}") // memberId를 사용해 특정 회원 정보 조회
@Operation( summary = "특정 회원 정보 조회 API", description = "[PathVariable]\n memberId\n[request]\n" +
@Operation(summary = "특정 회원 정보 조회 API", description = "[PathVariable]\n memberId\n[request]\n" +
"[response]\n uesrname, email, 소셜 프로필 이미지 url")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse
(responseCode = "SM005", description = "특정 회원 정보 조회 성공."),
@io.swagger.v3.oas.annotations.responses.ApiResponse
(responseCode = "EM001", description = "해당 memberId를 가진 회원이 존재하지 않습니다.",
@ApiResponse(responseCode = "SM005", description = "특정 회원 정보 조회 성공."),
@ApiResponse(responseCode = "EM001", description = "해당 memberId를 가진 회원이 존재하지 않습니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
public ResultResponse<MemberInfo> getMemberInfo(@PathVariable(name = "memberId") Long memberId) {
Expand All @@ -55,11 +54,9 @@ public ResultResponse<MemberInfo> getMyInfo(@LoginMember Member member) {
@GetMapping("/terms/{memberId}")
@Operation(summary = "마케팅 약관 동의 여부 조회 API", description = "[PathVariable]\n memberId\n[request]\n" +
"[response]\n 마케팅 동의 여부 -> 동의 => true, 비동의 => false")
@ApiResponses({
@io.swagger.v3.oas.annotations.responses.ApiResponse
(responseCode = "SM006", description = "마케팅 약관 동의 여부 조회 성공."),
@io.swagger.v3.oas.annotations.responses.ApiResponse
(responseCode = "EM001", description = "해당 memberId를 가진 회원이 존재하지 않습니다.",
@ApiResponses(value = {
@ApiResponse(responseCode = "SM006", description = "마케팅 약관 동의 여부 조회 성공."),
@ApiResponse(responseCode = "EM001", description = "해당 memberId를 가진 회원이 존재하지 않습니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
public ResultResponse<MemberResponse.MarketingAgreed> getMarketingAgreed(@PathVariable(name = "memberId") Long memberId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

import com.umc.naoman.domain.member.entity.Member;
import com.umc.naoman.domain.photo.converter.PhotoConverter;
import com.umc.naoman.domain.photo.dto.PhotoRequest;
import com.umc.naoman.domain.photo.dto.PhotoResponse;
import com.umc.naoman.domain.photo.dto.PhotoRequest.PhotoDeletedRequest;
import com.umc.naoman.domain.photo.dto.PhotoRequest.PhotoUploadRequest;
import com.umc.naoman.domain.photo.dto.PhotoRequest.PreSignedUrlRequest;
import com.umc.naoman.domain.photo.dto.PhotoRequest.UploadSamplePhotoRequest;
import com.umc.naoman.domain.photo.dto.PhotoResponse.PagedPhotoInfo;
import com.umc.naoman.domain.photo.dto.PhotoResponse.PhotoDeleteInfo;
import com.umc.naoman.domain.photo.dto.PhotoResponse.PhotoDownloadUrlListInfo;
import com.umc.naoman.domain.photo.dto.PhotoResponse.PhotoUploadInfo;
import com.umc.naoman.domain.photo.dto.PhotoResponse.PreSignedUrlInfo;
import com.umc.naoman.domain.photo.dto.PhotoResponse.PreSignedUrlListInfo;
import com.umc.naoman.domain.photo.dto.PhotoResponse.SamplePhotoUploadInfo;
import com.umc.naoman.domain.photo.elasticsearch.document.PhotoEs;
import com.umc.naoman.domain.photo.elasticsearch.service.PhotoEsService;
import com.umc.naoman.domain.photo.entity.Photo;
Expand Down Expand Up @@ -44,17 +53,24 @@ public class PhotoController {

@PostMapping("/preSignedUrl")
@Operation(summary = "Presigned URL 요청 API", description = "Presigned URL을 요청하는 API입니다.")
public ResultResponse<PhotoResponse.PreSignedUrlListInfo> getPreSignedUrlList(@Valid @RequestBody PhotoRequest.PreSignedUrlRequest request,
@LoginMember Member member) {
List<PhotoResponse.PreSignedUrlInfo> preSignedUrlList = photoService.getPreSignedUrlList(request, member);
public ResultResponse<PreSignedUrlListInfo> getPreSignedUrlList(@Valid @RequestBody PreSignedUrlRequest request,
@LoginMember Member member) {
List<PreSignedUrlInfo> preSignedUrlList = photoService.getPreSignedUrlList(request, member);
return ResultResponse.of(CREATE_PRESIGNED_URL, photoConverter.toPreSignedUrlListInfo(preSignedUrlList));
}

@PostMapping("/sample")
@Operation(summary = "샘플 사진 업로드 API", description = "얼굴 분류에 사용할 샘플 사진을 업로드하는 API입니다.")
public ResultResponse<SamplePhotoUploadInfo> uploadSamplePhotoList(@Valid @RequestBody UploadSamplePhotoRequest request,
@LoginMember Member member) {
return ResultResponse.of(UPLOAD_SAMPLE_PHOTO, photoService.uploadSamplePhotoList(request, member));
}

@PostMapping("/upload")
@Operation(summary = "사진 업로드 API", description = "Presigned URL을 통해 업로드한 사진을 데이터베이스에 저장하는 API입니다.")
public ResultResponse<PhotoResponse.PhotoUploadInfo> uploadPhotoList(@Valid @RequestBody PhotoRequest.PhotoUploadRequest request,
@LoginMember Member member) {
PhotoResponse.PhotoUploadInfo photoUploadInfo = photoService.uploadPhotoList(request, member);
public ResultResponse<PhotoUploadInfo> uploadPhotoList(@Valid @RequestBody PhotoUploadRequest request,
@LoginMember Member member) {
PhotoUploadInfo photoUploadInfo = photoService.uploadPhotoList(request, member);
return ResultResponse.of(UPLOAD_PHOTO, photoUploadInfo);
}

Expand All @@ -66,13 +82,13 @@ public ResultResponse<PhotoResponse.PhotoUploadInfo> uploadPhotoList(@Valid @Req
@Parameter(name = "page", description = "조회할 페이지를 입력해 주세요.(0번부터 시작)"),
@Parameter(name = "size", description = "한 페이지에 나타낼 사진 개수를 입력해주세요.")
})
public ResultResponse<PhotoResponse.PagedPhotoEsInfo> getPhotoListByShareGroupAndProfile(@RequestParam Long shareGroupId,
@RequestParam Long profileId,
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC)
@Parameter(hidden = true) Pageable pageable,
@LoginMember Member member) {
public ResultResponse<PagedPhotoInfo> getPhotoListByShareGroupAndProfile(@RequestParam Long shareGroupId,
@RequestParam Long profileId,
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC)
@Parameter(hidden = true) Pageable pageable,
@LoginMember Member member) {
Page<PhotoEs> photoEsList = photoEsService.getPhotoEsListByShareGroupIdAndFaceTag(shareGroupId, profileId, member, pageable);
return ResultResponse.of(RETRIEVE_PHOTO, photoConverter.toPagedPhotoEsInfo(photoEsList, member));
return ResultResponse.of(RETRIEVE_PHOTO, photoConverter.toPagedPhotoInfo(photoEsList, member));
}

@GetMapping("/all")
Expand All @@ -82,12 +98,12 @@ public ResultResponse<PhotoResponse.PagedPhotoEsInfo> getPhotoListByShareGroupAn
@Parameter(name = "page", description = "조회할 페이지를 입력해 주세요.(0번부터 시작)"),
@Parameter(name = "size", description = "한 페이지에 나타낼 사진 개수를 입력해주세요.")
})
public ResultResponse<PhotoResponse.PagedPhotoEsInfo> getAllPhotoListByShareGroup(@RequestParam Long shareGroupId,
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC)
@Parameter(hidden = true) Pageable pageable,
@LoginMember Member member) {
public ResultResponse<PagedPhotoInfo> getAllPhotoListByShareGroup(@RequestParam Long shareGroupId,
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC)
@Parameter(hidden = true) Pageable pageable,
@LoginMember Member member) {
Page<PhotoEs> photoEsList = photoEsService.getAllPhotoEsListByShareGroupId(shareGroupId, member, pageable);
return ResultResponse.of(RETRIEVE_PHOTO, photoConverter.toPagedPhotoEsInfo(photoEsList, member));
return ResultResponse.of(RETRIEVE_PHOTO, photoConverter.toPagedPhotoInfo(photoEsList, member));
}

@GetMapping("/etc")
Expand All @@ -97,27 +113,28 @@ public ResultResponse<PhotoResponse.PagedPhotoEsInfo> getAllPhotoListByShareGrou
@Parameter(name = "page", description = "조회할 페이지를 입력해 주세요.(0번부터 시작)"),
@Parameter(name = "size", description = "한 페이지에 나타낼 사진 개수를 입력해주세요.")
})
public ResultResponse<PhotoResponse.PagedPhotoEsInfo> getEtcPhotoListByShareGroup(@RequestParam Long shareGroupId,
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC)
@Parameter(hidden = true) Pageable pageable,
@LoginMember Member member) {
public ResultResponse<PagedPhotoInfo> getEtcPhotoListByShareGroup(@RequestParam Long shareGroupId,
@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC)
@Parameter(hidden = true) Pageable pageable,
@LoginMember Member member) {
Page<PhotoEs> photoEsList = photoEsService.getEtcPhotoEsListByShareGroupId(shareGroupId, member, pageable);
return ResultResponse.of(RETRIEVE_PHOTO, photoConverter.toPagedPhotoEsInfo(photoEsList, member));
return ResultResponse.of(RETRIEVE_PHOTO, photoConverter.toPagedPhotoInfo(photoEsList, member));
}

@GetMapping("/download")
@Operation(summary = "사진 다운로드 API", description = "여러장의 사진을 다운로드할 주소를 받는 API입니다. 해당 공유그룹에 속해있는 회원만 다운로드 요청할 수 있습니다.")
public ResultResponse<PhotoDownloadUrlListInfo> getPhotoDownloadUrlList(@RequestParam List<Long> photoIdList,
@RequestParam Long shareGroupId,
@LoginMember Member member) {
PhotoDownloadUrlListInfo photoDownloadUrlList = photoService.getPhotoDownloadUrlList(photoIdList, shareGroupId, member);
return ResultResponse.of(DOWNLOAD_PHOTO, photoDownloadUrlList);
}

@DeleteMapping
@Operation(summary = "사진 삭제 API", description = "사진을 삭제하는 API입니다. 해당 공유그룹에 속해있는 회원만 삭제할 수 있습니다.")
public ResultResponse<PhotoResponse.PhotoDeleteInfo> deletePhotoList(@Valid @RequestBody PhotoRequest.PhotoDeletedRequest request,
@LoginMember Member member) {
public ResultResponse<PhotoDeleteInfo> deletePhotoList(@Valid @RequestBody PhotoDeletedRequest request,
@LoginMember Member member) {
List<Photo> photoList = photoService.deletePhotoList(request, member);
return ResultResponse.of(DELETE_PHOTO, photoConverter.toPhotoDeleteInfo(photoList));
}

@GetMapping("/download")
@Operation(summary = "사진 다운로드 API", description = "여러장의 사진을 다운로드할 주소를 받는 API입니다. 해당 공유그룹에 속해있는 회원만 다운로드 요청할 수 있습니다.")
public ResultResponse<PhotoResponse.PhotoDownloadUrlListInfo> getPhotoDownloadUrlList(@RequestParam List<Long> photoIdList, @RequestParam Long shareGroupId,
@LoginMember Member member) {
PhotoResponse.PhotoDownloadUrlListInfo photoDownloadUrlList = photoService.getPhotoDownloadUrlList(photoIdList, shareGroupId, member);
return ResultResponse.of(DOWNLOAD_PHOTO, photoDownloadUrlList);
}
}
Loading

0 comments on commit 1caa571

Please sign in to comment.