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

해치웠나 ...? #17

Open
wants to merge 15 commits into
base: suhyeon
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ out/
### VS Code ###
.vscode/
src/main/resources/application.yml
src/main/java/team/haedal/gifticionfunding/service/OAuth2SuccessHandler.java
src/main/java/team/haedal/gifticionfunding/service/OAuth2SuccessHandler.java
src/main/resources/dataSample.sql
20 changes: 20 additions & 0 deletions src/main/java/team/haedal/gifticionfunding/common/DateUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package team.haedal.gifticionfunding.common;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

public final class DateUtils{
public static String dateToString(LocalDateTime localDateTime) {
return localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}


public static long diff(LocalDate start, LocalDate end){
return ChronoUnit.DAYS.between(
LocalDate.of(1, start.getMonth(), start.getDayOfMonth()),
LocalDate.of(1, end.getMonth(), end.getDayOfMonth()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public class SecurityConfig {


private static final String[] WHITE_LIST = {
"/api/auth/**",
"/api-docs/**",
"/login/**",
"**"
};

private static final String[] AUTHENTICATION_LIST = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI openAPI() {
String jwt = "accessToken";
SecurityRequirement securityRequirement = new SecurityRequirement().addList(jwt);
Components components = new Components().addSecuritySchemes(jwt, new SecurityScheme()
.name(jwt)
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT")
);
return new OpenAPI()
.components(new Components())
.info(apiInfo());
.components(components)
.info(apiInfo())
.addSecurityItem(securityRequirement);
}

private Info apiInfo() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package team.haedal.gifticionfunding.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import team.haedal.gifticionfunding.dto.PageResponse;
import team.haedal.gifticionfunding.dto.response.friend.FriendResponse;
import team.haedal.gifticionfunding.service.FriendService;

@RestController
@RequiredArgsConstructor
@EnableWebMvc
@RequestMapping("/api/friend")
@Tag(name="Friend",description="친구 관련 API")
public class FriendController {
//TODO: 친구 목록, 요청받은 친구 목록
//TODO: 친구 요청, 요청 수락, 요청 거절, 요청 취소
private final FriendService friendService;

@GetMapping()
@Operation(summary = "친구 목록 조회 API")
public ResponseEntity<PageResponse<FriendResponse>> getFriends(Authentication authentication,
@RequestParam(value="page", defaultValue="0") int page){
return ResponseEntity.status(HttpStatus.OK).body(friendService.getFriends(page,authentication.getName()));
}

@PostMapping("/request")
@Operation(summary = "친구 요청 API")
public void requestFriend(Authentication authentication,
@RequestParam(name="friend") Long id){
friendService.requestFriend(authentication.getName(),id);
}

@PostMapping("/accept")
@Operation(summary = "친구 수락 API")
public void acceptFriend(Authentication authentication,
@RequestParam(name="friend") Long id){
friendService.acceptFriend(authentication.getName(),id); }

@PostMapping("/reject")
@Operation(summary = "친구 거절 API")
public void rejectFriend(Authentication authentication,
@RequestParam(name="friend") Long id){
friendService.rejectFriend(authentication.getName(),id);
}

@GetMapping("/request")
@Operation(summary = "친구 요청 조회 API", description ="수락 대기중인 요청만 나타낸다.")
public ResponseEntity<PageResponse<FriendResponse>> getRequestedFriends(Authentication authentication,
@RequestParam(value="page", defaultValue="0") int page){
return ResponseEntity.status(HttpStatus.OK).body(friendService.getRequestedFriends(page, authentication.getName()));
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package team.haedal.gifticionfunding.controller;

import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import team.haedal.gifticionfunding.dto.PageResponse;
import team.haedal.gifticionfunding.dto.request.FundingArticleRequest;
import team.haedal.gifticionfunding.dto.request.FundingJoinRequest;
import team.haedal.gifticionfunding.dto.response.FundingResponse;
import team.haedal.gifticionfunding.service.FundingService;

@RestController
@RequiredArgsConstructor
@EnableWebMvc
@RequestMapping("/api/funding")
@Tag(name="Funding",description="펀딩 관련 API")
public class FundingController {
//TODO: 가능한 펀딩 조회, 참여한 펀딩 조회, 생성한 펀딩 조회
//TODO: 펀딩 생성 (유효하지 않은 기프티콘이 하나라도 포함된다면 전체 fail)
private final FundingService fundingService;

@GetMapping()
@Operation(summary = "가능한 펀딩 조회 API")
public ResponseEntity<PageResponse<FundingResponse>> getFundings(Authentication authentication,
@RequestParam(value="page", defaultValue="0") int page){
return ResponseEntity.status(HttpStatus.OK).body(fundingService.getFundings(page, authentication.getName()));
}

@GetMapping("/participate")
@Operation(summary = "참여한 펀딩 조회 API")
@Hidden
public ResponseEntity<PageResponse<FundingResponse>> getTakenFundings(Authentication authentication,
@RequestParam(value="page", defaultValue="0") int page){
return ResponseEntity.status(HttpStatus.OK).body(fundingService.getTakenFundings(page, authentication.getName()));
}

@GetMapping("/created")
@Operation(summary = "생성한 펀딩 조회 API")
public ResponseEntity<PageResponse<FundingResponse>> getCreatedFundgins(Authentication authentication,
@RequestParam(value="page", defaultValue="0") int page){
return ResponseEntity.status(HttpStatus.OK).body(fundingService.getCreatedFundgins(page, authentication.getName()));
}

@PostMapping()
@Operation(summary = "펀딩 생성 API")
public void createFunding(Authentication authentication,
@RequestBody FundingArticleRequest request){
fundingService.createFunding(authentication.getName(), request);
}

@PostMapping("/participate")
@Operation(summary = "펀딩 참여 API")
public void participateFunding(Authentication authentication,
@RequestBody FundingJoinRequest request){
fundingService.participateFunding(authentication.getName(), request);
}

}
67 changes: 67 additions & 0 deletions src/main/java/team/haedal/gifticionfunding/domain/Friendship.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package team.haedal.gifticionfunding.domain;

import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import team.haedal.gifticionfunding.domain.enums.FriendStatus;

import java.time.LocalDateTime;

@Entity
@Getter
@NoArgsConstructor
public class Friendship {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@OnDelete(action = OnDeleteAction.CASCADE)
private Member member;

@ManyToOne(fetch = FetchType.LAZY)
@OnDelete(action = OnDeleteAction.CASCADE)
private Member friend;

private LocalDateTime createdAt;

@Enumerated(EnumType.STRING)
private FriendStatus status;

@Builder
private Friendship(Long id, Member member, Member friend, LocalDateTime createdAt, FriendStatus status) {
this.id = id;
this.member = member;
this.friend = friend;
this.createdAt = createdAt;
this.status = status;
}

public static Friendship request(Member member, Member friend) {
return Friendship.builder()
.member(member)
.friend(friend)
.createdAt(LocalDateTime.now())
.status(FriendStatus.WAITING)
.build();
}

public static Friendship finish(Member member, Member friend) {
return Friendship.builder()
.member(member)
.friend(friend)
.createdAt(LocalDateTime.now())
.status(FriendStatus.ACCEPT)
.build();
}

public Friendship accept(){
this.status = FriendStatus.ACCEPT;
return this;
}


}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package team.haedal.gifticionfunding.domain;

import jakarta.annotation.Nullable;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -21,6 +18,7 @@
public class Gifticon {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "gifticon_id")
private Long id;
private int price;
private String name;
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/team/haedal/gifticionfunding/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import jakarta.annotation.Nullable;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.*;
import team.haedal.gifticionfunding.domain.enums.Role;

import java.time.LocalDate;
Expand All @@ -14,6 +11,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
@Getter
public class Member {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package team.haedal.gifticionfunding.domain.enums;

public enum FriendStatus {
ACCEPT, WAITING
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package team.haedal.gifticionfunding.domain.funding;

import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import team.haedal.gifticionfunding.domain.Gifticon;
import team.haedal.gifticionfunding.domain.Member;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@NoArgsConstructor
public class FundingArticle {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "funding_id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@OnDelete(action = OnDeleteAction.CASCADE)
private Member member;

private LocalDateTime createdAt;

private LocalDate endAt;

private String title;

@Column(length = 50000)
private String content;

@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "funding_gifticon",
joinColumns = @JoinColumn(name = "funding_id"),
inverseJoinColumns = @JoinColumn(name = "gifticon_id"))
private List<Gifticon> gifticonList = new ArrayList<>();

@Builder
private FundingArticle(Long id, Member member, LocalDateTime createdAt, LocalDate endAt, String title, String content, List<Gifticon> gifticonList){
this.id = id;
this.member = member;
this.createdAt = createdAt;
this.endAt = endAt;
this.title = title;
this.content = content;
this.gifticonList = gifticonList;
}


public static FundingArticle of(Member member, LocalDate endAt, String title, String content, List<Gifticon> gifticonList){
return FundingArticle.builder()
.member(member)
.createdAt(LocalDateTime.now())
.endAt(endAt)
.title(title)
.content(content)
.gifticonList(gifticonList)
.build();
}
}
Loading