Skip to content

Commit

Permalink
Feat : 실종자 상세정보 및 검색기록 리스트 가져오기 api 추가
Browse files Browse the repository at this point in the history
Feat : 실종자 상세정보 및 검색기록 리스트 가져오기 api 추가
  • Loading branch information
begong313 authored May 3, 2024
2 parents 813467f + b941ca0 commit 2a0a922
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 41 deletions.
8 changes: 5 additions & 3 deletions server/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3"
version: "3"
services:
zookeeper:
image: wurstmeister/zookeeper
Expand All @@ -15,9 +15,11 @@ services:
- "9092:9092"
environment:
KAFKA_LISTENERS: PLAINTEXT://:9092
# KAFKA_ADVERTISED_HOST_NAME: localhost # TODO : 환경에 맞게 ip 변경 ex) 127.0.0.1
# KAFKA_ADVERTISED_HOST_NAME: localhost # TODO : 환경에 맞게 ip 변경 ex) 127.0.0.1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 # kafka가 zookeeper에 커넥션하기 위한 대상을 지정
KAFKA_CREATE_TOPICS: "start-searching"
KAFKA_CREATE_TOPICS: |
"start-searching":
replication-factor :1
volumes:
- /var/run/docker.sock:/var/run/docker.sock

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public ResponseEntity<?> getAllMissingPeople(
@RequestParam(required = false, defaultValue = "9", value = "size") int pageSize,
@RequestParam(required = false, defaultValue = "createdAt", value = "criteria") String criteria
) {
List<MissingPeopleResponseDto> missingPeopleResponseDtos = missingPeopleService.getAllMissingPeople(page - 1, pageSize, MissingPeopleSortBy.fromValue(criteria));
return ResponseEntity.ok().body(new SuccessResponse(missingPeopleResponseDtos));
List<MissingPeopleListResponseDto> missingPeopleListResponseDtos = missingPeopleService.getAllMissingPeople(page - 1, pageSize, MissingPeopleSortBy.fromValue(criteria));
return ResponseEntity.ok().body(new SuccessResponse(missingPeopleListResponseDtos));
}

@GetMapping("/status")
Expand All @@ -58,8 +58,8 @@ public ResponseEntity<?> getAllMissingPeopleByStatus(
@RequestParam(required = false, defaultValue = "createdAt", value = "criteria") String criteria,
@RequestParam(required = true, value = "status") String status
) {
List<MissingPeopleResponseDto> missingPeopleResponseDtos = missingPeopleService.getAllMissingPeopleByStatus(page - 1, pageSize, MissingPeopleSortBy.fromValue(criteria), Status.fromValue(status));
return ResponseEntity.ok().body(new SuccessResponse(missingPeopleResponseDtos));
List<MissingPeopleListResponseDto> missingPeopleListResponseDtos = missingPeopleService.getAllMissingPeopleByStatus(page - 1, pageSize, MissingPeopleSortBy.fromValue(criteria), Status.fromValue(status));
return ResponseEntity.ok().body(new SuccessResponse(missingPeopleListResponseDtos));
}

@GetMapping("/name")
Expand All @@ -70,8 +70,8 @@ public ResponseEntity<?> getAllMissingPeopleByNameContaining(
@RequestParam(required = false, defaultValue = "createdAt", value = "criteria") String criteria,
@RequestParam(required = true, value = "name") String name
) {
List<MissingPeopleResponseDto> missingPeopleResponseDtos = missingPeopleService.getAllMissingPeopleByNameContaining(page - 1, pageSize, MissingPeopleSortBy.fromValue(criteria), name);
return ResponseEntity.ok().body(new SuccessResponse(missingPeopleResponseDtos));
List<MissingPeopleListResponseDto> missingPeopleListResponseDtos = missingPeopleService.getAllMissingPeopleByNameContaining(page - 1, pageSize, MissingPeopleSortBy.fromValue(criteria), name);
return ResponseEntity.ok().body(new SuccessResponse(missingPeopleListResponseDtos));
}

@GetMapping("/name/status")
Expand All @@ -83,15 +83,17 @@ public ResponseEntity<?> getAllMissingPeopleByNameContainingAndStatus(
@RequestParam(required = true, value = "name") String name,
@RequestParam(required = true, value = "status") String status
) {
List<MissingPeopleResponseDto> missingPeopleResponseDtos = missingPeopleService.getAllMissingPeopleByNameContainingAndStatus(page - 1, pageSize, MissingPeopleSortBy.fromValue(criteria), name, Status.fromValue(status));
return ResponseEntity.ok().body(new SuccessResponse(missingPeopleResponseDtos));
List<MissingPeopleListResponseDto> missingPeopleListResponseDtos = missingPeopleService.getAllMissingPeopleByNameContainingAndStatus(page - 1, pageSize, MissingPeopleSortBy.fromValue(criteria), name, Status.fromValue(status));
return ResponseEntity.ok().body(new SuccessResponse(missingPeopleListResponseDtos));
}

// MissingPeople 하나 가져오기
@GetMapping("/{id}")
public ResponseEntity<?> getMissingPeopleById(@PathVariable Long id) {
MissingPeopleResponseDto missingPeopleResponseDto = missingPeopleService.getMissingPeopleById(id);
return ResponseEntity.ok().body(new SuccessResponse(missingPeopleResponseDto));

//todo : 리스트용이랑 창에띄어줄용 구분해야될듯
MissingPeopleDetailResponseDto missingPeopleDetailResponseDto = missingPeopleService.getMissingPeopleById(id);
return ResponseEntity.ok().body(new SuccessResponse(missingPeopleDetailResponseDto));
}

// TODO : AI 모델 탐색 코드 추가
Expand Down Expand Up @@ -164,6 +166,12 @@ public ResponseEntity<?> getProfilePresignedUrl(@PathVariable Long id) {
return ResponseEntity.ok(new SuccessResponse(missingPeopleService.downloadImageFromS3(imagePath, id)));
}

//검색기록 가져오기
@GetMapping("/{id}/search-history")
public ResponseEntity<?> getSearchHistoryList(@PathVariable Long id) {
return ResponseEntity.ok(new SuccessResponse(missingPeopleService.getSearchHistoryList(id)));
}

//탐색결과 이미지 등록하기 (안쓸듯)
@PostMapping("/{id}/search-history/{searchHistoryId}/step/{step}")
public ResponseEntity<?> uploadProfileImageToS3(
Expand Down Expand Up @@ -213,4 +221,5 @@ public ResponseEntity<?> test(@RequestBody DetectionRequestDto detectionRequestD
return ResponseEntity.ok().body(new SuccessResponse(detectService.callDetectAPI(detectionRequestDto)));
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.capstone.server.dto;


import com.capstone.server.model.MissingPeopleEntity;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Data
@AllArgsConstructor
public class MissingPeopleDetailResponseDto {
private Long id;
private String missingPeopleName;
private String gender;
private String status;
private LocalDate birthdate;
private LocalDateTime missingAt;
private String missingLocation;
private String missingPeopleType;
private String profileImage;
//보호자 정보
private String guardianName;
private String phoneNumber;
private String relationship;
//착장정보
private final String koQuery;

protected MissingPeopleDetailResponseDto(MissingPeopleEntity missingPeopleEntity) {
this.id = missingPeopleEntity.getId();
this.missingPeopleName = missingPeopleEntity.getName();
// TODO : 숫자로 변경 요망
this.gender = missingPeopleEntity.getGender().getValue();
this.status = missingPeopleEntity.getStatus().getValue();
this.birthdate = missingPeopleEntity.getBirthdate();
this.missingAt = missingPeopleEntity.getMissingAt();
this.missingLocation = missingPeopleEntity.getMissingLocation();
this.missingPeopleType = missingPeopleEntity.getMissingPeopleType().getKor();
this.profileImage = missingPeopleEntity.getProfileImage();
this.koQuery = missingPeopleEntity.getKoQuery();
}

public static MissingPeopleDetailResponseDto fromEntity(MissingPeopleEntity missingPeopleEntity) {
return new MissingPeopleDetailResponseDto(missingPeopleEntity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

@Data
@AllArgsConstructor
public class MissingPeopleResponseDto {
//리스트에 사용하는 dto
public class MissingPeopleListResponseDto {

private Long id;
private String name;
private String gender;
Expand All @@ -20,7 +22,8 @@ public class MissingPeopleResponseDto {
private String missingPeopleType;
private String profileImage;

private MissingPeopleResponseDto(MissingPeopleEntity missingPeopleEntity) {

protected MissingPeopleListResponseDto(MissingPeopleEntity missingPeopleEntity) {
this.id = missingPeopleEntity.getId();
this.name = missingPeopleEntity.getName();
// TODO : 숫자로 변경 요망
Expand All @@ -33,8 +36,8 @@ private MissingPeopleResponseDto(MissingPeopleEntity missingPeopleEntity) {
this.profileImage = missingPeopleEntity.getProfileImage();
}

public static MissingPeopleResponseDto fromEntity(MissingPeopleEntity missingPeopleEntity) {
return new MissingPeopleResponseDto(missingPeopleEntity);
public static MissingPeopleListResponseDto fromEntity(MissingPeopleEntity missingPeopleEntity) {
return new MissingPeopleListResponseDto(missingPeopleEntity);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.capstone.server.dto;


import com.capstone.server.model.SearchHistoryEntity;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.time.LocalDateTime;

@Data
@AllArgsConstructor
public class SearchHistoryListDto {
private Long searchId;
private LocalDateTime createdAt;

public SearchHistoryListDto(SearchHistoryEntity searchHistory) {
this.searchId = searchHistory.getId();
this.createdAt = searchHistory.getCreatedAt();
}

public static SearchHistoryListDto fromEntity(SearchHistoryEntity searchHistory) {
return new SearchHistoryListDto(searchHistory);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.capstone.server.repository;

import com.capstone.server.model.GuardianEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.capstone.server.model.GuardianEntity;

@Repository
public interface GuardianRepository extends JpaRepository<GuardianEntity, Long>{

public interface GuardianRepository extends JpaRepository<GuardianEntity, Long> {
GuardianEntity findByMissingPeopleEntityId(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.capstone.server.dto.MissingPeopleResponseDto;
import com.capstone.server.model.MissingPeopleEntity;
import com.capstone.server.model.enums.Status;
import java.util.List;

@Repository
public interface MissingPeopleRepository extends JpaRepository<MissingPeopleEntity, Long>{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.capstone.server.repository;

import com.capstone.server.model.SearchHistoryEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.capstone.server.model.SearchHistoryEntity;
import java.util.List;

@Repository
public interface SearchHistoryRepository extends JpaRepository<SearchHistoryEntity, Long>{

public interface SearchHistoryRepository extends JpaRepository<SearchHistoryEntity, Long> {
List<SearchHistoryEntity> findByMissingPeopleEntityId(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -82,61 +83,68 @@ public MissingPeopleCreateResponseDto createMissingPeople(MissingPeopleCreateReq
}
}

public List<MissingPeopleResponseDto> getAllMissingPeople(int page, int pageSize, MissingPeopleSortBy sortBy) {
public List<MissingPeopleListResponseDto> getAllMissingPeople(int page, int pageSize, MissingPeopleSortBy sortBy) {

Pageable pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, sortBy.getValue()));
Page<MissingPeopleEntity> missingPeoplePage = missingPeopleRepository.findAll(pageable);

List<MissingPeopleResponseDto> missingPeopleDtos = missingPeoplePage.getContent().stream()
.map(MissingPeopleResponseDto::fromEntity) // 엔티티를 DTO로 변환
List<MissingPeopleListResponseDto> missingPeopleDtos = missingPeoplePage.getContent().stream()
.map(MissingPeopleListResponseDto::fromEntity) // 엔티티를 DTO로 변환
.collect(Collectors.toList());

return missingPeopleDtos;
}

public List<MissingPeopleResponseDto> getAllMissingPeopleByStatus(int page, int pageSize, MissingPeopleSortBy sortBy, Status status) {
public List<MissingPeopleListResponseDto> getAllMissingPeopleByStatus(int page, int pageSize, MissingPeopleSortBy sortBy, Status status) {

Pageable pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, sortBy.getValue()));
Page<MissingPeopleEntity> missingPeoplePage = missingPeopleRepository.findByStatus(pageable, status);

List<MissingPeopleResponseDto> missingPeopleDtos = missingPeoplePage.getContent().stream()
.map(MissingPeopleResponseDto::fromEntity) // 엔티티를 DTO로 변환
List<MissingPeopleListResponseDto> missingPeopleDtos = missingPeoplePage.getContent().stream()
.map(MissingPeopleListResponseDto::fromEntity) // 엔티티를 DTO로 변환
.collect(Collectors.toList());

return missingPeopleDtos;
}

public List<MissingPeopleResponseDto> getAllMissingPeopleByNameContaining(int page, int pageSize, MissingPeopleSortBy sortBy, String name) {
public List<MissingPeopleListResponseDto> getAllMissingPeopleByNameContaining(int page, int pageSize, MissingPeopleSortBy sortBy, String name) {

Pageable pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, sortBy.getValue()));

Page<MissingPeopleEntity> missingPeoplePage = missingPeopleRepository.findByNameContaining(pageable, name.trim());

List<MissingPeopleResponseDto> missingPeopleDtos = missingPeoplePage.getContent().stream()
.map(MissingPeopleResponseDto::fromEntity) // 엔티티를 DTO로 변환
List<MissingPeopleListResponseDto> missingPeopleDtos = missingPeoplePage.getContent().stream()
.map(MissingPeopleListResponseDto::fromEntity) // 엔티티를 DTO로 변환
.collect(Collectors.toList());

return missingPeopleDtos;
}

public List<MissingPeopleResponseDto> getAllMissingPeopleByNameContainingAndStatus(int page, int pageSize, MissingPeopleSortBy sortBy, String name, Status status) {
public List<MissingPeopleListResponseDto> getAllMissingPeopleByNameContainingAndStatus(int page, int pageSize, MissingPeopleSortBy sortBy, String name, Status status) {

Pageable pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Direction.DESC, sortBy.getValue()));

Page<MissingPeopleEntity> missingPeoplePage = missingPeopleRepository.findByNameContainingAndStatus(pageable, name.trim(), status);

List<MissingPeopleResponseDto> missingPeopleDtos = missingPeoplePage.getContent().stream()
.map(MissingPeopleResponseDto::fromEntity) // 엔티티를 DTO로 변환
List<MissingPeopleListResponseDto> missingPeopleDtos = missingPeoplePage.getContent().stream()
.map(MissingPeopleListResponseDto::fromEntity) // 엔티티를 DTO로 변환
.collect(Collectors.toList());

return missingPeopleDtos;
}

public MissingPeopleResponseDto getMissingPeopleById(Long id) {
public MissingPeopleDetailResponseDto getMissingPeopleById(Long id) {
try {
MissingPeopleEntity missingPeopleEntity = missingPeopleRepository.findById(id)
.orElseThrow(() -> new NoSuchElementException("Missing person not found with ID: " + id));
return MissingPeopleResponseDto.fromEntity(missingPeopleEntity);
MissingPeopleDetailResponseDto missingPeopleDetailResponseDto = MissingPeopleDetailResponseDto.fromEntity(missingPeopleEntity);
//보호자 정보 가져오기
GuardianEntity guardianEntity = guardianRepository.findByMissingPeopleEntityId(id);
missingPeopleDetailResponseDto.setGuardianName(guardianEntity.getName());
missingPeopleDetailResponseDto.setPhoneNumber(guardianEntity.getPhoneNumber());
missingPeopleDetailResponseDto.setRelationship(guardianEntity.getRelationship());

return missingPeopleDetailResponseDto;
} catch (NoSuchElementException e) {
throw new CustomException(ErrorCode.MISSING_PEOPLE_NOT_FOUND_BY_ID, e);
} catch (Exception e) {
Expand Down Expand Up @@ -203,6 +211,17 @@ public void setProfileImagePath(Long id, String imagePath) {
missingPeopleRepository.save(missingPeopleEntity);
}

public List<SearchHistoryListDto> getSearchHistoryList(Long id) {
missingPeopleRepository.findById(id)
.orElseThrow(() -> new NoSuchElementException("Missing person not found with ID: " + id));
List<SearchHistoryEntity> searchHistory = searchHistoryRepository.findByMissingPeopleEntityId(id);
List<SearchHistoryListDto> searchHistoryDtos = new ArrayList<>();
for (SearchHistoryEntity searchHistoryEntity : searchHistory) {
searchHistoryDtos.add(SearchHistoryListDto.fromEntity(searchHistoryEntity));
}
return searchHistoryDtos;
}

// public List<S3UploadResponseDto> uploadSearchHistoryImageToS3(Long id, Long searchHistoryId ,List<MultipartFile> images, String setUploadImageName) {
// this.getMissingPeopleById(id);
// searchHistoryService.getSearchHistoryById(searchHistoryId);
Expand Down

0 comments on commit 2a0a922

Please sign in to comment.