-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/#2 map letter 기능 구현 #27
Changes from 74 commits
e934d24
0c94879
21c393a
eaf505b
19553f7
c9d8e83
c7bc828
f38047a
41e86fd
f0d8e3e
4f2fcff
9a347fe
d114e02
868e454
07b22ef
1efe773
6c8ac26
089118a
f4e9768
4854891
fed9a80
316e349
edc8d49
fd74dce
9b97f83
5aa40ea
d129e7f
08e7316
486d784
1a8d762
a42737d
3369b1a
0beaf07
5469442
4e07b40
fe5bd57
c258964
c2a40fa
811683f
f72ea0d
e41702a
3221941
5063e6c
a417f27
43dc166
50809b5
a8c8068
b373661
938dca3
f732470
5eec272
dc91265
94b84fb
29a1e99
51d73a6
036197d
11f0040
43a1f8e
1217a2e
a6fa394
925343c
910e8c4
7fcf9f0
c8b8dca
aae77bb
816f409
662b17d
63077ee
b01d5d6
2e7d96d
88072f1
0771528
63a6144
2e45a44
d63629c
bd85f3b
081fa92
ad82bd5
c89d7b7
5abff47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,162 @@ | ||
package postman.bottler.mapletter.controller; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.web.bind.annotation.*; | ||
import postman.bottler.global.response.ApiResponse; | ||
import postman.bottler.mapletter.dto.request.*; | ||
import postman.bottler.mapletter.dto.response.*; | ||
import postman.bottler.mapletter.exception.*; | ||
import postman.bottler.mapletter.service.MapLetterService; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/map") | ||
@RequiredArgsConstructor | ||
public class MapLetterController { | ||
|
||
private final MapLetterService mapLetterService; | ||
|
||
@PostMapping("/public") | ||
public ApiResponse<?> createMapLetter( | ||
@Valid @RequestBody CreatePublicMapLetterRequestDTO createPublicMapLetterRequestDTO, | ||
BindingResult bindingResult, Long userId) { | ||
if (bindingResult.hasErrors()) { | ||
bindingResult.getFieldErrors().forEach(error -> { | ||
if ("title".equals(error.getField())) { | ||
throw new EmptyMapLetterTitleException(error.getDefaultMessage()); | ||
} else if ("content".equals(error.getField())) { | ||
throw new EmptyMapLetterContentException(error.getDefaultMessage()); | ||
} else if ("description".equals(error.getField())) { | ||
throw new EmptyMapLetterDescriptionException(error.getDefaultMessage()); | ||
} | ||
}); | ||
|
||
throw new IllegalArgumentException(bindingResult.getAllErrors().get(0).getDefaultMessage()); //기타 오류 | ||
} | ||
mapLetterService.createPublicMapLetter(createPublicMapLetterRequestDTO, userId); | ||
return ApiResponse.onCreateSuccess("지도 편지 생성이 성공되었습니다."); | ||
} | ||
|
||
@PostMapping("/target") | ||
public ApiResponse<?> createTargetLetter( | ||
@Valid @RequestBody CreateTargetMapLetterRequestDTO createTargetMapLetterRequestDTO, | ||
BindingResult bindingResult, Long userId) { | ||
if (bindingResult.hasErrors()) { | ||
bindingResult.getFieldErrors().forEach(error -> { | ||
if ("title".equals(error.getField())) { | ||
throw new EmptyMapLetterTitleException(error.getDefaultMessage()); | ||
} else if ("content".equals(error.getField())) { | ||
throw new EmptyMapLetterContentException(error.getDefaultMessage()); | ||
} else if ("target".equals(error.getField())) { | ||
throw new EmptyMapLetterTargetException(error.getDefaultMessage()); | ||
} else if ("description".equals(error.getField())) { | ||
throw new EmptyMapLetterDescriptionException(error.getDefaultMessage()); | ||
} | ||
}); | ||
|
||
throw new IllegalArgumentException(bindingResult.getAllErrors().get(0).getDefaultMessage()); //기타 오류 | ||
} | ||
mapLetterService.createTargetMapLetter(createTargetMapLetterRequestDTO, userId); | ||
return ApiResponse.onCreateSuccess("타겟 편지 생성이 성공되었습니다."); | ||
} | ||
|
||
@GetMapping("/{letterId}") | ||
public ApiResponse<OneLetterResponseDTO> findOneMapLetter(@PathVariable Long letterId, Long userId) { | ||
return ApiResponse.onSuccess(mapLetterService.findOneMepLetter(letterId, userId)); | ||
} | ||
|
||
@DeleteMapping | ||
public ApiResponse<?> deleteMapLetter(@RequestBody DeleteMapLettersRequestDTO letters, Long userId) { | ||
mapLetterService.deleteMapLetter(letters.letterIds(), userId); | ||
return ApiResponse.onDeleteSuccess(letters); | ||
} | ||
|
||
@GetMapping("/sent") | ||
public ApiResponse<List<FindMapLetterResponseDTO>> findSentMapLetters(Long userId) { | ||
return ApiResponse.onSuccess(mapLetterService.findSentMapLetters(userId)); | ||
} | ||
|
||
@GetMapping("/received") | ||
public ApiResponse<List<FindReceivedMapLetterResponseDTO>> findReceivedMapLetters(Long userId) { | ||
return ApiResponse.onSuccess(mapLetterService.findReceivedMapLetters(userId)); | ||
} | ||
|
||
@GetMapping | ||
public ApiResponse<List<FindNearbyLettersResponseDTO>> findNearbyMapLetters(@RequestParam String latitude, | ||
@RequestParam String longitude, | ||
Long userId) { | ||
BigDecimal lat = BigDecimal.ZERO; | ||
BigDecimal lon = BigDecimal.ZERO; | ||
try { | ||
lat = new BigDecimal(latitude); | ||
lon = new BigDecimal(longitude); | ||
} catch (Exception e) { | ||
throw new LocationNotFoundException("해당 위치를 찾을 수 없습니다."); | ||
} | ||
|
||
return ApiResponse.onSuccess(mapLetterService.findNearByMapLetters(lat, lon, userId)); | ||
} | ||
|
||
@PostMapping("/reply") | ||
public ApiResponse<?> createReplyMapLetter( | ||
@Valid @RequestBody CreateReplyMapLetterRequestDTO createReplyMapLetterRequestDTO, | ||
BindingResult bindingResult, Long userId) { | ||
if (bindingResult.hasErrors()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 위의 메서드를 쓰면 이것도 줄일 수 있을 것 같아요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넴~~ |
||
bindingResult.getFieldErrors().forEach(error -> { | ||
if ("content".equals(error.getField())) { | ||
throw new EmptyMapLetterContentException(error.getDefaultMessage()); | ||
} else if ("sourceLetter".equals(error.getField())) { | ||
throw new EmptyReplyMapLetterSourceException(error.getDefaultMessage()); | ||
} | ||
}); | ||
|
||
throw new IllegalArgumentException(bindingResult.getAllErrors().get(0).getDefaultMessage()); //기타 오류 | ||
} | ||
mapLetterService.createReplyMapLetter(createReplyMapLetterRequestDTO, userId); | ||
return ApiResponse.onCreateSuccess("답장 편지 생성이 성공되었습니다."); | ||
} | ||
|
||
@GetMapping("/{letterId}/reply") | ||
public ApiResponse<List<FindAllReplyMapLettersResponseDTO>> findAllReplyMapLetter(@PathVariable Long letterId, | ||
Long userId) { | ||
return ApiResponse.onSuccess(mapLetterService.findAllReplyMapLetter(letterId, userId)); | ||
} | ||
|
||
@GetMapping("/reply/{letterId}") | ||
public ApiResponse<OneReplyLetterResponseDTO> findOneReplyMapLetter(@PathVariable Long letterId, Long userId) { | ||
return ApiResponse.onSuccess(mapLetterService.findOneReplyMapLetter(letterId, userId)); | ||
} | ||
|
||
@PostMapping("/{letterId}") | ||
public ApiResponse<?> mapLetterArchive(@PathVariable Long letterId, Long userId) { | ||
mapLetterService.mapLetterArchive(letterId, userId); | ||
return ApiResponse.onCreateSuccess("편지 저장이 성공되었습니다."); | ||
} | ||
|
||
@GetMapping("/archived") | ||
public ApiResponse<List<FindAllArchiveLetters>> findArchiveLetters(Long userId) { | ||
return ApiResponse.onSuccess(mapLetterService.findArchiveLetters(userId)); | ||
} | ||
|
||
@DeleteMapping("/archived") | ||
public ApiResponse<?> archiveLetter(@RequestBody DeleteArchivedLettersRequestDTO deleteArchivedLettersRequestDTO | ||
, Long userId) { | ||
mapLetterService.deleteArchivedLetter(deleteArchivedLettersRequestDTO, userId); | ||
return ApiResponse.onDeleteSuccess(deleteArchivedLettersRequestDTO); | ||
} | ||
|
||
@GetMapping("/reply/check/{letterId}") | ||
public ApiResponse<CheckReplyMapLetterResponseDTO> checkReplyMapLetter(@PathVariable Long letterId, Long userId) { | ||
return ApiResponse.onSuccess(mapLetterService.checkReplyMapLetter(letterId, userId)); | ||
} | ||
|
||
@DeleteMapping("/reply") | ||
public ApiResponse<?> deleteReplyMapLetter(@RequestBody DeleteMapLettersRequestDTO letters, Long userId) { | ||
mapLetterService.deleteReplyMapLetter(letters.letterIds(), userId); | ||
return ApiResponse.onDeleteSuccess(letters); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package postman.bottler.mapletter.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import postman.bottler.global.response.ApiResponse; | ||
import postman.bottler.mapletter.dto.PaperDTO; | ||
import postman.bottler.mapletter.service.PaperService; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/paper") | ||
@RequiredArgsConstructor | ||
public class PaperController { | ||
private final PaperService paperService; | ||
|
||
@GetMapping | ||
public ApiResponse<List<PaperDTO>> findPapers() { | ||
return ApiResponse.onSuccess(paperService.findPapers()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,92 @@ | ||
package postman.bottler.mapletter.domain; | ||
|
||
import java.math.BigDecimal; | ||
import java.time.LocalDateTime; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import postman.bottler.mapletter.dto.request.CreatePublicMapLetterRequestDTO; | ||
import postman.bottler.mapletter.dto.request.CreateTargetMapLetterRequestDTO; | ||
import postman.bottler.mapletter.dto.response.OneLetterResponseDTO; | ||
|
||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public class MapLetter { | ||
private Long id; | ||
private String title; | ||
private String content; | ||
private BigDecimal latitude; | ||
private BigDecimal longitude; | ||
private String font; | ||
private String paper; | ||
private String label; | ||
private String description; | ||
private MapLetterType type; | ||
private Long targetUserId; | ||
private Long createUserId; | ||
private LocalDateTime createdAt; | ||
private LocalDateTime updatedAt; | ||
private boolean isDeleted; | ||
private boolean isBlocked; | ||
|
||
public static MapLetter createPublicMapLetter(CreatePublicMapLetterRequestDTO createPublicMapLetterRequestDTO, | ||
Long userId) { | ||
return MapLetter.builder() | ||
.title(createPublicMapLetterRequestDTO.title()) | ||
.content(createPublicMapLetterRequestDTO.content()) | ||
.latitude(createPublicMapLetterRequestDTO.latitude()) | ||
.longitude(createPublicMapLetterRequestDTO.longitude()) | ||
.font(createPublicMapLetterRequestDTO.font()) | ||
.paper(createPublicMapLetterRequestDTO.paper()) | ||
.label(createPublicMapLetterRequestDTO.label()) | ||
.type(MapLetterType.PUBLIC) | ||
.createUserId(userId) | ||
.createdAt(LocalDateTime.now()) | ||
.updatedAt(LocalDateTime.now()) | ||
.isDeleted(false) | ||
.isBlocked(false) | ||
.description(createPublicMapLetterRequestDTO.description()) | ||
.build(); | ||
} | ||
|
||
public static MapLetter createTargetMapLetter(CreateTargetMapLetterRequestDTO createTargetMapLetterRequestDTO, | ||
Long userId) { | ||
return MapLetter.builder() | ||
.title(createTargetMapLetterRequestDTO.title()) | ||
.content(createTargetMapLetterRequestDTO.content()) | ||
.latitude(createTargetMapLetterRequestDTO.latitude()) | ||
.longitude(createTargetMapLetterRequestDTO.longitude()) | ||
.font(createTargetMapLetterRequestDTO.font()) | ||
.paper(createTargetMapLetterRequestDTO.paper()) | ||
.label(createTargetMapLetterRequestDTO.label()) | ||
.type(MapLetterType.PRIVATE) | ||
.createUserId(userId) | ||
.targetUserId(createTargetMapLetterRequestDTO.target()) | ||
.createdAt(LocalDateTime.now()) | ||
.updatedAt(LocalDateTime.now()) | ||
.isDeleted(false) | ||
.isBlocked(false) | ||
.description(createTargetMapLetterRequestDTO.description()) | ||
.build(); | ||
} | ||
|
||
public static OneLetterResponseDTO toOneLetterResponse(MapLetter mapLetter) { | ||
return OneLetterResponseDTO.builder() | ||
.title(mapLetter.getTitle()) | ||
.content(mapLetter.getContent()) | ||
.font(mapLetter.getFont()) | ||
.paper(mapLetter.getPaper()) | ||
.label(mapLetter.getLabel()) | ||
.createdAt(mapLetter.getCreatedAt()) | ||
.description(mapLetter.getDescription()) | ||
.build(); | ||
} | ||
|
||
public void updateDelete(boolean deleted) { | ||
this.isDeleted = deleted; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package postman.bottler.mapletter.domain; | ||
|
||
import lombok.*; | ||
|
||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public class MapLetterArchive { | ||
private Long mapLetterArchiveId; | ||
private Long mapLetterId; | ||
private Long userId; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package postman.bottler.mapletter.domain; | ||
|
||
public enum MapLetterType { | ||
PUBLIC, | ||
PRIVATE, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package postman.bottler.mapletter.domain; | ||
|
||
import lombok.*; | ||
import postman.bottler.mapletter.dto.PaperDTO; | ||
|
||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public class Paper { | ||
Long paperId; | ||
String paperUrl; | ||
|
||
public static PaperDTO toPaperDTO(Paper paper) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 이 부분을 DTO에 from으로 넣어서 스스로 DTO를 만들도록 했는데 어떤 방식이 좋은지 몰라서 |
||
return new PaperDTO(paper.paperId, paper.paperUrl); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어차피 bindingResult를 넘기니까
위의 처리랑 묶어서 메서드 처리 가능할거 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오호랏 수정하겠습니다 🪼