-
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 branch 'dev' into NABI-125--yejin--feat--suggestion
- Loading branch information
Showing
19 changed files
with
463 additions
and
42 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
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
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
62 changes: 62 additions & 0 deletions
62
src/main/java/org/prgrms/nabimarketbe/domain/dibs/api/DibController.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,62 @@ | ||
package org.prgrms.nabimarketbe.domain.dibs.api; | ||
|
||
import org.prgrms.nabimarketbe.domain.dibs.dto.response.DibCreateResponseDTO; | ||
import org.prgrms.nabimarketbe.domain.dibs.dto.response.DibListReadPagingResponseDTO; | ||
import org.prgrms.nabimarketbe.domain.dibs.dto.response.DibResponseDTO; | ||
import org.prgrms.nabimarketbe.domain.dibs.service.DibService; | ||
import org.prgrms.nabimarketbe.global.util.ResponseFactory; | ||
import org.prgrms.nabimarketbe.global.util.model.CommonResult; | ||
import org.prgrms.nabimarketbe.global.util.model.SingleResult; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/dibs") | ||
@RestController | ||
public class DibController { | ||
private final DibService dibService; | ||
|
||
@PostMapping("/{cardId}") | ||
public ResponseEntity<SingleResult<DibResponseDTO<DibCreateResponseDTO>>> createDib( | ||
@RequestHeader(name = "authorization") String token, | ||
@PathVariable Long cardId | ||
) { | ||
DibResponseDTO<DibCreateResponseDTO> dibResponseDTO = dibService.createDib(token, cardId); | ||
|
||
return ResponseEntity.ok(ResponseFactory.getSingleResult(dibResponseDTO)); | ||
} | ||
|
||
@DeleteMapping("/{cardId}") | ||
public ResponseEntity<CommonResult> deleteDib( | ||
@RequestHeader(name = "authorization") String token, | ||
@PathVariable Long cardId | ||
) { | ||
dibService.deleteDib(token, cardId); | ||
|
||
return ResponseEntity.ok(ResponseFactory.getSuccessResult()); | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<SingleResult<DibListReadPagingResponseDTO>> getUserDibsByUserId( | ||
@RequestHeader(name = "authorization") String token, | ||
@RequestParam(required = false) Long cursorId, | ||
@RequestParam Integer size | ||
) { | ||
DibListReadPagingResponseDTO dibListReadPagingResponseDTO = dibService.getUserDibsByUserId( | ||
token, | ||
cursorId, | ||
size | ||
); | ||
|
||
return ResponseEntity.ok(ResponseFactory.getSingleResult(dibListReadPagingResponseDTO)); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/org/prgrms/nabimarketbe/domain/dibs/dto/response/DibCreateResponseDTO.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,26 @@ | ||
package org.prgrms.nabimarketbe.domain.dibs.dto.response; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import org.prgrms.nabimarketbe.domain.dibs.entity.Dib; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record DibCreateResponseDTO( | ||
Long dibId, | ||
Long cardId, | ||
Long userId, | ||
LocalDateTime createdAt, | ||
LocalDateTime modifiedAt | ||
) { | ||
public static DibCreateResponseDTO from(Dib dib) { | ||
return DibCreateResponseDTO.builder() | ||
.dibId(dib.getDibId()) | ||
.userId(dib.getUser().getUserId()) | ||
.cardId(dib.getCard().getCardId()) | ||
.createdAt(dib.getCreatedDate()) | ||
.modifiedAt(dib.getModifiedDate()) | ||
.build(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...n/java/org/prgrms/nabimarketbe/domain/dibs/dto/response/DibListReadPagingResponseDTO.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.dibs.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record DibListReadPagingResponseDTO ( | ||
List<DibListReadResponseDTO> dibList, | ||
Long nextCursorId | ||
) { | ||
public static DibListReadPagingResponseDTO of( | ||
List<DibListReadResponseDTO> dibList, | ||
Long nextCursorId | ||
) { | ||
return new DibListReadPagingResponseDTO(dibList, nextCursorId); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/prgrms/nabimarketbe/domain/dibs/dto/response/DibListReadResponseDTO.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,22 @@ | ||
package org.prgrms.nabimarketbe.domain.dibs.dto.response; | ||
|
||
import org.prgrms.nabimarketbe.domain.item.entity.PriceRange; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor | ||
@Getter | ||
public class DibListReadResponseDTO { | ||
private Long dibId; | ||
|
||
private Long cardId; | ||
|
||
private String cardTitle; | ||
|
||
private String itemName; | ||
|
||
private PriceRange priceRange; | ||
|
||
private String thumbNail; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/org/prgrms/nabimarketbe/domain/dibs/dto/response/DibResponseDTO.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.dibs.dto.response; | ||
|
||
public record DibResponseDTO<T>( | ||
T dibInfo | ||
) { | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/org/prgrms/nabimarketbe/domain/dibs/entity/Dib.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,46 @@ | ||
package org.prgrms.nabimarketbe.domain.dibs.entity; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.Table; | ||
|
||
import org.prgrms.nabimarketbe.domain.card.entity.Card; | ||
import org.prgrms.nabimarketbe.domain.user.entity.User; | ||
import org.prgrms.nabimarketbe.global.BaseEntity; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Entity | ||
@Table(name = "dibs") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Dib extends BaseEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "dib_id", nullable = false) | ||
private Long dibId; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id", nullable = false) | ||
private User user; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "card_id", nullable = false) | ||
private Card card; | ||
|
||
public Dib( | ||
User user, | ||
Card card | ||
) { | ||
this.user = user; | ||
this.card = card; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/prgrms/nabimarketbe/domain/dibs/repository/DibRepository.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,14 @@ | ||
package org.prgrms.nabimarketbe.domain.dibs.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.prgrms.nabimarketbe.domain.card.entity.Card; | ||
import org.prgrms.nabimarketbe.domain.dibs.entity.Dib; | ||
import org.prgrms.nabimarketbe.domain.user.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface DibRepository extends JpaRepository<Dib, Long>, DibRepositoryCustom{ | ||
Optional<Dib> findDibByUserAndCard(User user, Card card); | ||
|
||
boolean existsDibByCardAndUser(Card card, User user); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/org/prgrms/nabimarketbe/domain/dibs/repository/DibRepositoryCustom.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.dibs.repository; | ||
|
||
import org.prgrms.nabimarketbe.domain.dibs.dto.response.DibListReadPagingResponseDTO; | ||
|
||
public interface DibRepositoryCustom { | ||
DibListReadPagingResponseDTO getUserDibsByUserId( | ||
Long userId, | ||
Long cursorId, | ||
Integer size | ||
); | ||
} |
Oops, something went wrong.