Skip to content
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

Open
wants to merge 16 commits into
base: jaehyeon
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LocalDateTime그대로 보내고 JsonFormat 해봐도 좋을듯

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
);
}
}
24 changes: 24 additions & 0 deletions src/main/java/team/haedal/gifticionfunding/dto/UserDto.java
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;
Expand All @@ -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)
Expand All @@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 setter사용인데 괜찮나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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;
Expand All @@ -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)
Expand All @@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거도 setter

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인정합니다

this.status = eFundingArticleGifticonStatus;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package team.haedal.gifticionfunding.entity.funding;

import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
Expand All @@ -11,8 +12,8 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import team.haedal.gifticionfunding.entity.common.BaseTimeEntity;
import team.haedal.gifticionfunding.entity.user.User;
import team.haedal.gifticionfunding.entity.gifticon.UserGifticon;
import team.haedal.gifticionfunding.entity.user.User;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand All @@ -24,23 +25,23 @@ public class FundingContribute extends BaseTimeEntity {

private Long point;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User contributor;

@ManyToOne
@JoinColumn(name = "funding_article_id")
private FundingArticle fundingArticle;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "funding_article_giftcion_id")
private FundingArticleGifticon fundingArticleGifticon;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_gifticon_id")
private UserGifticon userGifticon;

@Builder
private FundingContribute(Long point, User contributor, FundingArticle fundingArticle, UserGifticon userGifticon) {
private FundingContribute(Long point, User contributor, FundingArticleGifticon fundingArticleGifticon, UserGifticon userGifticon) {
this.point = point;
this.contributor = contributor;
this.fundingArticle = fundingArticle;
this.fundingArticleGifticon = fundingArticleGifticon;
this.userGifticon = userGifticon;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ public enum StoreBrand {
STARBUCKS, TWO_SOME_PLACE, EDIYA, HOLLYS, TOM_N_TOMS, COFFEE_BEAN, PARIS_BAGUETTE, BASKIN_ROBBINS, DUNKIN,

//Chicken
BBQ, BHC, GOOBNE, KYOCHON, NENE, PELicana, MOMS_TOUCH
BBQ, BHC, GOOBNE, KYOCHON, NENE,

//Clothes
ZARA, UNIQLO
}
Loading