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

Feature/3 branch mentoring -> weekly #16

Merged
merged 48 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
780764a
feat : MentorPost Entity
sjmjys954646 Oct 3, 2023
0010940
feat : MentorPost Entity Builder
sjmjys954646 Oct 3, 2023
320ba13
feat : MentorPost Service
sjmjys954646 Oct 3, 2023
9ec71bc
feat : MentorPostRequest
sjmjys954646 Oct 3, 2023
5ce263a
feat : MentorPost RestController
sjmjys954646 Oct 3, 2023
84a42fe
feat : MentorPostCreate Test
sjmjys954646 Oct 3, 2023
7305885
feat : Swagger 3.0 기능 추가
choboss00 Oct 4, 2023
f156e79
feat : swagger 라이브러리 추가
choboss00 Oct 4, 2023
9e0570c
feat : swagger 3.0 경로 설정
choboss00 Oct 4, 2023
a6e2a1b
feat : 예시 기능 작성
choboss00 Oct 4, 2023
4070e2f
Create SpringBoot-CI.yml
choboss00 Oct 4, 2023
0ffde67
Update SpringBoot-CI.yml
choboss00 Oct 4, 2023
3c0ef51
feat : CI 권한설정
choboss00 Oct 4, 2023
93defee
fix : java version 의 distribution 수정
choboss00 Oct 4, 2023
9e18b7c
feat : application-test.yml 경로 설정
choboss00 Oct 4, 2023
20e573f
fix : SpringBoot-CI 파일 수정
choboss00 Oct 4, 2023
5e33cdf
fix : SpringBoot-CI 파일의 잘못된 코드 수정
choboss00 Oct 4, 2023
5015c5f
Merge pull request #10 from choboss00/feature/3-branch-mentoring
sjmjys954646 Oct 4, 2023
be357e0
feat : interest 테이블, JPA 작성
choboss00 Oct 6, 2023
e5be801
feat : userInterest 테이블, JPA 작성
choboss00 Oct 6, 2023
77f6d72
fix : Account 의 id 이름 변경
choboss00 Oct 6, 2023
63d5191
feat : notConnectedRegisterUser 테이블 생성
choboss00 Oct 6, 2023
416b5c5
feat : 멘토 기준 contact 응답 DTO 작성
choboss00 Oct 6, 2023
39713ff
feat : 멘토 기준 contact 조회 기능 추가
choboss00 Oct 6, 2023
818b215
feat : ConnectedUser 테이블 생성
choboss00 Oct 6, 2023
d09ea8b
feat : contact 조회를 위해 mentorPost 테이블, mentorPostJPA 생성
choboss00 Oct 6, 2023
7a2ebeb
feat : findById method 추가
choboss00 Oct 6, 2023
5419c8c
fix : 고쳐야하는 부분 수정
choboss00 Oct 6, 2023
1f74365
docs : ContactSerivce 주석 수정
choboss00 Oct 6, 2023
bcaaf1d
fix : userInterest 생성자 수정
choboss00 Oct 6, 2023
b6bbefa
fix : 쿼리문 수정
choboss00 Oct 6, 2023
84b892b
test : 로직 실행 테스트
choboss00 Oct 6, 2023
237c463
fix : 쿼리문 수정
choboss00 Oct 6, 2023
cc3af90
fix : 쿼리문 수정
choboss00 Oct 6, 2023
7cddf55
fix : mentor, mentee DTO 에 role 추가
choboss00 Oct 6, 2023
10acfd5
fix : DTO 철자 수정
choboss00 Oct 6, 2023
7f06e1c
fix : mentee state 추가
choboss00 Oct 6, 2023
29523f8
Merge pull request #12 from choboss00/feature/3-branch-mentoring
comom87 Oct 7, 2023
d297105
feat : Merge and add MentorPostResponse
sjmjys954646 Oct 8, 2023
546ea95
fix : createDateTest
sjmjys954646 Oct 8, 2023
f30b5c0
Merge pull request #14 from sjmjys954646/feature/3-branch-mentoring
choboss00 Oct 8, 2023
fc6e946
merge : 1-branch, 3-branch
sjmjys954646 Oct 8, 2023
9374cae
merge : 1-branch, 3-branch change BaseTimeEntity to BaseTime
sjmjys954646 Oct 8, 2023
db1d795
fix : Account -> User 오타 수정 및 테스트 코드 통과
choboss00 Oct 8, 2023
ee06528
docs : 주석 제거
choboss00 Oct 8, 2023
2ba56b5
fix : H2 CI 테스트를 위해 인메모리 형식으로 변경
choboss00 Oct 8, 2023
685391d
fix : 테이블 이름 수정
choboss00 Oct 8, 2023
418a633
Merge pull request #17 from choboss00/feature/3-branch-mentoring
sjmjys954646 Oct 8, 2023
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
45 changes: 45 additions & 0 deletions .github/workflows/SpringBoot-CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Spring Boot CI
on:
pull_request:
branches:
- weekly # 'weekly' 브랜치로 PR이 생성될 때만 실행
jobs:
build:
runs-on: ubuntu-latest # job 가상환경 설정

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'temurin'
- name: Gradle 명령 실행을 위한 권한을 부여합니다
run: chmod +x gradlew
- name: Cache Gradle dependencies
uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build and Test
run: ./gradlew clean build
- name: Run Spring Boot App for 30 seconds
run: |
./gradlew bootRun &
APP_PID=$!
sleep 30
kill $APP_PID
continue-on-error: false
- name: 테스트 결과를 PR에 코멘트로 등록합니다
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
with:
files: '**/build/test-results/test/TEST-*.xml'
- name: 테스트 실패 시, 실패한 코드 라인에 Check 코멘트를 등록합니다
uses: mikepenz/action-junit-report@v3
if: always()
with:
report_paths: '**/build/test-results/test/TEST-*.xml'
token: ${{ github.token }}
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-devtools'

// local, test : h2
runtimeOnly 'com.h2database:h2'
implementation 'com.h2database:h2'

// swagger
implementation 'io.springfox:springfox-boot-starter:3.0.0'
implementation 'io.springfox:springfox-swagger-ui:3.0.0'
}

tasks.named('test') {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/demo/GardenBeApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@SpringBootApplication
@EnableJpaAuditing
@SpringBootApplication
public class GardenBeApplication {

public static void main(String[] args) {
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@
@RequiredArgsConstructor
@Getter
public class CustomUserDetails implements UserDetails {
private final User account;
private final User user;

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
return Arrays.stream(account.getEmail().split(",")).map(SimpleGrantedAuthority::new).collect(Collectors.toList());
return Arrays.stream(user.getEmail().split(",")).map(SimpleGrantedAuthority::new).collect(Collectors.toList());
}

@Override
public String getPassword() {
return account.getPassword();
return user.getPassword();
}

@Override
public String getUsername() {
return account.getEmail();
return user.getEmail();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse

try {
DecodedJWT decodedJWT = JWTTokenProvider.verify(jwt);
int uid = decodedJWT.getClaim("user_id").asInt();
int id = decodedJWT.getClaim("user_id").asInt();
String email = decodedJWT.getClaim("user_email").asString();
User user = User.builder().id(uid).email(email).build();
User user = User.builder().id(id).email(email).build();
CustomUserDetails customUserDetails = new CustomUserDetails(user);
Authentication authentication =
new UsernamePasswordAuthenticationToken(
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/example/demo/config/swagger/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.example.demo.config.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
private String version = "V0.1";

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo());
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("제목")
.description("설명")
.version(version)
.contact(new Contact("이름", "홈페이지 URL", "e-mail"))
.build();
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/example/demo/interest/Interest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name = "interest")
@Table(name = "interest_tb")
public class Interest {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/example/demo/mentoring/MentorPost.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.demo.mentoring;

import com.example.demo.config.utils.BaseTime;
import com.example.demo.user.User;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.*;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(name = "mentorPost_tb")
public class MentorPost extends BaseTime {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

@ManyToOne(fetch = FetchType.LAZY)
private User writer;

@Column(nullable = false)
private String title;

private String content;

@Builder
public MentorPost(User writer, String title, String content){
this.writer = writer;
this.title = title;
this.content = content;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.demo.mentoring;

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface MentorPostJPARepostiory extends JpaRepository<MentorPost, Integer> {

@Query("select m from MentorPost m where m.writer.id = :writer")
List<MentorPost> findAllByWriter(@Param("writer") int writer);

MentorPost findById(int id);
}
26 changes: 26 additions & 0 deletions src/main/java/com/example/demo/mentoring/MentorPostRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.demo.mentoring;

import com.example.demo.user.User;
import lombok.Getter;
import lombok.Setter;
import javax.validation.constraints.NotNull;

public class MentorPostRequest {

@Getter
@Setter
public class CreateDTO {
@NotNull
private String title;

private String content;

public MentorPost toEntity(User writer) {
return MentorPost.builder()
.writer(writer)
.title(title)
.content(content)
.build();
}
}
}
52 changes: 52 additions & 0 deletions src/main/java/com/example/demo/mentoring/MentorPostResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.example.demo.mentoring;


import com.example.demo.user.Role;
import com.example.demo.user.User;
import com.example.demo.user.userInterest.UserInterest;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.stream.Collectors;

public class MentorPostResponse {

@Getter
@Setter
public static class MentorPostDTO {
private int postId;
private String title;
private String content;
private WriterDTO writerDTO;

public MentorPostDTO(MentorPost mentorPost, WriterDTO writerDTO) {
this.postId = mentorPost.getId();
this.title = mentorPost.getTitle();
this.content = mentorPost.getContent();
this.writerDTO = writerDTO;
}

@Getter @Setter
public static class WriterDTO {
private int mentorId;
private String profileImage;
private String name;
private String country;
private Role role;
private List<String> favorites;

public WriterDTO(User user, List<UserInterest> userInterests) {
this.mentorId = user.getId();
this.profileImage = user.getProfileImage();
this.name = user.getFirstName() + " " + user.getLastName();
this.country = user.getCountry();
this.role = user.getRole();
this.favorites = userInterests.stream()
.filter(userInterest -> userInterest.getUser().getId() == user.getId())
.map(userInterest -> userInterest.getInterest().getCategory())
.collect(Collectors.toList());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.demo.mentoring;

import com.example.demo.config.auth.CustomUserDetails;
import com.example.demo.config.utils.ApiUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;

@RequiredArgsConstructor
@RestController
public class MentorPostRestController {
private final MentorPostService mentorPostService;

@PostMapping(value = "/mentorings")
public ResponseEntity<?> createMentorPost(@RequestPart MentorPostRequest.CreateDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) {
mentorPostService.createMentorPost(requestDTO, userDetails.getUser());
return ResponseEntity.ok().body(ApiUtils.success(true));
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/example/demo/mentoring/MentorPostService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.example.demo.mentoring;

import com.example.demo.user.User;
import com.example.demo.user.userInterest.UserInterest;
import com.example.demo.user.userInterest.UserInterestJPARepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Transactional
@RequiredArgsConstructor
@Service
public class MentorPostService {
private final MentorPostJPARepostiory mentorPostJPARepostiory;
private final UserInterestJPARepository userInterestJPARepository;

//mentorPost생성
@Transactional
public void createMentorPost(MentorPostRequest.CreateDTO createDTO, User writer) {
mentorPostJPARepostiory.save(createDTO.toEntity(writer));
}

/* 1. mentorPostList를 조회
2. 각 List당 writer별 writerInterests를 조회
3. MentorPostDTO 생성*/
public List<MentorPostResponse.MentorPostDTO> findAllMentorPost() {
List<MentorPost> mentorPostList = mentorPostJPARepostiory.findAll();
List<MentorPostResponse.MentorPostDTO> mentorPostDTOList = mentorPostList.stream().map(
mentorPost -> {
List<UserInterest> writerInterests = userInterestJPARepository.findAllById(mentorPost.getWriter().getId());
MentorPostResponse.MentorPostDTO.WriterDTO writerDTO = new MentorPostResponse.MentorPostDTO.WriterDTO(mentorPost.getWriter(), writerInterests);
return new MentorPostResponse.MentorPostDTO(mentorPost,writerDTO);
}
).collect(Collectors.toList());
return mentorPostDTOList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.demo.mentoring.contact;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ContactJPARepository extends JpaRepository<NotConnectedRegisterUser, Integer> {

@Query("SELECT ncru FROM NotConnectedRegisterUser ncru WHERE ncru.mentorPost.id = :mentorPostId")
List<NotConnectedRegisterUser> findAllByMentorPostId(@Param("mentorPostId") int mentorPostId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.example.demo.mentoring.contact;

public class ContactRequest {
}
Loading
Loading