Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/weekly' into week10
Browse files Browse the repository at this point in the history
  • Loading branch information
sunandrabbit committed Nov 14, 2024
2 parents 3fd4b9b + a6c4ef2 commit baa339e
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 311 deletions.
231 changes: 103 additions & 128 deletions README.md

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions src/main/java/team1/be/seamless/service/MemberService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package team1.be.seamless.service;

import java.time.LocalDateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
Expand All @@ -21,6 +20,8 @@
import team1.be.seamless.util.auth.AesEncrypt;
import team1.be.seamless.util.errorException.BaseHandler;

import java.time.LocalDateTime;

@Service
public class MemberService {

Expand All @@ -42,7 +43,7 @@ public MemberService(MemberRepository memberRepository, MemberMapper memberMappe

public MemberResponseDTO getMember(Long projectId, Long memberId, String role) {
// 팀원인지 확인하기
if (Role.MEMBER.isRole(role) || Role.USER.isRole(role) || Role.ADMIN.isRole(role)) {
if (role == null || role.isEmpty()) {
throw new BaseHandler(HttpStatus.UNAUTHORIZED, "권한이 없습니다.");
}

Expand All @@ -60,7 +61,7 @@ public MemberResponseDTO getMember(Long projectId, Long memberId, String role) {
public Page<MemberResponseDTO> getMemberList(Long projectId,
getMemberList memberList, String role) {
// 팀원인지 확인하기
if (Role.MEMBER.isRole(role) || Role.USER.isRole(role) || Role.ADMIN.isRole(role)) {
if (role == null || role.isEmpty()) {
throw new BaseHandler(HttpStatus.UNAUTHORIZED, "권한이 없습니다.");
}

Expand Down Expand Up @@ -102,7 +103,7 @@ public MemberResponseDTO createMember(MemberRequestDTO.CreateMember create) {
memberRepository.save(member);

// 코드 생성
String code = aesEncrypt.encrypt(project.getId().toString());
String code = aesEncrypt.encrypt(member.getId()+"_"+project.getId());

// 이메일로 코드 전달

Expand Down Expand Up @@ -130,7 +131,7 @@ public MemberResponseDTO createMember(MemberRequestDTO.CreateMember create) {
public MemberResponseDTO updateMember(Long projectId, Long memberId, UpdateMember update,
String role) {
// 팀장인지 확인(팀원인지 굳이 한번 더 확인하지 않음. 팀장인지만 검증.
if (Role.MEMBER.isRole(role) || Role.USER.isRole(role) || Role.ADMIN.isRole(role)) {
if (Role.MEMBER.isRole(role)) {
throw new BaseHandler(HttpStatus.UNAUTHORIZED, "수정 권한이 없습니다.");
}

Expand All @@ -149,7 +150,7 @@ public MemberResponseDTO updateMember(Long projectId, Long memberId, UpdateMembe
@Transactional
public MemberResponseDTO deleteMember(Long projectId, Long memberId, String role) {
// 팀장인지 확인(팀원인지 굳이 한번 더 확인하지 않음. 팀장인지만 검증.)
if (Role.USER.isRole(role) || Role.ADMIN.isRole(role)) {
if (Role.MEMBER.isRole(role)) {
throw new BaseHandler(HttpStatus.FORBIDDEN, "삭제 권한이 없습니다.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public OpenAPI openAPI() {
public Info apiInfo() {
return new Info()
.title("Seamless")
.description("kakao tech camp step3<br>"
+ "<li>추가 작성</li>")
.description("복잡한 협업 툴의 대안을 제시하는 Seamless API입니다.")
.version("0.1");
}
}
24 changes: 22 additions & 2 deletions src/test/java/team1/be/seamless/e2e/TaskE2ETest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import team1.be.seamless.dto.TaskDTO;
import team1.be.seamless.dto.TaskDTO.TaskCreate;
import team1.be.seamless.entity.enums.Priority;
import team1.be.seamless.entity.enums.Role;
Expand All @@ -23,8 +24,7 @@
import java.time.LocalDateTime;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.POST;
import static org.springframework.http.HttpMethod.*;
import static org.springframework.http.HttpStatus.*;

@ExtendWith(SpringExtension.class)
Expand Down Expand Up @@ -123,4 +123,24 @@ public void setUp() {
assertThat(responseEntity.getStatusCode()).isEqualTo(NOT_FOUND);
}

@Test
public void 태스크_수정_성공() {
TaskDTO.TaskUpdate body = new TaskDTO.TaskUpdate(
"수정된 태스크",
"수정된 태스크입니다.",
50,
1L,
LocalDateTime.of(2024, 12, 1, 0, 0, 0),
LocalDateTime.of(2024, 12, 2, 0, 0, 0),
Priority.HIGH,
TaskStatus.IN_PROGRESS);

HttpEntity<Long> requestEntity = new HttpEntity(body, headers);

ResponseEntity<String> responseEntity = restTemplate.exchange(
url + port + "/api/project/task/1", PUT, requestEntity, String.class);

assertThat(responseEntity.getStatusCode()).isEqualTo(OK);
}

}
197 changes: 62 additions & 135 deletions src/test/java/team1/be/seamless/mapper/UserMapperTest.java
Original file line number Diff line number Diff line change
@@ -1,160 +1,87 @@
package team1.be.seamless.mapper;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import team1.be.seamless.dto.TaskDTO.TaskCreate;
import team1.be.seamless.dto.TaskDTO.TaskDetail;
import team1.be.seamless.dto.TaskDTO.TaskUpdate;
import team1.be.seamless.dto.TaskDTO.TaskWithOwnerDetail;
import team1.be.seamless.entity.*;
import team1.be.seamless.entity.enums.Priority;
import team1.be.seamless.entity.enums.TaskStatus;
import team1.be.seamless.dto.UserDTO;
import team1.be.seamless.entity.UserEntity;

import java.time.LocalDateTime;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class UserMapperTest {

private TaskMapper taskMapper;
private UserMapper userMapper = new UserMapper();

private TaskEntity taskEntity;

private ProjectEntity projectEntity;

private OptionEntity optionEntity1;

private OptionEntity optionEntity2;

private List<ProjectOptionEntity> projectOptions;
@Test
void 유저엔티티생성() {
// given
String userName = "test";
String eamil = "[email protected]";
String picture = "https://img.com";

private UserEntity userEntity;
// when
UserEntity userEntity = userMapper.toEntity(userName, eamil, picture);

private MemberEntity memberEntity;
// then
assertEquals(userEntity.getName(), userName);
assertEquals(userEntity.getEmail(), eamil);
assertEquals(userEntity.getPicture(), picture);

@BeforeEach
void setUp() {
taskMapper = new TaskMapper();
userEntity = new UserEntity(
"사용자1", "[email protected]", "user1Image.jpg"
);
}

optionEntity1 = new OptionEntity("옵션1", "옵션 설명1", "타입1");
optionEntity2 = new OptionEntity("옵션2", "옵션 설명2", "타입2");
@Test
void 유저업데이트생성() {
// given
String userName = "test";
String eamil = "[email protected]";
String picture = "https://img.com";

String updateUserName = "test2";
String updatePicture = "https://img2.com";

UserEntity userEntity = userMapper.toEntity(userName, eamil, picture);
UserDTO.UserUpdate update = new UserDTO.UserUpdate(updateUserName, updatePicture);
// when
UserEntity updateUser = userMapper.toUpdate(userEntity, update);

// then
assertEquals(updateUser.getName(), updateUserName);
assertEquals(updateUser.getEmail(), eamil);
assertEquals(updateUser.getPicture(), updatePicture);
}

ProjectOptionEntity projectOption1 = new ProjectOptionEntity(optionEntity1);
ProjectOptionEntity projectOption2 = new ProjectOptionEntity(optionEntity2);
projectOptions = List.of(projectOption1, projectOption2);
@Test
void 유저심플생성() {
// given
String userName = "test";
String eamil = "[email protected]";
String picture = "https://img.com";

projectEntity = new ProjectEntity(
"프로젝트1",
"프로젝트 설명1",
"https://example.com/project1.jpg",
userEntity,
projectOptions,
LocalDateTime.of(2023, 11, 21, 0, 0, 0),
LocalDateTime.of(2025, 11, 21, 0, 0, 0)
);
UserEntity userEntity = userMapper.toEntity(userName, eamil, picture);
// when
UserDTO.UserSimple simple = userMapper.toUserSimple(userEntity);

memberEntity = new MemberEntity("멤버 1", "MEMBER", "[email protected]",
"https://abcdgef.com", projectEntity);
// then
assertEquals(simple.getUsername(), userName);
assertEquals(simple.getEmail(), eamil);
assertEquals(simple.getPicture(), picture);

taskEntity = new TaskEntity(
"태스크 1",
"첫번째 태스크 입니다.",
Priority.HIGH,
projectEntity,
memberEntity,
LocalDateTime.of(2023, 12, 22, 0, 0, 0),
LocalDateTime.of(2024, 12, 22, 0, 0, 0),
75,
TaskStatus.PENDING
);
}

@Test
void 생성_시_taskCreate_에서_Entity로_변환_검증() {
TaskCreate create = new TaskCreate(
"새로운 태스크",
"새로운 태스크 입니다.",
memberEntity.getId(),
LocalDateTime.of(2024, 10, 10, 0, 0),
LocalDateTime.of(2024, 11, 11, 0, 0),
Priority.HIGH,
TaskStatus.IN_PROGRESS,
50);

TaskEntity created_taskEntity = new TaskMapper().toEntity(projectEntity, memberEntity,
create);

Assertions.assertThat(created_taskEntity.getName()).isEqualTo("새로운 태스크");
Assertions.assertThat(created_taskEntity.getDescription()).isEqualTo("새로운 태스크 입니다.");
Assertions.assertThat(created_taskEntity.getStartDate())
.isEqualTo(LocalDateTime.of(2024, 10, 10, 0, 0));
Assertions.assertThat(created_taskEntity.getEndDate())
.isEqualTo(LocalDateTime.of(2024, 11, 11, 0, 0));
Assertions.assertThat(created_taskEntity.getPriority()).isEqualTo(Priority.HIGH);
Assertions.assertThat(created_taskEntity.getStatus()).isEqualTo(TaskStatus.IN_PROGRESS);
Assertions.assertThat(created_taskEntity.getProgress()).isEqualTo(50);
}
void 유저디테일생성() {
// given
String userName = "test";
String eamil = "[email protected]";
String picture = "https://img.com";

@Test
void 수정_시_taskUpdate_에서_Entity로_변환_검증() {
TaskUpdate update = new TaskUpdate(
"수정된 태스크",
"",
1,
memberEntity.getId(),
LocalDateTime.of(2024, 10, 10, 0, 0),
LocalDateTime.of(2024, 11, 20, 0, 0),
Priority.LOW,
TaskStatus.IN_PROGRESS
);

TaskEntity updated_taskEntity = new TaskMapper().toUpdate(taskEntity, update);

Assertions.assertThat(updated_taskEntity.getName()).isEqualTo("수정된 태스크");
Assertions.assertThat(updated_taskEntity.getDescription()).isEqualTo("");
Assertions.assertThat(updated_taskEntity.getStartDate())
.isEqualTo(LocalDateTime.of(2024, 10, 10, 0, 0));
Assertions.assertThat(updated_taskEntity.getEndDate())
.isEqualTo(LocalDateTime.of(2024, 11, 20, 0, 0));
Assertions.assertThat(updated_taskEntity.getPriority()).isEqualTo(Priority.LOW);
Assertions.assertThat(updated_taskEntity.getStatus()).isEqualTo(TaskStatus.IN_PROGRESS);
Assertions.assertThat(updated_taskEntity.getProgress()).isEqualTo(1);
}
UserEntity userEntity = userMapper.toEntity(userName, eamil, picture);
// when
UserDTO.UserDetails details = userMapper.toUserDetails(userEntity);

@Test
void TaskEntity가_TaskDetail로_반환_되는지_검증() {
TaskDetail taskDetail = taskMapper.toDetail(taskEntity);

Assertions.assertThat(taskDetail.getName()).isEqualTo("태스크 1");
Assertions.assertThat(taskDetail.getDescription()).isEqualTo("첫번째 태스크 입니다.");
Assertions.assertThat(taskDetail.getStartDate())
.isEqualTo(LocalDateTime.of(2023, 12, 22, 0, 0));
Assertions.assertThat(taskDetail.getEndDate())
.isEqualTo(LocalDateTime.of(2024, 12, 22, 0, 0));
Assertions.assertThat(taskDetail.getPriority()).isEqualTo(Priority.HIGH);
Assertions.assertThat(taskDetail.getStatus()).isEqualTo(TaskStatus.PENDING);
Assertions.assertThat(taskDetail.getProgress()).isEqualTo(75);
}
// then

@Test
void TaskEntity가_TaskWithOwnerDetail로_반환_되는지_검증() {
TaskWithOwnerDetail taskWithOwnerDetail = taskMapper.toDetailWithOwner(taskEntity);

Assertions.assertThat(taskWithOwnerDetail.getName()).isEqualTo("태스크 1");
Assertions.assertThat(taskWithOwnerDetail.getDescription()).isEqualTo("첫번째 태스크 입니다.");
Assertions.assertThat(taskWithOwnerDetail.getOwner().getName()).isEqualTo("멤버 1");
Assertions.assertThat(taskWithOwnerDetail.getOwner().getRole()).isEqualTo("MEMBER");
Assertions.assertThat(taskWithOwnerDetail.getOwner().getImageURL())
.isEqualTo("https://abcdgef.com");
Assertions.assertThat(taskWithOwnerDetail.getStartDate())
.isEqualTo(LocalDateTime.of(2023, 12, 22, 0, 0));
Assertions.assertThat(taskWithOwnerDetail.getEndDate())
.isEqualTo(LocalDateTime.of(2024, 12, 22, 0, 0));
Assertions.assertThat(taskWithOwnerDetail.getPriority()).isEqualTo(Priority.HIGH);
Assertions.assertThat(taskWithOwnerDetail.getStatus()).isEqualTo(TaskStatus.PENDING);
Assertions.assertThat(taskWithOwnerDetail.getProgress()).isEqualTo(75);
assertEquals(details.getUsername(), userName);
assertEquals(details.getEmail(), eamil);
assertEquals(details.getPicture(), picture);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void setup() {
void 특정_멤버_정상_조회_테스트() {
Long projectId = 1L;
Long memberId = 1L;
String role = Role.USER.toString();
String role = Role.ADMIN.toString();

ProjectEntity projectEntity = new ProjectEntity();
projectEntity.setEndDate(LocalDateTime.now().plusDays(10));
Expand All @@ -77,7 +77,7 @@ void setup() {
@Test // 프로젝트의 모든 멤버를 정상적으로 조회할 수 있는지 검증
void 프로젝트_멤버_전체_조회_테스트() {
Long projectId = 1L;
String role = Role.USER.toString();
String role = Role.ADMIN.toString();

MemberRequestDTO.getMemberList memberListDTO = new MemberRequestDTO.getMemberList();

Expand Down Expand Up @@ -122,7 +122,7 @@ void setup() {
void 멤버_정보_수정_테스트() {
Long projectId = 1L;
Long memberId = 1L;
String role = Role.USER.toString();
String role = Role.ADMIN.toString();
MemberRequestDTO.UpdateMember updateMember = new MemberRequestDTO.UpdateMember("New 이름", "New 역할", "[email protected]", "imageURL");

ProjectEntity projectEntity = new ProjectEntity();
Expand All @@ -142,7 +142,7 @@ void setup() {
void 멤버_삭제_테스트() {
Long projectId = 1L;
Long memberId = 1L;
String role = Role.USER.toString();
String role = Role.ADMIN.toString();

ProjectEntity projectEntity = new ProjectEntity();
MemberEntity memberEntity = new MemberEntity(projectEntity);
Expand Down
Loading

0 comments on commit baa339e

Please sign in to comment.