Skip to content

Commit

Permalink
Merge pull request #25 from team-nabi/NABI-125--yejin--feat--suggestion
Browse files Browse the repository at this point in the history
Nabi-125-- 제안 생성 / 조회 / 결정 구현
  • Loading branch information
born-A authored Nov 9, 2023
2 parents 97bb32e + d0a1375 commit 99917fb
Show file tree
Hide file tree
Showing 16 changed files with 516 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class Card extends BaseEntity {
@Column(name = "card_title", nullable = false)
private String cardTitle;

// @NotBlank(message = "공백을 허용하지 않습니다.")
@Column(name = "thumbnail_image")
private String thumbNailImage;

Expand Down
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);
}
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));
}
}
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
) {
}
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
) {
}
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;
}
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();
}
}
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
}
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;
}
}
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
}
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
}
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);
}
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
);
}
Loading

0 comments on commit 99917fb

Please sign in to comment.