-
Notifications
You must be signed in to change notification settings - Fork 4
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
마지막 #16
base: jaehyeon
Are you sure you want to change the base?
마지막 #16
Changes from all commits
8437a3b
3dc1b23
bf4ab5d
b7ca735
dd155fb
c438b3f
378656c
9cf625f
1d21d54
e453339
625a176
2428931
a187182
674ca32
0285e80
6bd4fa8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package team.haedal.gifticionfunding.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import team.haedal.gifticionfunding.annotation.UserId; | ||
import team.haedal.gifticionfunding.dto.UserDto; | ||
import team.haedal.gifticionfunding.dto.common.PagingResponse; | ||
import team.haedal.gifticionfunding.dto.common.ResponseDto; | ||
import team.haedal.gifticionfunding.service.FriendshipService; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
@RequiredArgsConstructor | ||
public class FriendshipController { | ||
private final FriendshipService friendshipService; | ||
|
||
@GetMapping("/v1/profile/friends") | ||
public ResponseEntity<?> getFriends( | ||
@UserId Long userId, | ||
@RequestParam(value = "depth", defaultValue = "1") Integer depth, | ||
@RequestParam(value = "page", defaultValue = "0") Integer page, | ||
@RequestParam(value = "size", defaultValue = "10") Integer size | ||
) { | ||
PagingResponse<UserDto> userDtoPage = friendshipService.getFriends(userId, depth, page, size); | ||
return new ResponseEntity<>( | ||
new ResponseDto<>(1, "친구 목록 조회 성공", userDtoPage), | ||
HttpStatus.OK | ||
); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package team.haedal.gifticionfunding.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import team.haedal.gifticionfunding.annotation.UserId; | ||
import team.haedal.gifticionfunding.dto.FundingArticleDetailDto; | ||
import team.haedal.gifticionfunding.dto.FundingArticleDto; | ||
import team.haedal.gifticionfunding.dto.common.PagingResponse; | ||
import team.haedal.gifticionfunding.dto.common.ResponseDto; | ||
import team.haedal.gifticionfunding.service.FundingArticleService; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
@RequiredArgsConstructor | ||
public class FundingArticleController { | ||
private final FundingArticleService fundingArticleService; | ||
|
||
@GetMapping("/v1/fundings/articles") | ||
public ResponseEntity<?> getFundingArticles( | ||
@UserId Long userId, | ||
@RequestParam(value = "page", defaultValue = "0") Integer page, | ||
@RequestParam(value = "size", defaultValue = "10") Integer size | ||
) { | ||
PagingResponse<FundingArticleDto> fundingArticleDtoPage = fundingArticleService.getFundingArticles(userId, page, size); | ||
return new ResponseEntity<>( | ||
new ResponseDto<>(1, "펀딩 게시글 목록 조회 성공", fundingArticleDtoPage), | ||
HttpStatus.OK | ||
); | ||
} | ||
|
||
@GetMapping("/v1/fundings/articles/{articleId}") | ||
public ResponseEntity<?> getFundingArticle( | ||
@UserId Long userId, | ||
@RequestParam(value = "articleId") Long articleId | ||
) { | ||
FundingArticleDetailDto fundingArticleDto = fundingArticleService.getFundingArticle(userId, articleId); | ||
return new ResponseEntity<>( | ||
new ResponseDto<>(1, "펀딩 게시글 조회 성공", fundingArticleDto), | ||
HttpStatus.OK | ||
); | ||
} | ||
|
||
@PatchMapping("/v1/fundings/articles/{articleId}/expiration") | ||
public ResponseEntity<?> updateFundingArticleExpiration( | ||
@UserId Long userId, | ||
@RequestParam(value = "articleId") Long articleId | ||
) { | ||
fundingArticleService.updateFundingArticleExpiration(userId, articleId); | ||
return new ResponseEntity<>( | ||
new ResponseDto<>(1, "펀딩 게시글 연장 성공", null), | ||
HttpStatus.OK | ||
); | ||
} | ||
|
||
@PostMapping("/v1/fundings/articles/gifticons/{fundingArticleGifticonId}/success") | ||
public ResponseEntity<?> receiveFunding( | ||
@UserId Long userId, | ||
@RequestParam(value = "fundingArticleGifticonId") Long fundingArticleGifticonId | ||
) { | ||
fundingArticleService.receiveFunding(userId, fundingArticleGifticonId); | ||
return new ResponseEntity<>( | ||
new ResponseDto<>(1, "펀딩 게시글 성공 처리 성공", null), | ||
HttpStatus.OK | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package team.haedal.gifticionfunding.dto; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import team.haedal.gifticionfunding.entity.funding.FundingArticle; | ||
|
||
public record FundingArticleDetailDto( | ||
String author, | ||
String birthdate, | ||
String title, | ||
String content, | ||
String endAt, | ||
List<FundingArticleGifticonDto> goalGifticons | ||
) { | ||
|
||
public static FundingArticleDetailDto of( | ||
FundingArticle fundingArticle, | ||
Map<Long, Integer> fundAmountMap, | ||
Map<Long, Integer> numberOfSupportersMap | ||
) { | ||
return new FundingArticleDetailDto( | ||
fundingArticle.getAuthor().getNickname(), | ||
fundingArticle.getAuthor().getBirthdate().toString(), | ||
fundingArticle.getTitle(), | ||
fundingArticle.getContent(), | ||
fundingArticle.getEndAt().toString(), | ||
fundingArticle.getGifticons().stream() | ||
.map(fundingArticleGifticon -> FundingArticleGifticonDto.of( | ||
fundingArticleGifticon, | ||
fundAmountMap.getOrDefault(fundingArticleGifticon.getId(), 0), | ||
numberOfSupportersMap.getOrDefault(fundingArticleGifticon.getId(), 0) | ||
) | ||
) | ||
.toList() | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package team.haedal.gifticionfunding.dto; | ||
|
||
import java.time.format.DateTimeFormatter; | ||
import java.util.List; | ||
import team.haedal.gifticionfunding.entity.funding.FundingArticle; | ||
|
||
public record FundingArticleDto( | ||
String author, | ||
String birthdate, | ||
String title, | ||
String content, | ||
String endAt, | ||
List<String> gificonImageUrls | ||
) { | ||
public static FundingArticleDto fromEntity(FundingArticle fundingArticle) { | ||
return new FundingArticleDto( | ||
fundingArticle.getAuthor().getNickname(), | ||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(fundingArticle.getAuthor().getBirthdate()), | ||
fundingArticle.getTitle(), | ||
fundingArticle.getContent(), | ||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(fundingArticle.getEndAt()), | ||
fundingArticle.getGifticons().stream() | ||
.map(g -> g.getGifticon().getImageUrl()) | ||
.toList() | ||
); | ||
|
||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package team.haedal.gifticionfunding.dto; | ||
|
||
import team.haedal.gifticionfunding.entity.funding.FundingArticleGifticon; | ||
|
||
public record FundingArticleGifticonDto( | ||
String gifticonName, | ||
Integer price, | ||
String category, | ||
String imageUrl, | ||
Integer achievementRate, | ||
Integer currentFundAmount, | ||
Integer numberOfSupporters | ||
) { | ||
|
||
public static FundingArticleGifticonDto of(FundingArticleGifticon fundingArticleGifticon, Integer currentFundAmount, Integer numberOfSupporters) { | ||
int achievementRate = (int) ((double) currentFundAmount / fundingArticleGifticon.getGifticon().getPrice() * 100); | ||
int price = fundingArticleGifticon.getGifticon().getPrice().intValue(); | ||
|
||
return new FundingArticleGifticonDto( | ||
fundingArticleGifticon.getGifticon().getName(), | ||
price, | ||
fundingArticleGifticon.getGifticon().getCategory().toString(), | ||
fundingArticleGifticon.getGifticon().getImageUrl(), | ||
achievementRate, | ||
currentFundAmount, | ||
numberOfSupporters | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package team.haedal.gifticionfunding.dto; | ||
|
||
import java.time.format.DateTimeFormatter; | ||
import lombok.Builder; | ||
import team.haedal.gifticionfunding.entity.user.User; | ||
|
||
@Builder | ||
public record UserDto ( | ||
Long id, | ||
String name, | ||
String birthdate, | ||
String profileImageUrl | ||
){ | ||
public static UserDto fromEntity(User user) { | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | ||
|
||
return UserDto.builder() | ||
.id(user.getId()) | ||
.birthdate(user.getBirthdate().format(formatter)) | ||
.profileImageUrl(user.getProfileImageUrl()) | ||
.name(user.getNickname()) | ||
.build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
package team.haedal.gifticionfunding.entity.funding; | ||
|
||
import jakarta.persistence.CascadeType; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
|
@@ -16,12 +19,15 @@ | |
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.DynamicUpdate; | ||
import team.haedal.gifticionfunding.entity.common.BaseTimeEntity; | ||
import team.haedal.gifticionfunding.entity.type.EFundingArticleStatus; | ||
import team.haedal.gifticionfunding.entity.user.User; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Entity | ||
@DynamicUpdate | ||
public class FundingArticle extends BaseTimeEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
|
@@ -40,13 +46,27 @@ public class FundingArticle extends BaseTimeEntity { | |
@Column(nullable = false) | ||
private LocalDateTime endAt; | ||
|
||
@OneToMany(mappedBy = "fundingArticle", fetch = FetchType.LAZY) | ||
@Enumerated(EnumType.STRING) | ||
@Column(nullable = false) | ||
private EFundingArticleStatus status; | ||
|
||
@OneToMany(mappedBy = "fundingArticle", fetch = FetchType.LAZY, cascade = CascadeType.ALL) | ||
private List<FundingArticleGifticon> gifticons = new ArrayList<>(); | ||
@Builder | ||
private FundingArticle(User author, String title, String content, LocalDateTime endAt) { | ||
this.author = author; | ||
this.title = title; | ||
this.content = content; | ||
this.endAt = endAt; | ||
|
||
this.status = EFundingArticleStatus.PROCESSING; | ||
} | ||
|
||
public void updateExpiration(int maxExtensionDate) { | ||
this.endAt = this.endAt.plusDays(maxExtensionDate); | ||
} | ||
|
||
public void updateStatus(EFundingArticleStatus status) { | ||
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. 이거 setter사용인데 괜찮나요? 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. 인정합니다 |
||
this.status = status; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package team.haedal.gifticionfunding.entity.funding; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
|
@@ -12,6 +15,7 @@ | |
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import team.haedal.gifticionfunding.entity.gifticon.Gifticon; | ||
import team.haedal.gifticionfunding.entity.type.EFundingArticleGifticonStatus; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
|
@@ -29,9 +33,17 @@ public class FundingArticleGifticon { | |
@JoinColumn(name = "funding_article_id") | ||
private FundingArticle fundingArticle; | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(nullable = false) | ||
private EFundingArticleGifticonStatus status; | ||
|
||
@Builder | ||
private FundingArticleGifticon(Gifticon gifticon, FundingArticle fundingArticle) { | ||
this.gifticon = gifticon; | ||
this.fundingArticle = fundingArticle; | ||
} | ||
|
||
public void updateStatus(EFundingArticleGifticonStatus eFundingArticleGifticonStatus) { | ||
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. 이거도 setter 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. 인정합니다 |
||
this.status = eFundingArticleGifticonStatus; | ||
} | ||
} |
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.
LocalDateTime그대로 보내고 JsonFormat 해봐도 좋을듯