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

Report old #135

Merged
merged 28 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b6cd4a1
Merge pull request #123 from DSM-PEAR/develop
syxxn Dec 15, 2020
95d212a
modify member testcode 4->5
syxxn Dec 15, 2020
e711c64
modify member controller test
syxxn Dec 15, 2020
d3a6e3a
modify notice controller test 4->5
syxxn Dec 15, 2020
88fc157
Merge pull request #124 from DSM-PEAR/profile
syxxn Dec 15, 2020
d85d515
add team name
jhhong0509 Dec 15, 2020
df800a1
Merge branch 'develop' of https://github.com/DSM-PEAR/user_backend in…
jhhong0509 Dec 15, 2020
df34041
Merge pull request #125 from DSM-PEAR/develop
syxxn Dec 16, 2020
be4f1cb
update test codes
jhhong0509 Dec 16, 2020
880a304
Merge pull request #126 from DSM-PEAR/report_old
jhhong0509 Dec 16, 2020
1ba3ff7
update searchControllerTest
jhhong0509 Dec 16, 2020
3390e28
modify: memberControllerTest
syxxn Dec 16, 2020
13d911a
modify: noticeControllerTest
syxxn Dec 16, 2020
9ff3afa
modify: noticeControllerTest
syxxn Dec 16, 2020
dd134cb
modify: myPageControllerTest
syxxn Dec 16, 2020
6608c5c
modify: questionControllerTest
syxxn Dec 16, 2020
a280fdd
Merge pull request #129 from DSM-PEAR/develop
syxxn Dec 16, 2020
adcec16
update report bug
jhhong0509 Dec 16, 2020
c3d2951
modify : memberContollerTest
syxxn Dec 16, 2020
bf85ea5
Merge pull request #130 from DSM-PEAR/develop
syxxn Dec 16, 2020
45ba1ce
modify : member Controller Test
syxxn Dec 16, 2020
de6ac4d
Merge pull request #131 from DSM-PEAR/member
syxxn Dec 16, 2020
088c799
modify notice controller test
syxxn Dec 16, 2020
e5ef866
modify: mypage controller test
syxxn Dec 16, 2020
0d15a77
Merge pull request #128 from DSM-PEAR/test
syxxn Dec 16, 2020
5e13f18
update report testcode
jhhong0509 Dec 16, 2020
b263a36
Merge branch 'develop' of https://github.com/DSM-PEAR/user_backend in…
jhhong0509 Dec 16, 2020
eaf912d
fix report entity
jhhong0509 Dec 16, 2020
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,18 @@
package com.dsmpear.main.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ObjectMapperConfiguration {
@Bean
public ObjectMapper objectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
return mapper;
}
}
11 changes: 8 additions & 3 deletions src/main/java/com/dsmpear/main/entity/report/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.time.LocalDateTime;
Expand All @@ -32,6 +33,7 @@ public class Report {
private String description;

@Column(name = "created_at", nullable = false)
@DateTimeFormat(pattern = "yyyy-MM-dd kk:mm:ss")
private LocalDateTime createdAt;

@Column(nullable = false)
Expand All @@ -47,10 +49,10 @@ public class Report {
private Type type;

@Column(name = "is_accepted", nullable = false)
private boolean isAccepted;
private Boolean isAccepted;

@Column(name = "is_submitted", nullable = false)
private boolean isSubmitted;
private Boolean isSubmitted;

@Column(name = "file_name",nullable = false)
private String fileName;
Expand All @@ -61,6 +63,9 @@ public class Report {
@Column(nullable = false)
private String languages;

@Column(nullable = false, name = "team_name")
private String teamName;

@OneToMany(cascade=CascadeType.ALL, mappedBy = "report")
private List<Member> members;

Expand All @@ -72,7 +77,7 @@ public Report update(ReportRequest reportRequest) {
this.access = reportRequest.getAccess();
this.field = reportRequest.getField();
this.grade = reportRequest.getGrade();
this.isSubmitted = reportRequest.isSubmitted();
this.isSubmitted = reportRequest.getIsSubmitted();
this.fileName = reportRequest.getFileName();
this.github = reportRequest.getGithub();
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ public interface ReportRepository extends CrudRepository<Report,Integer> {
Optional<Report> findByReportId(Integer reportId);

// 필터가 분야, 타입 모두 적용시 ORM
Page<Report> findAllByAccessAndFieldAndTypeAndGradeAndIsAcceptedTrueAndIsSubmittedTrue(Access access, Field field, Type type, Grade grade, Pageable page);
Page<Report> findAllByAccessAndFieldAndTypeAndGradeAndIsAcceptedTrueAndIsSubmittedTrueOrderByCreatedAtDesc(Access access, Field field, Type type, Grade grade, Pageable page);

// 필터가 학년만 적용시 ORM
Page<Report> findAllByAccessAndGradeAndIsAcceptedTrueAndIsSubmittedTrue(Access access, Grade grade, Pageable page);
Page<Report> findAllByAccessAndGradeAndIsAcceptedTrueAndIsSubmittedTrueOrderByCreatedAtDesc(Access access, Grade grade, Pageable page);

// 필터가 타입만 적용시 ORM
Page<Report> findAllByAccessAndTypeAndGradeAndIsAcceptedTrueAndIsSubmittedTrue(Access access, Type type,Grade grade, Pageable page);
Page<Report> findAllByAccessAndTypeAndGradeAndIsAcceptedTrueAndIsSubmittedTrueOrderByCreatedAtDesc(Access access, Type type,Grade grade, Pageable page);

// 필터가 분야만 적용시 ORM
Page<Report> findAllByAccessAndFieldAndGradeAndIsAcceptedTrueAndIsSubmittedTrue(Access access, Field field,Grade grade, Pageable page);
Page<Report> findAllByAccessAndFieldAndGradeAndIsAcceptedTrueAndIsSubmittedTrueOrderByCreatedAtDesc(Access access, Field field,Grade grade, Pageable page);

//제목 검색 ORM
Page<Report> findAllByAccessAndIsAcceptedTrueAndIsSubmittedTrueAndTitleContaining(Access access, String title, Pageable page);
Page<Report> findAllByAccessAndIsAcceptedTrueAndIsSubmittedTrueAndTitleContainingOrderByCreatedAtDesc(Access access, String title, Pageable page);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ public class ReportRequest {
private Grade grade;

@NotNull
private boolean isSubmitted;
private Boolean isSubmitted;

@NotNull
private String fileName;

@NotNull
private String github;

private String teamName;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@
import com.dsmpear.main.entity.report.Grade;
import com.dsmpear.main.entity.report.Type;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

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

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ReportContentResponse {

private String title;

private String description;

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createdAt;

private String languages;
Expand All @@ -34,8 +37,11 @@ public class ReportContentResponse {

private Field field;

private boolean isMine;
private boolean mine;

private List<ReportCommentsResponse> comments;

private String teamName;


}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public ProfileReportListResponse getReport(Pageable page) {
.reportId(report.getReportId())
.title(report.getTitle())
.createdAt(report.getCreatedAt())
.isSubmitted(report.isSubmitted())
.isAccepted(report.isAccepted())
.isSubmitted(report.getIsSubmitted())
.isAccepted(report.getIsAccepted())
.build()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public void writeReport(ReportRequest reportRequest) {
if(authenticationFacade.isLogin() == false) {
throw new UserNotFoundException();
}

String teamName = reportRequest.getTeamName()==null?
userRepository.findByEmail(authenticationFacade.getUserEmail()).get().getName()
:reportRequest.getTeamName();

Report report = reportRepository.save(
Report.builder()
Expand All @@ -62,10 +64,11 @@ public void writeReport(ReportRequest reportRequest) {
.field(reportRequest.getField())
.type(reportRequest.getType())
.isAccepted(false)
.isSubmitted(reportRequest.isSubmitted())
.isSubmitted(reportRequest.getIsSubmitted())
.fileName(reportRequest.getFileName())
.github(reportRequest.getGithub())
.languages(reportRequest.getLanguages())
.teamName(teamName)
.build()
);

Expand Down Expand Up @@ -111,9 +114,9 @@ public ReportContentResponse viewReport(Integer reportId) {
if(!isMine) {
if (report.getAccess().equals(Access.ADMIN)) {
throw new PermissionDeniedException();
} else if (!report.isAccepted()) {
} else if (!report.getIsAccepted()) {
throw new PermissionDeniedException();
} else if(!report.isSubmitted()) {
} else if(!report.getIsSubmitted()) {
throw new PermissionDeniedException();
}
}
Expand Down Expand Up @@ -157,7 +160,7 @@ public ReportContentResponse viewReport(Integer reportId) {
.fileName(report.getFileName())
.createdAt(report.getCreatedAt())
.description(report.getDescription())
.isMine(isMine)
.mine(isMine)
.comments(commentsResponses)
.build();
}
Expand All @@ -184,10 +187,10 @@ public Integer updateReport(Integer reportId, ReportRequest reportRequest) {

@Override
public void deleteReport(Integer reportId) {
User user = null;
Member user = null;
boolean isMine = false;
if(authenticationFacade.isLogin()) {
memberRepository.findByReportIdAndUserEmail(reportId, authenticationFacade.getUserEmail())
user = memberRepository.findByReportIdAndUserEmail(reportId, authenticationFacade.getUserEmail())
.orElseThrow(UserNotFoundException::new);
}else {
throw new UserNotFoundException();
Expand All @@ -206,7 +209,7 @@ public void deleteReport(Integer reportId) {
memberRepository.deleteById(member.getId());
}

UserReport userReport = userReportRepository.findByReportIdAndUserEmail(reportId,user.getEmail())
UserReport userReport = userReportRepository.findByReportIdAndUserEmail(reportId,user.getUserEmail())
.orElseThrow(ReportNotFoundException::new);

userReportRepository.deleteById(userReport.getReportId());
Expand All @@ -229,13 +232,13 @@ public ReportListResponse getReportList(Pageable page, Type type, Field field, G


if(type == null && field == null) {
reportPage = reportRepository.findAllByAccessAndGradeAndIsAcceptedTrueAndIsSubmittedTrue(Access.EVERY, grade, page);
reportPage = reportRepository.findAllByAccessAndGradeAndIsAcceptedTrueAndIsSubmittedTrueOrderByCreatedAtDesc(Access.EVERY, grade, page);
}else if(type == null) {
reportPage = reportRepository.findAllByAccessAndFieldAndGradeAndIsAcceptedTrueAndIsSubmittedTrue(Access.EVERY, field, grade, page);
reportPage = reportRepository.findAllByAccessAndFieldAndGradeAndIsAcceptedTrueAndIsSubmittedTrueOrderByCreatedAtDesc(Access.EVERY, field, grade, page);
}else if(field == null) {
reportPage = reportRepository.findAllByAccessAndTypeAndGradeAndIsAcceptedTrueAndIsSubmittedTrue(Access.EVERY, type, grade, page);
reportPage = reportRepository.findAllByAccessAndTypeAndGradeAndIsAcceptedTrueAndIsSubmittedTrueOrderByCreatedAtDesc(Access.EVERY, type, grade, page);
}else {
reportPage = reportRepository.findAllByAccessAndFieldAndTypeAndGradeAndIsAcceptedTrueAndIsSubmittedTrue(Access.EVERY, field, type, grade, page);
reportPage = reportRepository.findAllByAccessAndFieldAndTypeAndGradeAndIsAcceptedTrueAndIsSubmittedTrueOrderByCreatedAtDesc(Access.EVERY, field, type, grade, page);
}

for(Report report : reportPage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public SearchProfileResponse searchProfile(String keyword, Pageable page) {

@Override
public ReportListResponse searchReportByTitle(Pageable page, String title) {
Page<Report> reportPage = reportRepository.findAllByAccessAndIsAcceptedTrueAndIsSubmittedTrueAndTitleContaining(Access.EVERY, title, page);
Page<Report> reportPage = reportRepository.findAllByAccessAndIsAcceptedTrueAndIsSubmittedTrueAndTitleContainingOrderByCreatedAtDesc(Access.EVERY, title, page);

List<ReportResponse> reportResponses = new ArrayList<>();

Expand Down
22 changes: 10 additions & 12 deletions src/test/java/com/dsmpear/main/domain/MemberControllerTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dsmpear.main.domain;

import com.dsmpear.main.MainApplication;
import com.dsmpear.main.entity.member.Member;
import com.dsmpear.main.entity.member.MemberRepository;
import com.dsmpear.main.entity.report.*;
Expand All @@ -9,9 +10,6 @@
import com.dsmpear.main.entity.userreport.UserReportRepository;
import com.dsmpear.main.payload.request.MemberRequest;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.*;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -25,18 +23,17 @@
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;

import javax.annotation.PostConstruct;
import java.time.LocalDateTime;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(classes = MainApplication.class)
@ActiveProfiles("test")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class MemberControllerTest {
class MemberControllerTest {

@Autowired
private WebApplicationContext context;
Expand All @@ -58,7 +55,7 @@ public class MemberControllerTest {

private MockMvc mvc;

@Before
@BeforeEach
public void setUp(){
mvc = MockMvcBuilders
.webAppContextSetup(context)
Expand Down Expand Up @@ -93,7 +90,7 @@ public void setUp(){
}


@After
@AfterEach
public void after () {
memberRepository.deleteAll();
reportRepository.deleteAll();
Expand Down Expand Up @@ -196,7 +193,8 @@ private Integer addReport() {
.createdAt(LocalDateTime.now())
.github("깃허브으")
.languages("자바")
.fileName("이승윤 돼지")
.fileName("나는야 천재")
.teamName("룰루랄라")
.build()
).getReportId();

Expand All @@ -209,9 +207,9 @@ private Integer addReport() {

memberRepository.save(
Member.builder()
.reportId(reportId)
.userEmail("[email protected]")
.build()
.reportId(reportId)
.userEmail("[email protected]")
.build()
);

userReportRepository.save(
Expand Down
Loading