-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from team-nabi/NABI-125--yejin--feat--suggestion
Nabi-125-- 제안 생성 / 조회 / 결정 구현
- Loading branch information
Showing
16 changed files
with
516 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/org/prgrms/nabimarketbe/domain/card/repository/CardRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package org.prgrms.nabimarketbe.domain.card.repository; | ||
|
||
import org.prgrms.nabimarketbe.domain.card.entity.Card; | ||
import org.prgrms.nabimarketbe.domain.user.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface CardRepository extends JpaRepository<Card, Long>, CardRepositoryCustom { | ||
Optional<Card> findByCardIdAndUser(Long cardId, User user); | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/org/prgrms/nabimarketbe/domain/suggestion/api/SuggestionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package org.prgrms.nabimarketbe.domain.suggestion.api; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import org.prgrms.nabimarketbe.domain.suggestion.dto.request.SuggestionRequestDTO; | ||
import org.prgrms.nabimarketbe.domain.suggestion.dto.response.SuggestionListReadPagingResponseDTO; | ||
import org.prgrms.nabimarketbe.domain.suggestion.dto.response.SuggestionResponseDTO; | ||
import org.prgrms.nabimarketbe.domain.suggestion.entity.DirectionType; | ||
import org.prgrms.nabimarketbe.domain.suggestion.entity.SuggestionType; | ||
import org.prgrms.nabimarketbe.domain.suggestion.service.SuggestionService; | ||
import org.prgrms.nabimarketbe.global.util.ResponseFactory; | ||
import org.prgrms.nabimarketbe.global.util.model.SingleResult; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RequestMapping("/api/v1/suggestions") | ||
@RequiredArgsConstructor | ||
@RestController | ||
public class SuggestionController { | ||
private final SuggestionService suggestionService; | ||
|
||
@PostMapping("/{suggestionType}") | ||
public ResponseEntity<SingleResult<SuggestionResponseDTO>> createSuggestion( | ||
@RequestHeader(name = "Authorization") String token, | ||
@PathVariable String suggestionType, | ||
@RequestBody SuggestionRequestDTO suggestionRequestDTO | ||
) { | ||
SuggestionResponseDTO suggestionResponseDTO = suggestionService.createSuggestion( | ||
token, | ||
suggestionType, | ||
suggestionRequestDTO | ||
); | ||
|
||
return ResponseEntity.ok(ResponseFactory.getSingleResult(suggestionResponseDTO)); | ||
} | ||
|
||
@GetMapping("/{directionType}/{suggestionType}/{cardId}") | ||
public ResponseEntity<SingleResult<SuggestionListReadPagingResponseDTO>> getSuggestionsByType( | ||
@RequestHeader(name = "Authorization") String token, | ||
@PathVariable String directionType, | ||
@PathVariable String suggestionType, | ||
@PathVariable Long cardId, | ||
@RequestParam(required = false) String cursorId, | ||
@RequestParam Integer size | ||
) { | ||
SuggestionListReadPagingResponseDTO receivedSuggestions = suggestionService.getSuggestionsByType( | ||
token, | ||
DirectionType.valueOf(directionType), | ||
SuggestionType.valueOf(suggestionType), | ||
cardId, | ||
cursorId, | ||
size | ||
); | ||
|
||
return ResponseEntity.ok(ResponseFactory.getSingleResult(receivedSuggestions)); | ||
} | ||
|
||
@PutMapping("/decision") | ||
public ResponseEntity<SingleResult<SuggestionResponseDTO>> updateSugggestionStatus( | ||
@RequestHeader(name = "Authorization") String token, | ||
@RequestParam Long fromCardId, | ||
@RequestParam Long toCardId, | ||
@RequestParam Boolean isAccepted | ||
) { | ||
SuggestionResponseDTO suggestionResponseDTO = suggestionService.updateSuggestionStatus( | ||
token, | ||
fromCardId, | ||
toCardId, | ||
isAccepted | ||
); | ||
|
||
return ResponseEntity.ok(ResponseFactory.getSingleResult(suggestionResponseDTO)); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...main/java/org/prgrms/nabimarketbe/domain/suggestion/dto/request/SuggestionRequestDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.prgrms.nabimarketbe.domain.suggestion.dto.request; | ||
|
||
public record SuggestionRequestDTO( | ||
Long fromCardId, | ||
Long toCardId | ||
) { | ||
} |
9 changes: 9 additions & 0 deletions
9
...grms/nabimarketbe/domain/suggestion/dto/response/SuggestionListReadPagingResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.prgrms.nabimarketbe.domain.suggestion.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record SuggestionListReadPagingResponseDTO( | ||
List<SuggestionListReadResponseDTO> suggestionList, | ||
String nextCursorId | ||
) { | ||
} |
35 changes: 35 additions & 0 deletions
35
...org/prgrms/nabimarketbe/domain/suggestion/dto/response/SuggestionListReadResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.prgrms.nabimarketbe.domain.suggestion.dto.response; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import org.prgrms.nabimarketbe.domain.item.entity.PriceRange; | ||
import org.prgrms.nabimarketbe.domain.suggestion.entity.DirectionType; | ||
import org.prgrms.nabimarketbe.domain.suggestion.entity.SuggestionStatus; | ||
import org.prgrms.nabimarketbe.domain.suggestion.entity.SuggestionType; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@NoArgsConstructor | ||
@Getter | ||
public class SuggestionListReadResponseDTO{ | ||
private Long suggestionId; | ||
|
||
private Long cardId; | ||
|
||
private String cardTitle; | ||
|
||
private String itemName; | ||
|
||
private PriceRange priceRange; | ||
|
||
private String thumbnail; | ||
|
||
private SuggestionType suggestionType; | ||
|
||
private SuggestionStatus suggestionStatus; | ||
|
||
private LocalDateTime createdAt; | ||
|
||
private DirectionType directionType; | ||
} |
32 changes: 32 additions & 0 deletions
32
...in/java/org/prgrms/nabimarketbe/domain/suggestion/dto/response/SuggestionResponseDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.prgrms.nabimarketbe.domain.suggestion.dto.response; | ||
|
||
import lombok.Builder; | ||
import org.prgrms.nabimarketbe.domain.card.entity.Card; | ||
import org.prgrms.nabimarketbe.domain.suggestion.entity.Suggestion; | ||
import org.prgrms.nabimarketbe.domain.suggestion.entity.SuggestionStatus; | ||
import org.prgrms.nabimarketbe.domain.suggestion.entity.SuggestionType; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Builder | ||
public record SuggestionResponseDTO( | ||
Long suggestionId, | ||
SuggestionType suggestionType, | ||
Long fromCardId, | ||
Long toCardId, | ||
SuggestionStatus suggestionStatus, | ||
LocalDateTime createdAt | ||
) { | ||
public static SuggestionResponseDTO of( | ||
Suggestion suggestion | ||
) { | ||
return SuggestionResponseDTO.builder() | ||
.suggestionId(suggestion.getSuggestionId()) | ||
.suggestionType(suggestion.getSuggestionType()) | ||
.fromCardId(suggestion.getFromCard().getCardId()) | ||
.toCardId(suggestion.getToCard().getCardId()) | ||
.suggestionStatus(suggestion.getSuggestionStatus()) | ||
.createdAt(suggestion.getCreatedDate()) | ||
.build(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/org/prgrms/nabimarketbe/domain/suggestion/entity/DirectionType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.prgrms.nabimarketbe.domain.suggestion.entity; | ||
|
||
public enum DirectionType { | ||
SEND, | ||
RECEIVE | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/org/prgrms/nabimarketbe/domain/suggestion/entity/Suggestion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.prgrms.nabimarketbe.domain.suggestion.entity; | ||
|
||
import lombok.*; | ||
|
||
import org.prgrms.nabimarketbe.domain.card.entity.Card; | ||
import org.prgrms.nabimarketbe.global.BaseEntity; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
@Table(name = "suggestions") | ||
public class Suggestion extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long suggestionId; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private SuggestionType suggestionType; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "from_card", nullable = false) | ||
private Card fromCard; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "to_card", nullable = false) | ||
private Card toCard; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private SuggestionStatus suggestionStatus; | ||
|
||
@Builder | ||
public Suggestion( | ||
SuggestionType suggestionType, | ||
Card fromCard, | ||
Card toCard | ||
) { | ||
this.suggestionType = suggestionType; | ||
this.fromCard = fromCard; | ||
this.toCard = toCard; | ||
this.suggestionStatus = SuggestionStatus.WAITING; | ||
} | ||
|
||
public void acceptSuggestion() { | ||
this.suggestionStatus = SuggestionStatus.ACCEPTED; | ||
} | ||
|
||
public void refuseSuggestion() { | ||
this.suggestionStatus = SuggestionStatus.REFUSED; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/prgrms/nabimarketbe/domain/suggestion/entity/SuggestionStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.prgrms.nabimarketbe.domain.suggestion.entity; | ||
|
||
public enum SuggestionStatus { | ||
WAITING, | ||
ACCEPTED, | ||
REFUSED | ||
} |
3 changes: 2 additions & 1 deletion
3
src/main/java/org/prgrms/nabimarketbe/domain/suggestion/entity/SuggestionType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package org.prgrms.nabimarketbe.domain.suggestion.entity; | ||
|
||
public enum SuggestionType { | ||
OFFER, POKE | ||
OFFER, | ||
POKE | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/org/prgrms/nabimarketbe/domain/suggestion/repository/SuggestionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.prgrms.nabimarketbe.domain.suggestion.repository; | ||
|
||
import org.prgrms.nabimarketbe.domain.card.entity.Card; | ||
import org.prgrms.nabimarketbe.domain.suggestion.entity.Suggestion; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface SuggestionRepository extends JpaRepository<Suggestion, Long> , SuggestionRepositoryCustom{ | ||
Optional<Suggestion> findSuggestionByFromCardAndToCard(Card fromCard, Card toCard); | ||
} |
15 changes: 15 additions & 0 deletions
15
...java/org/prgrms/nabimarketbe/domain/suggestion/repository/SuggestionRepositoryCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.prgrms.nabimarketbe.domain.suggestion.repository; | ||
|
||
import org.prgrms.nabimarketbe.domain.suggestion.dto.response.SuggestionListReadPagingResponseDTO; | ||
import org.prgrms.nabimarketbe.domain.suggestion.entity.DirectionType; | ||
import org.prgrms.nabimarketbe.domain.suggestion.entity.SuggestionType; | ||
|
||
public interface SuggestionRepositoryCustom { | ||
SuggestionListReadPagingResponseDTO getSuggestionsByType( | ||
DirectionType directionType, | ||
SuggestionType suggestionType, | ||
Long cardId, | ||
String cursorId, | ||
Integer size | ||
); | ||
} |
Oops, something went wrong.