Skip to content

Commit

Permalink
Merge pull request #55 from Map-Pin/issue/54
Browse files Browse the repository at this point in the history
Issue/54
  • Loading branch information
seungheon123 authored Nov 7, 2023
2 parents d09f51c + 0c40d09 commit 454d0ae
Show file tree
Hide file tree
Showing 14 changed files with 305 additions and 85 deletions.
106 changes: 73 additions & 33 deletions src/main/java/com/server/mappin/controller/LostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,86 @@
import javax.persistence.Column;
import java.io.IOException;
import java.util.List;

@Tag(name = "Lost API", description = "분실물 관련 API 명세서")
@RestController
@Slf4j
@RequiredArgsConstructor
public class LostController {
private final LostService lostService;

@Operation(summary = "분실물 등록")
@ApiResponse(content = @Content(schema = @Schema(implementation = LostRegisterResponseDto.class)))
@PutMapping("/lost/register")
public ResponseEntity<?> registerLost(@ModelAttribute LostRegisterRequestDto lostRegisterRequestDto, Authentication authentication) throws IOException {
try{
LostRegisterResponseDto lostRegisterResponseDto = lostService.registerLost(lostRegisterRequestDto, authentication.getName());
return new ResponseEntity<>(lostRegisterResponseDto,HttpStatus.OK);
}catch (IllegalStateException e){
return new ResponseEntity<>("에러가 발생했습니다",HttpStatus.CONFLICT);
}
private final LostService lostService;

@Operation(summary = "분실물 등록")
@ApiResponse(content = @Content(schema = @Schema(implementation = LostRegisterResponseDto.class)))
@PutMapping("/lost/register")
public ResponseEntity<?> registerLost(@ModelAttribute LostRegisterRequestDto lostRegisterRequestDto, Authentication authentication) throws IOException {
try {
LostRegisterResponseDto lostRegisterResponseDto = lostService.registerLost(lostRegisterRequestDto, authentication.getName());
return new ResponseEntity<>(lostRegisterResponseDto, HttpStatus.OK);
} catch (IllegalStateException e) {
return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT);
}
}

@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) {
try {
FindByCategoryListResponseDto findByCategoryListResponseDto = lostService.findByCategory(name);
return new ResponseEntity<>(findByCategoryListResponseDto, HttpStatus.OK);
} catch (IllegalStateException e) {
return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT);
}
}

@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) {
try {
List<FindByDongResponseDto> byDong = lostService.findByDong(dongName);
return new ResponseEntity<>(byDong, HttpStatus.OK);
} catch (IllegalStateException e) {
return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT);
}
}

@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) {
try {
List<FindByShopResponseDto> byDong = lostService.findByShop(shopName);
return new ResponseEntity<>(byDong, HttpStatus.OK);
} catch (IllegalStateException e) {
return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT);
}
}

@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){
try{
FindByCategoryListResponseDto findByCategoryListResponseDto = lostService.findByCategory(name);
return new ResponseEntity<>(findByCategoryListResponseDto,HttpStatus.OK);
}catch (IllegalStateException e){
return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT);
}
@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) {
try {
List<FindByDongResponseDto> byDong = lostService.findByCurrentLocation(x, y);
return new ResponseEntity<>(byDong, HttpStatus.OK);
} catch (IllegalStateException e) {
return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT);
}
}

@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){
try{
List<FindByDongResponseDto> byDong = lostService.findByDong(dongName);
return new ResponseEntity<>(byDong,HttpStatus.OK);
}catch (IllegalStateException e){
return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT);
}
@Operation(summary = "분실물 상세 조회", description = "분실물 Id로 분실물 상세 조회")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "분실물 상세 조회 성공", content = @Content(schema = @Schema(implementation = LostSearchByIdResponseDto.class))),
@ApiResponse(responseCode = "400", description = "분실물 상세 조회 실패", content = @Content(schema = @Schema(implementation = LostSearchByIdResponseDto.class)))
})
@GetMapping("/lost/{lost_id}")
public ResponseEntity<?> getById(@RequestParam(value = "lost_id") Long id) {
try {
LostSearchByIdResponseDto lostSearchByIdResponseDto = lostService.getById(id);
return new ResponseEntity<>(lostSearchByIdResponseDto, HttpStatus.OK);
} catch (IllegalStateException e) {
return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT);
}
}
}
}
23 changes: 19 additions & 4 deletions src/main/java/com/server/mappin/controller/PostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.server.mappin.dto.PostCreateRequestDto;
import com.server.mappin.dto.PostCreateResponseDto;
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.media.Content;
Expand All @@ -15,9 +16,9 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@Tag(name = "Post API",description = "게시물 관련 API")
@RestController
Expand All @@ -32,14 +33,28 @@ public class PostController {
@ApiResponse(responseCode ="400",description ="게시물 작성 실패",content = @Content(schema = @Schema(implementation = PostCreateResponseDto.class)))
})
@PutMapping("/post")
public ResponseEntity<?> create(@RequestBody PostCreateRequestDto postCreateDto, Authentication authentication){
public ResponseEntity<?> create(@ModelAttribute PostCreateRequestDto postCreateDto, Authentication authentication) throws IOException {
try{
String email = authentication.getName();
PostCreateResponseDto postCreateResponseDto = postService.create(postCreateDto, email);
return new ResponseEntity<>(postCreateResponseDto,HttpStatus.OK);
}catch (IllegalStateException e){
return new ResponseEntity<>("에러가 발생했습니다", HttpStatus.CONFLICT);
}
}

@Operation(summary = "게시물 조회",description = "게시물 Id로 게시물을 상세 조회")
@ApiResponses({
@ApiResponse(responseCode = "200",description = "게시물 조회 성공",content = @Content(schema = @Schema(implementation = PostSearchResponseDto.class))),
@ApiResponse(responseCode = "400",description = "게시물 조회 실패",content = @Content(schema = @Schema(implementation = PostCreateResponseDto.class)))
})
@GetMapping("/post/{post_id}")
public ResponseEntity<?> search(@PathVariable("post_id") long id){
try{
PostSearchResponseDto search = postService.search(id);
return new ResponseEntity<>(search,HttpStatus.OK);
}catch (IllegalStateException e){
return new ResponseEntity<>("에러가 발생했습니다",HttpStatus.CONFLICT);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/server/mappin/domain/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Post {
private String content;

@Column(name = "created_at")
private LocalDate createdAt;
private LocalDateTime createdAt;

@Column(name = "lost_date")
private LocalDate lostDate;
Expand All @@ -50,7 +50,7 @@ public class Post {
private Category category;

@Builder
public Post(Member member, String title, String content, LocalDate createdAt, LocalDate lostDate, String imageUrl, Double x, Double y, Location location, Category category) {
public Post(Member member, String title, String content, LocalDateTime createdAt, LocalDate lostDate, String imageUrl, Double x, Double y, Location location, Category category) {
this.member = member;
this.title = title;
this.content = content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import lombok.Builder;
import lombok.Data;

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

@Data
@Builder
public class FindByCategoryResponseDto {
private Long id;
private String title;
private LocalDateTime creatdAt;
private String imageUrl;
}
16 changes: 16 additions & 0 deletions src/main/java/com/server/mappin/dto/FindByShopResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.server.mappin.dto;

import lombok.Builder;
import lombok.Data;

import java.time.LocalDateTime;

@Data
@Builder
public class FindByShopResponseDto {
private Long id;
private String title;
private LocalDateTime createdAt;
private String imageUrl;
private String shopName;
}
23 changes: 23 additions & 0 deletions src/main/java/com/server/mappin/dto/LostSearchByIdResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.server.mappin.dto;

import lombok.Builder;
import lombok.Data;

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

@Builder
@Data
public class LostSearchByIdResponseDto {
private int statusCode;
private String isSuccess;
private String title;
private String content;
private LocalDate foundDate;
private LocalDateTime createdAt;
private String image;
private Double x;
private Double y;
private String dong;
private String category;
}
7 changes: 4 additions & 3 deletions src/main/java/com/server/mappin/dto/PostCreateRequestDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import com.server.mappin.domain.Category;
import com.server.mappin.domain.Location;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDate;

@Data
public class PostCreateRequestDto {
private String title;
private String content;
private LocalDate date;
private String dong;
private String category;
private String lostDate;
private MultipartFile image;
private Double x;
private Double y;
private String category;

}
15 changes: 14 additions & 1 deletion src/main/java/com/server/mappin/dto/PostCreateResponseDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,24 @@
import lombok.Builder;
import lombok.Data;

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

@Data
@Builder
public class PostCreateResponseDto {
private int statusCode;
private String isSuccess;
private Long memberId;
private Long postId;

private String title;
private String content;
private LocalDate lostDate;
private LocalDateTime createdAt;
private String image;
private Double x;
private Double y;
private String dong;
private String category;
}

23 changes: 23 additions & 0 deletions src/main/java/com/server/mappin/dto/PostSearchResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.server.mappin.dto;

import lombok.Builder;
import lombok.Data;

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

@Builder
@Data
public class PostSearchResponseDto {
private int statusCode;
private String isSuccess;
private String title;
private String content;
private LocalDate lostDate;
private LocalDateTime createdAt;
private String image;
private Double x;
private Double y;
private String dong;
private String category;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ public interface LostRepository extends JpaRepository<Lost, Long> {

@Query(value = "select l from Lost l left join fetch l.location c where c.dong = :dong")
List<Lost> findLocationByDong(@Param("dong") String dong);

@Query("select l from Lost l " + "where l.member.id in (select s.member.id from Shop s where s.name = :name)")
List<Lost> findLostByShopName(@Param("name") String name);
@Override
<S extends Lost> S save(S entity);

@Override
Optional<Lost> findById(Long aLong);
}


Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface PostRepository extends JpaRepository<Post, Long> {

@Override
<S extends Post> S save(S entity);

@Override
Optional<Post> findById(Long aLong);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.server.mappin.repository;

import com.server.mappin.domain.Lost;
import com.server.mappin.domain.Member;
import com.server.mappin.domain.Shop;
import org.springframework.data.domain.Example;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface ShopRepository extends JpaRepository<Shop, Long> {
Optional<Shop> findByMember(Member member);
}
Optional<Shop> findByMember(Member member);
}
Loading

0 comments on commit 454d0ae

Please sign in to comment.