Skip to content

Commit

Permalink
Merge pull request #59 from Map-Pin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
seungheon123 authored Nov 7, 2023
2 parents 454d0ae + 561dc66 commit bdb6247
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
29 changes: 17 additions & 12 deletions src/main/java/com/server/mappin/controller/LostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.persistence.Column;
import java.io.IOException;
Expand All @@ -26,12 +28,15 @@
public class LostController {
private final LostService lostService;

@Operation(summary = "분실물 등록")
@Operation(summary = "분실물 등록", description = "Content-Type은 multipart/form-data이지만 info는 application/json입니다")
@ApiResponse(content = @Content(schema = @Schema(implementation = LostRegisterResponseDto.class)))
@PutMapping("/lost/register")
public ResponseEntity<?> registerLost(@ModelAttribute LostRegisterRequestDto lostRegisterRequestDto, Authentication authentication) throws IOException {
@PutMapping(value = "/lost/register", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<?> registerLost(
@ModelAttribute("image") MultipartFile file,
@RequestPart("info") LostRegisterRequestDto lostRegisterRequestDto,
Authentication authentication) throws IOException {
try {
LostRegisterResponseDto lostRegisterResponseDto = lostService.registerLost(lostRegisterRequestDto, authentication.getName());
LostRegisterResponseDto lostRegisterResponseDto = lostService.registerLost(lostRegisterRequestDto,file, authentication.getName());
return new ResponseEntity<>(lostRegisterResponseDto, HttpStatus.OK);
} catch (IllegalStateException e) {
return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT);
Expand All @@ -40,8 +45,8 @@ public ResponseEntity<?> registerLost(@ModelAttribute LostRegisterRequestDto los

@Operation(summary = "카테고리 검색", description = "분실물을 카테고리 별로 검색")
@ApiResponse(content = @Content(schema = @Schema(implementation = FindByCategoryListResponseDto.class)))
@GetMapping("/search/category/{category_name}")
public ResponseEntity<?> searchByCategory(@RequestParam(value = "category_name") String name) {
@GetMapping("lost/search?category={category_name}")
public ResponseEntity<?> searchByCategory(@PathVariable(value = "category_name") String name) {
try {
FindByCategoryListResponseDto findByCategoryListResponseDto = lostService.findByCategory(name);
return new ResponseEntity<>(findByCategoryListResponseDto, HttpStatus.OK);
Expand All @@ -52,8 +57,8 @@ public ResponseEntity<?> searchByCategory(@RequestParam(value = "category_name")

@Operation(summary = "동 검색", description = "분실물을 동 별로 검색")
@ApiResponse(content = @Content(schema = @Schema(implementation = FindByDongResponseDto.class)))
@GetMapping("/search/dong/{dong_name}")
public ResponseEntity<?> searchByDong(@RequestParam(value = "dong_name") String dongName) {
@GetMapping("lost/search?dong={dong_name}")
public ResponseEntity<?> searchByDong(@PathVariable(value = "dong_name") String dongName) {
try {
List<FindByDongResponseDto> byDong = lostService.findByDong(dongName);
return new ResponseEntity<>(byDong, HttpStatus.OK);
Expand All @@ -64,8 +69,8 @@ public ResponseEntity<?> searchByDong(@RequestParam(value = "dong_name") String

@Operation(summary = "가게 검색", description = "분실물을 가게이름 별로 검색")
@ApiResponse(content = @Content(schema = @Schema(implementation = FindByShopResponseDto.class)))
@GetMapping("/search/shop/{shop_name}")
public ResponseEntity<?> searchByShop(@RequestParam(value = "shop_name") String shopName) {
@GetMapping("lost/search?shop={shop_name}")
public ResponseEntity<?> searchByShop(@PathVariable(value = "shop_name") String shopName) {
try {
List<FindByShopResponseDto> byDong = lostService.findByShop(shopName);
return new ResponseEntity<>(byDong, HttpStatus.OK);
Expand All @@ -76,8 +81,8 @@ public ResponseEntity<?> searchByShop(@RequestParam(value = "shop_name") String

@Operation(summary = "현재위치로 검색", description = "분실물을 현재위치로 검색")
@ApiResponse(content = @Content(schema = @Schema(implementation = FindByDongResponseDto.class)))
@GetMapping("/search/location/{x}/{y}")
public ResponseEntity<?> searchByCurrentLocation(@RequestParam(value = "x") Double x, @RequestParam(value = "y") Double y) {
@GetMapping("lost/search?x={x}&y={y}")
public ResponseEntity<?> searchByCurrentLocation(@PathVariable(value = "x") Double x, @RequestParam(value = "y") Double y) {
try {
List<FindByDongResponseDto> byDong = lostService.findByCurrentLocation(x, y);
return new ResponseEntity<>(byDong, HttpStatus.OK);
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/server/mappin/controller/PostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.server.mappin.dto.PostSearchResponseDto;
import com.server.mappin.service.PostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand All @@ -14,9 +15,11 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

Expand All @@ -27,16 +30,20 @@
public class PostController {
private final PostService postService;

@Operation(summary = "게시물 작성",description = "게시물을 작성합니다")
@Operation(summary = "게시물 작성",description = "Content-type은 multipart/form-data이지만 info는 application/json입니다")
@ApiResponses({
@ApiResponse(responseCode ="200",description ="게시물 작성 성공",content = @Content(schema = @Schema(implementation = PostCreateResponseDto.class))),
@ApiResponse(responseCode ="400",description ="게시물 작성 실패",content = @Content(schema = @Schema(implementation = PostCreateResponseDto.class)))
})
@PutMapping("/post")
public ResponseEntity<?> create(@ModelAttribute PostCreateRequestDto postCreateDto, Authentication authentication) throws IOException {
@PutMapping(value = "/post/new",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<?> create(
@RequestPart("image")MultipartFile image,
@RequestPart("info") PostCreateRequestDto postCreateDto,
Authentication authentication
) throws IOException {
try{
String email = authentication.getName();
PostCreateResponseDto postCreateResponseDto = postService.create(postCreateDto, email);
PostCreateResponseDto postCreateResponseDto = postService.create(postCreateDto,image, email);
return new ResponseEntity<>(postCreateResponseDto,HttpStatus.OK);
}catch (IllegalStateException e){
return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class LostRegisterRequestDto {
private String title;
private String content;
private String foundDate;
private MultipartFile image;
private Double x;
private Double y;
private String dong;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class PostCreateRequestDto {
private String title;
private String content;
private String lostDate;
private MultipartFile image;
private Double x;
private Double y;
private String category;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/server/mappin/service/LostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDate;
Expand Down Expand Up @@ -70,7 +71,7 @@ public List<FindByDongResponseDto> findByCurrentLocation(Double x, Double y) {
}

@Transactional
public LostRegisterResponseDto registerLost(LostRegisterRequestDto lostRegisterRequestDto, String email) throws IOException {
public LostRegisterResponseDto registerLost(LostRegisterRequestDto lostRegisterRequestDto, MultipartFile image, String email) throws IOException {
//String으로 받아온 yyyy-MM-dd를 LocalDate 형식으로 변환
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate localDate = LocalDate.parse(lostRegisterRequestDto.getFoundDate(),formatter);
Expand All @@ -81,7 +82,7 @@ public LostRegisterResponseDto registerLost(LostRegisterRequestDto lostRegisterR
String dong = mapService.getDong(lostRegisterRequestDto.getX(), lostRegisterRequestDto.getY());
Optional<Location> locationByDong = locationRepository.findLocationByDong(dong);
//이미지 S3에 업로드
String imageUrl = s3Service.upload(lostRegisterRequestDto.getImage(), "images");
String imageUrl = s3Service.upload(image, "images");
if(memberRepositoryByEmail.isPresent() && categoryByName.isPresent() && locationByDong.isPresent()){
Member member = memberRepositoryByEmail.get();
Location location = locationByDong.get();
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/server/mappin/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDate;
Expand All @@ -37,7 +38,7 @@ public class PostService {


@Transactional
public PostCreateResponseDto create(PostCreateRequestDto postCreateRequestDto, String email) throws IOException {
public PostCreateResponseDto create(PostCreateRequestDto postCreateRequestDto, MultipartFile image, String email) throws IOException {
//String date -> LocalDate로 변경
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate localDate = LocalDate.parse(postCreateRequestDto.getLostDate(),formatter);
Expand All @@ -46,7 +47,7 @@ public PostCreateResponseDto create(PostCreateRequestDto postCreateRequestDto, S
Optional<Location> locationByDong = locationRepository.findLocationByDong(dong);
Optional<Category> categoryByName = categoryRepository.findCategoryByName(postCreateRequestDto.getCategory());
Optional<Member> memberByEmail = memberRepository.findByEmail(email);
String imageUrl = s3Service.upload(postCreateRequestDto.getImage(), "images");
String imageUrl = s3Service.upload(image, "images");
Location location;
Category category;
Member member;
Expand Down

0 comments on commit bdb6247

Please sign in to comment.