-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/buyornot' into dev
- Loading branch information
Showing
13 changed files
with
571 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.goolbitg.api.entity; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.MappedSuperclass; | ||
|
||
import org.hibernate.annotations.CreationTimestamp; | ||
import org.hibernate.annotations.UpdateTimestamp; | ||
|
||
/** | ||
* BaseEntity | ||
*/ | ||
@MappedSuperclass | ||
public abstract class BaseEntity { | ||
|
||
@CreationTimestamp | ||
@Column(name = "created_at", updatable = false) | ||
private LocalDateTime createdAt; | ||
|
||
@UpdateTimestamp | ||
@Column(name = "updated_at") | ||
private LocalDateTime updatedAt; | ||
|
||
} |
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,45 @@ | ||
package com.goolbitg.api.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
/** | ||
* BuyOrNot | ||
*/ | ||
@Entity | ||
@Table(name = "buyornots") | ||
@Getter | ||
@Setter | ||
public class BuyOrNot { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id") | ||
private Long id; | ||
|
||
@Column(name = "writer_id") | ||
private String writerId; | ||
|
||
@Column(name = "product_name") | ||
private String productName; | ||
|
||
@Column(name = "product_price") | ||
private Integer productPrice; | ||
|
||
@Column(name = "product_image_url") | ||
private String productImageUrl; | ||
|
||
@Column(name = "good_reason") | ||
private String goodReason; | ||
|
||
@Column(name = "bad_reason") | ||
private String badReason; | ||
|
||
} |
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,39 @@ | ||
package com.goolbitg.api.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.IdClass; | ||
import jakarta.persistence.Table; | ||
|
||
import com.goolbitg.api.model.BuyOrNotVoteType; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
/** | ||
* BuyOrNotVote | ||
*/ | ||
@Entity | ||
@Table(name = "buyornot_votes") | ||
@IdClass(BuyOrNotVoteId.class) | ||
@Getter | ||
@Setter | ||
// TODO: extends base entity | ||
public class BuyOrNotVote { | ||
|
||
@Id | ||
@Column(name = "post_id") | ||
private Long postId; | ||
|
||
@Id | ||
@Column(name = "voter_id") | ||
private String voterId; | ||
|
||
@Column(name = "vote") | ||
@Enumerated(EnumType.STRING) | ||
private BuyOrNotVoteType vote; | ||
|
||
} |
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 com.goolbitg.api.entity; | ||
|
||
/** | ||
* BuyOrNotVoteId | ||
*/ | ||
public record BuyOrNotVoteId(Long postId, String voterId) { | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/goolbitg/api/repository/BuyOrNotRepository.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,16 @@ | ||
package com.goolbitg.api.repository; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.goolbitg.api.entity.BuyOrNot; | ||
|
||
/** | ||
* BuyOrNotRepository | ||
*/ | ||
public interface BuyOrNotRepository extends JpaRepository<BuyOrNot, Long> { | ||
|
||
Page<BuyOrNot> findAllByWriterId(String loginUserId, Pageable pageReq); | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/goolbitg/api/repository/BuyOrNotVoteRepository.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,24 @@ | ||
package com.goolbitg.api.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import com.goolbitg.api.entity.BuyOrNotVote; | ||
import com.goolbitg.api.entity.BuyOrNotVoteId; | ||
import com.goolbitg.api.model.BuyOrNotVoteType; | ||
|
||
/** | ||
* BuyOrNotVoteRepository | ||
*/ | ||
public interface BuyOrNotVoteRepository extends JpaRepository<BuyOrNotVote, BuyOrNotVoteId> { | ||
|
||
@Query(""" | ||
SELECT COUNT(v) | ||
FROM BuyOrNotVote v | ||
WHERE v.postId = :postId | ||
AND v.vote = :vote | ||
""") | ||
Integer getCountOf(@Param("postId") Long postId, @Param("vote") BuyOrNotVoteType vote); | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/goolbitg/api/service/BuyOrNotService.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,20 @@ | ||
package com.goolbitg.api.service; | ||
|
||
import com.goolbitg.api.model.BuyOrNotDto; | ||
import com.goolbitg.api.model.BuyOrNotVoteChangeDto; | ||
import com.goolbitg.api.model.BuyOrNotVoteDto; | ||
import com.goolbitg.api.model.PaginatedBuyOrNotDto; | ||
|
||
/** | ||
* BuyOrNotService | ||
*/ | ||
public interface BuyOrNotService { | ||
|
||
BuyOrNotDto getBuyOrNot(Long postId); | ||
PaginatedBuyOrNotDto getBuyOrNots(Integer page, Integer size, Boolean created); | ||
BuyOrNotDto createBuyOrNot(BuyOrNotDto request); | ||
BuyOrNotDto updateBuyOrNot(Long postId, BuyOrNotDto request); | ||
void deleteBuyOrNot(Long postId); | ||
BuyOrNotVoteChangeDto voteBuyOrNot(Long postId, BuyOrNotVoteDto request); | ||
|
||
} |
Oops, something went wrong.